162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _VIDIOC_SUBDEV_G_FMT: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci********************************************** 762306a36Sopenharmony_ciioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT 862306a36Sopenharmony_ci********************************************** 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciVIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_SUBDEV_G_FMT 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp)`` 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci.. c:macro:: VIDIOC_SUBDEV_S_FMT 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp)`` 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciArguments 2762306a36Sopenharmony_ci========= 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci``fd`` 3062306a36Sopenharmony_ci File descriptor returned by :c:func:`open()`. 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci``argp`` 3362306a36Sopenharmony_ci Pointer to struct :c:type:`v4l2_subdev_format`. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciDescription 3662306a36Sopenharmony_ci=========== 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciThese ioctls are used to negotiate the frame format at specific subdev 3962306a36Sopenharmony_cipads in the image pipeline. 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciTo retrieve the current format applications set the ``pad`` field of a 4262306a36Sopenharmony_cistruct :c:type:`v4l2_subdev_format` to the desired 4362306a36Sopenharmony_cipad number as reported by the media API and the ``which`` field to 4462306a36Sopenharmony_ci``V4L2_SUBDEV_FORMAT_ACTIVE``. When they call the 4562306a36Sopenharmony_ci``VIDIOC_SUBDEV_G_FMT`` ioctl with a pointer to this structure the 4662306a36Sopenharmony_cidriver fills the members of the ``format`` field. 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ciTo change the current format applications set both the ``pad`` and 4962306a36Sopenharmony_ci``which`` fields and all members of the ``format`` field. When they call 5062306a36Sopenharmony_cithe ``VIDIOC_SUBDEV_S_FMT`` ioctl with a pointer to this structure the 5162306a36Sopenharmony_cidriver verifies the requested format, adjusts it based on the hardware 5262306a36Sopenharmony_cicapabilities and configures the device. Upon return the struct 5362306a36Sopenharmony_ci:c:type:`v4l2_subdev_format` contains the current 5462306a36Sopenharmony_ciformat as would be returned by a ``VIDIOC_SUBDEV_G_FMT`` call. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciApplications can query the device capabilities by setting the ``which`` 5762306a36Sopenharmony_cito ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' formats are not applied 5862306a36Sopenharmony_cito the device by the driver, but are changed exactly as active formats 5962306a36Sopenharmony_ciand stored in the sub-device file handle. Two applications querying the 6062306a36Sopenharmony_cisame sub-device would thus not interact with each other. 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ciFor instance, to try a format at the output pad of a sub-device, 6362306a36Sopenharmony_ciapplications would first set the try format at the sub-device input with 6462306a36Sopenharmony_cithe ``VIDIOC_SUBDEV_S_FMT`` ioctl. They would then either retrieve the 6562306a36Sopenharmony_cidefault format at the output pad with the ``VIDIOC_SUBDEV_G_FMT`` ioctl, 6662306a36Sopenharmony_cior set the desired output pad format with the ``VIDIOC_SUBDEV_S_FMT`` 6762306a36Sopenharmony_ciioctl and check the returned value. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciTry formats do not depend on active formats, but can depend on the 7062306a36Sopenharmony_cicurrent links configuration or sub-device controls value. For instance, 7162306a36Sopenharmony_cia low-pass noise filter might crop pixels at the frame boundaries, 7262306a36Sopenharmony_cimodifying its output frame size. 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ciIf the subdev device node has been registered in read-only mode, calls to 7562306a36Sopenharmony_ci``VIDIOC_SUBDEV_S_FMT`` are only valid if the ``which`` field is set to 7662306a36Sopenharmony_ci``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno 7762306a36Sopenharmony_civariable is set to ``-EPERM``. 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciDrivers must not return an error solely because the requested format 8062306a36Sopenharmony_cidoesn't match the device capabilities. They must instead modify the 8162306a36Sopenharmony_ciformat to match what the hardware can provide. The modified format 8262306a36Sopenharmony_cishould be as close as possible to the original request. 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci.. c:type:: v4l2_subdev_format 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci.. flat-table:: struct v4l2_subdev_format 8962306a36Sopenharmony_ci :header-rows: 0 9062306a36Sopenharmony_ci :stub-columns: 0 9162306a36Sopenharmony_ci :widths: 1 1 2 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci * - __u32 9462306a36Sopenharmony_ci - ``pad`` 9562306a36Sopenharmony_ci - Pad number as reported by the media controller API. 9662306a36Sopenharmony_ci * - __u32 9762306a36Sopenharmony_ci - ``which`` 9862306a36Sopenharmony_ci - Format to modified, from enum 9962306a36Sopenharmony_ci :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`. 10062306a36Sopenharmony_ci * - struct :c:type:`v4l2_mbus_framefmt` 10162306a36Sopenharmony_ci - ``format`` 10262306a36Sopenharmony_ci - Definition of an image format, see :c:type:`v4l2_mbus_framefmt` for 10362306a36Sopenharmony_ci details. 10462306a36Sopenharmony_ci * - __u32 10562306a36Sopenharmony_ci - ``stream`` 10662306a36Sopenharmony_ci - Stream identifier. 10762306a36Sopenharmony_ci * - __u32 10862306a36Sopenharmony_ci - ``reserved``\ [7] 10962306a36Sopenharmony_ci - Reserved for future extensions. Applications and drivers must set 11062306a36Sopenharmony_ci the array to zero. 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}| 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci.. _v4l2-subdev-format-whence: 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci.. flat-table:: enum v4l2_subdev_format_whence 11862306a36Sopenharmony_ci :header-rows: 0 11962306a36Sopenharmony_ci :stub-columns: 0 12062306a36Sopenharmony_ci :widths: 3 1 4 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci * - V4L2_SUBDEV_FORMAT_TRY 12362306a36Sopenharmony_ci - 0 12462306a36Sopenharmony_ci - Try formats, used for querying device capabilities. 12562306a36Sopenharmony_ci * - V4L2_SUBDEV_FORMAT_ACTIVE 12662306a36Sopenharmony_ci - 1 12762306a36Sopenharmony_ci - Active formats, applied to the hardware. 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ciReturn Value 13062306a36Sopenharmony_ci============ 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 13362306a36Sopenharmony_ciappropriately. The generic error codes are described at the 13462306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ciEBUSY 13762306a36Sopenharmony_ci The format can't be changed because the pad is currently busy. This 13862306a36Sopenharmony_ci can be caused, for instance, by an active video stream on the pad. 13962306a36Sopenharmony_ci The ioctl must not be retried without performing another action to 14062306a36Sopenharmony_ci fix the problem first. Only returned by ``VIDIOC_SUBDEV_S_FMT`` 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ciEINVAL 14362306a36Sopenharmony_ci The struct :c:type:`v4l2_subdev_format` 14462306a36Sopenharmony_ci ``pad`` references a non-existing pad, or the ``which`` field 14562306a36Sopenharmony_ci references a non-existing format. 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ciEPERM 14862306a36Sopenharmony_ci The ``VIDIOC_SUBDEV_S_FMT`` ioctl has been called on a read-only subdevice 14962306a36Sopenharmony_ci and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``. 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci============ 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 15462306a36Sopenharmony_ciappropriately. The generic error codes are described at the 15562306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 156