aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/DocBook
diff options
context:
space:
mode:
authorPawel Osciak <pawel@osciak.com>2011-01-12 03:57:26 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-21 19:31:35 -0400
commitc4c0a78d459f2e4fcc7c4f3621a34e71ec7970d0 (patch)
tree9bdbd40352a767b5dbec95aee82d514bf65da08e /Documentation/DocBook
parent08b99e26a347441c50c1113802801a122dd1eb7a (diff)
[media] Fix mmap() example in the V4L2 API DocBook
Correct ioctl return value handling and fix coding style issues. [mchehab@redhat.com: return -1 is OK, according with ioctl manpages. Reverting ioctl changes] Signed-off-by: Pawel Osciak <pawel@osciak.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'Documentation/DocBook')
-rw-r--r--Documentation/DocBook/v4l/io.xml36
1 files changed, 18 insertions, 18 deletions
diff --git a/Documentation/DocBook/v4l/io.xml b/Documentation/DocBook/v4l/io.xml
index d424886beda0..a9750437000c 100644
--- a/Documentation/DocBook/v4l/io.xml
+++ b/Documentation/DocBook/v4l/io.xml
@@ -141,63 +141,63 @@ struct {
141} *buffers; 141} *buffers;
142unsigned int i; 142unsigned int i;
143 143
144memset (&amp;reqbuf, 0, sizeof (reqbuf)); 144memset(&amp;reqbuf, 0, sizeof(reqbuf));
145reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 145reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
146reqbuf.memory = V4L2_MEMORY_MMAP; 146reqbuf.memory = V4L2_MEMORY_MMAP;
147reqbuf.count = 20; 147reqbuf.count = 20;
148 148
149if (-1 == ioctl (fd, &VIDIOC-REQBUFS;, &amp;reqbuf)) { 149if (-1 == ioctl (fd, &VIDIOC-REQBUFS;, &amp;reqbuf)) {
150 if (errno == EINVAL) 150 if (errno == EINVAL)
151 printf ("Video capturing or mmap-streaming is not supported\n"); 151 printf("Video capturing or mmap-streaming is not supported\n");
152 else 152 else
153 perror ("VIDIOC_REQBUFS"); 153 perror("VIDIOC_REQBUFS");
154 154
155 exit (EXIT_FAILURE); 155 exit(EXIT_FAILURE);
156} 156}
157 157
158/* We want at least five buffers. */ 158/* We want at least five buffers. */
159 159
160if (reqbuf.count &lt; 5) { 160if (reqbuf.count &lt; 5) {
161 /* You may need to free the buffers here. */ 161 /* You may need to free the buffers here. */
162 printf ("Not enough buffer memory\n"); 162 printf("Not enough buffer memory\n");
163 exit (EXIT_FAILURE); 163 exit(EXIT_FAILURE);
164} 164}
165 165
166buffers = calloc (reqbuf.count, sizeof (*buffers)); 166buffers = calloc(reqbuf.count, sizeof(*buffers));
167assert (buffers != NULL); 167assert(buffers != NULL);
168 168
169for (i = 0; i &lt; reqbuf.count; i++) { 169for (i = 0; i &lt; reqbuf.count; i++) {
170 &v4l2-buffer; buffer; 170 &v4l2-buffer; buffer;
171 171
172 memset (&amp;buffer, 0, sizeof (buffer)); 172 memset(&amp;buffer, 0, sizeof(buffer));
173 buffer.type = reqbuf.type; 173 buffer.type = reqbuf.type;
174 buffer.memory = V4L2_MEMORY_MMAP; 174 buffer.memory = V4L2_MEMORY_MMAP;
175 buffer.index = i; 175 buffer.index = i;
176 176
177 if (-1 == ioctl (fd, &VIDIOC-QUERYBUF;, &amp;buffer)) { 177 if (-1 == ioctl (fd, &VIDIOC-QUERYBUF;, &amp;buffer)) {
178 perror ("VIDIOC_QUERYBUF"); 178 perror("VIDIOC_QUERYBUF");
179 exit (EXIT_FAILURE); 179 exit(EXIT_FAILURE);
180 } 180 }
181 181
182 buffers[i].length = buffer.length; /* remember for munmap() */ 182 buffers[i].length = buffer.length; /* remember for munmap() */
183 183
184 buffers[i].start = mmap (NULL, buffer.length, 184 buffers[i].start = mmap(NULL, buffer.length,
185 PROT_READ | PROT_WRITE, /* recommended */ 185 PROT_READ | PROT_WRITE, /* recommended */
186 MAP_SHARED, /* recommended */ 186 MAP_SHARED, /* recommended */
187 fd, buffer.m.offset); 187 fd, buffer.m.offset);
188 188
189 if (MAP_FAILED == buffers[i].start) { 189 if (MAP_FAILED == buffers[i].start) {
190 /* If you do not exit here you should unmap() and free() 190 /* If you do not exit here you should unmap() and free()
191 the buffers mapped so far. */ 191 the buffers mapped so far. */
192 perror ("mmap"); 192 perror("mmap");
193 exit (EXIT_FAILURE); 193 exit(EXIT_FAILURE);
194 } 194 }
195} 195}
196 196
197/* Cleanup. */ 197/* Cleanup. */
198 198
199for (i = 0; i &lt; reqbuf.count; i++) 199for (i = 0; i &lt; reqbuf.count; i++)
200 munmap (buffers[i].start, buffers[i].length); 200 munmap(buffers[i].start, buffers[i].length);
201 </programlisting> 201 </programlisting>
202 </example> 202 </example>
203 203