Commit c4c0a78d authored by Pawel Osciak's avatar Pawel Osciak Committed by Mauro Carvalho Chehab

[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: default avatarPawel Osciak <pawel@osciak.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 08b99e26
...@@ -141,47 +141,47 @@ struct { ...@@ -141,47 +141,47 @@ struct {
} *buffers; } *buffers;
unsigned int i; unsigned int i;
memset (&amp;reqbuf, 0, sizeof (reqbuf)); memset(&amp;reqbuf, 0, sizeof(reqbuf));
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.memory = V4L2_MEMORY_MMAP;
reqbuf.count = 20; reqbuf.count = 20;
if (-1 == ioctl (fd, &VIDIOC-REQBUFS;, &amp;reqbuf)) { if (-1 == ioctl (fd, &VIDIOC-REQBUFS;, &amp;reqbuf)) {
if (errno == EINVAL) if (errno == EINVAL)
printf ("Video capturing or mmap-streaming is not supported\n"); printf("Video capturing or mmap-streaming is not supported\n");
else else
perror ("VIDIOC_REQBUFS"); perror("VIDIOC_REQBUFS");
exit (EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* We want at least five buffers. */ /* We want at least five buffers. */
if (reqbuf.count &lt; 5) { if (reqbuf.count &lt; 5) {
/* You may need to free the buffers here. */ /* You may need to free the buffers here. */
printf ("Not enough buffer memory\n"); printf("Not enough buffer memory\n");
exit (EXIT_FAILURE); exit(EXIT_FAILURE);
} }
buffers = calloc (reqbuf.count, sizeof (*buffers)); buffers = calloc(reqbuf.count, sizeof(*buffers));
assert (buffers != NULL); assert(buffers != NULL);
for (i = 0; i &lt; reqbuf.count; i++) { for (i = 0; i &lt; reqbuf.count; i++) {
&v4l2-buffer; buffer; &v4l2-buffer; buffer;
memset (&amp;buffer, 0, sizeof (buffer)); memset(&amp;buffer, 0, sizeof(buffer));
buffer.type = reqbuf.type; buffer.type = reqbuf.type;
buffer.memory = V4L2_MEMORY_MMAP; buffer.memory = V4L2_MEMORY_MMAP;
buffer.index = i; buffer.index = i;
if (-1 == ioctl (fd, &VIDIOC-QUERYBUF;, &amp;buffer)) { if (-1 == ioctl (fd, &VIDIOC-QUERYBUF;, &amp;buffer)) {
perror ("VIDIOC_QUERYBUF"); perror("VIDIOC_QUERYBUF");
exit (EXIT_FAILURE); exit(EXIT_FAILURE);
} }
buffers[i].length = buffer.length; /* remember for munmap() */ buffers[i].length = buffer.length; /* remember for munmap() */
buffers[i].start = mmap (NULL, buffer.length, buffers[i].start = mmap(NULL, buffer.length,
PROT_READ | PROT_WRITE, /* recommended */ PROT_READ | PROT_WRITE, /* recommended */
MAP_SHARED, /* recommended */ MAP_SHARED, /* recommended */
fd, buffer.m.offset); fd, buffer.m.offset);
...@@ -189,15 +189,15 @@ for (i = 0; i &lt; reqbuf.count; i++) { ...@@ -189,15 +189,15 @@ for (i = 0; i &lt; reqbuf.count; i++) {
if (MAP_FAILED == buffers[i].start) { if (MAP_FAILED == buffers[i].start) {
/* If you do not exit here you should unmap() and free() /* If you do not exit here you should unmap() and free()
the buffers mapped so far. */ the buffers mapped so far. */
perror ("mmap"); perror("mmap");
exit (EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
/* Cleanup. */ /* Cleanup. */
for (i = 0; i &lt; reqbuf.count; i++) for (i = 0; i &lt; reqbuf.count; i++)
munmap (buffers[i].start, buffers[i].length); munmap(buffers[i].start, buffers[i].length);
</programlisting> </programlisting>
</example> </example>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment