2020-08-26 15:03:09 +08:00
|
|
|
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
|
2020-09-24 20:04:26 +08:00
|
|
|
.. c:namespace:: V4L
|
2018-08-30 22:15:26 +08:00
|
|
|
|
2016-06-30 21:18:56 +08:00
|
|
|
.. _format:
|
|
|
|
|
|
|
|
************
|
|
|
|
Data Formats
|
|
|
|
************
|
|
|
|
|
|
|
|
Data Format Negotiation
|
|
|
|
=======================
|
|
|
|
|
|
|
|
Different devices exchange different kinds of data with applications,
|
|
|
|
for example video images, raw or sliced VBI data, RDS datagrams. Even
|
2018-10-26 20:18:33 +08:00
|
|
|
within one kind many different formats are possible, in particular there is an
|
2016-06-30 21:18:56 +08:00
|
|
|
abundance of image formats. Although drivers must provide a default and
|
|
|
|
the selection persists across closing and reopening a device,
|
|
|
|
applications should always negotiate a data format before engaging in
|
|
|
|
data exchange. Negotiation means the application asks for a particular
|
|
|
|
format and the driver selects and reports the best the hardware can do
|
|
|
|
to satisfy the request. Of course applications can also just query the
|
|
|
|
current selection.
|
|
|
|
|
|
|
|
A single mechanism exists to negotiate all data formats using the
|
2016-08-30 04:37:59 +08:00
|
|
|
aggregate struct :c:type:`v4l2_format` and the
|
2016-07-03 21:02:29 +08:00
|
|
|
:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and
|
2016-07-02 00:42:29 +08:00
|
|
|
:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctls. Additionally the
|
|
|
|
:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl can be used to examine
|
2016-06-30 21:18:56 +08:00
|
|
|
what the hardware *could* do, without actually selecting a new data
|
|
|
|
format. The data formats supported by the V4L2 API are covered in the
|
|
|
|
respective device section in :ref:`devices`. For a closer look at
|
|
|
|
image formats see :ref:`pixfmt`.
|
|
|
|
|
2016-07-02 01:33:56 +08:00
|
|
|
The :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl is a major turning-point in the
|
2016-06-30 21:18:56 +08:00
|
|
|
initialization sequence. Prior to this point multiple panel applications
|
|
|
|
can access the same device concurrently to select the current input,
|
2016-07-02 01:33:56 +08:00
|
|
|
change controls or modify other properties. The first :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
|
2016-06-30 21:18:56 +08:00
|
|
|
assigns a logical stream (video data, VBI data etc.) exclusively to one
|
|
|
|
file descriptor.
|
|
|
|
|
|
|
|
Exclusive means no other application, more precisely no other file
|
|
|
|
descriptor, can grab this stream or change device properties
|
|
|
|
inconsistent with the negotiated parameters. A video standard change for
|
|
|
|
example, when the new standard uses a different number of scan lines,
|
|
|
|
can invalidate the selected image format. Therefore only the file
|
|
|
|
descriptor owning the stream can make invalidating changes. Accordingly
|
|
|
|
multiple file descriptors which grabbed different logical streams
|
|
|
|
prevent each other from interfering with their settings. When for
|
|
|
|
example video overlay is about to start or already in progress,
|
|
|
|
simultaneous video capturing may be restricted to the same cropping and
|
|
|
|
image size.
|
|
|
|
|
2016-07-02 01:33:56 +08:00
|
|
|
When applications omit the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl its locking side
|
2016-06-30 21:18:56 +08:00
|
|
|
effects are implied by the next step, the selection of an I/O method
|
2016-07-02 00:58:44 +08:00
|
|
|
with the :ref:`VIDIOC_REQBUFS` ioctl or implicit
|
2020-09-24 20:04:26 +08:00
|
|
|
with the first :c:func:`read()` or
|
|
|
|
:c:func:`write()` call.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
Generally only one logical stream can be assigned to a file descriptor,
|
|
|
|
the exception being drivers permitting simultaneous video capturing and
|
|
|
|
overlay using the same file descriptor for compatibility with V4L and
|
|
|
|
earlier versions of V4L2. Switching the logical stream or returning into
|
|
|
|
"panel mode" is possible by closing and reopening the device. Drivers
|
2016-07-02 01:33:56 +08:00
|
|
|
*may* support a switch using :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
All drivers exchanging data with applications must support the
|
2016-07-03 21:02:29 +08:00
|
|
|
:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. Implementation of the
|
2016-07-02 01:33:56 +08:00
|
|
|
:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is highly recommended but optional.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
Image Format Enumeration
|
|
|
|
========================
|
|
|
|
|
|
|
|
Apart of the generic format negotiation functions a special ioctl to
|
|
|
|
enumerate all image formats supported by video capture, overlay or
|
2016-07-13 02:15:23 +08:00
|
|
|
output devices is available. [#f1]_
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-02 00:58:44 +08:00
|
|
|
The :ref:`VIDIOC_ENUM_FMT` ioctl must be supported
|
2016-06-30 21:18:56 +08:00
|
|
|
by all drivers exchanging image data with applications.
|
|
|
|
|
2017-09-03 17:10:44 +08:00
|
|
|
.. important::
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
Drivers are not supposed to convert image formats in kernel space.
|
|
|
|
They must enumerate only formats directly supported by the hardware.
|
|
|
|
If necessary driver writers should publish an example conversion
|
|
|
|
routine or library for integration into applications.
|
|
|
|
|
2016-07-13 02:15:23 +08:00
|
|
|
.. [#f1]
|
2016-06-30 21:18:56 +08:00
|
|
|
Enumerating formats an application has no a-priori knowledge of
|
|
|
|
(otherwise it could explicitly ask for them and need not enumerate)
|
|
|
|
seems useless, but there are applications serving as proxy between
|
|
|
|
drivers and the actual video applications for which this is useful.
|