diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2006-09-01 18:34:48 -0300 |
---|---|---|
committer | Hans Verkuil <hverkuil@xs4all.nl> | 2006-09-01 18:34:48 -0300 |
commit | efb6ed2c83300645cecca27f8b948d6e0380b52d (patch) | |
tree | 56a51b1fb7b315a2047d66397a0cda0cbb302e66 /v4l2-apps | |
parent | 81ff7db1a41de1a7dab9fc096780f8efbe2c19f4 (diff) | |
download | mediapointer-dvb-s2-efb6ed2c83300645cecca27f8b948d6e0380b52d.tar.gz mediapointer-dvb-s2-efb6ed2c83300645cecca27f8b948d6e0380b52d.tar.bz2 |
Add cropping support to v4l2-ctl, set buf_type in sliced_vbi_cap query.
From: Hans Verkuil <hverkuil@xs4all.nl>
VIDIOC_S/G_CROP is now handled by v4l2-ctl. The v4l2_buf_type is now filled in
in VIDIOC_G_SLICED_VBI_CAP. Several test tools now compile when v4l1 API is
disabled.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Diffstat (limited to 'v4l2-apps')
-rw-r--r-- | v4l2-apps/Makefile | 2 | ||||
-rw-r--r-- | v4l2-apps/test/ioctl-test.c | 6 | ||||
-rw-r--r-- | v4l2-apps/test/v4lgrab.c | 4 | ||||
-rw-r--r-- | v4l2-apps/test/vbi-test.c | 6 | ||||
-rw-r--r-- | v4l2-apps/util/v4l2-ctl.cpp | 177 |
5 files changed, 143 insertions, 52 deletions
diff --git a/v4l2-apps/Makefile b/v4l2-apps/Makefile index fc7d21650..cd5a18ff4 100644 --- a/v4l2-apps/Makefile +++ b/v4l2-apps/Makefile @@ -4,5 +4,5 @@ all clean install: $(MAKE) -C lib $@ - $(MAKE) -C test $@ $(MAKE) -C util $@ + $(MAKE) -C test $@ diff --git a/v4l2-apps/test/ioctl-test.c b/v4l2-apps/test/ioctl-test.c index 61659dc78..6d78ad0f8 100644 --- a/v4l2-apps/test/ioctl-test.c +++ b/v4l2-apps/test/ioctl-test.c @@ -54,6 +54,7 @@ union v4l_parms { unsigned long l; u32 u_32; +#ifdef CONFIG_VIDEO_V4L1_COMPAT /* V4L1 structs */ struct vbi_format p_vbi_format; struct video_audio p_video_audio; @@ -71,6 +72,7 @@ union v4l_parms { struct video_tuner p_video_tuner; struct video_unit p_video_unit; struct video_window p_video_window; +#endif /* V4L2 structs */ struct v4l2_audioout p_v4l2_audioout; @@ -106,8 +108,8 @@ union v4l_parms { /* All defined ioctls */ int ioctls[] = { +#ifdef CONFIG_VIDEO_V4L1_COMPAT /* V4L ioctls */ - VIDIOCCAPTURE,/* int */ VIDIOCGAUDIO,/* struct video_audio */ VIDIOCGCAP,/* struct video_capability */ @@ -137,7 +139,7 @@ int ioctls[] = { VIDIOCSWIN,/* struct video_window */ VIDIOCSWRITEMODE,/* int */ VIDIOCSYNC,/* int */ - +#endif /* V4L2 ioctls */ VIDIOC_CROPCAP,/* struct v4l2_cropcap */ diff --git a/v4l2-apps/test/v4lgrab.c b/v4l2-apps/test/v4lgrab.c index c8d433c1d..07c50ef89 100644 --- a/v4l2-apps/test/v4lgrab.c +++ b/v4l2-apps/test/v4lgrab.c @@ -91,6 +91,7 @@ int get_brightness_adj(unsigned char *image, long size, int *brightness) int main(int argc, char **argv) { +#ifdef CONFIG_VIDEO_V4L1_COMPAT int fd = open(FILE, O_RDONLY), f; struct video_capability cap; struct video_window win; @@ -190,5 +191,8 @@ int main(int argc, char **argv) } close(fd); +#else + fprintf(stderr, "V4L1 API is not configured!\n"); +#endif return 0; } diff --git a/v4l2-apps/test/vbi-test.c b/v4l2-apps/test/vbi-test.c index c1a141bff..febd86d43 100644 --- a/v4l2-apps/test/vbi-test.c +++ b/v4l2-apps/test/vbi-test.c @@ -29,8 +29,10 @@ /* All possible parameters used on v4l ioctls */ union v4l_parms { +#ifdef CONFIG_VIDEO_V4L1_COMPAT /* V4L1 structs */ struct vbi_format v1; +#endif /* V4L2 structs */ struct v4l2_format v2; @@ -38,9 +40,11 @@ union v4l_parms { /* All defined ioctls */ int ioctls[] = { +#ifdef CONFIG_VIDEO_V4L1_COMPAT /* V4L ioctls */ VIDIOCGVBIFMT,/* struct vbi_format */ +#endif /* V4L2 ioctls */ @@ -61,6 +65,7 @@ int main (void) } +#ifdef CONFIG_VIDEO_V4L1_COMPAT /* V4L1 call */ memset(&p,0,sizeof(p)); ret=ioctl(fd,VIDIOCGVBIFMT, (void *) &p); @@ -69,6 +74,7 @@ int main (void) "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", ret, p.v1.sampling_rate,p.v1.samples_per_line, p.v1.sample_format, p.v1.start[0],p.v1.start[1],p.v1.count[0],p.v1.count[1],p.v1.flags); +#endif /* V4L2 call */ diff --git a/v4l2-apps/util/v4l2-ctl.cpp b/v4l2-apps/util/v4l2-ctl.cpp index bb7b4bd81..df886581d 100644 --- a/v4l2-apps/util/v4l2-ctl.cpp +++ b/v4l2-apps/util/v4l2-ctl.cpp @@ -99,6 +99,8 @@ enum Option { OptSetVideoOutFormat, OptGetSlicedVbiCap, OptGetSlicedVbiOutCap, + OptGetVideoCrop, + OptSetVideoCrop, OptLast = 256 }; @@ -136,6 +138,12 @@ static const flag_def service_def[] = { #define FMTWidth (1L<<0) #define FMTHeight (1L<<1) +/* crop specified */ +#define CropWidth (1L<<0) +#define CropHeight (1L<<1) +#define CropLeft (1L<<2) +#define CropTop (1L<<3) + static struct option long_options[] = { {"list-audio-inputs", no_argument, 0, OptListAudioInputs}, {"list-audio-outputs", no_argument, 0, OptListAudioOutputs}, @@ -181,6 +189,8 @@ static struct option long_options[] = { {"get-fmt-vbi-out", no_argument, 0, OptGetVbiOutFormat}, {"get-sliced-vbi-cap", no_argument, 0, OptGetSlicedVbiCap}, {"get-sliced-vbi-out-cap", no_argument, 0, OptGetSlicedVbiOutCap}, + {"get-crop-video", no_argument, 0, OptGetVideoCrop}, + {"set-crop-video", required_argument, 0, OptSetVideoCrop}, {0, 0, 0, 0} }; @@ -245,12 +255,16 @@ static void usage(void) printf(" set the video output format [VIDIOC_S_FMT]\n"); printf(" --get-fmt-overlay\n"); printf(" query the video overlay format [VIDIOC_G_FMT]\n"); + printf(" --get-crop-video\n"); + printf(" query the video capture crop window [VIDIOC_G_CROP]\n"); + printf(" --set-crop-video=top=<x>,left=<y>,width=<w>,height=<h>\n"); + printf(" set the video capture crop window [VIDIOC_S_CROP]\n"); printf(" --get-sliced-vbi-cap\n"); - printf(" query the sliced VBI capture capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"); + printf(" query the sliced VBI capture capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"); printf(" --get-sliced-vbi-out-cap\n"); - printf(" query the sliced VBI output capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"); + printf(" query the sliced VBI output capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"); printf(" --get-fmt-sliced-vbi\n"); - printf(" query the sliced VBI capture format [VIDIOC_G_FMT]\n"); + printf(" query the sliced VBI capture format [VIDIOC_G_FMT]\n"); printf(" --set-fmt-sliced-vbi=<mode>\n"); printf(" set the sliced VBI capture format to <mode> [VIDIOC_S_FMT]\n"); printf(" <mode> is a comma separated list of:\n"); @@ -260,7 +274,7 @@ static void usage(void) printf(" wss: widescreen signal (PAL/SECAM)\n"); printf(" vps: VPS (PAL/SECAM)\n"); printf(" --get-fmt-sliced-vbi-out\n"); - printf(" query the sliced VBI output format [VIDIOC_G_FMT]\n"); + printf(" query the sliced VBI output format [VIDIOC_G_FMT]\n"); printf(" --set-fmt-sliced-vbi-out=<mode>\n"); printf(" set the sliced VBI output format to <mode> [VIDIOC_S_FMT]\n"); printf(" <mode> is a comma separated list of:\n"); @@ -388,7 +402,7 @@ static std::string flags2s(unsigned val, const flag_def *def) static void print_sliced_vbi_cap(struct v4l2_sliced_vbi_cap &cap) { // printf("\tType : %s\n", buftype2s(vfmt.type).c_str()); - printf("\tService Set : %s\n", + printf("\tService Set : %s\n", flags2s(cap.service_set, service_def).c_str()); for (int i = 0; i < 24; i++) { printf("\tService Line %2d: %8s / %-8s\n", i, @@ -550,6 +564,12 @@ static void find_controls(int fd) } } +static void printcrop(const struct v4l2_crop &crop) +{ + printf("Crop: Left %d, Top %d, Width %d, Height %d\n", + crop.c.left, crop.c.top, crop.c.width, crop.c.height); +} + static int printfmt(struct v4l2_format vfmt) { const flag_def vbi_def[] = { @@ -575,9 +595,9 @@ static int printfmt(struct v4l2_format vfmt) case V4L2_BUF_TYPE_VIDEO_OVERLAY: printf("\tType : %s\n", buftype2s(vfmt.type).c_str()); printf("\tLeft/Top : %d/%d\n", - vfmt.fmt.win.w.left, vfmt.fmt.win.w.top); + vfmt.fmt.win.w.left, vfmt.fmt.win.w.top); printf("\tWidth/Height: %d/%d\n", - vfmt.fmt.win.w.width, vfmt.fmt.win.w.height); + vfmt.fmt.win.w.width, vfmt.fmt.win.w.height); printf("\tField : %s\n", field2s(vfmt.fmt.win.field).c_str()); // TODO: check G_FBUF capabilities printf("\tChroma Key : %08x\n", vfmt.fmt.win.chromakey); @@ -588,8 +608,8 @@ static int printfmt(struct v4l2_format vfmt) printf("\tType : %s\n", buftype2s(vfmt.type).c_str()); printf("\tSampling Rate : %u Hz\n", vfmt.fmt.vbi.sampling_rate); printf("\tOffset : %u samples (%g secs after leading edge)\n", - vfmt.fmt.vbi.offset, - (double)vfmt.fmt.vbi.offset / (double)vfmt.fmt.vbi.sampling_rate); + vfmt.fmt.vbi.offset, + (double)vfmt.fmt.vbi.offset / (double)vfmt.fmt.vbi.sampling_rate); printf("\tSamples per Line: %u\n", vfmt.fmt.vbi.samples_per_line); printf("\tSample Format : %s\n", fcc2s(vfmt.fmt.vbi.sample_format).c_str()); printf("\tStart 1st Field : %u\n", vfmt.fmt.vbi.start[0]); @@ -602,7 +622,7 @@ static int printfmt(struct v4l2_format vfmt) case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: printf("\tType : %s\n", buftype2s(vfmt.type).c_str()); - printf("\tService Set : %s\n", + printf("\tService Set : %s\n", flags2s(vfmt.fmt.sliced.service_set, service_def).c_str()); for (int i = 0; i < 24; i++) { printf("\tService Line %2d: %8s / %-8s\n", i, @@ -890,6 +910,7 @@ int main(int argc, char **argv) /* bitfield for fmts */ unsigned int set_fmts = 0; unsigned int set_fmts_out = 0; + unsigned int set_crop = 0; int mode = V4L2_TUNER_MODE_STEREO; /* set audio mode */ @@ -908,6 +929,7 @@ int main(int argc, char **argv) struct v4l2_output vout; /* list_outputs */ struct v4l2_audio vaudio; /* list audio inputs */ struct v4l2_audioout vaudout; /* audio outputs */ + struct v4l2_rect vcrop; /* crop rect */ int input; /* set_input/get_input */ int output; /* set_output/get_output */ v4l2_std_id std; /* get_std/set_std */ @@ -929,6 +951,7 @@ int main(int argc, char **argv) memset(&vout, 0, sizeof(vout)); memset(&vaudio, 0, sizeof(vaudio)); memset(&vaudout, 0, sizeof(vaudout)); + memset(&vcrop, 0, sizeof(vcrop)); memset(&vf, 0, sizeof(vf)); memset(&vs, 0, sizeof(vs)); @@ -1007,6 +1030,37 @@ int main(int argc, char **argv) } } break; + case OptSetVideoCrop: + subs = optarg; + while (*subs != '\0') { + static char *const subopts[] = { + "left", + "top", + "width", + "height", + NULL + }; + + switch (parse_subopt(&subs, subopts, &value)) { + case 0: + vcrop.left = strtol(value, 0L, 0); + set_crop |= CropLeft; + break; + case 1: + vcrop.top = strtol(value, 0L, 0); + set_crop |= CropTop; + break; + case 2: + vcrop.width = strtol(value, 0L, 0); + set_crop |= CropWidth; + break; + case 3: + vcrop.height = strtol(value, 0L, 0); + set_crop |= CropHeight; + break; + } + } + break; case OptSetInput: input = strtol(optarg, 0L, 0); break; @@ -1182,6 +1236,7 @@ int main(int argc, char **argv) if (options[OptAll]) { options[OptGetVideoFormat] = 1; + options[OptGetVideoCrop] = 1; options[OptGetVideoOutFormat] = 1; options[OptGetDriverInfo] = 1; options[OptGetInput] = 1; @@ -1267,7 +1322,7 @@ int main(int argc, char **argv) if (doioctl(fd, VIDIOC_S_AUDOUT, &vaudout, "VIDIOC_S_AUDOUT") == 0) printf("Audio output set to %d\n", vaudout.index); } - + if (options[OptSetTuner]) { struct v4l2_tuner vt; @@ -1293,9 +1348,6 @@ int main(int argc, char **argv) in_vfmt.fmt.pix.height = vfmt.fmt.pix.height; if (ioctl(fd, VIDIOC_S_FMT, &in_vfmt) < 0) fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n"); - vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (ioctl(fd, VIDIOC_G_FMT, &vfmt) < 0) - fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n"); } } @@ -1312,34 +1364,51 @@ int main(int argc, char **argv) in_vfmt.fmt.pix.height = vfmt.fmt.pix.height; if (ioctl(fd, VIDIOC_S_FMT, &in_vfmt) < 0) fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n"); - vfmt_out.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; - if (ioctl(fd, VIDIOC_G_FMT, &vfmt_out) < 0) - fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n"); } } - + if (options[OptSetSlicedVbiFormat]) { - if (vbi_fmt.fmt.sliced.service_set == 0) { - // switch to raw mode - vbi_fmt.type = V4L2_BUF_TYPE_VBI_CAPTURE; - if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt, "VIDIOC_G_FMT") == 0) - doioctl(fd, VIDIOC_S_FMT, &vbi_fmt, "VIDIOC_S_FMT"); - } else { - vbi_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; - doioctl(fd, VIDIOC_S_FMT, &vbi_fmt, "VIDIOC_S_FMT"); - } - } - + if (vbi_fmt.fmt.sliced.service_set == 0) { + // switch to raw mode + vbi_fmt.type = V4L2_BUF_TYPE_VBI_CAPTURE; + if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt, "VIDIOC_G_FMT") == 0) + doioctl(fd, VIDIOC_S_FMT, &vbi_fmt, "VIDIOC_S_FMT"); + } else { + vbi_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; + doioctl(fd, VIDIOC_S_FMT, &vbi_fmt, "VIDIOC_S_FMT"); + } + } + if (options[OptSetSlicedVbiOutFormat]) { - if (vbi_fmt_out.fmt.sliced.service_set == 0) { - // switch to raw mode - vbi_fmt_out.type = V4L2_BUF_TYPE_VBI_OUTPUT; - if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out, "VIDIOC_G_FMT") == 0) - doioctl(fd, VIDIOC_S_FMT, &vbi_fmt_out, "VIDIOC_S_FMT"); - } else { - vbi_fmt_out.type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT; - doioctl(fd, VIDIOC_S_FMT, &vbi_fmt_out, "VIDIOC_S_FMT"); - } + if (vbi_fmt_out.fmt.sliced.service_set == 0) { + // switch to raw mode + vbi_fmt_out.type = V4L2_BUF_TYPE_VBI_OUTPUT; + if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out, "VIDIOC_G_FMT") == 0) + doioctl(fd, VIDIOC_S_FMT, &vbi_fmt_out, "VIDIOC_S_FMT"); + } else { + vbi_fmt_out.type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT; + doioctl(fd, VIDIOC_S_FMT, &vbi_fmt_out, "VIDIOC_S_FMT"); + } + } + + if (options[OptSetVideoCrop]) { + struct v4l2_crop in_crop; + printf("ioctl: VIDIOC_S_CROP\n"); + in_crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(fd, VIDIOC_G_CROP, &in_crop) < 0) + fprintf(stderr, "ioctl: VIDIOC_G_CROP failed\n"); + else { + if (set_crop & CropWidth) + in_crop.c.width = vcrop.width; + if (set_crop & CropHeight) + in_crop.c.height = vcrop.height; + if (set_crop & CropLeft) + in_crop.c.left = vcrop.left; + if (set_crop & CropTop) + in_crop.c.top = vcrop.top; + if (ioctl(fd, VIDIOC_S_CROP, &in_crop) < 0) + fprintf(stderr, "ioctl: VIDIOC_S_CROP failed\n"); + } } if (options[OptSetCtrl] && !set_ctrls.empty()) { @@ -1384,7 +1453,7 @@ int main(int argc, char **argv) } } } - + /* Get options */ if (options[OptGetVideoFormat]) { @@ -1411,17 +1480,17 @@ int main(int argc, char **argv) } if (options[OptGetSlicedVbiFormat]) { - vbi_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; - if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt, + vbi_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; + if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt, "VIDIOC_G_FMT") == 0) if (printfmt(vbi_fmt) != 0) fprintf(stderr, "error printing result\n"); } - + if (options[OptGetSlicedVbiOutFormat]) { - vbi_fmt_out.type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT; - if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out, + vbi_fmt_out.type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT; + if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out, "VIDIOC_G_FMT") == 0) if (printfmt(vbi_fmt_out) != 0) fprintf(stderr, @@ -1429,23 +1498,31 @@ int main(int argc, char **argv) } if (options[OptGetVbiFormat]) { - raw_fmt.type = V4L2_BUF_TYPE_VBI_CAPTURE; - if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt, + raw_fmt.type = V4L2_BUF_TYPE_VBI_CAPTURE; + if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt, "VIDIOC_G_FMT") == 0) if (printfmt(raw_fmt) != 0) fprintf(stderr, "error printing result\n"); } - + if (options[OptGetVbiOutFormat]) { - raw_fmt_out.type = V4L2_BUF_TYPE_VBI_OUTPUT; - if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt_out, + raw_fmt_out.type = V4L2_BUF_TYPE_VBI_OUTPUT; + if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt_out, "VIDIOC_G_FMT") == 0) if (printfmt(raw_fmt_out) != 0) fprintf(stderr, "error printing result\n"); } + if (options[OptGetVideoCrop]) { + struct v4l2_crop crop; + + crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (doioctl(fd, VIDIOC_G_CROP, &crop, "VIDIOC_G_CROP") == 0) + printcrop(crop); + } + if (options[OptGetInput]) { if (doioctl(fd, VIDIOC_G_INPUT, &input, "VIDIOC_G_INPUT") == 0) { printf("Video input : %d", input); @@ -1700,6 +1777,7 @@ int main(int argc, char **argv) if (options[OptGetSlicedVbiCap]) { struct v4l2_sliced_vbi_cap cap; + cap.type = V4L2_BUF_TYPE_VBI_CAPTURE; if (doioctl(fd, VIDIOC_G_SLICED_VBI_CAP, &cap, "VIDIOC_G_SLICED_VBI_CAP") == 0) { print_sliced_vbi_cap(cap); } @@ -1708,6 +1786,7 @@ int main(int argc, char **argv) if (options[OptGetSlicedVbiOutCap]) { struct v4l2_sliced_vbi_cap cap; + cap.type = V4L2_BUF_TYPE_VBI_OUTPUT; if (doioctl(fd, VIDIOC_G_SLICED_VBI_CAP, &cap, "VIDIOC_G_SLICED_VBI_CAP") == 0) { print_sliced_vbi_cap(cap); } |