aboutsummaryrefslogtreecommitdiffstats
path: root/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2019-03-29 11:18:06 +0100
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2019-03-29 16:05:22 +0100
commitff6990e710c5ebf6f1b262306acc49afc50ee81a (patch)
tree27d391d67ad7e8e49bf0f8afadcaa2ca7fd1bdbb /utils/v4l2-ctl/v4l2-ctl-streaming.cpp
parentd077345dc991a8359f4e3dcbfba214e5b36a2001 (diff)
v4l2-ctl: fixes relating to frame counting and draining
do_handle_cap assumed that it could skip frame counting for m2m devices, but that's not true. It should count frames for stateful encoders and for the cap2out streaming use-case. So make this an argument to do_handle_cap instead. Also fix various issues with detecting when the output side of an m2m device is stopped (e.g. because --stream-count buffers have been queued up). Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Diffstat (limited to 'utils/v4l2-ctl/v4l2-ctl-streaming.cpp')
-rw-r--r--utils/v4l2-ctl/v4l2-ctl-streaming.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index 8e9f7778..ad67e0c0 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -1357,18 +1357,13 @@ static void write_buffer_to_file(cv4l_fd &fd, cv4l_queue &q, cv4l_buffer &buf,
}
static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index,
- unsigned &count, fps_timestamps &fps_ts, cv4l_fmt &fmt)
+ unsigned &count, fps_timestamps &fps_ts, cv4l_fmt &fmt,
+ bool ignore_count_skip)
{
char ch = '<';
int ret;
cv4l_buffer buf(q);
- /*
- * The stream_count and stream_skip does not apply to capture path of
- * M2M devices.
- */
- bool ignore_count_skip = fd.has_vid_m2m();
-
for (;;) {
ret = fd.dqbuf(buf);
if (ret == EAGAIN)
@@ -1852,7 +1847,7 @@ recover:
if (FD_ISSET(fd.g_fd(), &read_fds)) {
r = do_handle_cap(fd, q, fout, NULL,
- count, fps_ts, fmt);
+ count, fps_ts, fmt, false);
if (r < 0)
break;
}
@@ -2302,7 +2297,10 @@ static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out,
if (rd_fds && FD_ISSET(fd.g_fd(), rd_fds)) {
r = do_handle_cap(fd, in, fin, NULL,
- count[CAP], fps_ts[CAP], fmt_in);
+ count[CAP], fps_ts[CAP], fmt_in,
+ codec_type == ENCODER);
+ if (codec_type != ENCODER && r == -2)
+ break;
if (r < 0) {
rd_fds = NULL;
if (!have_eos) {
@@ -2392,6 +2390,7 @@ static void stateless_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out,
fps_timestamps fps_ts[2];
unsigned count[2] = { 0, 0 };
int fd_flags = fcntl(fd.g_fd(), F_GETFL);
+ bool stopped = false;
if (out.reqbufs(&fd, reqbufs_count_out)) {
fprintf(stderr, "%s: out.reqbufs failed\n", __func__);
@@ -2441,6 +2440,9 @@ static void stateless_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out,
int req_fd = fwht_reqs[index].fd;
struct timeval tv = { 2, 0 };
+ if (req_fd < 0)
+ break;
+
FD_ZERO(&except_fds);
FD_SET(req_fd, &except_fds);
@@ -2471,8 +2473,8 @@ static void stateless_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out,
* written to the file in current function
*/
rc = do_handle_cap(fd, in, NULL, &buf_idx, count[CAP],
- fps_ts[CAP], fmt_in);
- if (rc) {
+ fps_ts[CAP], fmt_in, false);
+ if (rc && rc != -2) {
fprintf(stderr, "%s: do_handle_cap err\n", __func__);
return;
}
@@ -2506,11 +2508,19 @@ static void stateless_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out,
fmt_in, fin);
}
}
- rc = do_handle_out(fd, out, fout, NULL, count[OUT],
- fps_ts[OUT], fmt_out, true);
- if (rc) {
- fprintf(stderr, "%s: output stream ended\n", __func__);
- close(req_fd);
+ if (rc == -2)
+ return;
+
+ if (!stopped) {
+ rc = do_handle_out(fd, out, fout, NULL, count[OUT],
+ fps_ts[OUT], fmt_out, true);
+ if (rc) {
+ stopped = true;
+ if (rc != -2)
+ fprintf(stderr, "%s: output stream ended\n", __func__);
+ close(req_fd);
+ fwht_reqs[index].fd = -1;
+ }
}
index = (index + 1) % out.g_buffers();
}
@@ -2714,7 +2724,7 @@ static void streaming_set_cap2out(cv4l_fd &fd, cv4l_fd &out_fd)
int index = -1;
r = do_handle_cap(fd, in, file[CAP], &index,
- count[CAP], fps_ts[CAP], fmt[CAP]);
+ count[CAP], fps_ts[CAP], fmt[CAP], true);
if (r)
fprintf(stderr, "handle cap %d\n", r);
if (!r) {

Privacy Policy