LCOV - code coverage report
Current view: top level - zephyr/drivers - video.h Coverage Total Hit
Test: new.info Lines: 91.0 % 200 182
Test Date: 2025-10-20 12:20:01

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2019 Linaro Limited.
       3              :  * Copyright 2025 NXP
       4              :  * Copyright (c) 2025 STMicroelectronics
       5              :  *
       6              :  * SPDX-License-Identifier: Apache-2.0
       7              :  */
       8              : 
       9              : /**
      10              :  * @file
      11              :  * @ingroup video_interface
      12              :  * @brief Main header file for video driver API.
      13              :  */
      14              : 
      15              : #ifndef ZEPHYR_INCLUDE_VIDEO_H_
      16              : #define ZEPHYR_INCLUDE_VIDEO_H_
      17              : 
      18              : /**
      19              :  * @brief Interfaces for video devices.
      20              :  * @defgroup video_interface Video
      21              :  * @since 2.1
      22              :  * @version 1.1.0
      23              :  * @ingroup io_interfaces
      24              :  * @{
      25              :  */
      26              : 
      27              : #include <zephyr/device.h>
      28              : #include <stddef.h>
      29              : #include <zephyr/kernel.h>
      30              : 
      31              : #include <zephyr/types.h>
      32              : 
      33              : #ifdef __cplusplus
      34              : extern "C" {
      35              : #endif
      36              : 
      37              : struct video_control;
      38              : 
      39              : /**
      40              :  * @brief video_buf_type enum
      41              :  *
      42              :  * Supported video buffer types of a video device.
      43              :  * The direction (input or output) is defined from the device's point of view.
      44              :  * Devices like cameras support only output type, encoders support only input
      45              :  * types while m2m devices like ISP, PxP support both input and output types.
      46              :  */
      47            1 : enum video_buf_type {
      48              :         /** input buffer type */
      49              :         VIDEO_BUF_TYPE_INPUT,
      50              :         /** output buffer type */
      51              :         VIDEO_BUF_TYPE_OUTPUT,
      52              : };
      53              : 
      54              : /**
      55              :  * @brief Video format structure
      56              :  *
      57              :  * Used to configure frame format.
      58              :  */
      59            1 : struct video_format {
      60              :         /** type of the buffer */
      61            1 :         enum video_buf_type type;
      62              :         /** FourCC pixel format value (\ref video_pixel_formats) */
      63            1 :         uint32_t pixelformat;
      64              :         /** frame width in pixels. */
      65            1 :         uint32_t width;
      66              :         /** frame height in pixels. */
      67            1 :         uint32_t height;
      68              :         /**
      69              :          * @brief line stride.
      70              :          *
      71              :          * This is the number of bytes that needs to be added to the address in the
      72              :          * first pixel of a row in order to go to the address of the first pixel of
      73              :          * the next row (>=width).
      74              :          */
      75            1 :         uint32_t pitch;
      76              :         /**
      77              :          * @brief size of the buffer in bytes, need to be set by the drivers
      78              :          *
      79              :          * For uncompressed formats, this is the size of the raw data buffer in bytes,
      80              :          * which could be the whole raw image or a portion of the raw image in cases
      81              :          * the receiver / dma supports it.
      82              :          *
      83              :          * For compressed formats, this is the maximum number of bytes required to
      84              :          * hold a complete compressed frame, estimated for the worst case.
      85              :          */
      86            1 :         uint32_t size;
      87              : };
      88              : 
      89              : /**
      90              :  * @brief Video format capability
      91              :  *
      92              :  * Used to describe a video endpoint format capability.
      93              :  */
      94            1 : struct video_format_cap {
      95              :         /** FourCC pixel format value (\ref video_pixel_formats). */
      96            1 :         uint32_t pixelformat;
      97              :         /** minimum supported frame width in pixels. */
      98            1 :         uint32_t width_min;
      99              :         /** maximum supported frame width in pixels. */
     100            1 :         uint32_t width_max;
     101              :         /** minimum supported frame height in pixels. */
     102            1 :         uint32_t height_min;
     103              :         /** maximum supported frame height in pixels. */
     104            1 :         uint32_t height_max;
     105              :         /** width step size in pixels. */
     106            1 :         uint16_t width_step;
     107              :         /** height step size in pixels. */
     108            1 :         uint16_t height_step;
     109              : };
     110              : 
     111              : /**
     112              :  * @brief Video format capabilities
     113              :  *
     114              :  * Used to describe video endpoint capabilities.
     115              :  */
     116            1 : struct video_caps {
     117              :         /** type of the buffer */
     118            1 :         enum video_buf_type type;
     119              :         /** list of video format capabilities (zero terminated). */
     120            1 :         const struct video_format_cap *format_caps;
     121              :         /** minimal count of video buffers to enqueue before being able to start
     122              :          * the stream.
     123              :          */
     124            1 :         uint8_t min_vbuf_count;
     125              : };
     126              : 
     127              : /**
     128              :  * @brief Video buffer structure
     129              :  *
     130              :  * Represents a video frame.
     131              :  */
     132            1 : struct video_buffer {
     133              :         /** Pointer to driver specific data. */
     134              :         /* It must be kept as first field of the struct if used for @ref k_fifo APIs. */
     135            1 :         void *driver_data;
     136              :         /** type of the buffer */
     137            1 :         enum video_buf_type type;
     138              :         /** pointer to the start of the buffer. */
     139            1 :         uint8_t *buffer;
     140              :         /** index of the buffer, optionally set by the application */
     141            1 :         uint8_t index;
     142              :         /** size of the buffer in bytes. */
     143            1 :         uint32_t size;
     144              :         /** number of bytes occupied by the valid data in the buffer. */
     145            1 :         uint32_t bytesused;
     146              :         /** time reference in milliseconds at which the last data byte was
     147              :          * actually received for input endpoints or to be consumed for output
     148              :          * endpoints.
     149              :          */
     150            1 :         uint32_t timestamp;
     151              :         /** Line offset within frame this buffer represents, from the
     152              :          * beginning of the frame. This offset is given in pixels,
     153              :          * so `line_offset` * `pitch` provides offset from the start of
     154              :          * the frame in bytes.
     155              :          */
     156            1 :         uint16_t line_offset;
     157              : };
     158              : 
     159              : /**
     160              :  * @brief Supported frame interval type of a video device.
     161              :  */
     162            1 : enum video_frmival_type {
     163              :         /** discrete frame interval type */
     164              :         VIDEO_FRMIVAL_TYPE_DISCRETE = 1,
     165              :         /** stepwise frame interval type */
     166              :         VIDEO_FRMIVAL_TYPE_STEPWISE = 2,
     167              : };
     168              : 
     169              : /**
     170              :  * @brief Video frame interval structure
     171              :  *
     172              :  * Used to describe a video frame interval.
     173              :  */
     174            1 : struct video_frmival {
     175              :         /** numerator of the frame interval */
     176            1 :         uint32_t numerator;
     177              :         /** denominator of the frame interval */
     178            1 :         uint32_t denominator;
     179              : };
     180              : 
     181              : /**
     182              :  * @brief Video frame interval stepwise structure
     183              :  *
     184              :  * Used to describe the video frame interval stepwise type.
     185              :  */
     186            1 : struct video_frmival_stepwise {
     187              :         /** minimum frame interval in seconds */
     188            1 :         struct video_frmival min;
     189              :         /** maximum frame interval in seconds */
     190            1 :         struct video_frmival max;
     191              :         /** frame interval step size in seconds */
     192            1 :         struct video_frmival step;
     193              : };
     194              : 
     195              : /**
     196              :  * @brief Video frame interval enumeration structure
     197              :  *
     198              :  * Used to describe the supported video frame intervals of a given video format.
     199              :  */
     200            1 : struct video_frmival_enum {
     201              :         /** frame interval index during enumeration */
     202            1 :         uint32_t index;
     203              :         /** video format for which the query is made */
     204            1 :         const struct video_format *format;
     205              :         /** frame interval type the device supports */
     206            1 :         enum video_frmival_type type;
     207              :         /** the actual frame interval */
     208              :         union {
     209            0 :                 struct video_frmival discrete;
     210            0 :                 struct video_frmival_stepwise stepwise;
     211            1 :         };
     212              : };
     213              : 
     214              : /**
     215              :  * @brief Video signal result
     216              :  *
     217              :  * Identify video event.
     218              :  */
     219            1 : enum video_signal_result {
     220              :         VIDEO_BUF_DONE,    /**< Buffer is done */
     221              :         VIDEO_BUF_ABORTED, /**< Buffer is aborted */
     222              :         VIDEO_BUF_ERROR,   /**< Buffer is in error */
     223              : };
     224              : 
     225              : /**
     226              :  * @brief Video selection target
     227              :  *
     228              :  * Used to indicate which selection to query or set on a video device
     229              :  */
     230            1 : enum video_selection_target {
     231              :         /** Current crop setting */
     232              :         VIDEO_SEL_TGT_CROP,
     233              :         /** Crop bound (aka the maximum crop achievable) */
     234              :         VIDEO_SEL_TGT_CROP_BOUND,
     235              :         /** Native size of the input frame */
     236              :         VIDEO_SEL_TGT_NATIVE_SIZE,
     237              :         /** Current compose setting */
     238              :         VIDEO_SEL_TGT_COMPOSE,
     239              :         /** Compose bound (aka the maximum compose achievable) */
     240              :         VIDEO_SEL_TGT_COMPOSE_BOUND,
     241              : };
     242              : 
     243              : /**
     244              :  * @brief Description of a rectangle area.
     245              :  *
     246              :  * Used for crop/compose and possibly within drivers as well
     247              :  */
     248            1 : struct video_rect {
     249              :         /** left offset of selection rectangle */
     250            1 :         uint32_t left;
     251              :         /** top offset of selection rectangle */
     252            1 :         uint32_t top;
     253              :         /** width of selection rectangle */
     254            1 :         uint32_t width;
     255              :         /** height of selection rectangle */
     256            1 :         uint32_t height;
     257              : };
     258              : 
     259              : /**
     260              :  * @brief Video selection (crop / compose) structure
     261              :  *
     262              :  * Used to describe the query and set selection target on a video device
     263              :  */
     264            1 : struct video_selection {
     265              :         /** buffer type, allow to select for device having both input and output */
     266            1 :         enum video_buf_type type;
     267              :         /** selection target enum */
     268            1 :         enum video_selection_target target;
     269              :         /** selection target rectangle */
     270            1 :         struct video_rect rect;
     271              : };
     272              : 
     273              : /**
     274              :  * @typedef video_api_format_t
     275              :  * @brief Function pointer type for video_set/get_format()
     276              :  *
     277              :  * See video_set/get_format() for argument descriptions.
     278              :  */
     279            1 : typedef int (*video_api_format_t)(const struct device *dev, struct video_format *fmt);
     280              : 
     281              : /**
     282              :  * @typedef video_api_frmival_t
     283              :  * @brief Function pointer type for video_set/get_frmival()
     284              :  *
     285              :  * See video_set/get_frmival() for argument descriptions.
     286              :  */
     287            1 : typedef int (*video_api_frmival_t)(const struct device *dev, struct video_frmival *frmival);
     288              : 
     289              : /**
     290              :  * @typedef video_api_enum_frmival_t
     291              :  * @brief List all supported frame intervals of a given format
     292              :  *
     293              :  * See video_enum_frmival() for argument descriptions.
     294              :  */
     295            1 : typedef int (*video_api_enum_frmival_t)(const struct device *dev, struct video_frmival_enum *fie);
     296              : 
     297              : /**
     298              :  * @typedef video_api_enqueue_t
     299              :  * @brief Enqueue a buffer in the driver’s incoming queue.
     300              :  *
     301              :  * See video_enqueue() for argument descriptions.
     302              :  */
     303            1 : typedef int (*video_api_enqueue_t)(const struct device *dev, struct video_buffer *buf);
     304              : 
     305              : /**
     306              :  * @typedef video_api_dequeue_t
     307              :  * @brief Dequeue a buffer from the driver’s outgoing queue.
     308              :  *
     309              :  * See video_dequeue() for argument descriptions.
     310              :  */
     311            1 : typedef int (*video_api_dequeue_t)(const struct device *dev, struct video_buffer **buf,
     312              :                                    k_timeout_t timeout);
     313              : 
     314              : /**
     315              :  * @typedef video_api_flush_t
     316              :  * @brief Flush endpoint buffers, buffer are moved from incoming queue to
     317              :  *        outgoing queue.
     318              :  *
     319              :  * See video_flush() for argument descriptions.
     320              :  */
     321            1 : typedef int (*video_api_flush_t)(const struct device *dev, bool cancel);
     322              : 
     323              : /**
     324              :  * @typedef video_api_set_stream_t
     325              :  * @brief Start or stop streaming on the video device.
     326              :  *
     327              :  * Start (enable == true) or stop (enable == false) streaming on the video device.
     328              :  *
     329              :  * @param dev Pointer to the device structure.
     330              :  * @param enable If true, start streaming, otherwise stop streaming.
     331              :  * @param type The type of the buffers stream to start or stop.
     332              :  *
     333              :  * @retval 0 on success, otherwise a negative errno code.
     334              :  */
     335            1 : typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable,
     336              :                                       enum video_buf_type type);
     337              : 
     338              : /**
     339              :  * @typedef video_api_ctrl_t
     340              :  * @brief Set/Get a video control value.
     341              :  *
     342              :  * @param dev Pointer to the device structure.
     343              :  * @param cid Id of the control to set/get its value.
     344              :  */
     345            1 : typedef int (*video_api_ctrl_t)(const struct device *dev, uint32_t cid);
     346              : 
     347              : /**
     348              :  * @typedef video_api_get_caps_t
     349              :  * @brief Get capabilities of a video endpoint.
     350              :  *
     351              :  * See video_get_caps() for argument descriptions.
     352              :  */
     353            1 : typedef int (*video_api_get_caps_t)(const struct device *dev, struct video_caps *caps);
     354              : 
     355              : /**
     356              :  * @typedef video_api_set_signal_t
     357              :  * @brief Register/Unregister poll signal for buffer events.
     358              :  *
     359              :  * See video_set_signal() for argument descriptions.
     360              :  */
     361            1 : typedef int (*video_api_set_signal_t)(const struct device *dev, struct k_poll_signal *sig);
     362              : 
     363              : /**
     364              :  * @typedef video_api_selection_t
     365              :  * @brief Get/Set video selection (crop / compose)
     366              :  *
     367              :  * See @ref video_set_selection and @ref video_get_selection for argument descriptions.
     368              :  */
     369            1 : typedef int (*video_api_selection_t)(const struct device *dev, struct video_selection *sel);
     370              : 
     371            0 : __subsystem struct video_driver_api {
     372              :         /* mandatory callbacks */
     373            0 :         video_api_format_t set_format;
     374            0 :         video_api_format_t get_format;
     375            0 :         video_api_set_stream_t set_stream;
     376            0 :         video_api_get_caps_t get_caps;
     377              :         /* optional callbacks */
     378            0 :         video_api_enqueue_t enqueue;
     379            0 :         video_api_dequeue_t dequeue;
     380            0 :         video_api_flush_t flush;
     381            0 :         video_api_ctrl_t set_ctrl;
     382            0 :         video_api_ctrl_t get_volatile_ctrl;
     383            0 :         video_api_set_signal_t set_signal;
     384            0 :         video_api_frmival_t set_frmival;
     385            0 :         video_api_frmival_t get_frmival;
     386            0 :         video_api_enum_frmival_t enum_frmival;
     387            0 :         video_api_selection_t set_selection;
     388            0 :         video_api_selection_t get_selection;
     389              : };
     390              : 
     391              : /**
     392              :  * @brief Set video format.
     393              :  *
     394              :  * Configure video device with a specific format.
     395              :  *
     396              :  * @param dev Pointer to the device structure for the driver instance.
     397              :  * @param fmt Pointer to a video format struct.
     398              :  *
     399              :  * @retval 0 Is successful.
     400              :  * @retval -EINVAL If parameters are invalid.
     401              :  * @retval -ENOTSUP If format is not supported.
     402              :  * @retval -EIO General input / output error.
     403              :  */
     404            1 : static inline int video_set_format(const struct device *dev, struct video_format *fmt)
     405              : {
     406              :         const struct video_driver_api *api;
     407              : 
     408              :         __ASSERT_NO_MSG(dev != NULL);
     409              :         __ASSERT_NO_MSG(fmt != NULL);
     410              : 
     411              :         api = (const struct video_driver_api *)dev->api;
     412              :         if (api->set_format == NULL) {
     413              :                 return -ENOSYS;
     414              :         }
     415              : 
     416              :         return api->set_format(dev, fmt);
     417              : }
     418              : 
     419              : /**
     420              :  * @brief Get video format.
     421              :  *
     422              :  * Get video device current video format.
     423              :  *
     424              :  * @param dev Pointer to the device structure for the driver instance.
     425              :  * @param fmt Pointer to video format struct.
     426              :  *
     427              :  * @retval pointer to video format
     428              :  */
     429            1 : static inline int video_get_format(const struct device *dev, struct video_format *fmt)
     430              : {
     431              :         const struct video_driver_api *api;
     432              : 
     433              :         __ASSERT_NO_MSG(dev != NULL);
     434              :         __ASSERT_NO_MSG(fmt != NULL);
     435              : 
     436              :         api = (const struct video_driver_api *)dev->api;
     437              :         if (api->get_format == NULL) {
     438              :                 return -ENOSYS;
     439              :         }
     440              : 
     441              :         return api->get_format(dev, fmt);
     442              : }
     443              : 
     444              : /**
     445              :  * @brief Set video frame interval.
     446              :  *
     447              :  * Configure video device with a specific frame interval.
     448              :  *
     449              :  * Drivers must not return an error solely because the requested interval doesn’t match the device
     450              :  * capabilities. They must instead modify the interval to match what the hardware can provide.
     451              :  *
     452              :  * @param dev Pointer to the device structure for the driver instance.
     453              :  * @param frmival Pointer to a video frame interval struct.
     454              :  *
     455              :  * @retval 0 If successful.
     456              :  * @retval -ENOSYS If API is not implemented.
     457              :  * @retval -EINVAL If parameters are invalid.
     458              :  * @retval -EIO General input / output error.
     459              :  */
     460            1 : static inline int video_set_frmival(const struct device *dev, struct video_frmival *frmival)
     461              : {
     462              :         const struct video_driver_api *api;
     463              : 
     464              :         __ASSERT_NO_MSG(dev != NULL);
     465              :         __ASSERT_NO_MSG(frmival != NULL);
     466              : 
     467              :         if (frmival->numerator == 0 || frmival->denominator == 0) {
     468              :                 return -EINVAL;
     469              :         }
     470              : 
     471              :         api = (const struct video_driver_api *)dev->api;
     472              :         if (api->set_frmival == NULL) {
     473              :                 return -ENOSYS;
     474              :         }
     475              : 
     476              :         return api->set_frmival(dev, frmival);
     477              : }
     478              : 
     479              : /**
     480              :  * @brief Get video frame interval.
     481              :  *
     482              :  * Get current frame interval of the video device.
     483              :  *
     484              :  * @param dev Pointer to the device structure for the driver instance.
     485              :  * @param frmival Pointer to a video frame interval struct.
     486              :  *
     487              :  * @retval 0 If successful.
     488              :  * @retval -ENOSYS If API is not implemented.
     489              :  * @retval -EINVAL If parameters are invalid.
     490              :  * @retval -EIO General input / output error.
     491              :  */
     492            1 : static inline int video_get_frmival(const struct device *dev, struct video_frmival *frmival)
     493              : {
     494              :         const struct video_driver_api *api;
     495              : 
     496              :         __ASSERT_NO_MSG(dev != NULL);
     497              :         __ASSERT_NO_MSG(frmival != NULL);
     498              : 
     499              :         api = (const struct video_driver_api *)dev->api;
     500              :         if (api->get_frmival == NULL) {
     501              :                 return -ENOSYS;
     502              :         }
     503              : 
     504              :         return api->get_frmival(dev, frmival);
     505              : }
     506              : 
     507              : /**
     508              :  * @brief List video frame intervals.
     509              :  *
     510              :  * List all supported video frame intervals of a given format.
     511              :  *
     512              :  * Applications should fill the pixelformat, width and height fields of the
     513              :  * video_frmival_enum struct first to form a query. Then, the index field is
     514              :  * used to iterate through the supported frame intervals list.
     515              :  *
     516              :  * @param dev Pointer to the device structure for the driver instance.
     517              :  * @param fie Pointer to a video frame interval enumeration struct.
     518              :  *
     519              :  * @retval 0 If successful.
     520              :  * @retval -ENOSYS If API is not implemented.
     521              :  * @retval -EINVAL If parameters are invalid.
     522              :  * @retval -EIO General input / output error.
     523              :  */
     524            1 : static inline int video_enum_frmival(const struct device *dev, struct video_frmival_enum *fie)
     525              : {
     526              :         const struct video_driver_api *api;
     527              : 
     528              :         __ASSERT_NO_MSG(dev != NULL);
     529              :         __ASSERT_NO_MSG(fie != NULL);
     530              :         __ASSERT_NO_MSG(fie->format != NULL);
     531              : 
     532              :         api = (const struct video_driver_api *)dev->api;
     533              :         if (api->enum_frmival == NULL) {
     534              :                 return -ENOSYS;
     535              :         }
     536              : 
     537              :         return api->enum_frmival(dev, fie);
     538              : }
     539              : 
     540              : /**
     541              :  * @brief Enqueue a video buffer.
     542              :  *
     543              :  * Enqueue an empty (capturing) or filled (output) video buffer in the driver’s
     544              :  * endpoint incoming queue.
     545              :  *
     546              :  * @param dev Pointer to the device structure for the driver instance.
     547              :  * @param buf Pointer to the video buffer.
     548              :  *
     549              :  * @retval 0 Is successful.
     550              :  * @retval -EINVAL If parameters are invalid.
     551              :  * @retval -EIO General input / output error.
     552              :  */
     553            1 : static inline int video_enqueue(const struct device *dev, struct video_buffer *buf)
     554              : {
     555              :         const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
     556              : 
     557              :         __ASSERT_NO_MSG(dev != NULL);
     558              :         __ASSERT_NO_MSG(buf != NULL);
     559              :         __ASSERT_NO_MSG(buf->buffer != NULL);
     560              : 
     561              :         api = (const struct video_driver_api *)dev->api;
     562              :         if (api->enqueue == NULL) {
     563              :                 return -ENOSYS;
     564              :         }
     565              : 
     566              :         return api->enqueue(dev, buf);
     567              : }
     568              : 
     569              : /**
     570              :  * @brief Dequeue a video buffer.
     571              :  *
     572              :  * Dequeue a filled (capturing) or displayed (output) buffer from the driver’s
     573              :  * endpoint outgoing queue.
     574              :  *
     575              :  * @param dev Pointer to the device structure for the driver instance.
     576              :  * @param buf Pointer a video buffer pointer.
     577              :  * @param timeout Timeout
     578              :  *
     579              :  * @retval 0 Is successful.
     580              :  * @retval -EINVAL If parameters are invalid.
     581              :  * @retval -EIO General input / output error.
     582              :  */
     583            1 : static inline int video_dequeue(const struct device *dev, struct video_buffer **buf,
     584              :                                 k_timeout_t timeout)
     585              : {
     586              :         const struct video_driver_api *api;
     587              : 
     588              :         __ASSERT_NO_MSG(dev != NULL);
     589              :         __ASSERT_NO_MSG(buf != NULL);
     590              : 
     591              :         api = (const struct video_driver_api *)dev->api;
     592              :         if (api->dequeue == NULL) {
     593              :                 return -ENOSYS;
     594              :         }
     595              : 
     596              :         return api->dequeue(dev, buf, timeout);
     597              : }
     598              : 
     599              : /**
     600              :  * @brief Flush endpoint buffers.
     601              :  *
     602              :  * A call to flush finishes when all endpoint buffers have been moved from
     603              :  * incoming queue to outgoing queue. Either because canceled or fully processed
     604              :  * through the video function.
     605              :  *
     606              :  * @param dev Pointer to the device structure for the driver instance.
     607              :  * @param cancel If true, cancel buffer processing instead of waiting for
     608              :  *        completion.
     609              :  *
     610              :  * @retval 0 Is successful, -ERRNO code otherwise.
     611              :  */
     612            1 : static inline int video_flush(const struct device *dev, bool cancel)
     613              : {
     614              :         const struct video_driver_api *api;
     615              : 
     616              :         __ASSERT_NO_MSG(dev != NULL);
     617              : 
     618              :         api = (const struct video_driver_api *)dev->api;
     619              :         if (api->flush == NULL) {
     620              :                 return -ENOSYS;
     621              :         }
     622              : 
     623              :         return api->flush(dev, cancel);
     624              : }
     625              : 
     626              : /**
     627              :  * @brief Start the video device function.
     628              :  *
     629              :  * video_stream_start is called to enter ‘streaming’ state (capture, output...).
     630              :  * The driver may receive buffers with video_enqueue() before video_stream_start
     631              :  * is called. If driver/device needs a minimum number of buffers before being
     632              :  * able to start streaming, then driver set the min_vbuf_count to the related
     633              :  * endpoint capabilities.
     634              :  *
     635              :  * @param dev Pointer to the device structure.
     636              :  * @param type The type of the buffers stream to start.
     637              :  *
     638              :  * @retval 0 Is successful.
     639              :  * @retval -EIO General input / output error.
     640              :  */
     641            1 : static inline int video_stream_start(const struct device *dev, enum video_buf_type type)
     642              : {
     643              :         const struct video_driver_api *api;
     644              : 
     645              :         __ASSERT_NO_MSG(dev != NULL);
     646              : 
     647              :         api = (const struct video_driver_api *)dev->api;
     648              :         if (api->set_stream == NULL) {
     649              :                 return -ENOSYS;
     650              :         }
     651              : 
     652              :         return api->set_stream(dev, true, type);
     653              : }
     654              : 
     655              : /**
     656              :  * @brief Stop the video device function.
     657              :  *
     658              :  * On video_stream_stop, driver must stop any transactions or wait until they
     659              :  * finish.
     660              :  *
     661              :  * @param dev Pointer to the device structure.
     662              :  * @param type The type of the buffers stream to stop.
     663              :  *
     664              :  * @retval 0 Is successful.
     665              :  * @retval -EIO General input / output error.
     666              :  */
     667            1 : static inline int video_stream_stop(const struct device *dev, enum video_buf_type type)
     668              : {
     669              :         const struct video_driver_api *api;
     670              :         int ret;
     671              : 
     672              :         __ASSERT_NO_MSG(dev != NULL);
     673              : 
     674              :         api = (const struct video_driver_api *)dev->api;
     675              :         if (api->set_stream == NULL) {
     676              :                 return -ENOSYS;
     677              :         }
     678              : 
     679              :         ret = api->set_stream(dev, false, type);
     680              :         video_flush(dev, true);
     681              : 
     682              :         return ret;
     683              : }
     684              : 
     685              : /**
     686              :  * @brief Get the capabilities of a video endpoint.
     687              :  *
     688              :  * @param dev Pointer to the device structure for the driver instance.
     689              :  * @param caps Pointer to the video_caps struct to fill.
     690              :  *
     691              :  * @retval 0 Is successful, -ERRNO code otherwise.
     692              :  */
     693            1 : static inline int video_get_caps(const struct device *dev, struct video_caps *caps)
     694              : {
     695              :         const struct video_driver_api *api;
     696              : 
     697              :         __ASSERT_NO_MSG(dev != NULL);
     698              :         __ASSERT_NO_MSG(caps != NULL);
     699              : 
     700              :         api = (const struct video_driver_api *)dev->api;
     701              :         if (api->get_caps == NULL) {
     702              :                 return -ENOSYS;
     703              :         }
     704              : 
     705              :         return api->get_caps(dev, caps);
     706              : }
     707              : 
     708              : /**
     709              :  * @brief Set the value of a control.
     710              :  *
     711              :  * This set the value of a video control, value type depends on control ID, and
     712              :  * must be interpreted accordingly.
     713              :  *
     714              :  * @param dev Pointer to the device structure for the driver instance.
     715              :  * @param control Pointer to the video control struct.
     716              :  *
     717              :  * @retval 0 Is successful.
     718              :  * @retval -EINVAL If parameters are invalid.
     719              :  * @retval -ENOTSUP If format is not supported.
     720              :  * @retval -EIO General input / output error.
     721              :  */
     722            1 : int video_set_ctrl(const struct device *dev, struct video_control *control);
     723              : 
     724              : /**
     725              :  * @brief Get the current value of a control.
     726              :  *
     727              :  * This retrieve the value of a video control, value type depends on control ID,
     728              :  * and must be interpreted accordingly.
     729              :  *
     730              :  * @param dev Pointer to the device structure.
     731              :  * @param control Pointer to the video control struct.
     732              :  *
     733              :  * @retval 0 Is successful.
     734              :  * @retval -EINVAL If parameters are invalid.
     735              :  * @retval -ENOTSUP If format is not supported.
     736              :  * @retval -EIO General input / output error.
     737              :  */
     738            1 : int video_get_ctrl(const struct device *dev, struct video_control *control);
     739              : 
     740              : struct video_ctrl_query;
     741              : 
     742              : /**
     743              :  * @brief Query information about a control.
     744              :  *
     745              :  * Applications set the id field of the query structure, the function fills the rest of this
     746              :  * structure. It is possible to enumerate base class controls (i.e., VIDEO_CID_BASE + x) by calling
     747              :  * this function with successive id values starting from VIDEO_CID_BASE up to and exclusive
     748              :  * VIDEO_CID_LASTP1. The function may return -ENOTSUP if a control in this range is not supported.
     749              :  * Applications can also enumerate private controls by starting at VIDEO_CID_PRIVATE_BASE and
     750              :  * incrementing the id until the driver returns -ENOTSUP. For other control classes, it's a bit more
     751              :  * difficult. Hence, the best way to enumerate all kinds of device's supported controls is to
     752              :  * iterate with VIDEO_CTRL_FLAG_NEXT_CTRL.
     753              :  *
     754              :  * @param cq Pointer to the control query struct.
     755              :  *
     756              :  * @retval 0 If successful.
     757              :  * @retval -EINVAL If the control id is invalid.
     758              :  * @retval -ENOTSUP If the control id is not supported.
     759              :  */
     760            1 : int video_query_ctrl(struct video_ctrl_query *cq);
     761              : 
     762              : /**
     763              :  * @brief Print all the information of a control.
     764              :  *
     765              :  * Print all the information of a control including its name, type, flag, range,
     766              :  * menu (if any) and current value, i.e. by invoking the video_get_ctrl(), in a
     767              :  * human readble format.
     768              :  *
     769              :  * @param cq Pointer to the control query struct.
     770              :  */
     771            1 : void video_print_ctrl(const struct video_ctrl_query *const cq);
     772              : 
     773              : /**
     774              :  * @brief Register/Unregister k_poll signal for a video endpoint.
     775              :  *
     776              :  * Register a poll signal to the endpoint, which will be signaled on frame
     777              :  * completion (done, aborted, error). Registering a NULL poll signal
     778              :  * unregisters any previously registered signal.
     779              :  *
     780              :  * @param dev Pointer to the device structure for the driver instance.
     781              :  * @param sig Pointer to k_poll_signal
     782              :  *
     783              :  * @retval 0 Is successful, -ERRNO code otherwise.
     784              :  */
     785            1 : static inline int video_set_signal(const struct device *dev, struct k_poll_signal *sig)
     786              : {
     787              :         const struct video_driver_api *api;
     788              : 
     789              :         __ASSERT_NO_MSG(dev != NULL);
     790              :         __ASSERT_NO_MSG(sig != NULL);
     791              : 
     792              :         api = (const struct video_driver_api *)dev->api;
     793              :         if (api->set_signal == NULL) {
     794              :                 return -ENOSYS;
     795              :         }
     796              : 
     797              :         return api->set_signal(dev, sig);
     798              : }
     799              : 
     800              : /**
     801              :  * @brief Set video selection (crop/compose).
     802              :  *
     803              :  * Configure the optional crop and compose feature of a video device.
     804              :  * Crop is first applied on the input frame, and the result of that crop is applied
     805              :  * to the compose. The result of the compose (width/height) is equal to the format
     806              :  * width/height given to the @ref video_set_format function.
     807              :  *
     808              :  * Some targets are inter-dependents. For instance, setting a @ref VIDEO_SEL_TGT_CROP will
     809              :  * reset @ref VIDEO_SEL_TGT_COMPOSE to the same size.
     810              :  *
     811              :  * @param dev Pointer to the device structure for the driver instance.
     812              :  * @param sel Pointer to a video selection structure
     813              :  *
     814              :  * @retval 0 Is successful.
     815              :  * @retval -EINVAL If parameters are invalid.
     816              :  * @retval -ENOTSUP If format is not supported.
     817              :  * @retval -EIO General input / output error.
     818              :  */
     819            1 : static inline int video_set_selection(const struct device *dev, struct video_selection *sel)
     820              : {
     821              :         const struct video_driver_api *api;
     822              : 
     823              :         __ASSERT_NO_MSG(dev != NULL);
     824              :         __ASSERT_NO_MSG(sel != NULL);
     825              : 
     826              :         api = (const struct video_driver_api *)dev->api;
     827              :         if (api->set_selection == NULL) {
     828              :                 return -ENOSYS;
     829              :         }
     830              : 
     831              :         return api->set_selection(dev, sel);
     832              : }
     833              : 
     834              : /**
     835              :  * @brief Get video selection (crop/compose).
     836              :  *
     837              :  * Retrieve the current settings related to the crop and compose of the video device.
     838              :  * This can also be used to read the native size of the input stream of the video
     839              :  * device.
     840              :  * This function can be used to read crop / compose capabilities of the device prior
     841              :  * to performing configuration via the @ref video_set_selection api.
     842              :  *
     843              :  * @param dev Pointer to the device structure for the driver instance.
     844              :  * @param sel Pointer to a video selection structure, @c type and @c target set by the caller
     845              :  *
     846              :  * @retval 0 Is successful.
     847              :  * @retval -EINVAL If parameters are invalid.
     848              :  * @retval -ENOTSUP If format is not supported.
     849              :  * @retval -EIO General input / output error.
     850              :  */
     851            1 : static inline int video_get_selection(const struct device *dev, struct video_selection *sel)
     852              : {
     853              :         const struct video_driver_api *api;
     854              : 
     855              :         __ASSERT_NO_MSG(dev != NULL);
     856              :         __ASSERT_NO_MSG(sel != NULL);
     857              : 
     858              :         api = (const struct video_driver_api *)dev->api;
     859              :         if (api->get_selection == NULL) {
     860              :                 return -ENOSYS;
     861              :         }
     862              : 
     863              :         return api->get_selection(dev, sel);
     864              : }
     865              : 
     866              : /**
     867              :  * @brief Allocate aligned video buffer.
     868              :  *
     869              :  * @param size Size of the video buffer (in bytes).
     870              :  * @param align Alignment of the requested memory, must be a power of two.
     871              :  * @param timeout Timeout duration or K_NO_WAIT
     872              :  *
     873              :  * @retval pointer to allocated video buffer
     874              :  */
     875            1 : struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align, k_timeout_t timeout);
     876              : 
     877              : /**
     878              :  * @brief Allocate video buffer.
     879              :  *
     880              :  * @param size Size of the video buffer (in bytes).
     881              :  * @param timeout Timeout duration or K_NO_WAIT
     882              :  *
     883              :  * @retval pointer to allocated video buffer
     884              :  */
     885            1 : struct video_buffer *video_buffer_alloc(size_t size, k_timeout_t timeout);
     886              : 
     887              : /**
     888              :  * @brief Release a video buffer.
     889              :  *
     890              :  * @param buf Pointer to the video buffer to release.
     891              :  */
     892            1 : void video_buffer_release(struct video_buffer *buf);
     893              : 
     894              : /**
     895              :  * @brief Search for a format that matches in a list of capabilities
     896              :  *
     897              :  * @param fmts The format capability list to search.
     898              :  * @param fmt The format to find in the list.
     899              :  * @param idx The pointer to a number of the first format that matches.
     900              :  *
     901              :  * @return 0 when a format is found.
     902              :  * @return -ENOENT when no matching format is found.
     903              :  */
     904            1 : int video_format_caps_index(const struct video_format_cap *fmts, const struct video_format *fmt,
     905              :                             size_t *idx);
     906              : 
     907              : /**
     908              :  * @brief Compute the difference between two frame intervals
     909              :  *
     910              :  * @param frmival Frame interval to turn into microseconds.
     911              :  *
     912              :  * @return The frame interval value in microseconds.
     913              :  */
     914            1 : static inline uint64_t video_frmival_nsec(const struct video_frmival *frmival)
     915              : {
     916              :         __ASSERT_NO_MSG(frmival != NULL);
     917              :         __ASSERT_NO_MSG(frmival->denominator != 0);
     918              : 
     919              :         return (uint64_t)NSEC_PER_SEC * frmival->numerator / frmival->denominator;
     920              : }
     921              : 
     922              : /**
     923              :  * @brief Find the closest match to a frame interval value within a stepwise frame interval.
     924              :  *
     925              :  * @param stepwise The stepwise frame interval range to search
     926              :  * @param desired The frame interval for which find the closest match
     927              :  * @param match The resulting frame interval closest to @p desired
     928              :  */
     929            1 : void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwise,
     930              :                                     const struct video_frmival *desired,
     931              :                                     struct video_frmival *match);
     932              : 
     933              : /**
     934              :  * @brief Find the closest match to a frame interval value within a video device.
     935              :  *
     936              :  * To compute the closest match, fill @p match with the following fields:
     937              :  *
     938              :  * - @c match->format to the @ref video_format of interest.
     939              :  * - @c match->type to @ref VIDEO_FRMIVAL_TYPE_DISCRETE.
     940              :  * - @c match->discrete to the desired frame interval.
     941              :  *
     942              :  * The result will be loaded into @p match, with the following fields set:
     943              :  *
     944              :  * - @c match->discrete to the value of the closest frame interval.
     945              :  * - @c match->index to the index of the closest frame interval.
     946              :  *
     947              :  * @param dev Video device to query.
     948              :  * @param match Frame interval enumerator with the query, and loaded with the result.
     949              :  */
     950            1 : void video_closest_frmival(const struct device *dev, struct video_frmival_enum *match);
     951              : 
     952              : /**
     953              :  * @brief Return the link-frequency advertised by a device
     954              :  *
     955              :  * Device exposing a CSI link should advertise at least one of the following two controls:
     956              :  *   - @ref VIDEO_CID_LINK_FREQ
     957              :  *   - @ref VIDEO_CID_PIXEL_RATE
     958              :  *
     959              :  * At first the helper will try read the @ref VIDEO_CID_LINK_FREQ and if not available will
     960              :  * approximate the link-frequency from the @ref VIDEO_CID_PIXEL_RATE value, taking into
     961              :  * consideration the bits per pixel of the format and the number of lanes.
     962              :  *
     963              :  * @param dev Video device to query.
     964              :  * @param bpp Amount of bits per pixel of the pixel format produced by the device
     965              :  * @param lane_nb Number of CSI-2 lanes used
     966              :  */
     967            1 : int64_t video_get_csi_link_freq(const struct device *dev, uint8_t bpp, uint8_t lane_nb);
     968              : 
     969              : /**
     970              :  * @brief Estimate the size and pitch in bytes of a @ref video_format
     971              :  *
     972              :  * This helper should only be used by drivers that support the whole image frame.
     973              :  *
     974              :  * For uncompressed formats, it gives the actual size and pitch of the
     975              :  * whole raw image without any padding.
     976              :  *
     977              :  * For compressed formats, it gives a rough estimate size of a complete
     978              :  * compressed frame.
     979              :  *
     980              :  * @param fmt Pointer to the video format structure
     981              :  * @return 0 on success, otherwise a negative errno code
     982              :  */
     983            1 : int video_estimate_fmt_size(struct video_format *fmt);
     984              : 
     985              : /**
     986              :  * @defgroup video_pixel_formats Video pixel formats
     987              :  * The '|' characters separate the pixels or logical blocks, and spaces separate the bytes.
     988              :  * The uppercase letter represents the most significant bit.
     989              :  * The lowercase letters represent the rest of the bits.
     990              :  * @{
     991              :  */
     992              : 
     993              : /**
     994              :  * @brief Four-character-code uniquely identifying the pixel format
     995              :  */
     996            1 : #define VIDEO_FOURCC(a, b, c, d)                                                                   \
     997              :         ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
     998              : 
     999              : /**
    1000              :  * @brief Convert a four-character-string to a four-character-code
    1001              :  *
    1002              :  * Convert a string literal or variable into a four-character-code
    1003              :  * as defined by @ref VIDEO_FOURCC.
    1004              :  *
    1005              :  * @param str String to be converted
    1006              :  * @return Four-character-code.
    1007              :  */
    1008            1 : #define VIDEO_FOURCC_FROM_STR(str) VIDEO_FOURCC((str)[0], (str)[1], (str)[2], (str)[3])
    1009              : 
    1010              : /**
    1011              :  * @brief Convert a four-character-code to a four-character-string
    1012              :  *
    1013              :  * Convert a four-character code as defined by @ref VIDEO_FOURCC into a string that can be used
    1014              :  * anywhere, such as in debug logs with the %s print formatter.
    1015              :  *
    1016              :  * @param fourcc The 32-bit four-character-code integer to be converted, in CPU-native endinaness.
    1017              :  * @return Four-character-string built out of it.
    1018              :  */
    1019            1 : #define VIDEO_FOURCC_TO_STR(fourcc)                                                                \
    1020              :         ((char[]){                                                                                 \
    1021              :                 (char)((fourcc) & 0xFF),                                                           \
    1022              :                 (char)(((fourcc) >> 8) & 0xFF),                                                    \
    1023              :                 (char)(((fourcc) >> 16) & 0xFF),                                                   \
    1024              :                 (char)(((fourcc) >> 24) & 0xFF),                                                   \
    1025              :                 '\0'                                                                               \
    1026              :         })
    1027              : 
    1028              : /**
    1029              :  * @name Bayer formats (R, G, B channels).
    1030              :  *
    1031              :  * The full color information is spread over multiple pixels.
    1032              :  *
    1033              :  * When the format includes more than 8-bit per pixel, a strategy becomes needed to pack
    1034              :  * the bits over multiple bytes, as illustrated for each format.
    1035              :  *
    1036              :  * The number above the 'R', 'r', 'G', 'g', 'B', 'b' are hints about which pixel number the
    1037              :  * following bits belong to.
    1038              :  *
    1039              :  * @{
    1040              :  */
    1041              : 
    1042              : /**
    1043              :  * @code{.unparsed}
    1044              :  *   0          1          2          3
    1045              :  * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
    1046              :  * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
    1047              :  * @endcode
    1048              :  */
    1049            1 : #define VIDEO_PIX_FMT_SBGGR8 VIDEO_FOURCC('B', 'A', '8', '1')
    1050              : 
    1051              : /**
    1052              :  * @code{.unparsed}
    1053              :  *   0          1          2          3
    1054              :  * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...
    1055              :  * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
    1056              :  * @endcode
    1057              :  */
    1058            1 : #define VIDEO_PIX_FMT_SGBRG8 VIDEO_FOURCC('G', 'B', 'R', 'G')
    1059              : 
    1060              : /**
    1061              :  * @code{.unparsed}
    1062              :  *   0          1          2          3
    1063              :  * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
    1064              :  * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
    1065              :  * @endcode
    1066              :  */
    1067            1 : #define VIDEO_PIX_FMT_SGRBG8 VIDEO_FOURCC('G', 'R', 'B', 'G')
    1068              : 
    1069              : /**
    1070              :  * @code{.unparsed}
    1071              :  *   0          1          2          3
    1072              :  * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
    1073              :  * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...
    1074              :  * @endcode
    1075              :  */
    1076            1 : #define VIDEO_PIX_FMT_SRGGB8 VIDEO_FOURCC('R', 'G', 'G', 'B')
    1077              : 
    1078              : /**
    1079              :  * @code{.unparsed}
    1080              :  *   0          1          2          3          3 2 1 0
    1081              :  * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbggbb | ...
    1082              :  * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrggrrgg | ...
    1083              :  * @endcode
    1084              :  */
    1085            1 : #define VIDEO_PIX_FMT_SBGGR10P VIDEO_FOURCC('p', 'B', 'A', 'A')
    1086              : 
    1087              : /**
    1088              :  * @code{.unparsed}
    1089              :  *   0          1          2          3          3 2 1 0
    1090              :  * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbggbbgg | ...
    1091              :  * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrggrr | ...
    1092              :  * @endcode
    1093              :  */
    1094            1 : #define VIDEO_PIX_FMT_SGBRG10P VIDEO_FOURCC('p', 'G', 'A', 'A')
    1095              : 
    1096              : /**
    1097              :  * @code{.unparsed}
    1098              :  *   0          1          2          3          3 2 1 0
    1099              :  * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrggrrgg | ...
    1100              :  * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbggbb | ...
    1101              :  * @endcode
    1102              :  */
    1103            1 : #define VIDEO_PIX_FMT_SGRBG10P VIDEO_FOURCC('p', 'g', 'A', 'A')
    1104              : 
    1105              : /**
    1106              :  * @code{.unparsed}
    1107              :  *   0          1          2          3          3 2 1 0
    1108              :  * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrggrr | ...
    1109              :  * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbggbbgg | ...
    1110              :  * @endcode
    1111              :  */
    1112            1 : #define VIDEO_PIX_FMT_SRGGB10P VIDEO_FOURCC('p', 'R', 'A', 'A')
    1113              : 
    1114              : /**
    1115              :  * @code{.unparsed}
    1116              :  *   0          1          1   0      2          3          3   2
    1117              :  * | Bbbbbbbb | Gggggggg | ggggbbbb | Bbbbbbbb | Gggggggg | ggggbbbb | ...
    1118              :  * | Gggggggg | Rrrrrrrr | rrrrgggg | Gggggggg | Rrrrrrrr | rrrrgggg | ...
    1119              :  * @endcode
    1120              :  */
    1121            1 : #define VIDEO_PIX_FMT_SBGGR12P VIDEO_FOURCC('p', 'B', 'C', 'C')
    1122              : 
    1123              : /**
    1124              :  * @code{.unparsed}
    1125              :  *   0          1          1   0      2          3          3   2
    1126              :  * | Gggggggg | Bbbbbbbb | bbbbgggg | Gggggggg | Bbbbbbbb | bbbbgggg | ...
    1127              :  * | Rrrrrrrr | Gggggggg | ggggrrrr | Rrrrrrrr | Gggggggg | ggggrrrr | ...
    1128              :  * @endcode
    1129              :  */
    1130            1 : #define VIDEO_PIX_FMT_SGBRG12P VIDEO_FOURCC('p', 'G', 'C', 'C')
    1131              : 
    1132              : /**
    1133              :  * @code{.unparsed}
    1134              :  *   0          1          1   0      2          3          3   2
    1135              :  * | Gggggggg | Rrrrrrrr | rrrrgggg | Gggggggg | Rrrrrrrr | rrrrgggg | ...
    1136              :  * | Bbbbbbbb | Gggggggg | ggggbbbb | Bbbbbbbb | Gggggggg | ggggbbbb | ...
    1137              :  * @endcode
    1138              :  */
    1139            1 : #define VIDEO_PIX_FMT_SGRBG12P VIDEO_FOURCC('p', 'g', 'C', 'C')
    1140              : 
    1141              : /**
    1142              :  * @code{.unparsed}
    1143              :  *   0          1          1   0      2          3          3   2
    1144              :  * | Rrrrrrrr | Gggggggg | ggggrrrr | Rrrrrrrr | Gggggggg | ggggrrrr | ...
    1145              :  * | Gggggggg | Bbbbbbbb | bbbbgggg | Gggggggg | Bbbbbbbb | bbbbgggg | ...
    1146              :  * @endcode
    1147              :  */
    1148            1 : #define VIDEO_PIX_FMT_SRGGB12P VIDEO_FOURCC('p', 'R', 'C', 'C')
    1149              : 
    1150              : /**
    1151              :  * @code{.unparsed}
    1152              :  *   0          1          2          3          1 0      2   1    3     2
    1153              :  * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbbbbb bbbbgggg ggggggbb | ...
    1154              :  * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrgggggg ggggrrrr rrrrrrgg | ...
    1155              :  * @endcode
    1156              :  */
    1157            1 : #define VIDEO_PIX_FMT_SBGGR14P VIDEO_FOURCC('p', 'B', 'E', 'E')
    1158              : 
    1159              : /**
    1160              :  * @code{.unparsed}
    1161              :  *   0          1          2          3          1 0      2   1    3     2
    1162              :  * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbgggggg ggggbbbb bbbbbbgg | ...
    1163              :  * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrrrrr rrrrgggg ggggggrr | ...
    1164              :  * @endcode
    1165              :  */
    1166            1 : #define VIDEO_PIX_FMT_SGBRG14P VIDEO_FOURCC('p', 'G', 'E', 'E')
    1167              : 
    1168              : /**
    1169              :  * @code{.unparsed}
    1170              :  *   0          1          2          3          1 0      2   1    3     2
    1171              :  * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrgggggg ggggrrrr rrrrrrgg | ...
    1172              :  * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbbbbb bbbbgggg ggggggbb | ...
    1173              :  * @endcode
    1174              :  */
    1175            1 : #define VIDEO_PIX_FMT_SGRBG14P VIDEO_FOURCC('p', 'g', 'E', 'E')
    1176              : 
    1177              : /**
    1178              :  * @code{.unparsed}
    1179              :  *   0          1          2          3          1 0      2   1    3     2
    1180              :  * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrrrrr rrrrgggg ggggggrr | ...
    1181              :  * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbgggggg ggggbbbb bbbbbbgg | ...
    1182              :  * @endcode
    1183              :  */
    1184            1 : #define VIDEO_PIX_FMT_SRGGB14P VIDEO_FOURCC('p', 'R', 'E', 'E')
    1185              : 
    1186              : /**
    1187              :  * @code{.unparsed}
    1188              :  * | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | ...
    1189              :  * | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | ...
    1190              :  * @endcode
    1191              :  */
    1192            1 : #define VIDEO_PIX_FMT_SBGGR10 VIDEO_FOURCC('B', 'G', '1', '0')
    1193              : 
    1194              : /**
    1195              :  * @code{.unparsed}
    1196              :  * | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | ...
    1197              :  * | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | ...
    1198              :  * @endcode
    1199              :  */
    1200            1 : #define VIDEO_PIX_FMT_SGBRG10 VIDEO_FOURCC('G', 'B', '1', '0')
    1201              : 
    1202              : /**
    1203              :  * @code{.unparsed}
    1204              :  * | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | ...
    1205              :  * | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | ...
    1206              :  * @endcode
    1207              :  */
    1208            1 : #define VIDEO_PIX_FMT_SGRBG10 VIDEO_FOURCC('B', 'A', '1', '0')
    1209              : 
    1210              : /**
    1211              :  * @code{.unparsed}
    1212              :  * | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | ...
    1213              :  * | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | ...
    1214              :  * @endcode
    1215              :  */
    1216            1 : #define VIDEO_PIX_FMT_SRGGB10 VIDEO_FOURCC('R', 'G', '1', '0')
    1217              : 
    1218              : /**
    1219              :  * @code{.unparsed}
    1220              :  * | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | ...
    1221              :  * | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | ...
    1222              :  * @endcode
    1223              :  */
    1224            1 : #define VIDEO_PIX_FMT_SBGGR12 VIDEO_FOURCC('B', 'G', '1', '2')
    1225              : 
    1226              : /**
    1227              :  * @code{.unparsed}
    1228              :  * | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | ...
    1229              :  * | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | ...
    1230              :  * @endcode
    1231              :  */
    1232            1 : #define VIDEO_PIX_FMT_SGBRG12 VIDEO_FOURCC('G', 'B', '1', '2')
    1233              : 
    1234              : /**
    1235              :  * @code{.unparsed}
    1236              :  * | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | ...
    1237              :  * | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | ...
    1238              :  * @endcode
    1239              :  */
    1240            1 : #define VIDEO_PIX_FMT_SGRBG12 VIDEO_FOURCC('B', 'A', '1', '2')
    1241              : 
    1242              : /**
    1243              :  * @code{.unparsed}
    1244              :  * | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | ...
    1245              :  * | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | ...
    1246              :  * @endcode
    1247              :  */
    1248            1 : #define VIDEO_PIX_FMT_SRGGB12 VIDEO_FOURCC('R', 'G', '1', '2')
    1249              : 
    1250              : /**
    1251              :  * @code{.unparsed}
    1252              :  * | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | ...
    1253              :  * | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | ...
    1254              :  * @endcode
    1255              :  */
    1256            1 : #define VIDEO_PIX_FMT_SBGGR14 VIDEO_FOURCC('B', 'G', '1', '4')
    1257              : 
    1258              : /**
    1259              :  * @code{.unparsed}
    1260              :  * | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | ...
    1261              :  * | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | ...
    1262              :  * @endcode
    1263              :  */
    1264            1 : #define VIDEO_PIX_FMT_SGBRG14 VIDEO_FOURCC('G', 'B', '1', '4')
    1265              : 
    1266              : /**
    1267              :  * @code{.unparsed}
    1268              :  * | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | ...
    1269              :  * | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | ...
    1270              :  * @endcode
    1271              :  */
    1272            1 : #define VIDEO_PIX_FMT_SGRBG14 VIDEO_FOURCC('G', 'R', '1', '4')
    1273              : 
    1274              : /**
    1275              :  * @code{.unparsed}
    1276              :  * | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | ...
    1277              :  * | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | ...
    1278              :  * @endcode
    1279              :  */
    1280            1 : #define VIDEO_PIX_FMT_SRGGB14 VIDEO_FOURCC('R', 'G', '1', '4')
    1281              : 
    1282              : /**
    1283              :  * @code{.unparsed}
    1284              :  * | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | ...
    1285              :  * | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | ...
    1286              :  * @endcode
    1287              :  */
    1288            1 : #define VIDEO_PIX_FMT_SBGGR16 VIDEO_FOURCC('B', 'Y', 'R', '2')
    1289              : 
    1290              : /**
    1291              :  * @code{.unparsed}
    1292              :  * | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | ...
    1293              :  * | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | ...
    1294              :  * @endcode
    1295              :  */
    1296            1 : #define VIDEO_PIX_FMT_SGBRG16 VIDEO_FOURCC('G', 'B', '1', '6')
    1297              : 
    1298              : /**
    1299              :  * @code{.unparsed}
    1300              :  * | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | ...
    1301              :  * | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | ...
    1302              :  * @endcode
    1303              :  */
    1304            1 : #define VIDEO_PIX_FMT_SGRBG16 VIDEO_FOURCC('G', 'R', '1', '6')
    1305              : 
    1306              : /**
    1307              :  * @code{.unparsed}
    1308              :  * | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | ...
    1309              :  * | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | ...
    1310              :  * @endcode
    1311              :  */
    1312            1 : #define VIDEO_PIX_FMT_SRGGB16 VIDEO_FOURCC('R', 'G', '1', '6')
    1313              : 
    1314              : /**
    1315              :  * @}
    1316              :  */
    1317              : 
    1318              : /**
    1319              :  * @name Grayscale formats
    1320              :  * Luminance (Y) channel only, in various bit depth and packing.
    1321              :  *
    1322              :  * When the format includes more than 8-bit per pixel, a strategy becomes needed to pack
    1323              :  * the bits over multiple bytes, as illustrated for each format.
    1324              :  *
    1325              :  * The number above the 'Y', 'y' are hints about which pixel number the following bits belong to.
    1326              :  *
    1327              :  * @{
    1328              :  */
    1329              : 
    1330              : /**
    1331              :  * Same as Y8 (8-bit luma-only) following the standard FOURCC naming,
    1332              :  * or L8 in some graphics libraries.
    1333              :  *
    1334              :  * @code{.unparsed}
    1335              :  *   0          1          2          3
    1336              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1337              :  * @endcode
    1338              :  */
    1339            1 : #define VIDEO_PIX_FMT_GREY VIDEO_FOURCC('G', 'R', 'E', 'Y')
    1340              : 
    1341              : /**
    1342              :  * @code{.unparsed}
    1343              :  *   0          1          2          3          3 2 1 0
    1344              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | ...
    1345              :  * @endcode
    1346              :  */
    1347            1 : #define VIDEO_PIX_FMT_Y10P VIDEO_FOURCC('Y', '1', '0', 'P')
    1348              : 
    1349              : /**
    1350              :  * @code{.unparsed}
    1351              :  *   0          1          1   0      2          3          3   2
    1352              :  * | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | ...
    1353              :  * | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | ...
    1354              :  * @endcode
    1355              :  */
    1356            1 : #define VIDEO_PIX_FMT_Y12P VIDEO_FOURCC('Y', '1', '2', 'P')
    1357              : 
    1358              : /**
    1359              :  * @code{.unparsed}
    1360              :  *   0          1          2          3          1 0      2   1    3     2
    1361              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy yyyyyyyy yyyyyyyy | ...
    1362              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy yyyyyyyy yyyyyyyy | ...
    1363              :  * @endcode
    1364              :  */
    1365            1 : #define VIDEO_PIX_FMT_Y14P VIDEO_FOURCC('Y', '1', '4', 'P')
    1366              : 
    1367              : /**
    1368              :  * Little endian, with the 6 most significant bits set to Zero.
    1369              :  * @code{.unparsed}
    1370              :  *   0                   1                   2                   3
    1371              :  * | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | ...
    1372              :  * | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | ...
    1373              :  * @endcode
    1374              :  */
    1375            1 : #define VIDEO_PIX_FMT_Y10 VIDEO_FOURCC('Y', '1', '0', ' ')
    1376              : 
    1377              : /**
    1378              :  * Little endian, with the 4 most significant bits set to Zero.
    1379              :  * @code{.unparsed}
    1380              :  *   0                   1                   2                   3
    1381              :  * | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | ...
    1382              :  * | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | ...
    1383              :  * @endcode
    1384              :  */
    1385            1 : #define VIDEO_PIX_FMT_Y12 VIDEO_FOURCC('Y', '1', '2', ' ')
    1386              : 
    1387              : /**
    1388              :  * Little endian, with the 2 most significant bits set to Zero.
    1389              :  * @code{.unparsed}
    1390              :  *   0                   1                   2                   3
    1391              :  * | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | ...
    1392              :  * | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | ...
    1393              :  * @endcode
    1394              :  */
    1395            1 : #define VIDEO_PIX_FMT_Y14 VIDEO_FOURCC('Y', '1', '4', ' ')
    1396              : 
    1397              : /**
    1398              :  * Little endian.
    1399              :  * @code{.unparsed}
    1400              :  *   0                   1                   2                   3
    1401              :  * | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | ...
    1402              :  * | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | ...
    1403              :  * @endcode
    1404              :  */
    1405            1 : #define VIDEO_PIX_FMT_Y16 VIDEO_FOURCC('Y', '1', '6', ' ')
    1406              : 
    1407              : /**
    1408              :  * @}
    1409              :  */
    1410              : 
    1411              : /**
    1412              :  * @name RGB formats
    1413              :  * Per-color (R, G, B) channels.
    1414              :  * @{
    1415              :  */
    1416              : 
    1417              : /**
    1418              :  * 5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
    1419              :  * This 16-bit integer is then packed in big endian format over two bytes:
    1420              :  *
    1421              :  * @code{.unparsed}
    1422              :  *   15.....8 7......0
    1423              :  * | RrrrrGgg gggBbbbb | ...
    1424              :  * @endcode
    1425              :  */
    1426            1 : #define VIDEO_PIX_FMT_RGB565X VIDEO_FOURCC('R', 'G', 'B', 'R')
    1427              : 
    1428              : /**
    1429              :  * 5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
    1430              :  * This 16-bit integer is then packed in little endian format over two bytes:
    1431              :  *
    1432              :  * @code{.unparsed}
    1433              :  *   7......0 15.....8
    1434              :  * | gggBbbbb RrrrrGgg | ...
    1435              :  * @endcode
    1436              :  */
    1437            1 : #define VIDEO_PIX_FMT_RGB565 VIDEO_FOURCC('R', 'G', 'B', 'P')
    1438              : 
    1439              : /**
    1440              :  * 24 bit RGB format with 8 bit per component
    1441              :  *
    1442              :  * @code{.unparsed}
    1443              :  * | Bbbbbbbb Gggggggg Rggggggg | ...
    1444              :  * @endcode
    1445              :  */
    1446            1 : #define VIDEO_PIX_FMT_BGR24 VIDEO_FOURCC('B', 'G', 'R', '3')
    1447              : 
    1448              : /**
    1449              :  * 24 bit RGB format with 8 bit per component
    1450              :  *
    1451              :  * @code{.unparsed}
    1452              :  * | Rggggggg Gggggggg Bbbbbbbb | ...
    1453              :  * @endcode
    1454              :  */
    1455            1 : #define VIDEO_PIX_FMT_RGB24 VIDEO_FOURCC('R', 'G', 'B', '3')
    1456              : 
    1457              : /**
    1458              :  * @code{.unparsed}
    1459              :  * | Aaaaaaaa Rrrrrrrr Gggggggg Bbbbbbbb | ...
    1460              :  * @endcode
    1461              :  */
    1462              : 
    1463            1 : #define VIDEO_PIX_FMT_ARGB32 VIDEO_FOURCC('B', 'A', '2', '4')
    1464              : 
    1465              : /**
    1466              :  * @code{.unparsed}
    1467              :  * | Bbbbbbbb Gggggggg Rrrrrrrr Aaaaaaaa | ...
    1468              :  * @endcode
    1469              :  */
    1470              : 
    1471            1 : #define VIDEO_PIX_FMT_ABGR32 VIDEO_FOURCC('A', 'R', '2', '4')
    1472              : 
    1473              : /**
    1474              :  * @code{.unparsed}
    1475              :  * | Rrrrrrrr Gggggggg Bbbbbbbb Aaaaaaaa | ...
    1476              :  * @endcode
    1477              :  */
    1478              : 
    1479            1 : #define VIDEO_PIX_FMT_RGBA32 VIDEO_FOURCC('A', 'B', '2', '4')
    1480              : 
    1481              : /**
    1482              :  * @code{.unparsed}
    1483              :  * | Aaaaaaaa Bbbbbbbb Gggggggg Rrrrrrrr | ...
    1484              :  * @endcode
    1485              :  */
    1486              : 
    1487            1 : #define VIDEO_PIX_FMT_BGRA32 VIDEO_FOURCC('R', 'A', '2', '4')
    1488              : 
    1489              : /**
    1490              :  * The first byte is empty (X) for each pixel.
    1491              :  *
    1492              :  * @code{.unparsed}
    1493              :  * | Xxxxxxxx Rrrrrrrr Gggggggg Bbbbbbbb | ...
    1494              :  * @endcode
    1495              :  */
    1496            1 : #define VIDEO_PIX_FMT_XRGB32 VIDEO_FOURCC('B', 'X', '2', '4')
    1497              : 
    1498              : /**
    1499              :  * @}
    1500              :  */
    1501              : 
    1502              : /**
    1503              :  * @name YUV formats
    1504              :  * Luminance (Y) and chrominance (U, V) channels.
    1505              :  * @{
    1506              :  */
    1507              : 
    1508              : /**
    1509              :  * There is either a missing channel per pixel, U or V.
    1510              :  * The value is to be averaged over 2 pixels to get the value of individual pixel.
    1511              :  *
    1512              :  * @code{.unparsed}
    1513              :  * | Yyyyyyyy Uuuuuuuu | Yyyyyyyy Vvvvvvvv | ...
    1514              :  * @endcode
    1515              :  */
    1516            1 : #define VIDEO_PIX_FMT_YUYV VIDEO_FOURCC('Y', 'U', 'Y', 'V')
    1517              : 
    1518              : /**
    1519              :  * @code{.unparsed}
    1520              :  * | Yyyyyyyy Vvvvvvvv | Yyyyyyyy Uuuuuuuu | ...
    1521              :  * @endcode
    1522              :  */
    1523            1 : #define VIDEO_PIX_FMT_YVYU VIDEO_FOURCC('Y', 'V', 'Y', 'U')
    1524              : 
    1525              : /**
    1526              :  * @code{.unparsed}
    1527              :  * | Vvvvvvvv Yyyyyyyy | Uuuuuuuu Yyyyyyyy | ...
    1528              :  * @endcode
    1529              :  */
    1530            1 : #define VIDEO_PIX_FMT_VYUY VIDEO_FOURCC('V', 'Y', 'U', 'Y')
    1531              : 
    1532              : /**
    1533              :  * @code{.unparsed}
    1534              :  * | Uuuuuuuu Yyyyyyyy | Vvvvvvvv Yyyyyyyy | ...
    1535              :  * @endcode
    1536              :  */
    1537            1 : #define VIDEO_PIX_FMT_UYVY VIDEO_FOURCC('U', 'Y', 'V', 'Y')
    1538              : 
    1539              : /**
    1540              :  * The first byte is empty (X) for each pixel.
    1541              :  *
    1542              :  * @code{.unparsed}
    1543              :  * | Xxxxxxxx Yyyyyyyy Uuuuuuuu Vvvvvvvv | ...
    1544              :  * @endcode
    1545              :  */
    1546            1 : #define VIDEO_PIX_FMT_XYUV32 VIDEO_FOURCC('X', 'Y', 'U', 'V')
    1547              : 
    1548              : /**
    1549              :  * Planar formats
    1550              :  */
    1551              : /**
    1552              :  * Chroma (U/V) are subsampled horizontaly and vertically
    1553              :  *
    1554              :  * @code{.unparsed}
    1555              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1556              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1557              :  * | ... |
    1558              :  * | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv | ...
    1559              :  * | ... |
    1560              :  * @endcode
    1561              :  *
    1562              :  * Below diagram show how luma and chroma relate to each others
    1563              :  *
    1564              :  * @code{.unparsed}
    1565              :  *  Y0        Y1        Y2        Y3        ...
    1566              :  *  Y6        Y7        Y8        Y9        ...
    1567              :  *  ...
    1568              :  *
    1569              :  *  U0/1/6/7  V0/1/6/7  U2/3/8/9  V2/3/8/9  ...
    1570              :  *  ...
    1571              :  * @endcode
    1572              :  */
    1573            1 : #define VIDEO_PIX_FMT_NV12 VIDEO_FOURCC('N', 'V', '1', '2')
    1574              : 
    1575              : /**
    1576              :  * Chroma (U/V) are subsampled horizontaly and vertically
    1577              :  *
    1578              :  * @code{.unparsed}
    1579              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1580              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1581              :  * | ... |
    1582              :  * | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu | ...
    1583              :  * | ... |
    1584              :  * @endcode
    1585              :  *
    1586              :  * Below diagram show how luma and chroma relate to each others
    1587              :  *
    1588              :  * @code{.unparsed}
    1589              :  *  Y0        Y1        Y2        Y3        ...
    1590              :  *  Y6        Y7        Y8        Y9        ...
    1591              :  *  ...
    1592              :  *
    1593              :  *  V0/1/6/7  U0/1/6/7  V2/3/8/9  U2/3/8/9  ...
    1594              :  *  ...
    1595              :  * @endcode
    1596              :  */
    1597            1 : #define VIDEO_PIX_FMT_NV21 VIDEO_FOURCC('N', 'V', '2', '1')
    1598              : 
    1599              : /**
    1600              :  * Chroma (U/V) are subsampled horizontaly
    1601              :  *
    1602              :  * @code{.unparsed}
    1603              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1604              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1605              :  * | ... |
    1606              :  * | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv | ...
    1607              :  * | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv | ...
    1608              :  * | ... |
    1609              :  * @endcode
    1610              :  *
    1611              :  * Below diagram show how luma and chroma relate to each others
    1612              :  *
    1613              :  * @code{.unparsed}
    1614              :  *  Y0        Y1        Y2        Y3        ...
    1615              :  *  Y6        Y7        Y8        Y9        ...
    1616              :  *  ...
    1617              :  *
    1618              :  *  U0/1      V0/1      U2/3      V2/3      ...
    1619              :  *  U6/7      V6/7      U8/9      V8/9      ...
    1620              :  *  ...
    1621              :  * @endcode
    1622              :  */
    1623            1 : #define VIDEO_PIX_FMT_NV16 VIDEO_FOURCC('N', 'V', '1', '6')
    1624              : 
    1625              : /**
    1626              :  * Chroma (U/V) are subsampled horizontaly
    1627              :  *
    1628              :  * @code{.unparsed}
    1629              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1630              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
    1631              :  * | ... |
    1632              :  * | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu | ...
    1633              :  * | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu | ...
    1634              :  * | ... |
    1635              :  * @endcode
    1636              :  *
    1637              :  * Below diagram show how luma and chroma relate to each others
    1638              :  *
    1639              :  * @code{.unparsed}
    1640              :  *  Y0        Y1        Y2        Y3        ...
    1641              :  *  Y6        Y7        Y8        Y9        ...
    1642              :  *  ...
    1643              :  *
    1644              :  *  V0/1      U0/1      V2/3      U2/3      ...
    1645              :  *  V6/7      U6/7      V8/9      U8/9      ...
    1646              :  *  ...
    1647              :  * @endcode
    1648              :  */
    1649              : 
    1650            1 : #define VIDEO_PIX_FMT_NV61 VIDEO_FOURCC('N', 'V', '6', '1')
    1651              : 
    1652              : /**
    1653              :  * Chroma (U/V) are not subsampled
    1654              :  *
    1655              :  * @code{.unparsed}
    1656              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1657              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1658              :  * | ... |
    1659              :  * | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv |
    1660              :  * | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv | Uuuuuuuu   Vvvvvvvv |
    1661              :  * | ... |
    1662              :  * @endcode
    1663              :  *
    1664              :  * Below diagram show how luma and chroma relate to each others
    1665              :  *
    1666              :  * @code{.unparsed}
    1667              :  *  Y0        Y1        Y2        Y3        ...
    1668              :  *  Y6        Y7        Y8        Y9        ...
    1669              :  *  ...
    1670              :  *
    1671              :  *  U0        V0        U1        V1        U2        V2        U3        V3        ...
    1672              :  *  U6        V6        U7        V7        U8        V8        U9        V9        ...
    1673              :  *  ...
    1674              :  * @endcode
    1675              :  */
    1676            1 : #define VIDEO_PIX_FMT_NV24 VIDEO_FOURCC('N', 'V', '2', '4')
    1677              : 
    1678              : /**
    1679              :  * Chroma (U/V) are not subsampled
    1680              :  *
    1681              :  * @code{.unparsed}
    1682              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1683              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1684              :  * | ... |
    1685              :  * | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu |
    1686              :  * | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu | Vvvvvvvv   Uuuuuuuu |
    1687              :  * | ... |
    1688              :  * @endcode
    1689              :  *
    1690              :  * Below diagram show how luma and chroma relate to each others
    1691              :  *
    1692              :  * @code{.unparsed}
    1693              :  *  Y0        Y1        Y2        Y3        ...
    1694              :  *  Y6        Y7        Y8        Y9        ...
    1695              :  *  ...
    1696              :  *
    1697              :  *  V0        U0        V1        U1        V2        U2        V3        U3        ...
    1698              :  *  V6        U6        V7        U7        V8        U8        V9        U9        ...
    1699              :  *  ...
    1700              :  * @endcode
    1701              :  */
    1702            1 : #define VIDEO_PIX_FMT_NV42 VIDEO_FOURCC('N', 'V', '4', '2')
    1703              : 
    1704              : /**
    1705              :  * Chroma (U/V) are subsampled horizontaly and vertically
    1706              :  *
    1707              :  * @code{.unparsed}
    1708              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1709              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1710              :  * | ... |
    1711              :  * | Uuuuuuuu | Uuuuuuuu |
    1712              :  * | ... |
    1713              :  * | Vvvvvvvv | Vvvvvvvv |
    1714              :  * | ... |
    1715              :  * @endcode
    1716              :  *
    1717              :  * Below diagram show how luma and chroma relate to each others
    1718              :  *
    1719              :  * @code{.unparsed}
    1720              :  *  Y0        Y1        Y2        Y3        ...
    1721              :  *  Y6        Y7        Y8        Y9        ...
    1722              :  *  ...
    1723              :  *
    1724              :  *  U0/1/6/7      U2/3/8/9      ...
    1725              :  *  ...
    1726              :  *
    1727              :  *  V0/1/6/7      V2/3/8/9      ...
    1728              :  *  ...
    1729              :  * @endcode
    1730              :  */
    1731            1 : #define VIDEO_PIX_FMT_YUV420 VIDEO_FOURCC('Y', 'U', '1', '2')
    1732              : 
    1733              : /**
    1734              :  * Chroma (U/V) are subsampled horizontaly and vertically
    1735              :  *
    1736              :  * @code{.unparsed}
    1737              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1738              :  * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
    1739              :  * | ... |
    1740              :  * | Vvvvvvvv | Vvvvvvvv |
    1741              :  * | ... |
    1742              :  * | Uuuuuuuu | Uuuuuuuu |
    1743              :  * | ... |
    1744              :  * @endcode
    1745              :  *
    1746              :  * Below diagram show how luma and chroma relate to each others
    1747              :  *
    1748              :  * @code{.unparsed}
    1749              :  *  Y0        Y1        Y2        Y3        ...
    1750              :  *  Y6        Y7        Y8        Y9        ...
    1751              :  *  ...
    1752              :  *
    1753              :  *  V0/1/6/7      V2/3/8/9      ...
    1754              :  *  ...
    1755              :  *
    1756              :  *  U0/1/6/7      U2/3/8/9      ...
    1757              :  *  ...
    1758              :  * @endcode
    1759              :  */
    1760            1 : #define VIDEO_PIX_FMT_YVU420 VIDEO_FOURCC('Y', 'V', '1', '2')
    1761              : 
    1762              : /**
    1763              :  * @}
    1764              :  */
    1765              : 
    1766              : /**
    1767              :  * @name Compressed formats
    1768              :  * @{
    1769              :  */
    1770              : 
    1771              : /**
    1772              :  * Both JPEG (single frame) and Motion-JPEG (MJPEG, multiple JPEG frames concatenated)
    1773              :  */
    1774            1 : #define VIDEO_PIX_FMT_JPEG VIDEO_FOURCC('J', 'P', 'E', 'G')
    1775              : 
    1776              : /**
    1777              :  * H264 with start code
    1778              :  */
    1779            1 : #define VIDEO_PIX_FMT_H264 VIDEO_FOURCC('H', '2', '6', '4')
    1780              : 
    1781              : /**
    1782              :  * H264 without start code
    1783              :  */
    1784            1 : #define VIDEO_PIX_FMT_H264_NO_SC VIDEO_FOURCC('A', 'V', 'C', '1')
    1785              : 
    1786              : /**
    1787              :  * @}
    1788              :  */
    1789              : 
    1790              : /**
    1791              :  * @brief Get number of bits per pixel of a pixel format
    1792              :  *
    1793              :  * @param pixfmt FourCC pixel format value (@ref video_pixel_formats).
    1794              :  *
    1795              :  * @retval 0 if the format is unhandled or if it is variable number of bits
    1796              :  * @retval >0 bit size of one pixel for this format
    1797              :  */
    1798            1 : static inline unsigned int video_bits_per_pixel(uint32_t pixfmt)
    1799              : {
    1800              :         switch (pixfmt) {
    1801              :         case VIDEO_PIX_FMT_SBGGR8:
    1802              :         case VIDEO_PIX_FMT_SGBRG8:
    1803              :         case VIDEO_PIX_FMT_SGRBG8:
    1804              :         case VIDEO_PIX_FMT_SRGGB8:
    1805              :         case VIDEO_PIX_FMT_GREY:
    1806              :                 return 8;
    1807              :         case VIDEO_PIX_FMT_SBGGR10P:
    1808              :         case VIDEO_PIX_FMT_SGBRG10P:
    1809              :         case VIDEO_PIX_FMT_SGRBG10P:
    1810              :         case VIDEO_PIX_FMT_SRGGB10P:
    1811              :         case VIDEO_PIX_FMT_Y10P:
    1812              :                 return 10;
    1813              :         case VIDEO_PIX_FMT_SBGGR12P:
    1814              :         case VIDEO_PIX_FMT_SGBRG12P:
    1815              :         case VIDEO_PIX_FMT_SGRBG12P:
    1816              :         case VIDEO_PIX_FMT_SRGGB12P:
    1817              :         case VIDEO_PIX_FMT_Y12P:
    1818              :         case VIDEO_PIX_FMT_NV12:
    1819              :         case VIDEO_PIX_FMT_NV21:
    1820              :         case VIDEO_PIX_FMT_YUV420:
    1821              :         case VIDEO_PIX_FMT_YVU420:
    1822              :                 return 12;
    1823              :         case VIDEO_PIX_FMT_SBGGR14P:
    1824              :         case VIDEO_PIX_FMT_SGBRG14P:
    1825              :         case VIDEO_PIX_FMT_SGRBG14P:
    1826              :         case VIDEO_PIX_FMT_SRGGB14P:
    1827              :         case VIDEO_PIX_FMT_Y14P:
    1828              :                 return 14;
    1829              :         case VIDEO_PIX_FMT_RGB565:
    1830              :         case VIDEO_PIX_FMT_YUYV:
    1831              :         case VIDEO_PIX_FMT_YVYU:
    1832              :         case VIDEO_PIX_FMT_UYVY:
    1833              :         case VIDEO_PIX_FMT_VYUY:
    1834              :         case VIDEO_PIX_FMT_SBGGR10:
    1835              :         case VIDEO_PIX_FMT_SGBRG10:
    1836              :         case VIDEO_PIX_FMT_SGRBG10:
    1837              :         case VIDEO_PIX_FMT_SRGGB10:
    1838              :         case VIDEO_PIX_FMT_SBGGR12:
    1839              :         case VIDEO_PIX_FMT_SGBRG12:
    1840              :         case VIDEO_PIX_FMT_SGRBG12:
    1841              :         case VIDEO_PIX_FMT_SRGGB12:
    1842              :         case VIDEO_PIX_FMT_SBGGR14:
    1843              :         case VIDEO_PIX_FMT_SGBRG14:
    1844              :         case VIDEO_PIX_FMT_SGRBG14:
    1845              :         case VIDEO_PIX_FMT_SRGGB14:
    1846              :         case VIDEO_PIX_FMT_SBGGR16:
    1847              :         case VIDEO_PIX_FMT_SGBRG16:
    1848              :         case VIDEO_PIX_FMT_SGRBG16:
    1849              :         case VIDEO_PIX_FMT_SRGGB16:
    1850              :         case VIDEO_PIX_FMT_Y10:
    1851              :         case VIDEO_PIX_FMT_Y12:
    1852              :         case VIDEO_PIX_FMT_Y14:
    1853              :         case VIDEO_PIX_FMT_Y16:
    1854              :         case VIDEO_PIX_FMT_NV16:
    1855              :         case VIDEO_PIX_FMT_NV61:
    1856              :                 return 16;
    1857              :         case VIDEO_PIX_FMT_BGR24:
    1858              :         case VIDEO_PIX_FMT_RGB24:
    1859              :         case VIDEO_PIX_FMT_NV24:
    1860              :         case VIDEO_PIX_FMT_NV42:
    1861              :                 return 24;
    1862              :         case VIDEO_PIX_FMT_XRGB32:
    1863              :         case VIDEO_PIX_FMT_XYUV32:
    1864              :         case VIDEO_PIX_FMT_ARGB32:
    1865              :         case VIDEO_PIX_FMT_ABGR32:
    1866              :         case VIDEO_PIX_FMT_RGBA32:
    1867              :         case VIDEO_PIX_FMT_BGRA32:
    1868              :                 return 32;
    1869              :         default:
    1870              :                 /* Variable number of bits per pixel or unknown format */
    1871              :                 return 0;
    1872              :         }
    1873              : }
    1874              : 
    1875              : /**
    1876              :  * @}
    1877              :  */
    1878              : 
    1879              : /**
    1880              :  * @name MIPI CSI-2 Data Types
    1881              :  * @brief Standard MIPI CSI-2 data type identifiers for camera sensor interfaces
    1882              :  *
    1883              :  * These constants define the data type field values used in MIPI CSI-2 packet headers to identify
    1884              :  * the format and encoding of transmitted image data. The data type field is 6 bits wide, allowing
    1885              :  * values from 0x00 to 0x3F.
    1886              :  *
    1887              :  * @{
    1888              :  */
    1889              : 
    1890              : /** NULL data type - used for padding or synchronization */
    1891            1 : #define VIDEO_MIPI_CSI2_DT_NULL                 0x10
    1892              : /** Blanking data - horizontal/vertical blanking information */
    1893            1 : #define VIDEO_MIPI_CSI2_DT_BLANKING             0x11
    1894              : /** Embedded 8-bit data - sensor metadata or configuration data */
    1895            1 : #define VIDEO_MIPI_CSI2_DT_EMBEDDED_8           0x12
    1896              : /** YUV 4:2:0 format with 8 bits per component */
    1897            1 : #define VIDEO_MIPI_CSI2_DT_YUV420_8             0x18
    1898              : /** YUV 4:2:0 format with 10 bits per component */
    1899            1 : #define VIDEO_MIPI_CSI2_DT_YUV420_10            0x19
    1900              : /** YUV 4:2:0 CSPS (Chroma Shifted Pixel Sampling) 8-bit format */
    1901            1 : #define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_8        0x1c
    1902              : /** YUV 4:2:0 CSPS (Chroma Shifted Pixel Sampling) 10-bit format */
    1903            1 : #define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_10       0x1d
    1904              : /** YUV 4:2:2 format with 8 bits per component */
    1905            1 : #define VIDEO_MIPI_CSI2_DT_YUV422_8             0x1e
    1906              : /** YUV 4:2:2 format with 10 bits per component */
    1907            1 : #define VIDEO_MIPI_CSI2_DT_YUV422_10            0x1f
    1908              : /** RGB format with 4 bits per color component */
    1909            1 : #define VIDEO_MIPI_CSI2_DT_RGB444               0x20
    1910              : /** RGB format with 5 bits per color component */
    1911            1 : #define VIDEO_MIPI_CSI2_DT_RGB555               0x21
    1912              : /** RGB format with 5-6-5 bits per R-G-B components */
    1913            1 : #define VIDEO_MIPI_CSI2_DT_RGB565               0x22
    1914              : /** RGB format with 6 bits per color component */
    1915            1 : #define VIDEO_MIPI_CSI2_DT_RGB666               0x23
    1916              : /** RGB format with 8 bits per color component */
    1917            1 : #define VIDEO_MIPI_CSI2_DT_RGB888               0x24
    1918              : /** Raw sensor data with 6 bits per pixel */
    1919            1 : #define VIDEO_MIPI_CSI2_DT_RAW6                 0x28
    1920              : /** Raw sensor data with 7 bits per pixel */
    1921            1 : #define VIDEO_MIPI_CSI2_DT_RAW7                 0x29
    1922              : /** Raw sensor data with 8 bits per pixel */
    1923            1 : #define VIDEO_MIPI_CSI2_DT_RAW8                 0x2a
    1924              : /** Raw sensor data with 10 bits per pixel */
    1925            1 : #define VIDEO_MIPI_CSI2_DT_RAW10                0x2b
    1926              : /** Raw sensor data with 12 bits per pixel */
    1927            1 : #define VIDEO_MIPI_CSI2_DT_RAW12                0x2c
    1928              : /** Raw sensor data with 14 bits per pixel */
    1929            1 : #define VIDEO_MIPI_CSI2_DT_RAW14                0x2d
    1930              : 
    1931              : /**
    1932              :  * @brief User-defined data type generator macro
    1933              :  *
    1934              :  * Generates user-defined data type identifier for custom or proprietary formats.
    1935              :  * The MIPI CSI-2 specification reserves data types 0x30 to 0x37 for user-specific implementations.
    1936              :  *
    1937              :  * @note Parameter n must be in range 0-7 to generate valid user-defined data types
    1938              :  *
    1939              :  * @param n User-defined type index (0-7)
    1940              :  * @return Data type value in user-defined range (0x30-0x37)
    1941              :  */
    1942            1 : #define VIDEO_MIPI_CSI2_DT_USER(n)      (0x30 + (n))
    1943              : 
    1944              : /**
    1945              :  * @}
    1946              :  */
    1947              : 
    1948              : #ifdef __cplusplus
    1949              : }
    1950              : #endif
    1951              : 
    1952              : /**
    1953              :  * @}
    1954              :  */
    1955              : 
    1956              : #endif /* ZEPHYR_INCLUDE_VIDEO_H_ */
        

Generated by: LCOV version 2.0-1