18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: V4L
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _VIDIOC_SUBDEV_G_FMT:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci**********************************************
78c2ecf20Sopenharmony_ciioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT
88c2ecf20Sopenharmony_ci**********************************************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciVIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSynopsis
168c2ecf20Sopenharmony_ci========
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_SUBDEV_G_FMT
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp)``
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_SUBDEV_S_FMT
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp)``
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciArguments
278c2ecf20Sopenharmony_ci=========
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci``fd``
308c2ecf20Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci``argp``
338c2ecf20Sopenharmony_ci    Pointer to struct :c:type:`v4l2_subdev_format`.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciDescription
368c2ecf20Sopenharmony_ci===========
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciThese ioctls are used to negotiate the frame format at specific subdev
398c2ecf20Sopenharmony_cipads in the image pipeline.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciTo retrieve the current format applications set the ``pad`` field of a
428c2ecf20Sopenharmony_cistruct :c:type:`v4l2_subdev_format` to the desired
438c2ecf20Sopenharmony_cipad number as reported by the media API and the ``which`` field to
448c2ecf20Sopenharmony_ci``V4L2_SUBDEV_FORMAT_ACTIVE``. When they call the
458c2ecf20Sopenharmony_ci``VIDIOC_SUBDEV_G_FMT`` ioctl with a pointer to this structure the
468c2ecf20Sopenharmony_cidriver fills the members of the ``format`` field.
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciTo change the current format applications set both the ``pad`` and
498c2ecf20Sopenharmony_ci``which`` fields and all members of the ``format`` field. When they call
508c2ecf20Sopenharmony_cithe ``VIDIOC_SUBDEV_S_FMT`` ioctl with a pointer to this structure the
518c2ecf20Sopenharmony_cidriver verifies the requested format, adjusts it based on the hardware
528c2ecf20Sopenharmony_cicapabilities and configures the device. Upon return the struct
538c2ecf20Sopenharmony_ci:c:type:`v4l2_subdev_format` contains the current
548c2ecf20Sopenharmony_ciformat as would be returned by a ``VIDIOC_SUBDEV_G_FMT`` call.
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciApplications can query the device capabilities by setting the ``which``
578c2ecf20Sopenharmony_cito ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' formats are not applied
588c2ecf20Sopenharmony_cito the device by the driver, but are changed exactly as active formats
598c2ecf20Sopenharmony_ciand stored in the sub-device file handle. Two applications querying the
608c2ecf20Sopenharmony_cisame sub-device would thus not interact with each other.
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciFor instance, to try a format at the output pad of a sub-device,
638c2ecf20Sopenharmony_ciapplications would first set the try format at the sub-device input with
648c2ecf20Sopenharmony_cithe ``VIDIOC_SUBDEV_S_FMT`` ioctl. They would then either retrieve the
658c2ecf20Sopenharmony_cidefault format at the output pad with the ``VIDIOC_SUBDEV_G_FMT`` ioctl,
668c2ecf20Sopenharmony_cior set the desired output pad format with the ``VIDIOC_SUBDEV_S_FMT``
678c2ecf20Sopenharmony_ciioctl and check the returned value.
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciTry formats do not depend on active formats, but can depend on the
708c2ecf20Sopenharmony_cicurrent links configuration or sub-device controls value. For instance,
718c2ecf20Sopenharmony_cia low-pass noise filter might crop pixels at the frame boundaries,
728c2ecf20Sopenharmony_cimodifying its output frame size.
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ciIf the subdev device node has been registered in read-only mode, calls to
758c2ecf20Sopenharmony_ci``VIDIOC_SUBDEV_S_FMT`` are only valid if the ``which`` field is set to
768c2ecf20Sopenharmony_ci``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
778c2ecf20Sopenharmony_civariable is set to ``-EPERM``.
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciDrivers must not return an error solely because the requested format
808c2ecf20Sopenharmony_cidoesn't match the device capabilities. They must instead modify the
818c2ecf20Sopenharmony_ciformat to match what the hardware can provide. The modified format
828c2ecf20Sopenharmony_cishould be as close as possible to the original request.
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci.. c:type:: v4l2_subdev_format
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_subdev_format
898c2ecf20Sopenharmony_ci    :header-rows:  0
908c2ecf20Sopenharmony_ci    :stub-columns: 0
918c2ecf20Sopenharmony_ci    :widths:       1 1 2
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci    * - __u32
948c2ecf20Sopenharmony_ci      - ``pad``
958c2ecf20Sopenharmony_ci      - Pad number as reported by the media controller API.
968c2ecf20Sopenharmony_ci    * - __u32
978c2ecf20Sopenharmony_ci      - ``which``
988c2ecf20Sopenharmony_ci      - Format to modified, from enum
998c2ecf20Sopenharmony_ci	:ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
1008c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_mbus_framefmt`
1018c2ecf20Sopenharmony_ci      - ``format``
1028c2ecf20Sopenharmony_ci      - Definition of an image format, see :c:type:`v4l2_mbus_framefmt` for
1038c2ecf20Sopenharmony_ci	details.
1048c2ecf20Sopenharmony_ci    * - __u32
1058c2ecf20Sopenharmony_ci      - ``reserved``\ [8]
1068c2ecf20Sopenharmony_ci      - Reserved for future extensions. Applications and drivers must set
1078c2ecf20Sopenharmony_ci	the array to zero.
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci.. _v4l2-subdev-format-whence:
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci.. flat-table:: enum v4l2_subdev_format_whence
1158c2ecf20Sopenharmony_ci    :header-rows:  0
1168c2ecf20Sopenharmony_ci    :stub-columns: 0
1178c2ecf20Sopenharmony_ci    :widths:       3 1 4
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci    * - V4L2_SUBDEV_FORMAT_TRY
1208c2ecf20Sopenharmony_ci      - 0
1218c2ecf20Sopenharmony_ci      - Try formats, used for querying device capabilities.
1228c2ecf20Sopenharmony_ci    * - V4L2_SUBDEV_FORMAT_ACTIVE
1238c2ecf20Sopenharmony_ci      - 1
1248c2ecf20Sopenharmony_ci      - Active formats, applied to the hardware.
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciReturn Value
1278c2ecf20Sopenharmony_ci============
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
1308c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the
1318c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ciEBUSY
1348c2ecf20Sopenharmony_ci    The format can't be changed because the pad is currently busy. This
1358c2ecf20Sopenharmony_ci    can be caused, for instance, by an active video stream on the pad.
1368c2ecf20Sopenharmony_ci    The ioctl must not be retried without performing another action to
1378c2ecf20Sopenharmony_ci    fix the problem first. Only returned by ``VIDIOC_SUBDEV_S_FMT``
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciEINVAL
1408c2ecf20Sopenharmony_ci    The struct :c:type:`v4l2_subdev_format`
1418c2ecf20Sopenharmony_ci    ``pad`` references a non-existing pad, or the ``which`` field
1428c2ecf20Sopenharmony_ci    references a non-existing format.
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ciEPERM
1458c2ecf20Sopenharmony_ci    The ``VIDIOC_SUBDEV_S_FMT`` ioctl has been called on a read-only subdevice
1468c2ecf20Sopenharmony_ci    and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci============
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
1518c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the
1528c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
153