* [PATCH] v4l2-ctl: Print UVC meta info @ 2019-09-03 10:58 Vandana BN 2019-09-16 11:46 ` Hans Verkuil 0 siblings, 1 reply; 7+ messages in thread From: Vandana BN @ 2019-09-03 10:58 UTC (permalink / raw) To: linux-media, linux-kernel-mentees; +Cc: Vandana BN Print UVC Metadata information in verbose mode. Signed-off-by: Vandana BN <bnvandana@gmail.com> --- utils/v4l2-ctl/v4l2-ctl-meta.cpp | 20 ++++++++++++++++++++ utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 ++++++++------ utils/v4l2-ctl/v4l2-ctl.h | 1 + 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp index 75fbd6f4..f1003604 100644 --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp @@ -127,3 +127,23 @@ void meta_list(cv4l_fd &fd) print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); } } + +static struct vivid_uvc_meta_buf { + __u64 ns; + __u16 sof; + __u8 length; + __u8 flags; + __u8 buf[]; +} __packed; + +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q) +{ + struct vivid_uvc_meta_buf *vbuf; + if (fmt.g_pixelformat() == V4L2_META_FMT_UVC) { + fprintf(f, "META format V4L2_META_FMT_UVC:"); + for (unsigned i = 0; i< buf.g_num_planes(); i++) { + vbuf = (vivid_uvc_meta_buf *)(q.g_dataptr(buf.g_index(), i) + buf.g_mem_offset(i)); + fprintf(f, "ns %llu sof %u, len %u, flags 0x%x\n",vbuf[i].ns, vbuf[i].sof, vbuf[i].length, vbuf[i].flags); + } + } +} diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 11157434..46d53f23 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -540,9 +540,9 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf) fprintf(f, "\n"); } -static void print_concise_buffer(FILE *f, cv4l_buffer &buf, - fps_timestamps &fps_ts, int comp_perc, - bool skip_ts = false) +static void print_concise_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, + cv4l_queue &q, fps_timestamps &fps_ts, + int comp_perc, bool skip_ts = false) { static double last_ts; @@ -592,6 +592,8 @@ static void print_concise_buffer(FILE *f, cv4l_buffer &buf, if (fl) fprintf(f, " (%s)", bufferflags2s(fl).c_str()); fprintf(f, "\n"); + if (v4l_type_is_meta(buf.g_type())) + print_meta_buffer(f, buf, fmt, q); } static void stream_buf_caps(cv4l_fd &fd, unsigned buftype) @@ -1390,7 +1392,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, if (!(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) break; if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); if (fd.qbuf(buf)) return QUEUE_ERROR; } @@ -1412,7 +1414,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, else if (buf.g_flags() & V4L2_BUF_FLAG_BFRAME) ch = 'B'; if (verbose) { - print_concise_buffer(stderr, buf, fps_ts, + print_concise_buffer(stderr, buf, fmt, q, fps_ts, host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); comp_perc_count = comp_perc = 0; } @@ -1502,7 +1504,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap double ts_secs = buf.g_timestamp().tv_sec + buf.g_timestamp().tv_usec / 1000000.0; fps_ts.add_ts(ts_secs, buf.g_sequence(), buf.g_field()); if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); for (unsigned j = 0; j < buf.g_num_planes(); j++) buf.s_bytesused(buf.g_length(j), j); diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h index 5797d784..36051566 100644 --- a/utils/v4l2-ctl/v4l2-ctl.h +++ b/utils/v4l2-ctl/v4l2-ctl.h @@ -406,6 +406,7 @@ void meta_cmd(int ch, char *optarg); void meta_set(cv4l_fd &fd); void meta_get(cv4l_fd &fd); void meta_list(cv4l_fd &fd); +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); // v4l2-ctl-subdev.cpp void subdev_usage(void); -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] v4l2-ctl: Print UVC meta info 2019-09-03 10:58 [PATCH] v4l2-ctl: Print UVC meta info Vandana BN @ 2019-09-16 11:46 ` Hans Verkuil 2019-09-16 14:19 ` [PATCH v2] " Vandana BN 0 siblings, 1 reply; 7+ messages in thread From: Hans Verkuil @ 2019-09-16 11:46 UTC (permalink / raw) To: Vandana BN, linux-media, linux-kernel-mentees On 9/3/19 12:58 PM, Vandana BN wrote: > Print UVC Metadata information in verbose mode. > > Signed-off-by: Vandana BN <bnvandana@gmail.com> > --- > utils/v4l2-ctl/v4l2-ctl-meta.cpp | 20 ++++++++++++++++++++ > utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 ++++++++------ > utils/v4l2-ctl/v4l2-ctl.h | 1 + > 3 files changed, 29 insertions(+), 6 deletions(-) > > diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp > index 75fbd6f4..f1003604 100644 > --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp > +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp > @@ -127,3 +127,23 @@ void meta_list(cv4l_fd &fd) > print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); > } > } > + > +static struct vivid_uvc_meta_buf { Drop static. See the note about __packed below. > + __u64 ns; > + __u16 sof; > + __u8 length; > + __u8 flags; > + __u8 buf[]; > +} __packed; __packed is not needed. And in fact produces this warning: v4l2-ctl-meta.cpp: At global scope: v4l2-ctl-meta.cpp:137:3: warning: ‘__packed’ defined but not used [-Wunused-variable] } __packed; ^~~~~~~~ gcc doesn't know about it, so it thinks __packed is the name of a variable. (__packed is a linux kernel define) > + > +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q) > +{ > + struct vivid_uvc_meta_buf *vbuf; > + if (fmt.g_pixelformat() == V4L2_META_FMT_UVC) { > + fprintf(f, "META format V4L2_META_FMT_UVC:"); That's too long. Just use "UVC: ". > + for (unsigned i = 0; i< buf.g_num_planes(); i++) { > + vbuf = (vivid_uvc_meta_buf *)(q.g_dataptr(buf.g_index(), i) + buf.g_mem_offset(i)); Why buf.g_mem_offset(i)? Just use q.g_dataptr(buf.g_index(), i), that does the right thing. > + fprintf(f, "ns %llu sof %u, len %u, flags 0x%x\n",vbuf[i].ns, vbuf[i].sof, vbuf[i].length, vbuf[i].flags); Print the time in seconds: "%.6fs," , (double)vbuf[i].ns / 1000000000.0 That's easier to read. Regards, Hans > + } > + } > +} > diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > index 11157434..46d53f23 100644 > --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > @@ -540,9 +540,9 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf) > fprintf(f, "\n"); > } > > -static void print_concise_buffer(FILE *f, cv4l_buffer &buf, > - fps_timestamps &fps_ts, int comp_perc, > - bool skip_ts = false) > +static void print_concise_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, > + cv4l_queue &q, fps_timestamps &fps_ts, > + int comp_perc, bool skip_ts = false) > { > static double last_ts; > > @@ -592,6 +592,8 @@ static void print_concise_buffer(FILE *f, cv4l_buffer &buf, > if (fl) > fprintf(f, " (%s)", bufferflags2s(fl).c_str()); > fprintf(f, "\n"); > + if (v4l_type_is_meta(buf.g_type())) > + print_meta_buffer(f, buf, fmt, q); > } > > static void stream_buf_caps(cv4l_fd &fd, unsigned buftype) > @@ -1390,7 +1392,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, > if (!(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) > break; > if (verbose) > - print_concise_buffer(stderr, buf, fps_ts, -1); > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); > if (fd.qbuf(buf)) > return QUEUE_ERROR; > } > @@ -1412,7 +1414,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, > else if (buf.g_flags() & V4L2_BUF_FLAG_BFRAME) > ch = 'B'; > if (verbose) { > - print_concise_buffer(stderr, buf, fps_ts, > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, > host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); > comp_perc_count = comp_perc = 0; > } > @@ -1502,7 +1504,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap > double ts_secs = buf.g_timestamp().tv_sec + buf.g_timestamp().tv_usec / 1000000.0; > fps_ts.add_ts(ts_secs, buf.g_sequence(), buf.g_field()); > if (verbose) > - print_concise_buffer(stderr, buf, fps_ts, -1); > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); > > for (unsigned j = 0; j < buf.g_num_planes(); j++) > buf.s_bytesused(buf.g_length(j), j); > diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h > index 5797d784..36051566 100644 > --- a/utils/v4l2-ctl/v4l2-ctl.h > +++ b/utils/v4l2-ctl/v4l2-ctl.h > @@ -406,6 +406,7 @@ void meta_cmd(int ch, char *optarg); > void meta_set(cv4l_fd &fd); > void meta_get(cv4l_fd &fd); > void meta_list(cv4l_fd &fd); > +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); > > // v4l2-ctl-subdev.cpp > void subdev_usage(void); > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] v4l2-ctl: Print UVC meta info 2019-09-16 11:46 ` Hans Verkuil @ 2019-09-16 14:19 ` Vandana BN 2019-09-16 14:23 ` Hans Verkuil 0 siblings, 1 reply; 7+ messages in thread From: Vandana BN @ 2019-09-16 14:19 UTC (permalink / raw) To: linux-media, linux-kernel-mentees; +Cc: hverkuil, Vandana BN Print UVC Metadata information in verbose mode. Signed-off-by: Vandana BN <bnvandana@gmail.com> --- Changes since v1 - Removed static form type declaration of structure vivid_uvc_meta_buf. - to print time in seconds. - extract vivid_uvc_meta_buf properly from buf. --- utils/v4l2-ctl/v4l2-ctl-meta.cpp | 22 ++++++++++++++++++++++ utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 ++++++++------ utils/v4l2-ctl/v4l2-ctl.h | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp index 75fbd6f4..bee0eed0 100644 --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp @@ -127,3 +127,25 @@ void meta_list(cv4l_fd &fd) print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); } } + +struct vivid_uvc_meta_buf { + __u64 ns; + __u16 sof; + __u8 length; + __u8 flags; + __u8 buf[]; +}; + +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q) +{ + struct vivid_uvc_meta_buf *vbuf; + if (fmt.g_pixelformat() == V4L2_META_FMT_UVC) { + fprintf(f, "UVC: "); + for (unsigned i = 0; i< buf.g_num_planes(); i++) { + vbuf = (vivid_uvc_meta_buf *)q.g_dataptr(buf.g_index(), i); + fprintf(f, "ns %6fs sof %u, len %u, flags 0x%x\n", + (double)vbuf[i].ns / 1000000000.0, vbuf[i].sof, + vbuf[i].length, vbuf[i].flags); + } + } +} diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 11157434..46d53f23 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -540,9 +540,9 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf) fprintf(f, "\n"); } -static void print_concise_buffer(FILE *f, cv4l_buffer &buf, - fps_timestamps &fps_ts, int comp_perc, - bool skip_ts = false) +static void print_concise_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, + cv4l_queue &q, fps_timestamps &fps_ts, + int comp_perc, bool skip_ts = false) { static double last_ts; @@ -592,6 +592,8 @@ static void print_concise_buffer(FILE *f, cv4l_buffer &buf, if (fl) fprintf(f, " (%s)", bufferflags2s(fl).c_str()); fprintf(f, "\n"); + if (v4l_type_is_meta(buf.g_type())) + print_meta_buffer(f, buf, fmt, q); } static void stream_buf_caps(cv4l_fd &fd, unsigned buftype) @@ -1390,7 +1392,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, if (!(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) break; if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); if (fd.qbuf(buf)) return QUEUE_ERROR; } @@ -1412,7 +1414,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, else if (buf.g_flags() & V4L2_BUF_FLAG_BFRAME) ch = 'B'; if (verbose) { - print_concise_buffer(stderr, buf, fps_ts, + print_concise_buffer(stderr, buf, fmt, q, fps_ts, host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); comp_perc_count = comp_perc = 0; } @@ -1502,7 +1504,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap double ts_secs = buf.g_timestamp().tv_sec + buf.g_timestamp().tv_usec / 1000000.0; fps_ts.add_ts(ts_secs, buf.g_sequence(), buf.g_field()); if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); for (unsigned j = 0; j < buf.g_num_planes(); j++) buf.s_bytesused(buf.g_length(j), j); diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h index 5797d784..36051566 100644 --- a/utils/v4l2-ctl/v4l2-ctl.h +++ b/utils/v4l2-ctl/v4l2-ctl.h @@ -406,6 +406,7 @@ void meta_cmd(int ch, char *optarg); void meta_set(cv4l_fd &fd); void meta_get(cv4l_fd &fd); void meta_list(cv4l_fd &fd); +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); // v4l2-ctl-subdev.cpp void subdev_usage(void); -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] v4l2-ctl: Print UVC meta info 2019-09-16 14:19 ` [PATCH v2] " Vandana BN @ 2019-09-16 14:23 ` Hans Verkuil 2019-09-16 18:00 ` [PATCH v3] " Vandana BN 0 siblings, 1 reply; 7+ messages in thread From: Hans Verkuil @ 2019-09-16 14:23 UTC (permalink / raw) To: Vandana BN, linux-media, linux-kernel-mentees On 9/16/19 4:19 PM, Vandana BN wrote: > Print UVC Metadata information in verbose mode. > > Signed-off-by: Vandana BN <bnvandana@gmail.com> > --- > Changes since v1 > - Removed static form type declaration of structure vivid_uvc_meta_buf. > - to print time in seconds. > - extract vivid_uvc_meta_buf properly from buf. > --- > utils/v4l2-ctl/v4l2-ctl-meta.cpp | 22 ++++++++++++++++++++++ > utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 ++++++++------ > utils/v4l2-ctl/v4l2-ctl.h | 1 + > 3 files changed, 31 insertions(+), 6 deletions(-) > > diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp > index 75fbd6f4..bee0eed0 100644 > --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp > +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp > @@ -127,3 +127,25 @@ void meta_list(cv4l_fd &fd) > print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); > } > } > + > +struct vivid_uvc_meta_buf { > + __u64 ns; > + __u16 sof; > + __u8 length; > + __u8 flags; > + __u8 buf[]; > +}; > + > +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q) > +{ > + struct vivid_uvc_meta_buf *vbuf; Add a newline. It is good practice to leave an empty line between declaring variables and the following code. > + if (fmt.g_pixelformat() == V4L2_META_FMT_UVC) { Let's make this a switch, so it is easy to add new formats in the future. > + fprintf(f, "UVC: "); > + for (unsigned i = 0; i< buf.g_num_planes(); i++) { > + vbuf = (vivid_uvc_meta_buf *)q.g_dataptr(buf.g_index(), i); > + fprintf(f, "ns %6fs sof %u, len %u, flags 0x%x\n" This should be "%.6fs" and drop the ns (since it now prints seconds, not ns). , > + (double)vbuf[i].ns / 1000000000.0, vbuf[i].sof, > + vbuf[i].length, vbuf[i].flags); > + } > + } > +} > diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > index 11157434..46d53f23 100644 > --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > @@ -540,9 +540,9 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf) > fprintf(f, "\n"); > } > > -static void print_concise_buffer(FILE *f, cv4l_buffer &buf, > - fps_timestamps &fps_ts, int comp_perc, > - bool skip_ts = false) > +static void print_concise_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, > + cv4l_queue &q, fps_timestamps &fps_ts, > + int comp_perc, bool skip_ts = false) > { > static double last_ts; > > @@ -592,6 +592,8 @@ static void print_concise_buffer(FILE *f, cv4l_buffer &buf, > if (fl) > fprintf(f, " (%s)", bufferflags2s(fl).c_str()); > fprintf(f, "\n"); > + if (v4l_type_is_meta(buf.g_type())) > + print_meta_buffer(f, buf, fmt, q); > } > > static void stream_buf_caps(cv4l_fd &fd, unsigned buftype) > @@ -1390,7 +1392,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, > if (!(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) > break; > if (verbose) > - print_concise_buffer(stderr, buf, fps_ts, -1); > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); > if (fd.qbuf(buf)) > return QUEUE_ERROR; > } > @@ -1412,7 +1414,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, > else if (buf.g_flags() & V4L2_BUF_FLAG_BFRAME) > ch = 'B'; > if (verbose) { > - print_concise_buffer(stderr, buf, fps_ts, > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, > host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); > comp_perc_count = comp_perc = 0; > } > @@ -1502,7 +1504,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap > double ts_secs = buf.g_timestamp().tv_sec + buf.g_timestamp().tv_usec / 1000000.0; > fps_ts.add_ts(ts_secs, buf.g_sequence(), buf.g_field()); > if (verbose) > - print_concise_buffer(stderr, buf, fps_ts, -1); > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); > > for (unsigned j = 0; j < buf.g_num_planes(); j++) > buf.s_bytesused(buf.g_length(j), j); > diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h > index 5797d784..36051566 100644 > --- a/utils/v4l2-ctl/v4l2-ctl.h > +++ b/utils/v4l2-ctl/v4l2-ctl.h > @@ -406,6 +406,7 @@ void meta_cmd(int ch, char *optarg); > void meta_set(cv4l_fd &fd); > void meta_get(cv4l_fd &fd); > void meta_list(cv4l_fd &fd); > +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); > > // v4l2-ctl-subdev.cpp > void subdev_usage(void); > Regards, Hans ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] v4l2-ctl: Print UVC meta info 2019-09-16 14:23 ` Hans Verkuil @ 2019-09-16 18:00 ` Vandana BN 2019-09-17 9:29 ` Hans Verkuil 0 siblings, 1 reply; 7+ messages in thread From: Vandana BN @ 2019-09-16 18:00 UTC (permalink / raw) To: linux-media, linux-kernel-mentees; +Cc: hverkuil, Vandana BN Print UVC Metadata information in verbose mode. Signed-off-by: Vandana BN <bnvandana@gmail.com> --- Changes since v2 - Converted if to switch statement. - Corrected format specifier in print. --- utils/v4l2-ctl/v4l2-ctl-meta.cpp | 25 +++++++++++++++++++++++++ utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 ++++++++------ utils/v4l2-ctl/v4l2-ctl.h | 1 + 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp index 75fbd6f4..5d7b28d6 100644 --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp @@ -127,3 +127,28 @@ void meta_list(cv4l_fd &fd) print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); } } + +struct vivid_uvc_meta_buf { + __u64 ns; + __u16 sof; + __u8 length; + __u8 flags; + __u8 buf[]; +}; + +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q) +{ + struct vivid_uvc_meta_buf *vbuf; + + switch(fmt.g_pixelformat()) { + case V4L2_META_FMT_UVC: + fprintf(f, "UVC: "); + for (unsigned i = 0; i < buf.g_num_planes(); i++) { + vbuf = (vivid_uvc_meta_buf *)q.g_dataptr(buf.g_index(), i); + fprintf(f, "%.6fs, sof %u, len %u, flags 0x%x\n", + (double)vbuf[i].ns / 1000000000.0, vbuf[i].sof, + vbuf[i].length, vbuf[i].flags); + } + break; + } +} diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 11157434..46d53f23 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -540,9 +540,9 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf) fprintf(f, "\n"); } -static void print_concise_buffer(FILE *f, cv4l_buffer &buf, - fps_timestamps &fps_ts, int comp_perc, - bool skip_ts = false) +static void print_concise_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, + cv4l_queue &q, fps_timestamps &fps_ts, + int comp_perc, bool skip_ts = false) { static double last_ts; @@ -592,6 +592,8 @@ static void print_concise_buffer(FILE *f, cv4l_buffer &buf, if (fl) fprintf(f, " (%s)", bufferflags2s(fl).c_str()); fprintf(f, "\n"); + if (v4l_type_is_meta(buf.g_type())) + print_meta_buffer(f, buf, fmt, q); } static void stream_buf_caps(cv4l_fd &fd, unsigned buftype) @@ -1390,7 +1392,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, if (!(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) break; if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); if (fd.qbuf(buf)) return QUEUE_ERROR; } @@ -1412,7 +1414,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, else if (buf.g_flags() & V4L2_BUF_FLAG_BFRAME) ch = 'B'; if (verbose) { - print_concise_buffer(stderr, buf, fps_ts, + print_concise_buffer(stderr, buf, fmt, q, fps_ts, host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); comp_perc_count = comp_perc = 0; } @@ -1502,7 +1504,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap double ts_secs = buf.g_timestamp().tv_sec + buf.g_timestamp().tv_usec / 1000000.0; fps_ts.add_ts(ts_secs, buf.g_sequence(), buf.g_field()); if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); for (unsigned j = 0; j < buf.g_num_planes(); j++) buf.s_bytesused(buf.g_length(j), j); diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h index 5797d784..36051566 100644 --- a/utils/v4l2-ctl/v4l2-ctl.h +++ b/utils/v4l2-ctl/v4l2-ctl.h @@ -406,6 +406,7 @@ void meta_cmd(int ch, char *optarg); void meta_set(cv4l_fd &fd); void meta_get(cv4l_fd &fd); void meta_list(cv4l_fd &fd); +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); // v4l2-ctl-subdev.cpp void subdev_usage(void); -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] v4l2-ctl: Print UVC meta info 2019-09-16 18:00 ` [PATCH v3] " Vandana BN @ 2019-09-17 9:29 ` Hans Verkuil 2019-09-17 9:56 ` [PATCH v4] " Vandana BN 0 siblings, 1 reply; 7+ messages in thread From: Hans Verkuil @ 2019-09-17 9:29 UTC (permalink / raw) To: Vandana BN, linux-media, linux-kernel-mentees On 9/16/19 8:00 PM, Vandana BN wrote: > Print UVC Metadata information in verbose mode. > > Signed-off-by: Vandana BN <bnvandana@gmail.com> > --- > Changes since v2 > - Converted if to switch statement. > - Corrected format specifier in print. > --- > utils/v4l2-ctl/v4l2-ctl-meta.cpp | 25 +++++++++++++++++++++++++ > utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 ++++++++------ > utils/v4l2-ctl/v4l2-ctl.h | 1 + > 3 files changed, 34 insertions(+), 6 deletions(-) > > diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp > index 75fbd6f4..5d7b28d6 100644 > --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp > +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp > @@ -127,3 +127,28 @@ void meta_list(cv4l_fd &fd) > print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); > } > } > + > +struct vivid_uvc_meta_buf { > + __u64 ns; > + __u16 sof; > + __u8 length; > + __u8 flags; > + __u8 buf[]; > +}; > + > +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q) > +{ > + struct vivid_uvc_meta_buf *vbuf; > + > + switch(fmt.g_pixelformat()) { Add space before ( > + case V4L2_META_FMT_UVC: We use the kernel coding style, so the case statement should be aligned with the switch. > + fprintf(f, "UVC: "); > + for (unsigned i = 0; i < buf.g_num_planes(); i++) { > + vbuf = (vivid_uvc_meta_buf *)q.g_dataptr(buf.g_index(), i); > + fprintf(f, "%.6fs, sof %u, len %u, flags 0x%x\n", > + (double)vbuf[i].ns / 1000000000.0, vbuf[i].sof, > + vbuf[i].length, vbuf[i].flags); Properly align the arguments: fprintf(f, "%.6fs, sof %u, len %u, flags 0x%x\n", (double)vbuf[i].ns / 1000000000.0, vbuf[i].sof, vbuf[i].length, vbuf[i].flags); (looks like there was a tab too many for some reason) These issues may seem like nitpicking, but from a code maintenance perspective it is very important. It's like reading a book with a weird layout, it's just harder to read. Regards, Hans > + } > + break; > + } > +} > diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > index 11157434..46d53f23 100644 > --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp > @@ -540,9 +540,9 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf) > fprintf(f, "\n"); > } > > -static void print_concise_buffer(FILE *f, cv4l_buffer &buf, > - fps_timestamps &fps_ts, int comp_perc, > - bool skip_ts = false) > +static void print_concise_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, > + cv4l_queue &q, fps_timestamps &fps_ts, > + int comp_perc, bool skip_ts = false) > { > static double last_ts; > > @@ -592,6 +592,8 @@ static void print_concise_buffer(FILE *f, cv4l_buffer &buf, > if (fl) > fprintf(f, " (%s)", bufferflags2s(fl).c_str()); > fprintf(f, "\n"); > + if (v4l_type_is_meta(buf.g_type())) > + print_meta_buffer(f, buf, fmt, q); > } > > static void stream_buf_caps(cv4l_fd &fd, unsigned buftype) > @@ -1390,7 +1392,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, > if (!(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) > break; > if (verbose) > - print_concise_buffer(stderr, buf, fps_ts, -1); > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); > if (fd.qbuf(buf)) > return QUEUE_ERROR; > } > @@ -1412,7 +1414,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, > else if (buf.g_flags() & V4L2_BUF_FLAG_BFRAME) > ch = 'B'; > if (verbose) { > - print_concise_buffer(stderr, buf, fps_ts, > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, > host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); > comp_perc_count = comp_perc = 0; > } > @@ -1502,7 +1504,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap > double ts_secs = buf.g_timestamp().tv_sec + buf.g_timestamp().tv_usec / 1000000.0; > fps_ts.add_ts(ts_secs, buf.g_sequence(), buf.g_field()); > if (verbose) > - print_concise_buffer(stderr, buf, fps_ts, -1); > + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); > > for (unsigned j = 0; j < buf.g_num_planes(); j++) > buf.s_bytesused(buf.g_length(j), j); > diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h > index 5797d784..36051566 100644 > --- a/utils/v4l2-ctl/v4l2-ctl.h > +++ b/utils/v4l2-ctl/v4l2-ctl.h > @@ -406,6 +406,7 @@ void meta_cmd(int ch, char *optarg); > void meta_set(cv4l_fd &fd); > void meta_get(cv4l_fd &fd); > void meta_list(cv4l_fd &fd); > +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); > > // v4l2-ctl-subdev.cpp > void subdev_usage(void); > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4] v4l2-ctl: Print UVC meta info 2019-09-17 9:29 ` Hans Verkuil @ 2019-09-17 9:56 ` Vandana BN 0 siblings, 0 replies; 7+ messages in thread From: Vandana BN @ 2019-09-17 9:56 UTC (permalink / raw) To: linux-media, linux-kernel-mentees; +Cc: hverkuil, Vandana BN Print UVC Metadata information in verbose mode. Signed-off-by: Vandana BN <bnvandana@gmail.com> --- Changes since v3: - Coding style corrections in print_meta_buffer. --- utils/v4l2-ctl/v4l2-ctl-meta.cpp | 27 +++++++++++++++++++++++++++ utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 ++++++++------ utils/v4l2-ctl/v4l2-ctl.h | 1 + 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp index 75fbd6f4..1755798a 100644 --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp @@ -127,3 +127,30 @@ void meta_list(cv4l_fd &fd) print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); } } + +struct vivid_uvc_meta_buf { + __u64 ns; + __u16 sof; + __u8 length; + __u8 flags; + __u8 buf[]; +}; + +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q) +{ + struct vivid_uvc_meta_buf *vbuf; + + switch (fmt.g_pixelformat()) { + case V4L2_META_FMT_UVC: + fprintf(f, "UVC: "); + for (unsigned i = 0; i < buf.g_num_planes(); i++) { + vbuf = (vivid_uvc_meta_buf *)q.g_dataptr(buf.g_index(), i); + fprintf(f, "%.6fs, sof %u, len %u, flags 0x%x\n", + (double)vbuf[i].ns / 1000000000.0, + vbuf[i].sof, + vbuf[i].length, + vbuf[i].flags); + } + break; + } +} diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 11157434..46d53f23 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -540,9 +540,9 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf) fprintf(f, "\n"); } -static void print_concise_buffer(FILE *f, cv4l_buffer &buf, - fps_timestamps &fps_ts, int comp_perc, - bool skip_ts = false) +static void print_concise_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, + cv4l_queue &q, fps_timestamps &fps_ts, + int comp_perc, bool skip_ts = false) { static double last_ts; @@ -592,6 +592,8 @@ static void print_concise_buffer(FILE *f, cv4l_buffer &buf, if (fl) fprintf(f, " (%s)", bufferflags2s(fl).c_str()); fprintf(f, "\n"); + if (v4l_type_is_meta(buf.g_type())) + print_meta_buffer(f, buf, fmt, q); } static void stream_buf_caps(cv4l_fd &fd, unsigned buftype) @@ -1390,7 +1392,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, if (!(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) break; if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); if (fd.qbuf(buf)) return QUEUE_ERROR; } @@ -1412,7 +1414,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, else if (buf.g_flags() & V4L2_BUF_FLAG_BFRAME) ch = 'B'; if (verbose) { - print_concise_buffer(stderr, buf, fps_ts, + print_concise_buffer(stderr, buf, fmt, q, fps_ts, host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); comp_perc_count = comp_perc = 0; } @@ -1502,7 +1504,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap double ts_secs = buf.g_timestamp().tv_sec + buf.g_timestamp().tv_usec / 1000000.0; fps_ts.add_ts(ts_secs, buf.g_sequence(), buf.g_field()); if (verbose) - print_concise_buffer(stderr, buf, fps_ts, -1); + print_concise_buffer(stderr, buf, fmt, q, fps_ts, -1); for (unsigned j = 0; j < buf.g_num_planes(); j++) buf.s_bytesused(buf.g_length(j), j); diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h index 5797d784..36051566 100644 --- a/utils/v4l2-ctl/v4l2-ctl.h +++ b/utils/v4l2-ctl/v4l2-ctl.h @@ -406,6 +406,7 @@ void meta_cmd(int ch, char *optarg); void meta_set(cv4l_fd &fd); void meta_get(cv4l_fd &fd); void meta_list(cv4l_fd &fd); +void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); // v4l2-ctl-subdev.cpp void subdev_usage(void); -- 2.17.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-09-17 9:56 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-09-03 10:58 [PATCH] v4l2-ctl: Print UVC meta info Vandana BN 2019-09-16 11:46 ` Hans Verkuil 2019-09-16 14:19 ` [PATCH v2] " Vandana BN 2019-09-16 14:23 ` Hans Verkuil 2019-09-16 18:00 ` [PATCH v3] " Vandana BN 2019-09-17 9:29 ` Hans Verkuil 2019-09-17 9:56 ` [PATCH v4] " Vandana BN
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).