v4l2-ctl/compliance: use the correct mmap/munmap functions.
authorHans Verkuil <hans.verkuil@cisco.com>
Sat, 8 Mar 2014 11:25:35 +0000 (12:25 +0100)
committerHans Verkuil <hans.verkuil@cisco.com>
Sat, 8 Mar 2014 11:25:35 +0000 (12:25 +0100)
If the libv4l2 wrapper library is used, then use v4l2_munmap instead of munmap.

For DMABUF file descriptors always use mmap/munmap since these buffers are not
known to libv4l2.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-compliance/v4l2-test-buffers.cpp
utils/v4l2-ctl/v4l2-ctl-streaming.cpp

index d1500dc..6576d11 100644 (file)
@@ -40,6 +40,11 @@ static inline void *test_mmap(void *start, size_t length, int prot, int flags,
                mmap(start, length, prot, flags, fd, offset);
 }
 
+static inline int test_munmap(void *start, size_t length)
+{
+       return wrapper ? v4l2_munmap(start, length) : munmap(start, length);
+}
+
 static void *ptrs[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
 static int dmabufs[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
 static struct v4l2_format cur_fmt;
@@ -909,7 +914,7 @@ static int releaseMmap(struct node *node, struct v4l2_requestbuffers &bufs)
                unsigned num_planes = process_buf(buf, planes);
 
                for (unsigned p = 0; p < num_planes; p++)
-                       munmap(ptrs[i][p], planes[p].length);
+                       test_munmap(ptrs[i][p], planes[p].length);
        }
        return 0;
 }
index 2a43b1e..8b16881 100644 (file)
@@ -38,6 +38,12 @@ static void *test_mmap(void *start, size_t length, int prot, int flags,
                mmap(start, length, prot, flags, fd, offset);
 }
 
+static int test_munmap(void *start, size_t length)
+{
+       return options[OptUseWrapper] ? v4l2_munmap(start, length) :
+               munmap(start, length);
+}
+
 void streaming_usage(void)
 {
        printf("\nVideo Streaming options:\n"
@@ -421,7 +427,7 @@ static int do_setup_cap_buffers(int fd, buffers &b)
                                                return -1;
                                        }
                                } else if (b.memory == V4L2_MEMORY_DMABUF) {
-                                       b.bufs[i][j] = test_mmap(NULL, p.length,
+                                       b.bufs[i][j] = mmap(NULL, p.length,
                                                          PROT_READ | PROT_WRITE, MAP_SHARED,
                                                          b.fds[i][j], 0);
 
@@ -449,7 +455,7 @@ static int do_setup_cap_buffers(int fd, buffers &b)
                                        return -1;
                                }
                        } else if (b.memory == V4L2_MEMORY_DMABUF) {
-                               b.bufs[i][0] = test_mmap(NULL, p.length,
+                               b.bufs[i][0] = mmap(NULL, p.length,
                                                PROT_READ | PROT_WRITE, MAP_SHARED,
                                                b.fds[i][0], 0);
 
@@ -510,7 +516,7 @@ static int do_setup_out_buffers(int fd, buffers &b, FILE *fin, bool qbuf)
                                                return -1;
                                        }
                                } else if (b.memory == V4L2_MEMORY_DMABUF) {
-                                       b.bufs[i][j] = test_mmap(NULL, p.length,
+                                       b.bufs[i][j] = mmap(NULL, p.length,
                                                          PROT_READ | PROT_WRITE, MAP_SHARED,
                                                          b.fds[i][j], 0);
 
@@ -532,7 +538,7 @@ static int do_setup_out_buffers(int fd, buffers &b, FILE *fin, bool qbuf)
                        b.planes[i][0].length = buf.length;
                        buf.bytesused = buf.length;
                        if (b.memory == V4L2_MEMORY_MMAP) {
-                               b.bufs[i][0] = mmap(NULL, buf.length,
+                               b.bufs[i][0] = test_mmap(NULL, buf.length,
                                                  PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset);
 
                                if (b.bufs[i][0] == MAP_FAILED) {
@@ -540,7 +546,7 @@ static int do_setup_out_buffers(int fd, buffers &b, FILE *fin, bool qbuf)
                                        return -1;
                                }
                        } else if (b.memory == V4L2_MEMORY_DMABUF) {
-                               b.bufs[i][0] = test_mmap(NULL, buf.length,
+                               b.bufs[i][0] = mmap(NULL, buf.length,
                                                PROT_READ | PROT_WRITE, MAP_SHARED,
                                                b.fds[i][0], 0);
 
@@ -573,8 +579,10 @@ static void do_release_buffers(buffers &b)
                for (unsigned j = 0; j < b.num_planes; j++) {
                        if (b.memory == V4L2_MEMORY_USERPTR)
                                free(b.bufs[i][j]);
-                       else
+                       else if (b.memory == V4L2_MEMORY_DMABUF)
                                munmap(b.bufs[i][j], b.planes[i][j].length);
+                       else
+                               test_munmap(b.bufs[i][j], b.planes[i][j].length);
                }
        }
 }