2016-06-30 16:18:56 +03:00
|
|
|
.. -*- coding: utf-8; mode: rst -*-
|
|
|
|
|
2016-07-01 19:42:29 +03:00
|
|
|
.. _VIDIOC_G_SELECTION:
|
2016-06-30 16:18:56 +03:00
|
|
|
|
|
|
|
********************************************
|
|
|
|
ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
|
|
|
|
********************************************
|
|
|
|
|
2016-07-05 21:14:35 +03:00
|
|
|
Name
|
2016-07-05 13:58:48 +03:00
|
|
|
====
|
2016-06-30 16:18:56 +03:00
|
|
|
|
2016-07-05 13:58:48 +03:00
|
|
|
VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles
|
2016-06-30 16:18:56 +03:00
|
|
|
|
2016-07-05 21:14:35 +03:00
|
|
|
|
|
|
|
Synopsis
|
2016-06-30 16:18:56 +03:00
|
|
|
========
|
|
|
|
|
2016-08-19 22:53:38 +03:00
|
|
|
.. c:function:: int ioctl( int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp )
|
|
|
|
:name: VIDIOC_G_SELECTION
|
|
|
|
|
|
|
|
|
|
|
|
.. c:function:: int ioctl( int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp )
|
|
|
|
:name: VIDIOC_S_SELECTION
|
2016-06-30 16:18:56 +03:00
|
|
|
|
2016-07-05 13:58:48 +03:00
|
|
|
|
2016-07-05 21:14:35 +03:00
|
|
|
Arguments
|
2016-06-30 16:18:56 +03:00
|
|
|
=========
|
|
|
|
|
|
|
|
``fd``
|
|
|
|
File descriptor returned by :ref:`open() <func-open>`.
|
|
|
|
|
|
|
|
``argp``
|
2017-09-02 16:54:48 +03:00
|
|
|
Pointer to struct :c:type:`v4l2_selection`.
|
2016-06-30 16:18:56 +03:00
|
|
|
|
2016-07-05 21:14:35 +03:00
|
|
|
Description
|
2016-06-30 16:18:56 +03:00
|
|
|
===========
|
|
|
|
|
|
|
|
The ioctls are used to query and configure selection rectangles.
|
|
|
|
|
|
|
|
To query the cropping (composing) rectangle set struct
|
2016-08-29 23:37:59 +03:00
|
|
|
:c:type:`v4l2_selection` ``type`` field to the
|
2017-05-08 17:35:06 +03:00
|
|
|
respective buffer type. The next step is setting the
|
2016-08-29 23:37:59 +03:00
|
|
|
value of struct :c:type:`v4l2_selection` ``target``
|
2016-06-30 16:18:56 +03:00
|
|
|
field to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer
|
|
|
|
to table :ref:`v4l2-selections-common` or :ref:`selection-api` for
|
|
|
|
additional targets. The ``flags`` and ``reserved`` fields of struct
|
2016-08-29 23:37:59 +03:00
|
|
|
:c:type:`v4l2_selection` are ignored and they must be
|
2016-06-30 16:18:56 +03:00
|
|
|
filled with zeros. The driver fills the rest of the structure or returns
|
|
|
|
EINVAL error code if incorrect buffer type or target was used. If
|
|
|
|
cropping (composing) is not supported then the active rectangle is not
|
|
|
|
mutable and it is always equal to the bounds rectangle. Finally, the
|
2016-08-29 23:37:59 +03:00
|
|
|
struct :c:type:`v4l2_rect` ``r`` rectangle is filled with
|
2016-06-30 16:18:56 +03:00
|
|
|
the current cropping (composing) coordinates. The coordinates are
|
|
|
|
expressed in driver-dependent units. The only exception are rectangles
|
|
|
|
for images in raw formats, whose coordinates are always expressed in
|
|
|
|
pixels.
|
|
|
|
|
|
|
|
To change the cropping (composing) rectangle set the struct
|
2016-08-29 23:37:59 +03:00
|
|
|
:c:type:`v4l2_selection` ``type`` field to the
|
2017-05-08 17:35:06 +03:00
|
|
|
respective buffer type. The next step is setting the
|
2016-08-29 23:37:59 +03:00
|
|
|
value of struct :c:type:`v4l2_selection` ``target`` to
|
2016-06-30 16:18:56 +03:00
|
|
|
``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table
|
|
|
|
:ref:`v4l2-selections-common` or :ref:`selection-api` for additional
|
2016-08-29 23:37:59 +03:00
|
|
|
targets. The struct :c:type:`v4l2_rect` ``r`` rectangle need
|
2016-06-30 16:18:56 +03:00
|
|
|
to be set to the desired active area. Field struct
|
2016-08-29 23:37:59 +03:00
|
|
|
:c:type:`v4l2_selection` ``reserved`` is ignored and
|
2016-06-30 16:18:56 +03:00
|
|
|
must be filled with zeros. The driver may adjust coordinates of the
|
|
|
|
requested rectangle. An application may introduce constraints to control
|
2016-08-29 23:37:59 +03:00
|
|
|
rounding behaviour. The struct :c:type:`v4l2_selection`
|
2016-06-30 16:18:56 +03:00
|
|
|
``flags`` field must be set to one of the following:
|
|
|
|
|
|
|
|
- ``0`` - The driver can adjust the rectangle size freely and shall
|
|
|
|
choose a crop/compose rectangle as close as possible to the requested
|
|
|
|
one.
|
|
|
|
|
|
|
|
- ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the
|
|
|
|
rectangle. The original rectangle must lay inside the adjusted one.
|
|
|
|
|
|
|
|
- ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the
|
|
|
|
rectangle. The adjusted rectangle must lay inside the original one.
|
|
|
|
|
|
|
|
- ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the
|
|
|
|
size exactly the same as in the requested rectangle.
|
|
|
|
|
|
|
|
Please refer to :ref:`sel-const-adjust`.
|
|
|
|
|
|
|
|
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. The closest possible values of
|
|
|
|
horizontal and vertical offset and sizes are chosen according to
|
|
|
|
following priority:
|
|
|
|
|
|
|
|
1. Satisfy constraints from struct
|
2016-08-29 23:37:59 +03:00
|
|
|
:c:type:`v4l2_selection` ``flags``.
|
2016-06-30 16:18:56 +03:00
|
|
|
|
|
|
|
2. Adjust width, height, left, and top to hardware limits and
|
|
|
|
alignments.
|
|
|
|
|
|
|
|
3. Keep center of adjusted rectangle as close as possible to the
|
|
|
|
original one.
|
|
|
|
|
|
|
|
4. Keep width and height as close as possible to original ones.
|
|
|
|
|
|
|
|
5. Keep horizontal and vertical offset as close as possible to original
|
|
|
|
ones.
|
|
|
|
|
2016-08-29 23:37:59 +03:00
|
|
|
On success the struct :c:type:`v4l2_rect` ``r`` field
|
2016-06-30 16:18:56 +03:00
|
|
|
contains the adjusted rectangle. When the parameters are unsuitable the
|
|
|
|
application may modify the cropping (composing) or image parameters and
|
|
|
|
repeat the cycle until satisfactory parameters have been negotiated. If
|
2016-07-03 17:53:09 +03:00
|
|
|
constraints flags have to be violated at then ``ERANGE`` is returned. The
|
2016-06-30 16:18:56 +03:00
|
|
|
error indicates that *there exist no rectangle* that satisfies the
|
|
|
|
constraints.
|
|
|
|
|
|
|
|
Selection targets and flags are documented in
|
|
|
|
:ref:`v4l2-selections-common`.
|
|
|
|
|
|
|
|
|
|
|
|
.. _sel-const-adjust:
|
|
|
|
|
2017-06-19 02:33:00 +03:00
|
|
|
.. kernel-figure:: constraints.svg
|
|
|
|
:alt: constraints.svg
|
2016-06-30 16:18:56 +03:00
|
|
|
:align: center
|
|
|
|
|
|
|
|
Size adjustments with constraint flags.
|
|
|
|
|
|
|
|
Behaviour of rectangle adjustment for different constraint flags.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-29 23:37:59 +03:00
|
|
|
.. c:type:: v4l2_selection
|
2016-06-30 16:18:56 +03:00
|
|
|
|
[media] docs-rst: add tabularcolumns to all tables
LaTeX doesn't handle too well auto-width on tables, and ReST
markup requires an special tag to give it the needed hints.
As we're using A4 paper, we have 17cm of useful spaces. As
most media tables have widths, let's use it to generate the
needed via the following perl script:
my ($line_size, $table_header, $has_cols) = (17.5, 0, 0);
my $out;
my $header = "";
my @widths = ();
sub round { $_[0] > 0 ? int($_[0] + .5) : -int(-$_[0] + .5) }
while (<>) {
if (!$table_header) {
$has_cols = 1 if (m/..\s+tabularcolumns::/);
if (m/..\s+flat-table::/) {
$table_header = 1;
$header = $_;
next;
}
$out .= $_;
next;
}
$header .= $_;
@widths = split(/ /, $1) if (m/:widths:\s+(.*)/);
if (m/^\n$/) {
if (!$has_cols && @widths) {
my ($tot, $t, $i) = (0, 0, 0);
foreach my $v(@widths) { $tot += $v; };
$out .= ".. tabularcolumns:: |";
for ($i = 0; $i < scalar @widths - 1; $i++) {
my $v = $widths[$i];
my $w = round(10 * ($v * $line_size) / $tot) / 10;
$out .= sprintf "p{%.1fcm}|", $w;
$t += $w;
}
my $w = $line_size - $t;
$out .= sprintf "p{%.1fcm}|\n\n", $w;
}
$out .= $header;
$table_header = 0;
$has_cols = 0;
$header = "";
@widths = ();
}
}
print $out;
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-08-17 14:14:19 +03:00
|
|
|
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
|
|
|
|
|
2016-06-30 16:18:56 +03:00
|
|
|
.. flat-table:: struct v4l2_selection
|
|
|
|
:header-rows: 0
|
|
|
|
:stub-columns: 0
|
|
|
|
:widths: 1 1 2
|
|
|
|
|
[media] v4l: doc: Remove row numbers from tables
Shorten the tables by removing row numbers in comments, allowing for
later insertion of rows with minimal diffs.
All changes have been generated by the following script.
import io
import re
import sys
def process_table(fname, data):
if fname.endswith('hist-v4l2.rst'):
data = re.sub(u'\n{1,2}\t( ?) -( ?) ?', u'\n\t\\1 -\\2', data, flags = re.MULTILINE)
data = re.sub(u'\n(\t| )- \.\. row [0-9]+\n\t ?-( ?) ?', u'\\1* -\\2', data, flags = re.MULTILINE)
else:
data = re.sub(u'\n{1,2} -( ?) ?', u'\n -\\1', data, flags = re.MULTILINE)
data = re.sub(u'(\n?)(\n\n - \.\. row 1\n)', u'\n\\2', data, flags = re.MULTILINE)
data = re.sub(u'\n - \.\. row [0-9]+\n -( ?) ?', u' * -\\1', data, flags = re.MULTILINE)
data = re.sub(u'\n - \.\. row [0-9]+\n \.\. (_[A-Z0-9_`-]*:)', u'\n - .. \\1', data, flags = re.MULTILINE)
data = re.sub(u'\n - \.\. (_[A-Z0-9_`-]*:)\n -', u' * .. \\1\n\n -', data, flags = re.MULTILINE)
data = re.sub(u'^ - ', u' -', data, flags = re.MULTILINE)
data = re.sub(u'^(\t{1,2}) ', u'\\1', data, flags = re.MULTILINE)
return data
def process_file(fname, data):
buf = io.StringIO(data)
output = ''
in_table = False
table_separator = 0
for line in buf.readlines():
if line.find('.. flat-table::') != -1:
in_table = True
table = ''
elif in_table and not re.match('^[\t\n]|( )', line):
in_table = False
output += process_table(fname, table)
if in_table:
table += line
else:
output += line
if in_table:
in_table = False
output += process_table(fname, table)
return output
fname = sys.argv[1]
data = file(fname, 'rb').read().decode('utf-8')
data = process_file(fname, data)
file(fname, 'wb').write(data.encode('utf-8'))
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2016-09-05 14:44:34 +03:00
|
|
|
* - __u32
|
|
|
|
- ``type``
|
|
|
|
- Type of the buffer (from enum
|
|
|
|
:c:type:`v4l2_buf_type`).
|
|
|
|
* - __u32
|
|
|
|
- ``target``
|
|
|
|
- Used to select between
|
|
|
|
:ref:`cropping and composing rectangles <v4l2-selections-common>`.
|
|
|
|
* - __u32
|
|
|
|
- ``flags``
|
|
|
|
- Flags controlling the selection rectangle adjustments, refer to
|
|
|
|
:ref:`selection flags <v4l2-selection-flags>`.
|
|
|
|
* - struct :c:type:`v4l2_rect`
|
|
|
|
- ``r``
|
|
|
|
- The selection rectangle.
|
|
|
|
* - __u32
|
|
|
|
- ``reserved[9]``
|
|
|
|
- Reserved fields for future use. Drivers and applications must zero
|
|
|
|
this array.
|
2016-06-30 16:18:56 +03:00
|
|
|
|
2017-05-08 17:35:06 +03:00
|
|
|
.. note::
|
|
|
|
Unfortunately in the case of multiplanar buffer types
|
|
|
|
(``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``)
|
|
|
|
this API was messed up with regards to how the :c:type:`v4l2_selection` ``type`` field
|
|
|
|
should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while
|
|
|
|
other drivers only accepted a non-multiplanar buffer type (i.e. without the
|
|
|
|
``_MPLANE`` at the end).
|
|
|
|
|
|
|
|
Starting with kernel 4.13 both variations are allowed.
|
|
|
|
|
2016-06-30 16:18:56 +03:00
|
|
|
|
2016-07-05 21:14:35 +03:00
|
|
|
Return Value
|
2016-06-30 16:18:56 +03:00
|
|
|
============
|
|
|
|
|
|
|
|
On success 0 is returned, on error -1 and the ``errno`` variable is set
|
|
|
|
appropriately. The generic error codes are described at the
|
|
|
|
:ref:`Generic Error Codes <gen-errors>` chapter.
|
|
|
|
|
|
|
|
EINVAL
|
|
|
|
Given buffer type ``type`` or the selection target ``target`` is not
|
|
|
|
supported, or the ``flags`` argument is not valid.
|
|
|
|
|
|
|
|
ERANGE
|
2016-08-29 23:37:59 +03:00
|
|
|
It is not possible to adjust struct :c:type:`v4l2_rect`
|
2016-06-30 16:18:56 +03:00
|
|
|
``r`` rectangle to satisfy all constraints given in the ``flags``
|
|
|
|
argument.
|
|
|
|
|
2016-07-20 15:39:42 +03:00
|
|
|
ENODATA
|
|
|
|
Selection is not supported for this input or output.
|
|
|
|
|
2016-06-30 16:18:56 +03:00
|
|
|
EBUSY
|
|
|
|
It is not possible to apply change of the selection rectangle at the
|
|
|
|
moment. Usually because streaming is in progress.
|