Westeros-sink-soc Module

Created on August 1, 2024

The Westeros Sink Soc module is a component of the Westeros project that is designed to work with various soc platforms. It provides a mechanism for rendering and displaying multimedia content on the target device. It is responsible for interacting with the display hardware on the SoC platform, using the Direct Rendering Manager (DRM) module to access the graphics and multimedia resources. It provides a mechanism for displaying graphical content and video streams and also handles audio output through the audio subsystem on the target device.

Public API’s Exposed

Sl.
no.

API

Return TypeParametersDescription
1gst_westeros_sink_soc_class_initvoidGstWesterosSinkClass *It is a class initialization function that initializes the class structure and takes a pointer to the GstWesterosSinkClass structure as a parameter.
2gst_westeros_sink_soc_initgboolean GstWesterosSink *This function takes a pointer to the GstWesterosSink object as a parameter, which represents the instance of the GstWesterosSink that is being initialized. During initialization, the function sets up the hardware-specific state of the GstWesterosSink object, by setting up the underlying hardware resources needed for playback.
3gst_westeros_sink_soc_termvoidGstWesterosSink *It is responsible for cleaning up the hardware-specific state of the GstWesterosSink object and freeing any resources that were allocated during the initialization process.
4gst_westeros_sink_soc_set_propertyvoidGObject *
guint prop_id
const Gvalue *
GParamSpec *
It is a callback function that is called when a property of a GstWesterosSink object is being set. It takes four parameters: a pointer to the GObject, an unsigned integer that represents the ID of the property that is being set, a pointer to a Gvalue that represents the new value of the property, and a pointer GParamSpec that represents the property specification.
5gst_westeros_sink_soc_get_propertyvoidGObject *
guint prop_id
Gvalue *
GParamSpec *
It is a callback function that is called when a property of a GstWesterosSink object is being retrieved. 
6gst_westeros_sink_soc_null_to_readygbooleanGstWesterosSink *
gboolean *passToDefault 
This function is called when the GstWesterosSink object transitions from the null state to the ready state.
7gst_westeros_sink_soc_ready_to_pausedgbooleanGstWesterosSink *sink,
gboolean *passToDefault
This function is called when the GstWesterosSink object transitions from the ready state to the paused state.
8gst_westeros_sink_soc_paused_to_playinggbooleanGstWesterosSink *sink,
gboolean *passToDefault
This function is called when the GstWesterosSink object is transitioning from the paused to the playing state.
9gst_westeros_sink_soc_playing_to_pausedgbooleanGstWesterosSink *sink,
gboolean *passToDefault
This function is called when the GstWesterosSink object is transitioning from the playing to the paused state.
10gst_westeros_sink_soc_paused_to_readygbooleanGstWesterosSink *sink,
gboolean *passToDefault
This function is called when the GstWesterosSink object is transitioning from the paused to the ready state.
11gst_westeros_sink_soc_ready_to_nullgbooleanGstWesterosSink *sink,
gboolean *passToDefault
This function is called when the GstWesterosSink object is transitioning from the ready to the null state.
12gst_westeros_sink_soc_registryHandleGlobalvoidGstWesterosSink *sink,
struct wl_registry *registry, uint32_t id,
const char *interface,
uint32_t version)
The function takes several parameters: a pointer to the GstWesterosSink instance, a pointer to the Wayland registry object, an ID for the new global object, the name of the interface, and its version. This function is a callback that is called when the Wayland registry receives a new global object.
13gst_westeros_sink_soc_registryHandleGlobalRemovevoidGstWesterosSink *sink,
struct wl_registry *registry,
uint32_t name
This function takes in a pointer to GstWesterosSink structure, a pointer to the Wayland registry object, and the ID of the removed object. It is a callback that gets called when a global object is removed from the Wayland registry.
14gst_westeros_sink_soc_accept_capsgbooleanGstWesterosSink *sink,
GstCaps *caps
This function takes two parameters: a pointer to the GstWesterosSink instance and a pointer to the caps to be checked. It returns a boolean value indicating whether the caps are supported by the GstWesterosSink.
15gst_westeros_sink_soc_set_startPTSvoidGstWesterosSink *sink,
gint64 pts 
This function sets the start presentation time stamp (PTS) for the media pipeline of the given GstWesterosSink instance.
16gst_westeros_sink_soc_rendervoidGstWesterosSink *sink,
GstBuffer *buffer
This function is responsible for rendering the video frames to the display and it takes a pointer to the GstWesterosSink object and a pointer to the GstBuffer containing the video frame data as input.
17gst_westeros_sink_soc_flushvoidGstWesterosSink *sinkThis function is used to reset and flush the state of the Westeros sink element. It is typically called when the pipeline is being reset or when there is a need to discard all buffered frames and start fresh.
18ean gst_westeros_sink_soc_start_videogbooleanGstWesterosSink *sinkThis function is used to start the video playback in the Westeros sink. It returns a boolean indicating whether the start operation was successful.
19gst_westeros_sink_soc_eos_eventvoidGstWesterosSink *sinkThis function handles an end-of-stream (eos) event for the Westeros sink element and takes a pointer to the GstWesterosSink object as a parameter.
20gst_westeros_sink_soc_set_video_pathvoidGstWesterosSink *sink,
 bool useGfxPath
The function is used to set the video path for a given GstWesterosSink object. It takes a boolean argument useGFXPath which indicates whether to use the graphics path or not.
21gst_westeros_sink_soc_update_video_positionvoidGstWesterosSink *sinkThis function updates the position and size of the video display in the window.
22gst_westeros_sink_soc_querygbooleanGstWesterosSink *sink,
GstQuery *query
This function is a callback function that is used by GStreamer to handle queries related to the GstWesterosSink element and takes a pointer to the GstQuery.
23gst_westeros_sink_soc_set_compositor_lockvoidGstWesterosSink *sink,
bool lock
This function takes a pointer to the GstWesterosSink and lock parameter, to set the compositor lock state.
24gst_westeros_sink_soc_set_speedvoidGstWesterosSink *sink,
const GValue *value
This function takes a pointer to the GstWesterosSink and a pointer to the GValue, to set the playback speed of a video to the specified value.

Events exposed

Sl.

no.

Signal

Event

         DescriptionSignal Emit Function NameSignal Emit ConditionsHow to use this signal from the Application
1

SIGNAL_FIRSTFRAME

first-video-frame-callback

The signal emitted by this API will be emitted when the first video frame is ready and available for processing.gst_westeros_sink_soc_render

1. when gst_westeros_sink_soc_init() is called, the sink calls on the display function, with that to generate the first frame thread it checks if the sink is not NULL, the signal is called.
2. when the gst_westeros_sink_soc_start_video() is called, with the capture_start event, a no. of functions are called to check the condition and collect data related to buffer, plane and get frame-related data like frame rate, frame size, frame-width, frame height, under this condition: sink->soc.emitFirstFrameSignal is set to TRUE; signal is called.

g_signal_connect (decoder_instance, “first-video-frame-callback”, G_CALLBACK(callback_fnc), Callback_fnc_data)
gst_westeros_sink_soc_start_video
gst_westeros_sink_soc_init
2SIGNAL_UNDERFLOWbuffer-underflow-callbackThe signal emitted by this API will be emitted when there is a buffer underflow condition in the element. A buffer underflow occurs when the element is unable to produce or process data quickly enough to keep up with the data flow rate, resulting in a depletion of the buffer. When it happens, this signal is emitted.gst_westeros_sink_soc_start_video1. when the gst_westeros_sink_soc_start_video() is called, with the capture_start event, a no. of functions is called to check the condition and collect data related to buffer, plane and get frame-related data like frame rate, frame size, frame width, frame height, under this condition: sink->soc.emitUnderflowSignal is set to TRUE; signal is called.g_signal_connect (decoder_instance, “buffer-underflow-callback”, G_CALLBACK(callback_fnc), Callback_fnc_data)
gst_westeros_sink_soc_render
3

SIGNAL_NEWTEXTURE

new-video-texture-callback

The signal emitted by this API will be emitted when a new video texture is ready and available for processing. The callback function associated with this signal may need to parse and interpret the various arguments in order to properly process the new video texture data related to the video texture format, dimensions, and planes.gst_westeros_sink_soc_start_video

1. This signal is emitted when a new texture is ready to be displayed by the video sink. Various parameters are passed based on whether the texture is multi-planar or not and sets the appropriate values for the file descriptor, length, stride, and pointer of each plane of the texture buffer.
2. It can also be emitted when westeros_sink_dispatch event comes into play and sink->soc.enableTextureSignal is called.

g_signal_connect (decoder_instance, “new-video-texture-callback”, G_CALLBACK(callback_fnc), Callback_fnc_data)
gst_westeros_sink_soc_render
gst_westeros_sink_soc_init
4SIGNAL_DECODEERRORdecode-error-callbackThe signal emitted by this API will be emitted when there is a decoding error in the element. A decoding error occurs when the element is unable to decode the input data stream properly, resulting in a failure to produce valid output data. When this happens, this signal is emitted.
1. This signal can be emitted under the conditions where if the video decoder captures any error related to video decoding status and any respective flag is set, this signal can be generated and to further handle the decode errors.g_signal_connect (decoder_instance, “decode-error-callback”, G_CALLBACK(callback_fnc), Callback_fnc_data)
5SIGNAL_TIMECODEtimecode-callbackThe signal emitted by this API will be emitted when a new timecode is available. It is used to indicate the current timecode of the media being processed by the element which can be helpful in synchronizing multiple elements.gst_westeros_sink_soc_start_video

1. This signal can be emitted under the condition that if a set position from the frame currently is being presented by the video server
2. This signal can be emitted under another condition that if any video status message is received from the video server related to if timecode is present where the message may contain the presentation timestamp of frames being displayed, this information can help to process messages in video synchronisation or video client connection.

g_signal_connect (decoder_instance, “timecode-callback”, G_CALLBACK(callback_fnc), Callback_fnc_data)
gst_westeros_sink_soc_render

 

V4L2 IOCTL for SOC Implementation

Sl.

no.

IOCTL CallAbout

Description

SynopsisIOCTL Definition file
1VIDIOC_QUERYCAPQuery device capabilitiesAll V4L2 devices support the VIDIOC_QUERYCAP ioctl. It is used to identify kernel devices compatible with this specification and to obtain information about driver and hardware capabilities. The ioctl takes a pointer to a struct v4l2_capability which is filled by the driver. When the driver is not compatible with this specification the ioctl returns an EINVAL error code.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-querycap.html#_CPPv25ioctliiP15v4l2_capabilitylinux/videodev2.h
2VIDIOC_ENUM_FMTEnumerate image formatsTo enumerate image formats applications initialize the type and index field of struct v4l2_fmtdesc and call the ioctl VIDIOC_ENUM_FMT ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an EINVAL error code. All formats are enumerable by beginning at index zero and incrementing by one until EINVAL is returned.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-enum-fmt.htmllinux/videodev2.h
3VIDIOC_G_FMTGet the data format (typically image format) exchanged b/w driver & application.To query the current parameters applications set the type field of a struct struct v4l2_format to the respective buffer (stream) type. For example, video capture devices use V4L2_BUF_TYPE_VIDEO_CAPTURE or V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE. When the application calls the VIDIOC_G_FMT ioctl with a pointer to this structure the driver fills the respective member of the fmt union. When the requested buffer type is not supported drivers return an EINVAL error code.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-fmt.htmllinux/videodev2.h
4VIDIOC_S_FMTSet the data format (typically image format) exchanged b/w driver & applicationWhen the application calls the VIDIOC_S_FMT ioctl with a pointer to a struct v4l2_format structure the driver checks and adjusts the parameters against hardware abilities. Drivers should not return an error code unless the type field is invalid, this is a mechanism to fathom device capabilities and to approach parameters acceptable for both the application and driver. On success, the driver may program the hardware, allocate resources, and generally prepare for data exchange. Finally, the VIDIOC_S_FMT ioctl returns the current format parameters as VIDIOC_G_FMT does. https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-fmt.htmllinux/videodev2.h
5VIDIOC_REQBUFSInitiate Memory Mapping, User Pointer I/O or DMA buffer I/OTo allocate device buffers applications initialize all fields of the struct v4l2_requestbuffers structure. They set the type field to the respective stream or buffer type, the count field to the desired number of buffers, memory must be set to the requested I/O method and the reserved array must be zeroed. When the ioctl is called with a pointer to this structure the driver will attempt to allocate the requested number of buffers and it stores the actual number allocated in the count field. For example, video output requires at least two buffers, one displayed and one filled by the application. When the I/O method is not supported the ioctl returns an EINVAL error code.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-reqbufs.htmllinux/videodev2.h
6VIDIOC_QUERYBUFQuery the status of a buffer.Applications set the type field of a struct v4l2_buffer to the same buffer type as was previously used with struct v4l2_format type and struct v4l2_requestbuffers type, and the index field. Valid index numbers range from zero to the number of buffers allocated with ioctl VIDIOC_REQBUFS (struct v4l2_requestbuffers count) minus one. The reserved and reserved2 fields must be set to 0. After calling ioctl VIDIOC_QUERYBUF with a pointer to this structure drivers return an error code or fill the rest of the structure.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-querybuf.htmllinux/videodev2.h
7VIDIOC_G_FBUFGet frame buffer overlay parameters.To get the current parameters applications call the VIDIOC_G_FBUF ioctl with a pointer to a struct v4l2_framebuffer structure. The driver fills all fields of the structure or returns an EINVAL error code when overlays are not supported.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-fbuf.htmllinux/videodev2.h
8VIDIOC_S_FBUFSet frame buffer overlay parameters.

To set the parameters for a Video Output Overlay, applications must initialize the flags field of a struct struct v4l2_framebuffer. Since the framebuffer is implemented on the TV card all other parameters are determined by the driver. When an application calls VIDIOC_S_FBUF with a pointer to this structure, the driver prepares for the overlay and returns the framebuffer parameters as VIDIOC_G_FBUF does, or it returns an error code. 

To set the parameters for a non-destructive Video Overlay, applications must initialize the flags field, the fmt substructure, and call VIDIOC_S_FBUF. 

For a destructive Video Overlay applications must additionally provide a base address. 

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-fbuf.htmllinux/videodev2.h
9VIDIOC_OVERLAYStart or stop video overlay

This ioctl is part of the video overlay I/O method. Applications call ioctl VIDIOC_OVERLAY to start or stop the overlay. It takes a pointer to an integer which must be set to zero by the application to stop overlay, to one to start. Drivers do not support ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF or VIDIOC_STREAMOFF with V4L2_BUF_TYPE_VIDEO_OVERLAY.  

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-overlay.htmllinux/videodev2.h
10VIDIOC_QBUFExchange a buffer with the driver

Applications call the VIDIOC_QBUF ioctl to enqueue an empty (capturing) or filled (output) buffer in the driver’s incoming queue. The semantics depend on the selected I/O method.

To enqueue a memory mapped buffer applications set the memory field to V4L2_MEMORY_MMAP. When VIDIOC_QBUF is called with a pointer to this structure the driver sets the V4L2_BUF_FLAG_MAPPED and V4L2_BUF_FLAG_QUEUED flags and clears the V4L2_BUF_FLAG_DONE flag in the flags field, or it returns an EINVAL error code.

To enqueue a user pointer buffer applications set the memory field to V4L2_MEMORY_USERPTR, the m.userptr field to the address of the buffer and length to its size. To enqueue a DMABUF buffer applications set the memory field to V4L2_MEMORY_DMABUF & m.fd field to file descriptor associated with a DMABUF buffer.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-qbuf.htmllinux/videodev2.h
11VIDIOC_EXPBUFExport a buffer as a DMABUF file descriptor

This ioctl is an extension to the memory mapping I/O method, hence it is available only for V4L2_MEMORY_MMAP buffers. To export a buffer, applications fill struct v4l2_exportbuffer. The type field is set to the same buffer type as was previously used with struct v4l2_requestbuffers type. Applications must also set the index field. Valid index numbers range from zero to the number of buffers allocated with ioctl VIDIOC_REQBUFS (struct v4l2_requestbuffers count) minus one. Additional flags may be posted in the flags field. After calling ioctl VIDIOC_EXPBUF the fd field will be set by a driver. 

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-expbuf.htmllinux/videodev2.h
12VIDIOC_DQBUFExchange a buffer with the driver

Applications call the VIDIOC_DQBUF ioctl to dequeue a filled (capturing) or displayed (output) buffer from the driver’s outgoing queue. They just set the type, memory and reserved fields of a struct v4l2_buffer as above, when VIDIOC_DQBUF is called with a pointer to this structure the driver fills the remaining fields or returns an error code. The driver may also set V4L2_BUF_FLAG_ERROR in the flags field. By default, VIDIOC_DQBUF blocks when no buffer is in the outgoing queue. 

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-qbuf.htmllinux/videodev2.h
13VIDIOC_STREAMONStart streaming I/O

This ioctl start the capture or output process during streaming (memory mapping, user pointer or DMABUF) I/O.

Capture hardware is disabled and no input buffers are filled (if there are any empty buffers in the incoming queue) until VIDIOC_STREAMON has been called. Output hardware is disabled and no video signal is produced until VIDIOC_STREAMON has been called. The ioctl will succeed when at least one output buffer is in the incoming queue. Memory-to-memory devices will not start until VIDIOC_STREAMON has been called for both the capture and output stream types.

If VIDIOC_STREAMON fails, then any already queued buffers will remain queued.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-streamon.htmllinux/videodev2.h
14VIDIOC_STREAMOFFStop streaming I/OThe VIDIOC_STREAMOFF ioctl, apart from aborting or finishing any DMA in progress, unlocks any user pointer buffers locked in physical memory, and it removes all buffers from the incoming and outgoing queues. That means all images captured but not dequeued yet will be lost, likewise, all images enqueued for output but not transmitted yet. I/O returns to the same state as after calling ioctl VIDIOC_REQBUFS and can be restarted accordingly.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-streamon.htmllinux/videodev2.h
15VIDIOC_G_PARMGet streaming parameters.

The current video standard determines a nominal number of frames per second. If less than this number of frames is to be captured or output, applications can request frame skipping or duplicating on the driver side. This is especially useful when using the read() or write(), which are not augmented by timestamps or sequence counters, and to avoid unnecessary data copying. Further, get/set can be used to determine the number of buffers used internally by a driver in read/write mode. For implications see the section discussing the read() function.

To get the streaming parameters applications call the VIDIOC_G_PARM ioctl. It takes a pointer to a struct struct v4l2_streamparm which contains a union holding separate parameters for input and output devices.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-parm.htmllinux/videodev2.h
16VIDIOC_S_PARMSet streaming parameters.To set the streaming parameters applications call the VIDIOC_S_PARM ioctl. It takes a pointer to a struct struct v4l2_streamparm which contains a union holding separate parameters for input and output devices.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-parm.htmllinux/videodev2.h
17VIDIOC_G_STDQuery the video standard of the current input

It takes a pointer to a v4l2_std_id type as an argument. VIDIOC_G_STD can return a single flag or a set of flags as in the struct v4l2_standard field id. The flags must be unambiguous such that they appear in only one enumerated struct v4l2_standard structure.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-std.htmllinux/videodev2.h
18VIDIOC_S_STDSelect the video standard of the current input.

It takes a pointer to a v4l2_std_id type as an argument. VIDIOC_G_STD can return a single flag or a set of flags as in the struct v4l2_standard field id. The flags must be unambiguous such that they appear in only one enumerated struct v4l2_standard structure.

VIDIOC_S_STD accepts one or more flags, being a write-only ioctl it does not return the actual new standard as VIDIOC_G_STD does. 

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-std.htmllinux/videodev2.h
19VIDIOC_ENUMSTDEnumerate supported video standardsTo query the attributes of a video standard, especially a custom (driver-defined) one, applications initialize the index field of struct v4l2_standard and call the ioctl VIDIOC_ENUMSTD ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds. To enumerate all standards applications shall begin at index zero, incrementing by one until the driver returns EINVAL. Drivers may enumerate a different set of standards after switching the video input or output.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-enumstd.htmllinux/videodev2.h
20VIDIOC_ENUMINPUTEnumerate video inputsTo query the attributes of a video input application initialize the index field of struct v4l2_input and call the ioctl VIDIOC_ENUMINPUT ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an EINVAL error code when the index is out of bounds. To enumerate all inputs applications shall begin at index zero, incrementing by one until the driver returns EINVAL.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-enuminput.htmllinux/videodev2.h
21VIDIOC_G_CTRLGet the value of a control.To get the current value of control applications initialize the id field of a struct struct v4l2_control and call the VIDIOC_G_CTRL ioctl with a pointer to this structure. Works only with user controls.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-ctrl.htmllinux/videodev2.h
22VIDIOC_S_CTRLSet the value of a control.To change the value of a control applications, initialize the id and value fields of a struct struct v4l2_control and call the VIDIOC_S_CTRL ioctl. VIDIOC_S_CTRL is a write-only ioctl, it does not return the actual new value. Works only with user controls.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-ctrl.htmllinux/videodev2.h
23VIDIOC_QUERYCTRLEnumerate controlsTo query the attributes of a control applications set the id field of a struct v4l2_queryctrl and call the VIDIOC_QUERYCTRL ioctl with a pointer to this structure. The driver fills the rest of the structure or returns an EINVAL error code when the id is invalid. It is possible to enumerate controls by calling VIDIOC_QUERYCTRL with successive id values starting from V4L2_CID_BASE up to and exclusive V4L2_CID_LASTP1. Drivers may return EINVAL if control in this range is not supported.https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-queryctrl.htmllinux/videodev2.h
24

VIDIOC_ENUM_

FRAMESIZES

Enumerate frame sizes.

This ioctl allows applications to enumerate all frame sizes (i. e. width and height in pixels) that the device supports for the given pixel format. The supported pixel formats can be obtained by using the ioctl VIDIOC_ENUM_FMT function.

The return value and the content of the v4l2_frmsizeenum. type field depends on the type of frame size the device supports. When the application calls the function with index zero, it must check the type field to determine the type of frame size enumeration the device supports.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-enum-framesizes.htmllinux/videodev2.h
25VIDIOC_TRY_FMTTry a data format.

The VIDIOC_TRY_FMT ioctl is equivalent to VIDIOC_S_FMT with 1 exception: it does not change the driver state. It can also be called at any time, never returning EBUSY. This function is provided to negotiate parameters, to learn about hardware limitations, without disabling I/O or possibly time-consuming hardware preparations. Although strongly recommended drivers are not required to implement this ioctl. The format as returned by VIDIOC_TRY_FMT must be identical to what VIDIOC_S_FMT returns for the same i/p or o/p.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-fmt.htmllinux/videodev2.h
26VIDIOC_CROPCAPInformation about the video cropping and scaling abilities

Applications use this function to query the cropping limits, the pixel aspect of images and to calculate scale factors. They set the type field of a v4l2_cropcap structure to the respective buffer (stream) type and call the ioctl VIDIOC_CROPCAP ioctl with a pointer to this structure. Drivers fill the rest of the structure. The results are constant except when switching the video standard. Remember this switch can occur implicit when switching the video input or output.
This ioctl must be implemented for video capture or output devices that support cropping and/or scaling and/or have non-square pixels and for overlay devices.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-cropcap.htmllinux/videodev2.h
27VIDIOC_CREATE_BUFSCreate buffers for Memory Mapped or User Pointer or DMA Buffer I/O

This can be used as an alternative or in addition to the ioctl VIDIOC_REQBUFS ioctl, when tighter control over buffers is required. This ioctl can be called multiple times to create buffers of different sizes. To allocate the device buffers applications must initialize the relevant fields of the struct v4l2_create_buffers structure. The count field must be set to the number of requested buffers, the memory field specifies the requested I/O method and the reserved array must be zeroed. The format field specifies the image format that the buffers must be able to handle.

When the ioctl is called with a pointer to this structure the driver will attempt to allocate up to the requested number of buffers and store the actual number allocated and the starting index in the count and the index fields respectively. On return count can be smaller than the number requested.

https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-create-bufs.htmllinux/videodev2.h
28VIDIOC_G_SELECTIONGet one of the selection rectangles.To query the cropping (composing) rectangle set the struct v4l2_selection type field to the respective buffer type. Do not use the multiplanar buffer types. The next step is setting the value of the struct v4l2_selection target field to V4L2_SEL_TGT_CROP (V4L2_SEL_TGT_COMPOSE). The flags and reserved fields of struct v4l2_selection are ignored, and they must be filled with zeros. The driver fills the rest of the structure or returns EINVAL error code if an 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 struct v4l2_rect rectangle is filled with the current cropping (composing) coordinates. https://www.kernel.org/doc/html/v4.8/media/uapi/v4l/vidioc-g-selection.htmllinux/videodev2.h

V4L2 IOCTL Code flow

V4L2CodeFlow
Go To Top