From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from perceval.ideasonboard.com ([95.142.166.194]:45549 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754013Ab1IVWlc (ORCPT ); Thu, 22 Sep 2011 18:41:32 -0400 From: Laurent Pinchart To: Tomasz Stanislawski Subject: Re: [PATCH 2/4] v4l: add documentation for selection API Date: Fri, 23 Sep 2011 00:41:26 +0200 Cc: linux-media@vger.kernel.org, m.szyprowski@samsung.com, kyungmin.park@samsung.com, hverkuil@xs4all.nl, sakari.ailus@iki.fi References: <1314793703-32345-1-git-send-email-t.stanislaws@samsung.com> <1314793703-32345-3-git-send-email-t.stanislaws@samsung.com> In-Reply-To: <1314793703-32345-3-git-send-email-t.stanislaws@samsung.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201109230041.27712.laurent.pinchart@ideasonboard.com> Sender: linux-media-owner@vger.kernel.org List-ID: Hi Tomasz, Thanks for the patch, and sorry for the late reply. On Wednesday 31 August 2011 14:28:21 Tomasz Stanislawski wrote: > This patch adds a documentation for VIDIOC_{G/S}_SELECTION ioctl. Moreover, > the patch adds the description of modeling of composing, cropping and > scaling features in V4L2. Finally, some examples are presented. > > Signed-off-by: Tomasz Stanislawski > Signed-off-by: Kyungmin Park The documentation looks very good. Thank you for your great work. Just a couple of small comments below, mostly about typo fixes. [snip] > diff --git a/Documentation/DocBook/media/v4l/selection-api.xml > b/Documentation/DocBook/media/v4l/selection-api.xml new file mode 100644 > index 0000000..d9fd57d8 > --- /dev/null > +++ b/Documentation/DocBook/media/v4l/selection-api.xml > @@ -0,0 +1,278 @@ > +
> + > + Cropping, composing and scaling > + > +Some video capture devices can sample a subsection of a picture and > +shrink or enlarge it to an image of arbitrary size. Next, the devices can > +insert the image into larger one. Some video output devices can crop part of an > +input image, scale it up or down and insert it at an arbitrary scan line and > +horizontal offset into a video signal. We call these abilities cropping, > +scaling and composing. > + > +On a video capture device the source is a video > +signal, and the cropping target determine the area actually sampled. The sink > +is an image stored in a memory buffer. The composing area specify which part s/specify/specifies/ > +of the buffer is actually written by the hardware. s/written/written to/ > +On a video output device the source is an image in a > +memory buffer, and the cropping target is a part of an image to shown on a s/shown/show/ or s/shown/be shown/ > +display. The sink is the display or the graphics screen. The application may > +select the part of display where the image should be displayed. The size and > +position of such a window is controlled by compose target. s/compose target/the compose target/ > +Rectangles for all cropping and composing targets are defined even if the > +device does not support neither cropping nor composing. Their size and position s/does not support/supports/ or s/neither cropping nor/cropping or/ > +will be fixed in such a case. If the device does not support scaling then the > +cropping and composing rectangles have the same size. > + > +
> + Selection targets > + > +
> + Cropping and composing targets > + > + > + > + > + > + Targets used by a cropping, composing and scaling > + process > + > + > +
> +
> + > +
> + > + Configuration > + > +Applications can use the selection > +API to select an area in a video signal or a buffer, and to query for > +default settings and hardware limits. > + > +Video hardware can have various cropping, composing and scaling > +limitations. It may only scale up or down, support only discrete scaling > +factors, or have different scaling abilities in horizontal and vertical > +direction. Also it may not support scaling at all. At the same time the s/horizontal and vertical direction/the horizontal and vertical directions/ > +cropping/composing rectangles may have to be aligned, and both the source and > +the sink may have arbitrary upper and lower size limits. Therefore, as usual, > +drivers are expected to adjust the requested parameters and return the actual > +values selected. An application can control the rounding behaviour using +linkend="v4l2-sel-flags"> constraint flags . > + > +
> + > + Configuration of video capture > + > +See the figure for examples of the s/the figure/figure/ > +selection targets available for a video capture device. The targets should be > +configured according to the pipeline configuration rules for a capture device. Do we have such rules written somewhere ? > +It means that the cropping targets must be configured in prior to the composing > +targets. > + > +The range of coordinates of the top left corner, width and height of a > +area which can be sampled is given by the V4L2_SEL_CROP_BOUNDS s/a area which/areas that/ > + target. To support a wide range of hardware this specification does > +not define an origin or units. > + > +The top left corner, width and height of the source rectangle, that is > +the area actually sampled, is given by V4L2_SEL_CROP_ACTIVE s/by/by the/ > + target. It uses the same coordinate system as > +V4L2_SEL_CROP_BOUNDS . The active cropping area must lie completely > +inside the capture boundaries. The driver may further adjust the requested size > +and/or position according to hardware limitations. > + > +Each capture device has a default source rectangle, given by the > + V4L2_SEL_CROP_DEFAULT target. The center of this > +rectangle shall align with the center of the active picture area of the video > +signal, and cover what the driver writer considers the complete picture. > +Drivers shall reset the crop rectangle to the default when the driver is first s/reset the crop rectangle/set the active crop rectangle/ > +loaded, but not later. > + > +The composing targets refer to a memory buffer. The limits of composing > +coordinates are obtained using V4L2_SEL_COMPOSE_BOUNDS . > +All coordinates are expressed in pixels. The top/left corner is always point > + {0,0} . The width and height is equal to the image size > +specified using VIDIOC_S_FMT . We support sub-pixel cropping, but not sub-pixel composition. Can you remind me of the rationale for that ? > +The part of a buffer into which the image is inserted by the hardware is > +controlled by V4L2_SEL_COMPOSE_ACTIVE target. The s/by/by the/ > +rectangle's coordinates are also expressed in pixels. The composing rectangle > +must lie completely inside bounds rectangle. The driver must adjust the > +composing rectangle to fit to the bounding limits. Moreover, the driver can > +perform other adjustments according to hardware limitations. The application > +can control rounding behaviour using constraint > +flags . > + > +For capture devices the default composing rectangle is queried using > + V4L2_SEL_COMPOSE_DEFAULT and it is always equal to > +bounding rectangle. If they're always equal, why do we have two different targets ? :-) Maybe "is usually identical to" or "is most of the time identical to" would be better ? > +The part of a buffer that is modified by the hardware is given by > + V4L2_SEL_COMPOSE_PADDED . It contains all pixels defined > +using V4L2_SEL_COMPOSE_ACTIVE plus all padding data > +modified by hardware during insertion process. All pixel outside this rectangle s/All pixel/All pixels/ > +must not be changed by the hardware. The content of pixels > +that lie inside the padded area but outside active area is undefined. The > +application can use the padded and active rectangles to detect where the > +rubbish pixels are located and remove them if needed. How would an application remove them ? > + > +
> + > +
> + > + Configuration of video output > + > +For output devices targets and ioctls are used accordingly to the video s/accordingly/similarly/ > +capture case. The composing rectangle refer to insertion s/refer/refers/ or s/rectangle/rectangles/ s/insertion/the insertion/ > +of an image into a video signal. The cropping rectangles refer to a memory > +buffer. The targets are should be configured according to the pipeline s/are// > +configuration rules for a output device. It means that the compose targets must s/a output/an output/ > +be configured in prior to cropping targets. s/in prior to/before the/ > + > +The cropping targets refer to the memory buffer which contains an image s/which/that/ > +to be inserted into video signal or graphical screen. The limits of cropping s/into/into a/ > +coordinates are obtained using V4L2_SEL_CROP_BOUNDS . All > +coordinates are expressed in pixels. The top/left corner is always point > + {0,0} . The width and height is equal to the image size > +specified using VIDIOC_S_FMT ioctl. > + > +The top left corner, width and height of the source rectangle, that is > +the area from which pixels are processed by the hardware. The target identifier > +is V4L2_SEL_CROP_ACTIVE . Its coordinates are expressed s/. The target identifier is/, is given by/ > +in pixels. The active cropping area must lie completely inside the crop > +boundaries and the driver may further adjust the requested size and/or position > +according to hardware limitations. > + > +For output devices the default cropping rectangle is queried using > + V4L2_SEL_CROP_DEFAULT and it is always equal to cropping > +bounding rectangle. Same, comment maybe "is usually identical to the" or "is most of the time identical to the" would be better ? > + > +The part of a video signal or graphics display where the image is > +inserted by the hardware is controlled by V4L2_SEL_COMPOSE_ACTIVE s/by/by the/ > + target. The rectangle's coordinates are expressed driver dependant s/expressed/expressed in/ > +units. The only exception are digital outputs where the units are pixels. The > +composing rectangle must lie completely inside bounds rectangle. The driver s/bounds rectangle/the bounds rectangle/ > +must adjust the area to fit to the bounding limits. Moreover, the driver can > +perform other adjustments according to hardware limitations. > + > +The device has a default composing rectangle, given by the > +V4L2_SEL_COMPOSE_DEFAULT target. The center of this rectangle shall > +align with the center of the active picture area of the video signal, and cover > +what the driver writer considers the complete picture. Drivers shall reset the s/reset/set/ > +composing rectangle to the default one when the driver is first loaded. > + > +The devices may introduce additional content to video signal other then s/then/than/ > +an image from memory buffers. It includes borders around an image. However, > +such a padding area is very driver-dependant issue. Driver developers are s/ issue// (?) > +encouraged to keep padding rectangle equal to active one. The padding target > +is accessed by V4L2_SEL_COMPOSE_PADDED identifier. It s/by/by the/ > +must contain all pixels from V4L2_SEL_COMPOSE_ACTIVE s/from/from the/ > +target. > + > +
> + > +
> + > + Scaling control. > + > +An application can detect if scaling is performed by comparing width and s/width/the width/ > +height of rectangles obtained using V4L2_SEL_CROP_ACTIVE > +and V4L2_SEL_COMPOSE_ACTIVE targets. If these are not > +equal then the scaling is applied. The application can compute scaling ratios s/the scaling/scaling/ > +using these values. > + > +
> + > +
> + > +
> + Examples > + > + Resetting the cropping parameters > + > + (A video capture device is assumed; change > +V4L2_BUF_TYPE_VIDEO_CAPTURE for other devices; change target to > + V4L2_SEL_COMPOSE_* family to configure composing > +area) > + > + > + > + &v4l2-selection; sel = { > + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, > + .target = V4L2_SEL_CROP_DEFAULT, > + }; > + ret = ioctl(fd, &VIDIOC-G-SELECTION;, &sel); > + if (ret) > + exit(-1); > + sel.target = V4L2_SEL_CROP_ACTIVE; > + ret = ioctl(fd, &VIDIOC-S-SELECTION;, &sel); > + if (ret) > + exit(-1); > + > + > + > + > + > + Simple downscaling > + Setting a composing area on output of size of at most > + half of limit placed at a center of a display. > + > + > + &v4l2-selection; sel = { > + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, > + .target = V4L2_SEL_COMPOSE_BOUNDS, > + }; > + struct v4l2_rect r; > + > + ret = ioctl(fd, &VIDIOC-G-SELECTION;, &sel); > + if (ret) > + exit(-1); > + /* setting smaller compose rectangle */ > + r.width = sel.r.width / 2; > + r.height = sel.r.height / 2; > + r.left = sel.r.width / 4; > + r.top = sel.r.height / 4; > + sel.r = r; > + sel.target = V4L2_SEL_COMPOSE_ACTIVE; > + sel.flags = V4L2_SEL_SIZE_LE; > + ret = ioctl(fd, &VIDIOC-S-SELECTION;, &sel); > + if (ret) > + exit(-1); > + > + > + > + > + > + Querying for scaling factors > + A video output device is assumed; change > +V4L2_BUF_TYPE_VIDEO_OUTPUT for other devices > + > + > + &v4l2-selection; compose = { > + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, > + .target = V4L2_SEL_COMPOSE_ACTIVE, > + }; > + &v4l2-selection; crop = { > + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, > + .target = V4L2_SEL_CROP_ACTIVE, > + }; > + double hscale, vscale; > + > + ret = ioctl(fd, &VIDIOC-G-SELECTION;, &compose); > + if (ret) > + exit(-1); > + ret = ioctl(fd, &VIDIOC-G-SELECTION;, &crop); > + if (ret) > + exit(-1); > + > + /* computing scaling factors */ > + hscale = (double)compose.r.width / crop.r.width; > + vscale = (double)compose.r.height / crop.r.height; > + > + > + > + > +
> + > +
> diff --git a/Documentation/DocBook/media/v4l/v4l2.xml > b/Documentation/DocBook/media/v4l/v4l2.xml index 0d05e87..54333a5 100644 > --- a/Documentation/DocBook/media/v4l/v4l2.xml > +++ b/Documentation/DocBook/media/v4l/v4l2.xml > @@ -493,6 +493,7 @@ and discussions on the V4L mailing list. > &sub-g-output; > &sub-g-parm; > &sub-g-priority; > + &sub-g-selection; > &sub-g-sliced-vbi-cap; > &sub-g-std; > &sub-g-tuner; > diff --git a/Documentation/DocBook/media/v4l/vidioc-g-selection.xml > b/Documentation/DocBook/media/v4l/vidioc-g-selection.xml new file mode > 100644 > index 0000000..6d93832 > --- /dev/null > +++ b/Documentation/DocBook/media/v4l/vidioc-g-selection.xml > @@ -0,0 +1,281 @@ > + > + > + ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION > + &manvol; > + > + > + > + VIDIOC_G_SELECTION > + VIDIOC_S_SELECTION > + Get or set one of the current selection rectangles s/current // (?) > + > + > + > + > + > + int ioctl > + int fd > + int request > + struct v4l2_selection *argp > + > + > + > + > + > + Arguments > + > + > + > + fd > + > + &fd; > + > + > + > + request > + > + VIDIOC_G_SELECTION, VIDIOC_S_SELECTION > + > + > + > + argp > + > + > + > + > + > + > + > + > + Description > + The ioctls are used to query and configure selection rectangles. > + > + To query the cropping (composing) rectangle set > +v4l2_selection::type to the respective buffer type. Then set > + v4l2_selection::target to value > +V4L2_SEL_CROP_ACTIVE ( V4L2_SEL_COMPOSE_ACTIVE > +). Please refer to table or > + for additional targets. Fields > +v4l2_selection::flags and v4l2_selection::reserved > + are ignored and they must be filled with zeros. The driver > +fills the rest of structure or returns &EINVAL; if incorrect buffer type or s/rest of/rest of the/ s/incorrect/an incorrect/ > +target was used. If cropping (composing) is not supported then the active > +rectangle is not mutable and it is always equal to bounds rectangle. Finally, s/to bounds/to the bounds/ > +structure v4l2-selection::r is filled with current s/with current/with the current/ > +cropping (composing) coordinates. The coordinates are expressed in > +driver-dependant units. The only exception are rectangles for images in raw s/dependant/dependent/ > +formats, which coordinates are always expressed in pixels. s/which/whose/ > + > + To change the cropping (composing) rectangle set > +v4l2_selection::type to the respective buffer type. Then set > + v4l2_selection::target to value > +V4L2_SEL_CROP_ACTIVE ( V4L2_SEL_COMPOSE_ACTIVE > +). Please refer to table or +linkend="selection-api" /> for additional targets. Set desired active area > +into the field v4l2_selection::r . Field > + v4l2_selection::reserved is ignored and they must s/they must/must/ > +be filled with zeros. The driver may adjust the rectangle coordinates. An > +application may introduce constraints to control rounding behaviour. Set the > +field v4l2_selection::flags to one of values: > + > + > + > +0 - driver is free to adjust size, it is recommended > +to choose the crop/compose rectangle as close as possible to the original > +one The driver can adjust the rectangle size freely and shall choose a crop/compose rectangle as close as possible to the requested one. > + > + > +SEL_SIZE_GE - driver is not allowed to shrink the > +rectangle. The original rectangle must lay inside the adjusted one > + > + > +SEL_SIZE_LE - drive is not allowed to grow the s/drive/driver/ s/grow/enlarge/ > +rectangle. The adjusted rectangle must lay inside the original one > + > + > +SEL_SIZE_GE | SEL_SIZE_LE - choose size exactly the > +same as in desired rectangle. > + > + > + > +Please refer to . > + > + > + > + The driver may have to adjusts the requested dimensions against hardware > +limits and other parts as the pipeline, i.e. the bounds given by the > +capture/output window or TV display. If constraints flags have to be violated > +at any stage then ERANGE is returned. You know that I still think that hints should be hints, and that ERANGE should not be returned, right ? :-) > The closest possible values of horizontal > +and vertical offset and sizes are chosen according to following priority: > + > + > + > + Satisfy constraints from v4l2_selection::flags. > + > + > + Adjust width, height, left, and top to hardware limits and alignments. > + > + > + Keep center of adjusted rectangle as close as possible to the original one. > + > + > + Keep width and height as close as possible to original ones. > + > + > + Keep horizontal and vertical offset as close as possible to original ones. > + > + > + > +On success field v4l2_selection::r contains s/field/the field/ > +adjusted rectangle. When the parameters are unsuitable the application may s/adjusted/the adjusted/ > +modify the cropping (composing) or image parameters and repeat the cycle until > +satisfactory parameters have been negotiated. > + > + > + > + > + > + Selection targets. > + > + &cs-def; > + > + > + V4L2_SEL_CROP_ACTIVE > + 0 > + area that is currently cropped by hardware > + > + > + V4L2_SEL_CROP_DEFAULT > + 1 > + suggested cropping rectangle that covers the "whole picture" > + > + > + V4L2_SEL_CROP_BOUNDS > + 2 > + limits for the cropping rectangle > + > + > + V4L2_SEL_COMPOSE_ACTIVE > + 256 > + area to which data are composed by hardware > + > + > + V4L2_SEL_COMPOSE_DEFAULT > + 257 > + suggested composing rectangle that covers the "whole picture" > + > + > + V4L2_SEL_COMPOSE_BOUNDS > + 258 > + limits for the composing rectangle > + > + > + V4L2_SEL_COMPOSE_PADDED > + 259 > + the active area and all padding pixels that are inserted or modified by the hardware > + > + > + > +
> +
> + > + > + > + Selection constraint flags > + > + &cs-def; > + > + > + V4L2_SEL_SIZE_GE > + 0x00000001 > + indicate that adjusted rectangle must contain a rectangle from v4l2_selection::r > + > + > + V4L2_SEL_SIZE_LE > + 0x00000002 > + indicate that adjusted rectangle must be inside a rectangle from v4l2_selection::r > + > + > + > +
> +
> + > +
> +
> + Size adjustments with constraint flags. > + > + > + > + > + > + Behaviour of rectangle adjustment for different constraint > + flags. > + > + > +
> +
> + > + > + > + struct <structname>v4l2_selection</structname> > + > + &cs-str; > + > + > + __u32 > + type > + Type of the buffer (from &v4l2-buf-type;) > + > + > + __u32 > + target > + used to select between cropping and composing rectangles > + > + > + __u32 > + flags > + control over coordinates adjustments, refer to selection flags > + > + > + &v4l2-rect; > + r > + selection rectangle > + > + > + __u32 > + reserved[9] > + Reserved fields for future use, adjust size to 64 bytes > + > + > + > +
> +
> + > + > + &return-value; > + > + > + EINVAL > + > + The buffer type or target > +is not supported, or the flags is invalid. s/is invalid/are invalid/ > + > + > + > + ERANGE > + > + it is not possible to adjust a selection rectangle r > +that satisfy all contraints from flags. s/satisfy/satisfies/ > + > + > + > + EBUSY > + > + it is not possible to apply change of selection rectangle at the moment. > +Usually because streaming is in progress. > + > + > + > + > + > +
-- Regards, Laurent Pinchart