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-loop for streaming to an output.
Author:  Hans Verkuil <[email protected]>
Date:    Fri Nov 23 14:14:57 2012 +0100

When streaming from a file to an output it can be useful to loop the file
when the end is reached. Add the --stream-off option to do that.

Also improve the code to stop when a partial frame is read instead of 
pointlessly
trying to read data from the filehandle even if there isn't any.

Signed-off-by: Hans Verkuil <[email protected]>

 utils/v4l2-ctl/v4l2-ctl-streaming.cpp |   25 +++++++++++++++++++------
 utils/v4l2-ctl/v4l2-ctl.cpp           |    1 +
 utils/v4l2-ctl/v4l2-ctl.h             |    1 +
 3 files changed, 21 insertions(+), 6 deletions(-)

---

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

diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp 
b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index 570727b..d5d5159 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -25,6 +25,7 @@
 static unsigned stream_count;
 static unsigned stream_skip;
 static unsigned stream_pat;
+static bool stream_loop;
 static unsigned reqbufs_count = 3;
 static char *file;
 
@@ -51,6 +52,8 @@ void streaming_usage(void)
               "                     count: the number of buffers to allocate. 
The default is 3.\n"
               "  --stream-from=<file> stream from this file. The default is to 
generate a pattern.\n"
               "                     If <file> is '-', then the data is read 
from stdin.\n"
+              "  --stream-loop      loop when the end of the file we are 
streaming from is reached.\n"
+              "                     The default is to stop.\n"
               "  --stream-pattern=<count>\n"
               "                     choose output pattern. The default is 0.\n"
               "  --stream-out-mmap=<count>\n"
@@ -168,6 +171,9 @@ void streaming_cmd(int ch, char *optarg)
        case OptStreamSkip:
                stream_skip = strtoul(optarg, 0L, 0);
                break;
+       case OptStreamLoop:
+               stream_loop = true;
+               break;
        case OptStreamPattern:
                stream_pat = strtoul(optarg, 0L, 0);
                stream_pat %= NUM_PATTERNS;
@@ -841,13 +847,23 @@ void streaming_set(int fd)
                                fprintf(stderr, "%s: failed: %s\n", 
"VIDIOC_DQBUF", strerror(errno));
                                return;
                        }
-                       if (fin && !stream_skip) {
+                       if (fin) {
                                for (unsigned j = 0; j < num_planes; j++) {
                                        unsigned p = buf.index * num_planes + j;
                                        unsigned sz = fread(buffers[p], 1,
                                                        buffer_lengths[p], fin);
-                                       if (sz != buffer_lengths[p])
+
+                                       if (j == 0 && sz == 0 && stream_loop) {
+                                               fseek(fin, 0, SEEK_SET);
+                                               sz = fread(buffers[p], 1,
+                                                       buffer_lengths[p], fin);
+                                       }
+                                       if (sz == buffer_lengths[p])
+                                               continue;
+                                       if (sz)
                                                fprintf(stderr, "%u != %u\n", 
sz, buffer_lengths[p]);
+                                       // Bail out if we get weird buffer 
sizes.
+                                       goto stream_out_eof;
                                }
                        }
                        if (doioctl(fd, VIDIOC_QBUF, &buf))
@@ -872,15 +888,12 @@ void streaming_set(int fd)
                                }
                        }
                        count++;
-                       if (stream_skip) {
-                               stream_skip--;
-                               continue;
-                       }
                        if (stream_count == 0)
                                continue;
                        if (--stream_count == 0)
                                break;
                }
+stream_out_eof:
                doioctl(fd, VIDIOC_STREAMOFF, &type);
                fcntl(fd, F_SETFL, fd_flags);
                fprintf(stderr, "\n");
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index 814905f..2918f2d 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -198,6 +198,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-loop", no_argument, 0, OptStreamLoop},
        {"stream-poll", no_argument, 0, OptStreamPoll},
        {"stream-to", required_argument, 0, OptStreamTo},
        {"stream-mmap", optional_argument, 0, OptStreamMmap},
diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h
index 896a29b..6a3c312 100644
--- a/utils/v4l2-ctl/v4l2-ctl.h
+++ b/utils/v4l2-ctl/v4l2-ctl.h
@@ -140,6 +140,7 @@ enum Option {
        OptListBuffersSlicedVbiOut,
        OptStreamCount,
        OptStreamSkip,
+       OptStreamLoop,
        OptStreamPoll,
        OptStreamTo,
        OptStreamMmap,

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

Reply via email to