[media] v4l: v4l2_subdev userspace format API

Add a userspace API to get, set and enumerate the media format on a
subdev pad.

The format at the output of a subdev usually depends on the format at
its input(s). The try format operation is thus not suitable for probing
format at individual pads, as it can't modify the device state and thus
can't remember the format tried at the input to compute the output
format.

To fix the problem, pass an extra argument to the get/set format
operations to select the 'try' or 'active' format.

The try format is used when probing the subdev. Setting the try format
must not change the device configuration but can store data for later
reuse. Data storage is provided at the file-handle level so applications
probing the subdev concurently won't interfere with each other.

The active format is used when configuring the subdev. It's identical to
the format handled by the usual get/set operations.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Stanimir Varbanov <svarbanov@mm-sol.com>
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Laurent Pinchart 2010-03-15 20:26:04 -03:00 committed by Mauro Carvalho Chehab
parent d3a7ed9975
commit 333c8b9778
13 changed files with 3332 additions and 1 deletions

View file

@ -53,7 +53,10 @@ MAN := $(patsubst %.xml, %.9, $(BOOKS))
mandocs: $(MAN)
build_images = mkdir -p $(objtree)/Documentation/DocBook/media/ && \
cp $(srctree)/Documentation/DocBook/dvb/*.png $(srctree)/Documentation/DocBook/v4l/*.gif $(objtree)/Documentation/DocBook/media/
cp $(srctree)/Documentation/DocBook/dvb/*.png \
$(srctree)/Documentation/DocBook/v4l/*.gif \
$(srctree)/Documentation/DocBook/v4l/*.png \
$(objtree)/Documentation/DocBook/media/
xmldoclinks:
ifneq ($(objtree),$(srctree))

View file

@ -86,6 +86,10 @@
<!ENTITY VIDIOC-S-PRIORITY "<link linkend='vidioc-g-priority'><constant>VIDIOC_S_PRIORITY</constant></link>">
<!ENTITY VIDIOC-S-STD "<link linkend='vidioc-g-std'><constant>VIDIOC_S_STD</constant></link>">
<!ENTITY VIDIOC-S-TUNER "<link linkend='vidioc-g-tuner'><constant>VIDIOC_S_TUNER</constant></link>">
<!ENTITY VIDIOC-SUBDEV-ENUM-FRAME-SIZE "<link linkend='vidioc-subdev-enum-frame-size'><constant>VIDIOC_SUBDEV_ENUM_FRAME_SIZE</constant></link>">
<!ENTITY VIDIOC-SUBDEV-ENUM-MBUS-CODE "<link linkend='vidioc-subdev-enum-mbus-code'><constant>VIDIOC_SUBDEV_ENUM_MBUS_CODE</constant></link>">
<!ENTITY VIDIOC-SUBDEV-G-FMT "<link linkend='vidioc-subdev-g-fmt'><constant>VIDIOC_SUBDEV_G_FMT</constant></link>">
<!ENTITY VIDIOC-SUBDEV-S-FMT "<link linkend='vidioc-subdev-g-fmt'><constant>VIDIOC_SUBDEV_S_FMT</constant></link>">
<!ENTITY VIDIOC-TRY-ENCODER-CMD "<link linkend='vidioc-encoder-cmd'><constant>VIDIOC_TRY_ENCODER_CMD</constant></link>">
<!ENTITY VIDIOC-TRY-EXT-CTRLS "<link linkend='vidioc-g-ext-ctrls'><constant>VIDIOC_TRY_EXT_CTRLS</constant></link>">
<!ENTITY VIDIOC-TRY-FMT "<link linkend='vidioc-g-fmt'><constant>VIDIOC_TRY_FMT</constant></link>">
@ -107,6 +111,7 @@
<!ENTITY v4l2-field "enum&nbsp;<link linkend='v4l2-field'>v4l2_field</link>">
<!ENTITY v4l2-frmivaltypes "enum&nbsp;<link linkend='v4l2-frmivaltypes'>v4l2_frmivaltypes</link>">
<!ENTITY v4l2-frmsizetypes "enum&nbsp;<link linkend='v4l2-frmsizetypes'>v4l2_frmsizetypes</link>">
<!ENTITY v4l2-mbus-pixelcode "enum&nbsp;<link linkend='v4l2-mbus-pixelcode'>v4l2_mbus_pixelcode</link>">
<!ENTITY v4l2-memory "enum&nbsp;<link linkend='v4l2-memory'>v4l2_memory</link>">
<!ENTITY v4l2-mpeg-audio-ac3-bitrate "enum&nbsp;<link linkend='v4l2-mpeg-audio-ac3-bitrate'>v4l2_mpeg_audio_ac3_bitrate</link>">
<!ENTITY v4l2-mpeg-audio-crc "enum&nbsp;<link linkend='v4l2-mpeg-audio-crc'>v4l2_mpeg_audio_crc</link>">
@ -130,6 +135,7 @@
<!ENTITY v4l2-mpeg-video-encoding "enum&nbsp;<link linkend='v4l2-mpeg-video-encoding'>v4l2_mpeg_video_encoding</link>">
<!ENTITY v4l2-power-line-frequency "enum&nbsp;<link linkend='v4l2-power-line-frequency'>v4l2_power_line_frequency</link>">
<!ENTITY v4l2-priority "enum&nbsp;<link linkend='v4l2-priority'>v4l2_priority</link>">
<!ENTITY v4l2-subdev-format-whence "enum&nbsp;<link linkend='v4l2-subdev-format-whence'>v4l2_subdev_format_whence</link>">
<!ENTITY v4l2-tuner-type "enum&nbsp;<link linkend='v4l2-tuner-type'>v4l2_tuner_type</link>">
<!ENTITY v4l2-preemphasis "enum&nbsp;<link linkend='v4l2-preemphasis'>v4l2_preemphasis</link>">
@ -172,6 +178,7 @@
<!ENTITY v4l2-hw-freq-seek "struct&nbsp;<link linkend='v4l2-hw-freq-seek'>v4l2_hw_freq_seek</link>">
<!ENTITY v4l2-input "struct&nbsp;<link linkend='v4l2-input'>v4l2_input</link>">
<!ENTITY v4l2-jpegcompression "struct&nbsp;<link linkend='v4l2-jpegcompression'>v4l2_jpegcompression</link>">
<!ENTITY v4l2-mbus-framefmt "struct&nbsp;<link linkend='v4l2-mbus-framefmt'>v4l2_mbus_framefmt</link>">
<!ENTITY v4l2-modulator "struct&nbsp;<link linkend='v4l2-modulator'>v4l2_modulator</link>">
<!ENTITY v4l2-mpeg-vbi-fmt-ivtv "struct&nbsp;<link linkend='v4l2-mpeg-vbi-fmt-ivtv'>v4l2_mpeg_vbi_fmt_ivtv</link>">
<!ENTITY v4l2-output "struct&nbsp;<link linkend='v4l2-output'>v4l2_output</link>">
@ -186,6 +193,9 @@
<!ENTITY v4l2-sliced-vbi-cap "struct&nbsp;<link linkend='v4l2-sliced-vbi-cap'>v4l2_sliced_vbi_cap</link>">
<!ENTITY v4l2-sliced-vbi-data "struct&nbsp;<link linkend='v4l2-sliced-vbi-data'>v4l2_sliced_vbi_data</link>">
<!ENTITY v4l2-sliced-vbi-format "struct&nbsp;<link linkend='v4l2-sliced-vbi-format'>v4l2_sliced_vbi_format</link>">
<!ENTITY v4l2-subdev-frame-size-enum "struct&nbsp;<link linkend='v4l2-subdev-frame-size-enum'>v4l2_subdev_frame_size_enum</link>">
<!ENTITY v4l2-subdev-format "struct&nbsp;<link linkend='v4l2-subdev-format'>v4l2_subdev_format</link>">
<!ENTITY v4l2-subdev-mbus-code-enum "struct&nbsp;<link linkend='v4l2-subdev-mbus-code-enum'>v4l2_subdev_mbus_code_enum</link>">
<!ENTITY v4l2-standard "struct&nbsp;<link linkend='v4l2-standard'>v4l2_standard</link>">
<!ENTITY v4l2-streamparm "struct&nbsp;<link linkend='v4l2-streamparm'>v4l2_streamparm</link>">
<!ENTITY v4l2-timecode "struct&nbsp;<link linkend='v4l2-timecode'>v4l2_timecode</link>">
@ -215,6 +225,7 @@
<!ENTITY ENXIO "<errorcode>ENXIO</errorcode> error code">
<!ENTITY EMFILE "<errorcode>EMFILE</errorcode> error code">
<!ENTITY EPERM "<errorcode>EPERM</errorcode> error code">
<!ENTITY EPIPE "<errorcode>EPIPE</errorcode> error code">
<!ENTITY ERANGE "<errorcode>ERANGE</errorcode> error code">
<!-- Subsections -->
@ -234,6 +245,7 @@
<!ENTITY sub-dev-raw-vbi SYSTEM "v4l/dev-raw-vbi.xml">
<!ENTITY sub-dev-rds SYSTEM "v4l/dev-rds.xml">
<!ENTITY sub-dev-sliced-vbi SYSTEM "v4l/dev-sliced-vbi.xml">
<!ENTITY sub-dev-subdev SYSTEM "v4l/dev-subdev.xml">
<!ENTITY sub-dev-teletext SYSTEM "v4l/dev-teletext.xml">
<!ENTITY sub-driver SYSTEM "v4l/driver.xml">
<!ENTITY sub-libv4l SYSTEM "v4l/libv4l.xml">
@ -319,6 +331,10 @@
<!ENTITY sub-reqbufs SYSTEM "v4l/vidioc-reqbufs.xml">
<!ENTITY sub-s-hw-freq-seek SYSTEM "v4l/vidioc-s-hw-freq-seek.xml">
<!ENTITY sub-streamon SYSTEM "v4l/vidioc-streamon.xml">
<!ENTITY sub-subdev-enum-frame-size SYSTEM "v4l/vidioc-subdev-enum-frame-size.xml">
<!ENTITY sub-subdev-enum-mbus-code SYSTEM "v4l/vidioc-subdev-enum-mbus-code.xml">
<!ENTITY sub-subdev-formats SYSTEM "v4l/subdev-formats.xml">
<!ENTITY sub-subdev-g-fmt SYSTEM "v4l/vidioc-subdev-g-fmt.xml">
<!ENTITY sub-capture-c SYSTEM "v4l/capture.c.xml">
<!ENTITY sub-keytable-c SYSTEM "v4l/keytable.c.xml">
<!ENTITY sub-v4l2grab-c SYSTEM "v4l/v4l2grab.c.xml">

View file

@ -0,0 +1,280 @@
<title>Sub-device Interface</title>
<note>
<title>Experimental</title>
<para>This is an <link linkend="experimental">experimental</link>
interface and may change in the future.</para>
</note>
<para>The complex nature of V4L2 devices, where hardware is often made of
several integrated circuits that need to interact with each other in a
controlled way, leads to complex V4L2 drivers. The drivers usually reflect
the hardware model in software, and model the different hardware components
as software blocks called sub-devices.</para>
<para>V4L2 sub-devices are usually kernel-only objects. If the V4L2 driver
implements the media device API, they will automatically inherit from media
entities. Applications will be able to enumerate the sub-devices and discover
the hardware topology using the media entities, pads and links enumeration
API.</para>
<para>In addition to make sub-devices discoverable, drivers can also choose
to make them directly configurable by applications. When both the sub-device
driver and the V4L2 device driver support this, sub-devices will feature a
character device node on which ioctls can be called to
<itemizedlist>
<listitem>query, read and write sub-devices controls</listitem>
<listitem>subscribe and unsubscribe to events and retrieve them</listitem>
<listitem>negotiate image formats on individual pads</listitem>
</itemizedlist>
</para>
<para>Sub-device character device nodes, conventionally named
<filename>/dev/v4l-subdev*</filename>, use major number 81.</para>
<section>
<title>Controls</title>
<para>Most V4L2 controls are implemented by sub-device hardware. Drivers
usually merge all controls and expose them through video device nodes.
Applications can control all sub-devices through a single interface.</para>
<para>Complex devices sometimes implement the same control in different
pieces of hardware. This situation is common in embedded platforms, where
both sensors and image processing hardware implement identical functions,
such as contrast adjustment, white balance or faulty pixels correction. As
the V4L2 controls API doesn't support several identical controls in a single
device, all but one of the identical controls are hidden.</para>
<para>Applications can access those hidden controls through the sub-device
node with the V4L2 control API described in <xref linkend="control" />. The
ioctls behave identically as when issued on V4L2 device nodes, with the
exception that they deal only with controls implemented in the sub-device.
</para>
<para>Depending on the driver, those controls might also be exposed through
one (or several) V4L2 device nodes.</para>
</section>
<section>
<title>Events</title>
<para>V4L2 sub-devices can notify applications of events as described in
<xref linkend="event" />. The API behaves identically as when used on V4L2
device nodes, with the exception that it only deals with events generated by
the sub-device. Depending on the driver, those events might also be reported
on one (or several) V4L2 device nodes.</para>
</section>
<section id="pad-level-formats">
<title>Pad-level Formats</title>
<warning>Pad-level formats are only applicable to very complex device that
need to expose low-level format configuration to user space. Generic V4L2
applications do <emphasis>not</emphasis> need to use the API described in
this section.</warning>
<note>For the purpose of this section, the term
<wordasword>format</wordasword> means the combination of media bus data
format, frame width and frame height.</note>
<para>Image formats are typically negotiated on video capture and output
devices using the <link linkend="crop">cropping and scaling</link> ioctls.
The driver is responsible for configuring every block in the video pipeline
according to the requested format at the pipeline input and/or
output.</para>
<para>For complex devices, such as often found in embedded systems,
identical image sizes at the output of a pipeline can be achieved using
different hardware configurations. One such exemple is shown on
<xref linkend="pipeline-scaling" xrefstyle="template: Figure %n" />, where
image scaling can be performed on both the video sensor and the host image
processing hardware.</para>
<figure id="pipeline-scaling">
<title>Image Format Negotation on Pipelines</title>
<mediaobject>
<imageobject>
<imagedata fileref="pipeline.pdf" format="PS" />
</imageobject>
<imageobject>
<imagedata fileref="pipeline.png" format="PNG" />
</imageobject>
<textobject>
<phrase>High quality and high speed pipeline configuration</phrase>
</textobject>
</mediaobject>
</figure>
<para>The sensor scaler is usually of less quality than the host scaler, but
scaling on the sensor is required to achieve higher frame rates. Depending
on the use case (quality vs. speed), the pipeline must be configured
differently. Applications need to configure the formats at every point in
the pipeline explicitly.</para>
<para>Drivers that implement the <link linkend="media-controller-intro">media
API</link> can expose pad-level image format configuration to applications.
When they do, applications can use the &VIDIOC-SUBDEV-G-FMT; and
&VIDIOC-SUBDEV-S-FMT; ioctls. to negotiate formats on a per-pad basis.</para>
<para>Applications are responsible for configuring coherent parameters on
the whole pipeline and making sure that connected pads have compatible
formats. The pipeline is checked for formats mismatch at &VIDIOC-STREAMON;
time, and an &EPIPE; is then returned if the configuration is
invalid.</para>
<para>Pad-level image format configuration support can be tested by calling
the &VIDIOC-SUBDEV-G-FMT; ioctl on pad 0. If the driver returns an &EINVAL;
pad-level format configuration is not supported by the sub-device.</para>
<section>
<title>Format Negotiation</title>
<para>Acceptable formats on pads can (and usually do) depend on a number
of external parameters, such as formats on other pads, active links, or
even controls. Finding a combination of formats on all pads in a video
pipeline, acceptable to both application and driver, can't rely on formats
enumeration only. A format negotiation mechanism is required.</para>
<para>Central to the format negotiation mechanism are the get/set format
operations. When called with the <structfield>which</structfield> argument
set to <constant>V4L2_SUBDEV_FORMAT_TRY</constant>, the
&VIDIOC-SUBDEV-G-FMT; and &VIDIOC-SUBDEV-S-FMT; ioctls operate on a set of
formats parameters that are not connected to the hardware configuration.
Modifying those 'try' formats leaves the device state untouched (this
applies to both the software state stored in the driver and the hardware
state stored in the device itself).</para>
<para>While not kept as part of the device state, try formats are stored
in the sub-device file handles. A &VIDIOC-SUBDEV-G-FMT; call will return
the last try format set <emphasis>on the same sub-device file
handle</emphasis>. Several applications querying the same sub-device at
the same time will thus not interact with each other.</para>
<para>To find out whether a particular format is supported by the device,
applications use the &VIDIOC-SUBDEV-S-FMT; ioctl. Drivers verify and, if
needed, change the requested <structfield>format</structfield> based on
device requirements and return the possibly modified value. Applications
can then choose to try a different format or accept the returned value and
continue.</para>
<para>Formats returned by the driver during a negotiation iteration are
guaranteed to be supported by the device. In particular, drivers guarantee
that a returned format will not be further changed if passed to an
&VIDIOC-SUBDEV-S-FMT; call as-is (as long as external parameters, such as
formats on other pads or links' configuration are not changed).</para>
<para>Drivers automatically propagate formats inside sub-devices. When a
try or active format is set on a pad, corresponding formats on other pads
of the same sub-device can be modified by the driver. Drivers are free to
modify formats as required by the device. However, they should comply with
the following rules when possible:
<itemizedlist>
<listitem>Formats should be propagated from sink pads to source pads.
Modifying a format on a source pad should not modify the format on any
sink pad.</listitem>
<listitem>Sub-devices that scale frames using variable scaling factors
should reset the scale factors to default values when sink pads formats
are modified. If the 1:1 scaling ratio is supported, this means that
source pads formats should be reset to the sink pads formats.</listitem>
</itemizedlist>
</para>
<para>Formats are not propagated across links, as that would involve
propagating them from one sub-device file handle to another. Applications
must then take care to configure both ends of every link explicitly with
compatible formats. Identical formats on the two ends of a link are
guaranteed to be compatible. Drivers are free to accept different formats
matching device requirements as being compatible.</para>
<para><xref linkend="sample-pipeline-config" xrefstyle="template:Table %n"/>
shows a sample configuration sequence for the pipeline described in
<xref linkend="pipeline-scaling" xrefstyle="template:Figure %n"/> (table
columns list entity names and pad numbers).</para>
<table pgwide="0" frame="none" id="sample-pipeline-config">
<title>Sample Pipeline Configuration</title>
<tgroup cols="3">
<colspec colname="what"/>
<colspec colname="sensor-0" />
<colspec colname="frontend-0" />
<colspec colname="frontend-1" />
<colspec colname="scaler-0" />
<colspec colname="scaler-1" />
<thead>
<row>
<entry></entry>
<entry>Sensor/0</entry>
<entry>Frontend/0</entry>
<entry>Frontend/1</entry>
<entry>Scaler/0</entry>
<entry>Scaler/1</entry>
</row>
</thead>
<tbody valign="top">
<row>
<entry>Initial state</entry>
<entry>2048x1536</entry>
<entry>-</entry>
<entry>-</entry>
<entry>-</entry>
<entry>-</entry>
</row>
<row>
<entry>Configure frontend input</entry>
<entry>2048x1536</entry>
<entry><emphasis>2048x1536</emphasis></entry>
<entry><emphasis>2046x1534</emphasis></entry>
<entry>-</entry>
<entry>-</entry>
</row>
<row>
<entry>Configure scaler input</entry>
<entry>2048x1536</entry>
<entry>2048x1536</entry>
<entry>2046x1534</entry>
<entry><emphasis>2046x1534</emphasis></entry>
<entry><emphasis>2046x1534</emphasis></entry>
</row>
<row>
<entry>Configure scaler output</entry>
<entry>2048x1536</entry>
<entry>2048x1536</entry>
<entry>2046x1534</entry>
<entry>2046x1534</entry>
<entry><emphasis>1280x960</emphasis></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<orderedlist>
<listitem>Initial state. The sensor output is set to its native 3MP
resolution. Resolutions on the host frontend and scaler input and output
pads are undefined.</listitem>
<listitem>The application configures the frontend input pad resolution to
2048x1536. The driver propagates the format to the frontend output pad.
Note that the propagated output format can be different, as in this case,
than the input format, as the hardware might need to crop pixels (for
instance when converting a Bayer filter pattern to RGB or YUV).</listitem>
<listitem>The application configures the scaler input pad resolution to
2046x1534 to match the frontend output resolution. The driver propagates
the format to the scaler output pad.</listitem>
<listitem>The application configures the scaler output pad resolution to
1280x960.</listitem>
</orderedlist>
</para>
<para>When satisfied with the try results, applications can set the active
formats by setting the <structfield>which</structfield> argument to
<constant>V4L2_SUBDEV_FORMAT_TRY</constant>. Active formats are changed
exactly as try formats by drivers. To avoid modifying the hardware state
during format negotiation, applications should negotiate try formats first
and then modify the active settings using the try formats returned during
the last negotiation iteration. This guarantees that the active format
will be applied as-is by the driver without being modified.
</para>
</section>
</section>
&sub-subdev-formats;

File diff suppressed because it is too large Load diff

View file

@ -439,6 +439,7 @@ and discussions on the V4L mailing list.</revremark>
<section id="radio"> &sub-dev-radio; </section>
<section id="rds"> &sub-dev-rds; </section>
<section id="event"> &sub-dev-event; </section>
<section id="subdev"> &sub-dev-subdev; </section>
</chapter>
<chapter id="driver">
@ -506,6 +507,9 @@ and discussions on the V4L mailing list.</revremark>
&sub-reqbufs;
&sub-s-hw-freq-seek;
&sub-streamon;
&sub-subdev-enum-frame-size;
&sub-subdev-enum-mbus-code;
&sub-subdev-g-fmt;
&sub-subscribe-event;
<!-- End of ioctls. -->
&sub-mmap;

View file

@ -93,6 +93,15 @@ synchronize with other events.</para>
been allocated (memory mapping) or enqueued (output) yet.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><errorcode>EPIPE</errorcode></term>
<listitem>
<para>The driver implements <link
linkend="pad-level-formats">pad-level format configuration</link> and
the pipeline configuration is invalid.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
</refentry>

View file

@ -0,0 +1,154 @@
<refentry id="vidioc-subdev-enum-frame-size">
<refmeta>
<refentrytitle>ioctl VIDIOC_SUBDEV_ENUM_FRAME_SIZE</refentrytitle>
&manvol;
</refmeta>
<refnamediv>
<refname>VIDIOC_SUBDEV_ENUM_FRAME_SIZE</refname>
<refpurpose>Enumerate media bus frame sizes</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ioctl</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
<paramdef>int <parameter>request</parameter></paramdef>
<paramdef>struct v4l2_subdev_frame_size_enum *
<parameter>argp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Arguments</title>
<variablelist>
<varlistentry>
<term><parameter>fd</parameter></term>
<listitem>
<para>&fd;</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>request</parameter></term>
<listitem>
<para>VIDIOC_SUBDEV_ENUM_FRAME_SIZE</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>argp</parameter></term>
<listitem>
<para></para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<note>
<title>Experimental</title>
<para>This is an <link linkend="experimental">experimental</link>
interface and may change in the future.</para>
</note>
<para>This ioctl allows applications to enumerate all frame sizes
supported by a sub-device on the given pad for the given media bus format.
Supported formats can be retrieved with the &VIDIOC-SUBDEV-ENUM-MBUS-CODE;
ioctl.</para>
<para>To enumerate frame sizes applications initialize the
<structfield>pad</structfield>, <structfield>code</structfield> and
<structfield>index</structfield> fields of the
&v4l2-subdev-mbus-code-enum; and call the
<constant>VIDIOC_SUBDEV_ENUM_FRAME_SIZE</constant> ioctl with a pointer to
the structure. Drivers fill the minimum and maximum frame sizes or return
an &EINVAL; if one of the input parameters is invalid.</para>
<para>Sub-devices that only support discrete frame sizes (such as most
sensors) will return one or more frame sizes with identical minimum and
maximum values.</para>
<para>Not all possible sizes in given [minimum, maximum] ranges need to be
supported. For instance, a scaler that uses a fixed-point scaling ratio
might not be able to produce every frame size between the minimum and
maximum values. Applications must use the &VIDIOC-SUBDEV-S-FMT; ioctl to
try the sub-device for an exact supported frame size.</para>
<para>Available frame sizes may depend on the current 'try' formats at other
pads of the sub-device, as well as on the current active links and the
current values of V4L2 controls. See &VIDIOC-SUBDEV-G-FMT; for more
information about try formats.</para>
<table pgwide="1" frame="none" id="v4l2-subdev-frame-size-enum">
<title>struct <structname>v4l2_subdev_frame_size_enum</structname></title>
<tgroup cols="3">
&cs-str;
<tbody valign="top">
<row>
<entry>__u32</entry>
<entry><structfield>index</structfield></entry>
<entry>Number of the format in the enumeration, set by the
application.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>pad</structfield></entry>
<entry>Pad number as reported by the media controller API.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>code</structfield></entry>
<entry>The media bus format code, as defined in
<xref linkend="v4l2-mbus-format" />.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>min_width</structfield></entry>
<entry>Minimum frame width, in pixels.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>max_width</structfield></entry>
<entry>Maximum frame width, in pixels.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>min_height</structfield></entry>
<entry>Minimum frame height, in pixels.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>max_height</structfield></entry>
<entry>Maximum frame height, in pixels.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>reserved</structfield>[9]</entry>
<entry>Reserved for future extensions. Applications and drivers must
set the array to zero.</entry>
</row>
</tbody>
</tgroup>
</table>
</refsect1>
<refsect1>
&return-value;
<variablelist>
<varlistentry>
<term><errorcode>EINVAL</errorcode></term>
<listitem>
<para>The &v4l2-subdev-frame-size-enum; <structfield>pad</structfield>
references a non-existing pad, the <structfield>code</structfield> is
invalid for the given pad or the <structfield>index</structfield>
field is out of bounds.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
</refentry>

View file

@ -0,0 +1,119 @@
<refentry id="vidioc-subdev-enum-mbus-code">
<refmeta>
<refentrytitle>ioctl VIDIOC_SUBDEV_ENUM_MBUS_CODE</refentrytitle>
&manvol;
</refmeta>
<refnamediv>
<refname>VIDIOC_SUBDEV_ENUM_MBUS_CODE</refname>
<refpurpose>Enumerate media bus formats</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ioctl</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
<paramdef>int <parameter>request</parameter></paramdef>
<paramdef>struct v4l2_subdev_mbus_code_enum *
<parameter>argp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Arguments</title>
<variablelist>
<varlistentry>
<term><parameter>fd</parameter></term>
<listitem>
<para>&fd;</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>request</parameter></term>
<listitem>
<para>VIDIOC_SUBDEV_ENUM_MBUS_CODE</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>argp</parameter></term>
<listitem>
<para></para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<note>
<title>Experimental</title>
<para>This is an <link linkend="experimental">experimental</link>
interface and may change in the future.</para>
</note>
<para>To enumerate media bus formats available at a given sub-device pad
applications initialize the <structfield>pad</structfield> and
<structfield>index</structfield> fields of &v4l2-subdev-mbus-code-enum; and
call the <constant>VIDIOC_SUBDEV_ENUM_MBUS_CODE</constant> ioctl with a
pointer to this structure. Drivers fill the rest of the structure or return
an &EINVAL; if either the <structfield>pad</structfield> or
<structfield>index</structfield> are invalid. All media bus formats are
enumerable by beginning at index zero and incrementing by one until
<errorcode>EINVAL</errorcode> is returned.</para>
<para>Available media bus formats may depend on the current 'try' formats
at other pads of the sub-device, as well as on the current active links. See
&VIDIOC-SUBDEV-G-FMT; for more information about the try formats.</para>
<table pgwide="1" frame="none" id="v4l2-subdev-mbus-code-enum">
<title>struct <structname>v4l2_subdev_mbus_code_enum</structname></title>
<tgroup cols="3">
&cs-str;
<tbody valign="top">
<row>
<entry>__u32</entry>
<entry><structfield>pad</structfield></entry>
<entry>Pad number as reported by the media controller API.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>index</structfield></entry>
<entry>Number of the format in the enumeration, set by the
application.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>code</structfield></entry>
<entry>The media bus format code, as defined in
<xref linkend="v4l2-mbus-format" />.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>reserved</structfield>[9]</entry>
<entry>Reserved for future extensions. Applications and drivers must
set the array to zero.</entry>
</row>
</tbody>
</tgroup>
</table>
</refsect1>
<refsect1>
&return-value;
<variablelist>
<varlistentry>
<term><errorcode>EINVAL</errorcode></term>
<listitem>
<para>The &v4l2-subdev-mbus-code-enum; <structfield>pad</structfield>
references a non-existing pad, or the <structfield>index</structfield>
field is out of bounds.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
</refentry>

View file

@ -0,0 +1,180 @@
<refentry id="vidioc-subdev-g-fmt">
<refmeta>
<refentrytitle>ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT</refentrytitle>
&manvol;
</refmeta>
<refnamediv>
<refname>VIDIOC_SUBDEV_G_FMT</refname>
<refname>VIDIOC_SUBDEV_S_FMT</refname>
<refpurpose>Get or set the data format on a subdev pad</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ioctl</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
<paramdef>int <parameter>request</parameter></paramdef>
<paramdef>struct v4l2_subdev_format *<parameter>argp</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Arguments</title>
<variablelist>
<varlistentry>
<term><parameter>fd</parameter></term>
<listitem>
<para>&fd;</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>request</parameter></term>
<listitem>
<para>VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>argp</parameter></term>
<listitem>
<para></para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<note>
<title>Experimental</title>
<para>This is an <link linkend="experimental">experimental</link>
interface and may change in the future.</para>
</note>
<para>These ioctls are used to negotiate the frame format at specific
subdev pads in the image pipeline.</para>
<para>To retrieve the current format applications set the
<structfield>pad</structfield> field of a &v4l2-subdev-format; to the
desired pad number as reported by the media API and the
<structfield>which</structfield> field to
<constant>V4L2_SUBDEV_FORMAT_ACTIVE</constant>. When they call the
<constant>VIDIOC_SUBDEV_G_FMT</constant> ioctl with a pointer to this
structure the driver fills the members of the <structfield>format</structfield>
field.</para>
<para>To change the current format applications set both the
<structfield>pad</structfield> and <structfield>which</structfield> fields
and all members of the <structfield>format</structfield> field. When they
call the <constant>VIDIOC_SUBDEV_S_FMT</constant> ioctl with a pointer to this
structure the driver verifies the requested format, adjusts it based on the
hardware capabilities and configures the device. Upon return the
&v4l2-subdev-format; contains the current format as would be returned by a
<constant>VIDIOC_SUBDEV_G_FMT</constant> call.</para>
<para>Applications can query the device capabilities by setting the
<structfield>which</structfield> to
<constant>V4L2_SUBDEV_FORMAT_TRY</constant>. When set, 'try' formats are not
applied to the device by the driver, but are changed exactly as active
formats and stored in the sub-device file handle. Two applications querying
the same sub-device would thus not interact with each other.</para>
<para>For instance, to try a format at the output pad of a sub-device,
applications would first set the try format at the sub-device input with the
<constant>VIDIOC_SUBDEV_S_FMT</constant> ioctl. They would then either
retrieve the default format at the output pad with the
<constant>VIDIOC_SUBDEV_G_FMT</constant> ioctl, or set the desired output
pad format with the <constant>VIDIOC_SUBDEV_S_FMT</constant> ioctl and check
the returned value.</para>
<para>Try formats do not depend on active formats, but can depend on the
current links configuration or sub-device controls value. For instance, a
low-pass noise filter might crop pixels at the frame boundaries, modifying
its output frame size.</para>
<para>Drivers must not return an error solely because the requested format
doesn't match the device capabilities. They must instead modify the format
to match what the hardware can provide. The modified format should be as
close as possible to the original request.</para>
<table pgwide="1" frame="none" id="v4l2-subdev-format">
<title>struct <structname>v4l2_subdev_format</structname></title>
<tgroup cols="3">
&cs-str;
<tbody valign="top">
<row>
<entry>__u32</entry>
<entry><structfield>pad</structfield></entry>
<entry>Pad number as reported by the media controller API.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>which</structfield></entry>
<entry>Format to modified, from &v4l2-subdev-format-whence;.</entry>
</row>
<row>
<entry>&v4l2-mbus-framefmt;</entry>
<entry><structfield>format</structfield></entry>
<entry>Definition of an image format, see <xref
linkend="v4l2-mbus-framefmt" /> for details.</entry>
</row>
<row>
<entry>__u32</entry>
<entry><structfield>reserved</structfield>[8]</entry>
<entry>Reserved for future extensions. Applications and drivers must
set the array to zero.</entry>
</row>
</tbody>
</tgroup>
</table>
<table pgwide="1" frame="none" id="v4l2-subdev-format-whence">
<title>enum <structname>v4l2_subdev_format_whence</structname></title>
<tgroup cols="3">
&cs-def;
<tbody valign="top">
<row>
<entry>V4L2_SUBDEV_FORMAT_TRY</entry>
<entry>0</entry>
<entry>Try formats, used for querying device capabilities.</entry>
</row>
<row>
<entry>V4L2_SUBDEV_FORMAT_ACTIVE</entry>
<entry>1</entry>
<entry>Active formats, applied to the hardware.</entry>
</row>
</tbody>
</tgroup>
</table>
</refsect1>
<refsect1>
&return-value;
<variablelist>
<varlistentry>
<term><errorcode>EBUSY</errorcode></term>
<listitem>
<para>The format can't be changed because the pad is currently busy.
This can be caused, for instance, by an active video stream on the
pad. The ioctl must not be retried without performing another action
to fix the problem first. Only returned by
<constant>VIDIOC_SUBDEV_S_FMT</constant></para>
</listitem>
</varlistentry>
<varlistentry>
<term><errorcode>EINVAL</errorcode></term>
<listitem>
<para>The &v4l2-subdev-format; <structfield>pad</structfield>
references a non-existing pad, or the <structfield>which</structfield>
field references a non-existing format.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
</refentry>

View file

@ -149,6 +149,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
struct video_device *vdev = video_devdata(file);
struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
struct v4l2_fh *vfh = file->private_data;
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh);
#endif
switch (cmd) {
case VIDIOC_QUERYCTRL:
@ -183,7 +186,53 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_UNSUBSCRIBE_EVENT:
return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg);
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
case VIDIOC_SUBDEV_G_FMT: {
struct v4l2_subdev_format *format = arg;
if (format->which != V4L2_SUBDEV_FORMAT_TRY &&
format->which != V4L2_SUBDEV_FORMAT_ACTIVE)
return -EINVAL;
if (format->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh, format);
}
case VIDIOC_SUBDEV_S_FMT: {
struct v4l2_subdev_format *format = arg;
if (format->which != V4L2_SUBDEV_FORMAT_TRY &&
format->which != V4L2_SUBDEV_FORMAT_ACTIVE)
return -EINVAL;
if (format->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh, format);
}
case VIDIOC_SUBDEV_ENUM_MBUS_CODE: {
struct v4l2_subdev_mbus_code_enum *code = arg;
if (code->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call(sd, pad, enum_mbus_code, subdev_fh,
code);
}
case VIDIOC_SUBDEV_ENUM_FRAME_SIZE: {
struct v4l2_subdev_frame_size_enum *fse = arg;
if (fse->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call(sd, pad, enum_frame_size, subdev_fh,
fse);
}
#endif
default:
return -ENOIOCTLCMD;
}

View file

@ -372,6 +372,7 @@ header-y += usbdevice_fs.h
header-y += utime.h
header-y += utsname.h
header-y += v4l2-mediabus.h
header-y += v4l2-subdev.h
header-y += veth.h
header-y += vhost.h
header-y += videodev2.h

View file

@ -0,0 +1,90 @@
/*
* V4L2 subdev userspace API
*
* Copyright (C) 2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LINUX_V4L2_SUBDEV_H
#define __LINUX_V4L2_SUBDEV_H
#include <linux/ioctl.h>
#include <linux/types.h>
#include <linux/v4l2-mediabus.h>
/**
* enum v4l2_subdev_format_whence - Media bus format type
* @V4L2_SUBDEV_FORMAT_TRY: try format, for negotiation only
* @V4L2_SUBDEV_FORMAT_ACTIVE: active format, applied to the device
*/
enum v4l2_subdev_format_whence {
V4L2_SUBDEV_FORMAT_TRY = 0,
V4L2_SUBDEV_FORMAT_ACTIVE = 1,
};
/**
* struct v4l2_subdev_format - Pad-level media bus format
* @which: format type (from enum v4l2_subdev_format_whence)
* @pad: pad number, as reported by the media API
* @format: media bus format (format code and frame size)
*/
struct v4l2_subdev_format {
__u32 which;
__u32 pad;
struct v4l2_mbus_framefmt format;
__u32 reserved[8];
};
/**
* struct v4l2_subdev_mbus_code_enum - Media bus format enumeration
* @pad: pad number, as reported by the media API
* @index: format index during enumeration
* @code: format code (from enum v4l2_mbus_pixelcode)
*/
struct v4l2_subdev_mbus_code_enum {
__u32 pad;
__u32 index;
__u32 code;
__u32 reserved[9];
};
/**
* struct v4l2_subdev_frame_size_enum - Media bus format enumeration
* @pad: pad number, as reported by the media API
* @index: format index during enumeration
* @code: format code (from enum v4l2_mbus_pixelcode)
*/
struct v4l2_subdev_frame_size_enum {
__u32 index;
__u32 pad;
__u32 code;
__u32 min_width;
__u32 max_width;
__u32 min_height;
__u32 max_height;
__u32 reserved[9];
};
#define VIDIOC_SUBDEV_G_FMT _IOWR('V', 4, struct v4l2_subdev_format)
#define VIDIOC_SUBDEV_S_FMT _IOWR('V', 5, struct v4l2_subdev_format)
#define VIDIOC_SUBDEV_ENUM_MBUS_CODE \
_IOWR('V', 2, struct v4l2_subdev_mbus_code_enum)
#define VIDIOC_SUBDEV_ENUM_FRAME_SIZE \
_IOWR('V', 74, struct v4l2_subdev_frame_size_enum)
#endif

View file

@ -21,6 +21,7 @@
#ifndef _V4L2_SUBDEV_H
#define _V4L2_SUBDEV_H
#include <linux/v4l2-subdev.h>
#include <media/media-entity.h>
#include <media/v4l2-common.h>
#include <media/v4l2-dev.h>
@ -414,6 +415,15 @@ struct v4l2_subdev_ir_ops {
};
struct v4l2_subdev_pad_ops {
int (*enum_mbus_code)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_mbus_code_enum *code);
int (*enum_frame_size)(struct v4l2_subdev *sd,
struct v4l2_subdev_fh *fh,
struct v4l2_subdev_frame_size_enum *fse);
int (*get_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *format);
int (*set_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *format);
};
struct v4l2_subdev_ops {