Re: [PATCH 4/5] v4l2-ctl: add support for SDR FMT
On 02/09/2014 07:05 AM, Antti Palosaari wrote: Add support for FMT IOCTL operations used for SDR receivers. Cc: Hans Verkuil hverk...@xs4all.nl Signed-off-by: Antti Palosaari cr...@iki.fi Acked-by: Hans Verkuil hans.verk...@cisco.com Thanks! Hans --- utils/v4l2-ctl/Makefile.am | 2 +- utils/v4l2-ctl/v4l2-ctl-common.cpp | 1 + utils/v4l2-ctl/v4l2-ctl-sdr.cpp| 104 + utils/v4l2-ctl/v4l2-ctl.cpp| 22 utils/v4l2-ctl/v4l2-ctl.h | 12 + 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 utils/v4l2-ctl/v4l2-ctl-sdr.cpp diff --git a/utils/v4l2-ctl/Makefile.am b/utils/v4l2-ctl/Makefile.am index b5744e7..becaa15 100644 --- a/utils/v4l2-ctl/Makefile.am +++ b/utils/v4l2-ctl/Makefile.am @@ -8,5 +8,5 @@ ivtv_ctl_LDFLAGS = -lm v4l2_ctl_SOURCES = v4l2-ctl.cpp v4l2-ctl.h v4l2-ctl-common.cpp v4l2-ctl-tuner.cpp \ v4l2-ctl-io.cpp v4l2-ctl-stds.cpp v4l2-ctl-vidcap.cpp v4l2-ctl-vidout.cpp \ v4l2-ctl-overlay.cpp v4l2-ctl-vbi.cpp v4l2-ctl-selection.cpp v4l2-ctl-misc.cpp \ - v4l2-ctl-streaming.cpp v4l2-ctl-test-patterns.cpp + v4l2-ctl-streaming.cpp v4l2-ctl-test-patterns.cpp v4l2-ctl-sdr.cpp v4l2_ctl_LDADD = ../../lib/libv4l2/libv4l2.la ../../lib/libv4lconvert/libv4lconvert.la diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp index fe570b0..37099cd 100644 --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp @@ -64,6 +64,7 @@ void common_usage(void) --help-io input/output options\n --help-miscmiscellaneous options\n --help-overlay overlay format options\n + --help-sdr SDR format options\n --help-selection crop/selection options\n --help-stdsstandards and other video timings options\n --help-streaming streaming options\n diff --git a/utils/v4l2-ctl/v4l2-ctl-sdr.cpp b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp new file mode 100644 index 000..9c9a6c4 --- /dev/null +++ b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp @@ -0,0 +1,104 @@ +#include unistd.h +#include stdlib.h +#include stdio.h +#include string.h +#include inttypes.h +#include getopt.h +#include sys/types.h +#include sys/stat.h +#include fcntl.h +#include ctype.h +#include errno.h +#include sys/ioctl.h +#include sys/time.h +#include dirent.h +#include math.h +#include config.h + +#include linux/videodev2.h +#include libv4l2.h +#include string + +#include v4l2-ctl.h + +static struct v4l2_format vfmt; /* set_format/get_format */ + +void sdr_usage(void) +{ + printf(\nSDR Formats options:\n + --list-formats-sdr display supported SDR formats [VIDIOC_ENUM_FMT]\n + --get-fmt-sdr query the SDR capture format [VIDIOC_G_FMT]\n + --set-fmt-sdr=f set the SDR capture format [VIDIOC_S_FMT]\n + parameter is either the format index as reported by\n + --list-formats-sdr, or the fourcc value as a string\n + --try-fmt-sdr=f try the SDR capture format [VIDIOC_TRY_FMT]\n + parameter is either the format index as reported by\n + --list-formats-sdr, or the fourcc value as a string\n +); +} + +void sdr_cmd(int ch, char *optarg) +{ + switch (ch) { + case OptSetSdrFormat: + case OptTrySdrFormat: + if (strlen(optarg) == 0) { + sdr_usage(); + exit(1); + } else if (strlen(optarg) == 4) { + vfmt.fmt.sdr.pixelformat = v4l2_fourcc(optarg[0], + optarg[1], optarg[2], optarg[3]); + } else { + vfmt.fmt.sdr.pixelformat = strtol(optarg, 0L, 0); + } + break; + } +} + +void sdr_set(int fd) +{ + int ret; + + if (options[OptSetSdrFormat] || options[OptTrySdrFormat]) { + struct v4l2_format in_vfmt; + + in_vfmt.type = V4L2_BUF_TYPE_SDR_CAPTURE; + in_vfmt.fmt.sdr.pixelformat = vfmt.fmt.sdr.pixelformat; + + if (in_vfmt.fmt.sdr.pixelformat 256) { + struct v4l2_fmtdesc fmt; + + fmt.index = in_vfmt.fmt.sdr.pixelformat; + fmt.type = V4L2_BUF_TYPE_SDR_CAPTURE; + + if (doioctl(fd, VIDIOC_ENUM_FMT, fmt)) + fmt.pixelformat = 0; + + in_vfmt.fmt.sdr.pixelformat = fmt.pixelformat; + } + + if (options[OptSetSdrFormat]) + ret = doioctl(fd, VIDIOC_S_FMT, in_vfmt); + else + ret = doioctl(fd, VIDIOC_TRY_FMT,
[PATCH 4/5] v4l2-ctl: add support for SDR FMT
Add support for FMT IOCTL operations used for SDR receivers. Cc: Hans Verkuil hverk...@xs4all.nl Signed-off-by: Antti Palosaari cr...@iki.fi --- utils/v4l2-ctl/Makefile.am | 2 +- utils/v4l2-ctl/v4l2-ctl-common.cpp | 1 + utils/v4l2-ctl/v4l2-ctl-sdr.cpp| 104 + utils/v4l2-ctl/v4l2-ctl.cpp| 22 utils/v4l2-ctl/v4l2-ctl.h | 12 + 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 utils/v4l2-ctl/v4l2-ctl-sdr.cpp diff --git a/utils/v4l2-ctl/Makefile.am b/utils/v4l2-ctl/Makefile.am index b5744e7..becaa15 100644 --- a/utils/v4l2-ctl/Makefile.am +++ b/utils/v4l2-ctl/Makefile.am @@ -8,5 +8,5 @@ ivtv_ctl_LDFLAGS = -lm v4l2_ctl_SOURCES = v4l2-ctl.cpp v4l2-ctl.h v4l2-ctl-common.cpp v4l2-ctl-tuner.cpp \ v4l2-ctl-io.cpp v4l2-ctl-stds.cpp v4l2-ctl-vidcap.cpp v4l2-ctl-vidout.cpp \ v4l2-ctl-overlay.cpp v4l2-ctl-vbi.cpp v4l2-ctl-selection.cpp v4l2-ctl-misc.cpp \ - v4l2-ctl-streaming.cpp v4l2-ctl-test-patterns.cpp + v4l2-ctl-streaming.cpp v4l2-ctl-test-patterns.cpp v4l2-ctl-sdr.cpp v4l2_ctl_LDADD = ../../lib/libv4l2/libv4l2.la ../../lib/libv4lconvert/libv4lconvert.la diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp index fe570b0..37099cd 100644 --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp @@ -64,6 +64,7 @@ void common_usage(void) --help-io input/output options\n --help-miscmiscellaneous options\n --help-overlay overlay format options\n +--help-sdr SDR format options\n --help-selection crop/selection options\n --help-stdsstandards and other video timings options\n --help-streaming streaming options\n diff --git a/utils/v4l2-ctl/v4l2-ctl-sdr.cpp b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp new file mode 100644 index 000..9c9a6c4 --- /dev/null +++ b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp @@ -0,0 +1,104 @@ +#include unistd.h +#include stdlib.h +#include stdio.h +#include string.h +#include inttypes.h +#include getopt.h +#include sys/types.h +#include sys/stat.h +#include fcntl.h +#include ctype.h +#include errno.h +#include sys/ioctl.h +#include sys/time.h +#include dirent.h +#include math.h +#include config.h + +#include linux/videodev2.h +#include libv4l2.h +#include string + +#include v4l2-ctl.h + +static struct v4l2_format vfmt;/* set_format/get_format */ + +void sdr_usage(void) +{ + printf(\nSDR Formats options:\n +--list-formats-sdr display supported SDR formats [VIDIOC_ENUM_FMT]\n +--get-fmt-sdr query the SDR capture format [VIDIOC_G_FMT]\n +--set-fmt-sdr=f set the SDR capture format [VIDIOC_S_FMT]\n + parameter is either the format index as reported by\n + --list-formats-sdr, or the fourcc value as a string\n +--try-fmt-sdr=f try the SDR capture format [VIDIOC_TRY_FMT]\n + parameter is either the format index as reported by\n + --list-formats-sdr, or the fourcc value as a string\n + ); +} + +void sdr_cmd(int ch, char *optarg) +{ + switch (ch) { + case OptSetSdrFormat: + case OptTrySdrFormat: + if (strlen(optarg) == 0) { + sdr_usage(); + exit(1); + } else if (strlen(optarg) == 4) { + vfmt.fmt.sdr.pixelformat = v4l2_fourcc(optarg[0], + optarg[1], optarg[2], optarg[3]); + } else { + vfmt.fmt.sdr.pixelformat = strtol(optarg, 0L, 0); + } + break; + } +} + +void sdr_set(int fd) +{ + int ret; + + if (options[OptSetSdrFormat] || options[OptTrySdrFormat]) { + struct v4l2_format in_vfmt; + + in_vfmt.type = V4L2_BUF_TYPE_SDR_CAPTURE; + in_vfmt.fmt.sdr.pixelformat = vfmt.fmt.sdr.pixelformat; + + if (in_vfmt.fmt.sdr.pixelformat 256) { + struct v4l2_fmtdesc fmt; + + fmt.index = in_vfmt.fmt.sdr.pixelformat; + fmt.type = V4L2_BUF_TYPE_SDR_CAPTURE; + + if (doioctl(fd, VIDIOC_ENUM_FMT, fmt)) + fmt.pixelformat = 0; + + in_vfmt.fmt.sdr.pixelformat = fmt.pixelformat; + } + + if (options[OptSetSdrFormat]) + ret = doioctl(fd, VIDIOC_S_FMT, in_vfmt); + else + ret = doioctl(fd, VIDIOC_TRY_FMT, in_vfmt); + if (ret == 0 (verbose || options[OptTrySdrFormat])) + printfmt(in_vfmt); + } +} + +void sdr_get(int fd)