Add function get_codec_type that returns the type of codec NOT_CODEC/ENCODER/DEOCDER. Move the functions get_cap_compose/crop_rect to the start of the file. Signed-off-by: Dafna Hirschfeld <dafna3@xxxxxxxxx> --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 126 ++++++++++++++++++-------- 1 file changed, 88 insertions(+), 38 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 8a98b6bd..3e81fdfc 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -82,6 +82,12 @@ static bool support_out_crop; #define TS_WINDOW 241 #define FILE_HDR_ID v4l2_fourcc('V', 'h', 'd', 'r') +enum codec_type { + NOT_CODEC, + ENCODER, + DECODER +}; + class fps_timestamps { private: unsigned idx; @@ -334,6 +340,88 @@ void streaming_usage(void) V4L_STREAM_PORT); } +static int get_codec_type(cv4l_fd &fd, enum codec_type &codec_type) +{ + struct v4l2_fmtdesc fmt_desc; + int num_cap_fmts = 0; + int num_compressed_cap_fmts = 0; + int num_out_fmts = 0; + int num_compressed_out_fmts = 0; + + codec_type = NOT_CODEC; + if (!fd.has_vid_m2m()) + return 0; + + if (fd.enum_fmt(fmt_desc, true, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE)) + return -1; + + do { + if (fmt_desc.flags & V4L2_FMT_FLAG_COMPRESSED) + num_compressed_cap_fmts++; + num_cap_fmts++; + } while (!fd.enum_fmt(fmt_desc)); + + + if (fd.enum_fmt(fmt_desc, true, 0, V4L2_BUF_TYPE_VIDEO_OUTPUT)) + return -1; + + do { + if (fmt_desc.flags & V4L2_FMT_FLAG_COMPRESSED) + num_compressed_out_fmts++; + num_out_fmts++; + } while (!fd.enum_fmt(fmt_desc)); + + if (num_compressed_out_fmts == 0 && num_compressed_cap_fmts == num_cap_fmts) { + codec_type = ENCODER; + return 0; + } + + if (num_compressed_cap_fmts == 0 && num_compressed_out_fmts == num_out_fmts) { + codec_type = DECODER; + return 0; + } + + return 0; +} + +static int get_cap_compose_rect(cv4l_fd &fd) +{ + v4l2_selection sel; + + memset(&sel, 0, sizeof(sel)); + sel.type = vidcap_buftype; + sel.target = V4L2_SEL_TGT_COMPOSE; + + if (fd.g_selection(sel) == 0) { + support_cap_compose = true; + composed_width = sel.r.width; + composed_height = sel.r.height; + return 0; + } + + support_cap_compose = false; + return 0; +} + +static int get_out_crop_rect(cv4l_fd &fd) +{ + v4l2_selection sel; + + memset(&sel, 0, sizeof(sel)); + sel.type = vidout_buftype; + sel.target = V4L2_SEL_TGT_CROP; + + if (fd.g_selection(sel) == 0) { + support_out_crop = true; + cropped_width = sel.r.width; + cropped_height = sel.r.height; + return 0; + } + + support_out_crop = false; + return 0; +} + static void set_time_stamp(cv4l_buffer &buf) { if ((buf.g_flags() & V4L2_BUF_FLAG_TIMESTAMP_MASK) != V4L2_BUF_FLAG_TIMESTAMP_COPY) @@ -2109,44 +2197,6 @@ done: fclose(file[OUT]); } -static int get_cap_compose_rect(cv4l_fd &fd) -{ - v4l2_selection sel; - - memset(&sel, 0, sizeof(sel)); - sel.type = vidcap_buftype; - sel.target = V4L2_SEL_TGT_COMPOSE; - - if (fd.g_selection(sel) == 0) { - support_cap_compose = true; - composed_width = sel.r.width; - composed_height = sel.r.height; - return 0; - } - - support_cap_compose = false; - return 0; -} - -static int get_out_crop_rect(cv4l_fd &fd) -{ - v4l2_selection sel; - - memset(&sel, 0, sizeof(sel)); - sel.type = vidout_buftype; - sel.target = V4L2_SEL_TGT_CROP; - - if (fd.g_selection(sel) == 0) { - support_out_crop = true; - cropped_width = sel.r.width; - cropped_height = sel.r.height; - return 0; - } - - support_out_crop = false; - return 0; -} - void streaming_set(cv4l_fd &fd, cv4l_fd &out_fd) { cv4l_disable_trace dt(fd); -- 2.17.1