Add function capture_setup that implements the capture setup sequence. Signed-off-by: Dafna Hirschfeld <dafna3@xxxxxxxxx> --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 58 +++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index fc204304..cd20dec7 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1836,6 +1836,48 @@ enum stream_type { OUT, }; +static int capture_setup(cv4l_fd &fd, cv4l_queue &in) +{ + struct v4l2_fmtdesc fmt_desc; + cv4l_fmt fmt; + + if (fd.streamoff(in.g_type())) { + fprintf(stderr, "%s: fd.streamoff error\n", __func__); + return -1; + } + get_cap_compose_rect(fd); + + /* release any buffer allocated */ + if (in.reqbufs(&fd)) { + fprintf(stderr, "%s: in.reqbufs 0 error\n", __func__); + return -1; + } + + if (fd.enum_fmt(fmt_desc, true, 0, in.g_type())) { + fprintf(stderr, "%s: fd.enum_fmt error\n", __func__); + return -1; + } + + fd.g_fmt(fmt, in.g_type()); + fmt.s_pixelformat(fmt_desc.pixelformat); + fd.s_fmt(fmt, in.g_type()); + + if (in.reqbufs(&fd, reqbufs_count_cap)) { + fprintf(stderr, "%s: in.reqbufs %u error\n", __func__, + reqbufs_count_cap); + return -1; + } + if (in.obtain_bufs(&fd) || in.queue_all(&fd)) { + fprintf(stderr, "%s: in.obtain_bufs error\n", __func__); + return -1; + } + if (fd.streamon(in.g_type())) { + fprintf(stderr, "%s: fd.streamon error\n", __func__); + return -1; + } + return 0; +} + static void streaming_set_m2m(cv4l_fd &fd) { int fd_flags = fcntl(fd.g_fd(), F_GETFL); @@ -1900,21 +1942,21 @@ static void streaming_set_m2m(cv4l_fd &fd) } } - if (in.reqbufs(&fd, reqbufs_count_cap) || - out.reqbufs(&fd, reqbufs_count_out)) + if (out.reqbufs(&fd, reqbufs_count_out)) goto done; - if (in.obtain_bufs(&fd) || - in.queue_all(&fd) || - do_setup_out_buffers(fd, out, file[OUT], true)) + if (do_setup_out_buffers(fd, out, file[OUT], true)) goto done; - fps_ts[CAP].determine_field(fd.g_fd(), in.g_type()); - fps_ts[OUT].determine_field(fd.g_fd(), out.g_type()); + if (fd.streamon(out.g_type())) + goto done; - if (fd.streamon(in.g_type()) || fd.streamon(out.g_type())) + if (capture_setup(fd, in)) goto done; + fps_ts[CAP].determine_field(fd.g_fd(), in.g_type()); + fps_ts[OUT].determine_field(fd.g_fd(), out.g_type()); + while (stream_sleep == 0) sleep(100); -- 2.17.1