This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/v4l-utils.git tree:

Subject: v4l2-ctl: add --stream-poll option.
Author:  Hans Verkuil <[email protected]>
Date:    Fri Jul 27 14:52:38 2012 +0200

This option makes the streaming loop use select() with the fd in
non-blocking mode, as opposed to the default blocking mode.

Signed-off-by: Hans Verkuil <[email protected]>
(cherry picked from commit 7bf48ded8308af160616b283b1808d05f107bc4c)

Signed-off-by: Gregor Jasny <[email protected]>

 utils/v4l2-ctl/v4l2-ctl-streaming.cpp |   35 +++++++++++++++++++++++++++++++++
 utils/v4l2-ctl/v4l2-ctl.cpp           |    1 +
 utils/v4l2-ctl/v4l2-ctl.h             |    1 +
 3 files changed, 37 insertions(+), 0 deletions(-)

---

http://git.linuxtv.org/v4l-utils.git?a=commitdiff;h=ddf3752854b1fef84f4e85917919a7ecc77e9b2a

diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp 
b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index f5b0921..7ed157b 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -38,6 +38,7 @@ void streaming_usage(void)
               "  --stream-to=<file> stream to this file. The default is to 
discard the\n"
               "                     data. If <file> is '-', then the data is 
written to stdout\n"
               "                     and the --silent option is turned on 
automatically.\n"
+              "  --stream-poll      use non-blocking mode and select() to 
stream.\n"
               "  --stream-mmap=<count>\n"
               "                     capture video using mmap() 
[VIDIOC_(D)QBUF]\n"
               "                     count: the number of buffers to allocate. 
The default is 3.\n"
@@ -177,7 +178,9 @@ void streaming_set(int fd)
 {
        if (options[OptStreamMmap] || options[OptStreamUser]) {
                struct v4l2_requestbuffers reqbufs;
+               int fd_flags = fcntl(fd, F_GETFL);
                bool is_mmap = options[OptStreamMmap];
+               bool use_poll = options[OptStreamPoll];
                FILE *fout = NULL;
 
                memset(&reqbufs, 0, sizeof(reqbufs));
@@ -226,10 +229,41 @@ void streaming_set(int fd)
                if (doioctl(fd, VIDIOC_STREAMON, &type))
                        return;
 
+               if (use_poll)
+                       fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK);
+
                for (;;) {
                        struct v4l2_buffer buf;
                        int ret;
 
+                       if (use_poll) {
+                               fd_set fds;
+                               struct timeval tv;
+                               int r;
+
+                               FD_ZERO(&fds);
+                               FD_SET(fd, &fds);
+
+                               /* Timeout. */
+                               tv.tv_sec = 2;
+                               tv.tv_usec = 0;
+
+                               r = select(fd + 1, &fds, NULL, NULL, &tv);
+
+                               if (r == -1) {
+                                       if (EINTR == errno)
+                                               continue;
+                                       fprintf(stderr, "select error: %s\n",
+                                                       strerror(errno));
+                                       return;
+                               }
+
+                               if (r == 0) {
+                                       fprintf(stderr, "select timeout\n");
+                                       return;
+                               }
+                       }
+
                        memset(&buf, 0, sizeof(buf));
                        buf.type = reqbufs.type;
                        buf.memory = reqbufs.memory;
@@ -260,6 +294,7 @@ void streaming_set(int fd)
                                break;
                }
                doioctl(fd, VIDIOC_STREAMOFF, &type);
+               fcntl(fd, F_SETFL, fd_flags);
 
                for (unsigned i = 0; i < reqbufs.count; i++) {
                        struct v4l2_buffer buf;
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index b9e89bf..65c603a 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -195,6 +195,7 @@ static struct option long_options[] = {
        {"list-buffers-sliced-vbi-out", no_argument, 0, 
OptListBuffersSlicedVbiOut},
        {"stream-count", required_argument, 0, OptStreamCount},
        {"stream-skip", required_argument, 0, OptStreamSkip},
+       {"stream-poll", no_argument, 0, OptStreamPoll},
        {"stream-to", required_argument, 0, OptStreamTo},
        {"stream-mmap", optional_argument, 0, OptStreamMmap},
        {"stream-user", optional_argument, 0, OptStreamUser},
diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h
index 7d5d889..4ff1cf7 100644
--- a/utils/v4l2-ctl/v4l2-ctl.h
+++ b/utils/v4l2-ctl/v4l2-ctl.h
@@ -141,6 +141,7 @@ enum Option {
        OptListBuffersSlicedVbiOut,
        OptStreamCount,
        OptStreamSkip,
+       OptStreamPoll,
        OptStreamTo,
        OptStreamMmap,
        OptStreamUser,

_______________________________________________
linuxtv-commits mailing list
[email protected]
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to