From patchwork Fri Sep 7 13:29:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 1422351 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id CD857DF283 for ; Fri, 7 Sep 2012 13:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759120Ab2IGNam (ORCPT ); Fri, 7 Sep 2012 09:30:42 -0400 Received: from smtp-vbr14.xs4all.nl ([194.109.24.34]:2681 "EHLO smtp-vbr14.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756327Ab2IGN3i (ORCPT ); Fri, 7 Sep 2012 09:29:38 -0400 Received: from alastor.dyndns.org (166.80-203-20.nextgentel.com [80.203.20.166] (may be forged)) (authenticated bits=0) by smtp-vbr14.xs4all.nl (8.13.8/8.13.8) with ESMTP id q87DTXVS035049 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 7 Sep 2012 15:29:34 +0200 (CEST) (envelope-from hverkuil@xs4all.nl) Received: from tschai.lan (tschai.lan [192.168.1.10]) (Authenticated sender: hans) by alastor.dyndns.org (Postfix) with ESMTPSA id D749835C0010; Fri, 7 Sep 2012 15:29:30 +0200 (CEST) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Hans Verkuil Subject: [RFCv2 API PATCH 15/28] DocBook: Mark CROPCAP as optional instead of as compulsory. Date: Fri, 7 Sep 2012 15:29:15 +0200 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1347024568-32602-1-git-send-email-hverkuil@xs4all.nl> References: <1347024568-32602-1-git-send-email-hverkuil@xs4all.nl> In-Reply-To: References: X-Virus-Scanned: by XS4ALL Virus Scanner Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Hans Verkuil While the documentation says that VIDIOC_CROPCAP is compulsory for all video capture and output devices, in practice VIDIOC_CROPCAP is only implemented for devices that can do cropping and/or scaling. Update the documentation to no longer require VIDIOC_CROPCAP if the driver does not support cropping or scaling or non-square pixels. Signed-off-by: Hans Verkuil --- Documentation/DocBook/media/v4l/common.xml | 145 +++++++++----------- Documentation/DocBook/media/v4l/vidioc-cropcap.xml | 10 +- 2 files changed, 75 insertions(+), 80 deletions(-) diff --git a/Documentation/DocBook/media/v4l/common.xml b/Documentation/DocBook/media/v4l/common.xml index 9378d7b..454258b 100644 --- a/Documentation/DocBook/media/v4l/common.xml +++ b/Documentation/DocBook/media/v4l/common.xml @@ -628,7 +628,7 @@ are available for the device. if (-1 == ioctl (fd, &VIDIOC-G-STD;, &std_id)) { /* Note when VIDIOC_ENUMSTD always returns EINVAL this is no video device or it falls under the USB exception, - and VIDIOC_G_STD returning EINVAL is no error. */ + and VIDIOC_G_STD returning ENOTTY is no error. */ perror ("VIDIOC_G_STD"); exit (EXIT_FAILURE); @@ -905,9 +905,9 @@ inserted. Source and target rectangles are defined even if the device does not support scaling or the VIDIOC_G/S_CROP ioctls. Their size (and position where applicable) will be fixed in -this case. All capture and output device must support the -VIDIOC_CROPCAP ioctl such that applications can -determine if scaling takes place. +this case. All capture and output device that support cropping +and/or scaling and/or have non-square pixels must support the VIDIOC_CROPCAP +ioctl such that applications can determine if scaling takes place.
Cropping Structures @@ -1032,24 +1032,21 @@ devices.) &v4l2-cropcap; cropcap; &v4l2-crop; crop; -memset (&cropcap, 0, sizeof (cropcap)); +memset(&cropcap, 0, sizeof(cropcap)); cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -if (-1 == ioctl (fd, &VIDIOC-CROPCAP;, &cropcap)) { - perror ("VIDIOC_CROPCAP"); - exit (EXIT_FAILURE); -} - -memset (&crop, 0, sizeof (crop)); -crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -crop.c = cropcap.defrect; +if (0 == ioctl(fd, &VIDIOC-CROPCAP;, &cropcap)) { + memset(&crop, 0, sizeof(crop)); + crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + crop.c = cropcap.defrect; -/* Ignore if cropping is not supported (EINVAL). */ + /* Ignore if cropping is not supported (ENOTTY). */ -if (-1 == ioctl (fd, &VIDIOC-S-CROP;, &crop) - && errno != EINVAL) { - perror ("VIDIOC_S_CROP"); - exit (EXIT_FAILURE); + if (-1 == ioctl(fd, &VIDIOC-S-CROP;, &crop) + && errno != ENOTTY) { + perror("VIDIOC_S_CROP"); + exit(EXIT_FAILURE); + } } @@ -1063,11 +1060,11 @@ if (-1 == ioctl (fd, &VIDIOC-S-CROP;, &crop) &v4l2-cropcap; cropcap; &v4l2-format; format; -reset_cropping_parameters (); +reset_cropping_parameters(); /* Scale down to 1/4 size of full picture. */ -memset (&format, 0, sizeof (format)); /* defaults */ +memset(&format, 0, sizeof(format)); /* defaults */ format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -1075,9 +1072,9 @@ format.fmt.pix.width = cropcap.defrect.width >> 1; format.fmt.pix.height = cropcap.defrect.height >> 1; format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; -if (-1 == ioctl (fd, &VIDIOC-S-FMT;, &format)) { - perror ("VIDIOC_S_FORMAT"); - exit (EXIT_FAILURE); +if (-1 == ioctl(fd, &VIDIOC-S-FMT;, &format)) { + perror("VIDIOC_S_FORMAT"); + exit(EXIT_FAILURE); } /* We could check the actual image size now, the actual scaling factor @@ -1092,33 +1089,30 @@ if (-1 == ioctl (fd, &VIDIOC-S-FMT;, &format)) { &v4l2-cropcap; cropcap; &v4l2-crop; crop; -memset (&cropcap, 0, sizeof (cropcap)); +memset(&cropcap, 0, sizeof (cropcap)); cropcap.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; -if (-1 == ioctl (fd, VIDIOC_CROPCAP;, &cropcap)) { - perror ("VIDIOC_CROPCAP"); - exit (EXIT_FAILURE); -} - -memset (&crop, 0, sizeof (crop)); +if (0 == ioctl(fd, &VIDIOC-CROPCAP;, &cropcap)) { + memset(&crop, 0, sizeof (crop)); -crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; -crop.c = cropcap.defrect; + crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; + crop.c = cropcap.defrect; -/* Scale the width and height to 50 % of their original size - and center the output. */ + /* Scale the width and height to 50 % of their original size + and center the output. */ -crop.c.width /= 2; -crop.c.height /= 2; -crop.c.left += crop.c.width / 2; -crop.c.top += crop.c.height / 2; + crop.c.width /= 2; + crop.c.height /= 2; + crop.c.left += crop.c.width / 2; + crop.c.top += crop.c.height / 2; -/* Ignore if cropping is not supported (EINVAL). */ + /* Ignore if cropping is not supported (ENOTTY). */ -if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop) - && errno != EINVAL) { - perror ("VIDIOC_S_CROP"); - exit (EXIT_FAILURE); + if (-1 == ioctl(fd, VIDIOC_S_CROP, &crop) + && errno != ENOTTY) { + perror("VIDIOC_S_CROP"); + exit(EXIT_FAILURE); + } } @@ -1136,50 +1130,47 @@ double hscale, vscale; double aspect; int dwidth, dheight; -memset (&cropcap, 0, sizeof (cropcap)); -cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +memset(&format, 0, sizeof(format)); +format.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -if (-1 == ioctl (fd, &VIDIOC-CROPCAP;, &cropcap)) { - perror ("VIDIOC_CROPCAP"); - exit (EXIT_FAILURE); +if (-1 == ioctl(fd, &VIDIOC-G-FMT;, &format)) { + perror("VIDIOC_G_FMT"); + exit(EXIT_FAILURE); } -memset (&crop, 0, sizeof (crop)); -crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +memset(&cropcap, 0, sizeof (cropcap)); +cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -if (-1 == ioctl (fd, &VIDIOC-G-CROP;, &crop)) { - if (errno != EINVAL) { - perror ("VIDIOC_G_CROP"); - exit (EXIT_FAILURE); - } +if (0 == ioctl(fd, &VIDIOC-CROPCAP;, &cropcap)) { + memset(&crop, 0, sizeof(crop)); + crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - /* Cropping not supported. */ - crop.c = cropcap.defrect; -} + if (-1 == ioctl(fd, &VIDIOC-G-CROP;, &crop)) { + if (errno != ENOTTY) { + perror("VIDIOC_G_CROP"); + exit(EXIT_FAILURE); + } -memset (&format, 0, sizeof (format)); -format.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - -if (-1 == ioctl (fd, &VIDIOC-G-FMT;, &format)) { - perror ("VIDIOC_G_FMT"); - exit (EXIT_FAILURE); -} + /* Cropping not supported. */ + crop.c = cropcap.defrect; + } -/* The scaling applied by the driver. */ + /* The scaling applied by the driver. */ -hscale = format.fmt.pix.width / (double) crop.c.width; -vscale = format.fmt.pix.height / (double) crop.c.height; + hscale = format.fmt.pix.width / (double)crop.c.width; + vscale = format.fmt.pix.height / (double)crop.c.height; -aspect = cropcap.pixelaspect.numerator / - (double) cropcap.pixelaspect.denominator; -aspect = aspect * hscale / vscale; + aspect = cropcap.pixelaspect.numerator / + (double)cropcap.pixelaspect.denominator; + aspect = aspect * hscale / vscale; -/* Devices following ITU-R BT.601 do not capture - square pixels. For playback on a computer monitor - we should scale the images to this size. */ + /* Devices following ITU-R BT.601 do not capture + square pixels. For playback on a computer monitor + we should scale the images to this size. */ -dwidth = format.fmt.pix.width / aspect; -dheight = format.fmt.pix.height; + dwidth = format.fmt.pix.width / aspect; + dheight = format.fmt.pix.height; +}
@@ -1212,5 +1203,5 @@ a pointer to a &v4l2-streamparm;, which contains a union holding separate parameters for input and output devices. These ioctls are optional, drivers need not implement -them. If so, they return the &EINVAL;. +them. If so, they return the &ENOTTY;. diff --git a/Documentation/DocBook/media/v4l/vidioc-cropcap.xml b/Documentation/DocBook/media/v4l/vidioc-cropcap.xml index 4559c45..bf7cc97 100644 --- a/Documentation/DocBook/media/v4l/vidioc-cropcap.xml +++ b/Documentation/DocBook/media/v4l/vidioc-cropcap.xml @@ -59,6 +59,9 @@ constant except when switching the video standard. Remember this switch can occur implicit when switching the video input or output. + This ioctl must be implemented for video capture or output devices that +support cropping and/or scaling and/or have non-square pixels, and for overlay devices. + struct <structname>v4l2_cropcap</structname> @@ -70,7 +73,9 @@ output. Type of the data stream, set by the application. Only these types are valid here: V4L2_BUF_TYPE_VIDEO_CAPTURE, -V4L2_BUF_TYPE_VIDEO_OUTPUT and +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, +V4L2_BUF_TYPE_VIDEO_OUTPUT, +V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE and V4L2_BUF_TYPE_VIDEO_OVERLAY. See . @@ -154,8 +159,7 @@ on 22 Oct 2002 subject "Re:[V4L][patches!] Re:v4l2/kernel-2.5" --> EINVAL The &v4l2-cropcap; type is -invalid. This is not permitted for video capture, output and overlay devices, -which must support VIDIOC_CROPCAP. +invalid.