From: Dafna Hirschfeld <dafna3@gmail.com>
To: linux-media@vger.kernel.org
Cc: hverkuil@xs4all.nl, helen.koike@collabora.com,
Dafna Hirschfeld <dafna3@gmail.com>
Subject: [v4l-utils PATCH v2 5/5] v4l2-ctl: Add --stream-pixformat option
Date: Mon, 21 Jan 2019 10:56:51 -0800 [thread overview]
Message-ID: <20190121185651.6229-6-dafna3@gmail.com> (raw)
In-Reply-To: <20190121185651.6229-1-dafna3@gmail.com>
This option sets the capture pixelformat in the
capture setup sequence.
If the format is not supported decoding will stop.
If the option is not given then the default is to set
the first supported format.
Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
---
utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 37 +++++++++++++++++++++++++
utils/v4l2-ctl/v4l2-ctl.cpp | 39 ++++++++++++++++++---------
utils/v4l2-ctl/v4l2-ctl.h | 2 ++
3 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index 8d034b85..3e0a449c 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -78,6 +78,7 @@ static unsigned int composed_width;
static unsigned int composed_height;
static bool support_cap_compose;
static bool support_out_crop;
+static unsigned int cap_pixelformat;
static bool in_source_change_event;
#define TS_WINDOW 241
@@ -272,6 +273,10 @@ void streaming_usage(void)
" --stream-from <file>\n"
" stream from this file. The default is to generate a pattern.\n"
" If <file> is '-', then the data is read from stdin.\n"
+ " --stream-pixformat <pixformat>\n"
+ " set the video pixelformat."
+ " <pixelformat> is either the format index as reported by\n"
+ " --list-formats-out, or the fourcc value as a string.\n"
" --stream-from-hdr <file> stream from this file. Same as --stream-from, but each\n"
" frame is prefixed by a header. Use for compressed data.\n"
" --stream-from-host <hostname[:port]>\n"
@@ -606,8 +611,16 @@ void streaming_cmd(int ch, char *optarg)
{
unsigned i;
int speed;
+ int r;
switch (ch) {
+ case OptStreamPixformat:
+ r = parse_pixelfmt(optarg, cap_pixelformat);
+ if (r) {
+ streaming_usage();
+ exit(1);
+ }
+ break;
case OptStreamCount:
stream_count = strtoul(optarg, 0L, 0);
break;
@@ -1853,6 +1866,9 @@ enum stream_type {
static int capture_setup(cv4l_fd &fd, cv4l_queue &in)
{
+ v4l2_fmtdesc fmt_desc;
+ cv4l_fmt fmt;
+
if (fd.streamoff(in.g_type())) {
fprintf(stderr, "%s: fd.streamoff error\n", __func__);
return -1;
@@ -1865,6 +1881,27 @@ static int capture_setup(cv4l_fd &fd, cv4l_queue &in)
return -1;
}
+ if (cap_pixelformat) {
+ if (fd.enum_fmt(fmt_desc, true, 0, in.g_type())) {
+ fprintf(stderr, "%s: fd.enum_fmt error\n", __func__);
+ return -1;
+ }
+
+ do {
+ if (cap_pixelformat == fmt_desc.pixelformat)
+ break;
+ } while (!fd.enum_fmt(fmt_desc));
+
+ if (cap_pixelformat != fmt_desc.pixelformat) {
+ fprintf(stderr, "%s: format from user not supported\n", __func__);
+ return -1;
+ }
+
+ fd.g_fmt(fmt, in.g_type());
+ fmt.s_pixelformat(cap_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);
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index 1783979d..2cbf519e 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -238,6 +238,7 @@ static struct option long_options[] = {
{"list-buffers-sdr", no_argument, 0, OptListBuffersSdr},
{"list-buffers-sdr-out", no_argument, 0, OptListBuffersSdrOut},
{"list-buffers-meta", no_argument, 0, OptListBuffersMeta},
+ {"stream-pixformat", required_argument, 0, OptStreamPixformat},
{"stream-count", required_argument, 0, OptStreamCount},
{"stream-skip", required_argument, 0, OptStreamSkip},
{"stream-loop", no_argument, 0, OptStreamLoop},
@@ -722,6 +723,30 @@ __u32 parse_quantization(const char *s)
return V4L2_QUANTIZATION_DEFAULT;
}
+int parse_pixelfmt(char *value, __u32 &pixelformat)
+{
+ int fmts = 0;
+ bool be_pixfmt;
+
+ if(!value)
+ return -EINVAL;
+
+ be_pixfmt = strlen(value) == 7 && !memcmp(value + 4, "-BE", 3);
+ if (be_pixfmt)
+ value[4] = 0;
+ if (strlen(value) == 4) {
+ pixelformat =
+ v4l2_fourcc(value[0], value[1],
+ value[2], value[3]);
+ if (be_pixfmt)
+ pixelformat |= 1 << 31;
+ } else {
+ pixelformat = strtol(value, 0L, 0);
+ }
+ fmts |= FmtPixelFormat;
+ return 0;
+}
+
int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
__u32 &field, __u32 &colorspace, __u32 &xfer_func, __u32 &ycbcr,
__u32 &quantization, __u32 &flags, __u32 *bytesperline)
@@ -729,7 +754,6 @@ int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
char *value, *subs;
int fmts = 0;
unsigned bpl_index = 0;
- bool be_pixfmt;
field = V4L2_FIELD_ANY;
flags = 0;
@@ -760,18 +784,7 @@ int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
fmts |= FmtHeight;
break;
case 2:
- be_pixfmt = strlen(value) == 7 && !memcmp(value + 4, "-BE", 3);
- if (be_pixfmt)
- value[4] = 0;
- if (strlen(value) == 4) {
- pixelformat =
- v4l2_fourcc(value[0], value[1],
- value[2], value[3]);
- if (be_pixfmt)
- pixelformat |= 1 << 31;
- } else {
- pixelformat = strtol(value, 0L, 0);
- }
+ parse_pixelfmt(value, pixelformat);
fmts |= FmtPixelFormat;
break;
case 3:
diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h
index 5a52a0a4..8eee5351 100644
--- a/utils/v4l2-ctl/v4l2-ctl.h
+++ b/utils/v4l2-ctl/v4l2-ctl.h
@@ -205,6 +205,7 @@ enum Option {
OptListBuffersSdr,
OptListBuffersSdrOut,
OptListBuffersMeta,
+ OptStreamPixformat,
OptStreamCount,
OptStreamSkip,
OptStreamLoop,
@@ -299,6 +300,7 @@ __u32 parse_xfer_func(const char *s);
__u32 parse_ycbcr(const char *s);
__u32 parse_hsv(const char *s);
__u32 parse_quantization(const char *s);
+int parse_pixelfmt(char *value, __u32 &pixelformat);
int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
__u32 &field, __u32 &colorspace, __u32 &xfer, __u32 &ycbcr,
__u32 &quantization, __u32 &flags, __u32 *bytesperline);
--
2.17.1
next prev parent reply other threads:[~2019-01-21 18:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-21 18:56 [v4l-utils PATCH v2 0/5] source change support in v4l2-ctl Dafna Hirschfeld
2019-01-21 18:56 ` [v4l-utils PATCH v2 1/5] v4l2-ctl: Add support for crop and compose selection in streaming Dafna Hirschfeld
2019-01-21 18:56 ` [v4l-utils PATCH v2 2/5] v4l2-ctl: Add function get_codec_type Dafna Hirschfeld
2019-01-21 18:56 ` [v4l-utils PATCH v2 3/5] v4l2-ctl: Introduce capture_setup Dafna Hirschfeld
2019-01-21 18:56 ` [v4l-utils PATCH v2 4/5] v4l2-ctl: Add support for source change event for m2m decoder Dafna Hirschfeld
2019-01-21 18:56 ` Dafna Hirschfeld [this message]
2019-01-28 9:17 ` [v4l-utils PATCH v2 5/5] v4l2-ctl: Add --stream-pixformat option Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190121185651.6229-6-dafna3@gmail.com \
--to=dafna3@gmail.com \
--cc=helen.koike@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.