Skip to content

Commit b01240b

Browse files
author
Alain Volmat
committed
video: api: addition of video_set/get_selection APIs
Addition of selection APIs (set/get) in order to be able to control the crop and compose of a video device. Signed-off-by: Alain Volmat <[email protected]>
1 parent 013abd8 commit b01240b

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

include/zephyr/drivers/video.h

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/*
88
* Copyright (c) 2019 Linaro Limited.
99
* Copyright 2025 NXP
10+
* Copyright (c) 2025 STMicroelectronics
1011
*
1112
* SPDX-License-Identifier: Apache-2.0
1213
*/
@@ -237,6 +238,57 @@ enum video_signal_result {
237238
VIDEO_BUF_ERROR,
238239
};
239240

241+
/**
242+
* @struct video_selection_target
243+
* @brief Video selection target enum
244+
*
245+
* Used to indicate which selection to query or set on a video device
246+
*/
247+
enum video_selection_target {
248+
/** Current crop setting */
249+
VIDEO_SEL_TGT_CROP,
250+
/** Crop bound (aka the maximum crop achievable) */
251+
VIDEO_SEL_TGT_CROP_BOUND,
252+
/** Native size of the input frame */
253+
VIDEO_SEL_TGT_NATIVE_SIZE,
254+
/** Current compose setting */
255+
VIDEO_SEL_TGT_COMPOSE,
256+
/** Compose bound (aka the maximum compose achievable) */
257+
VIDEO_SEL_TGT_COMPOSE_BOUND,
258+
};
259+
260+
/**
261+
* @struct video_rect
262+
* @brief Description of a rectangle area.
263+
*
264+
* Used for crop/compose and possibly within drivers as well
265+
*/
266+
struct video_rect {
267+
/** left offset of selection rectangle */
268+
uint32_t left;
269+
/** top offset of selection rectangle */
270+
uint32_t top;
271+
/** width of selection rectangle */
272+
uint32_t width;
273+
/** height of selection rectangle */
274+
uint32_t height;
275+
};
276+
277+
/**
278+
* @struct video_selection
279+
* @brief Video selection (crop / compose) structure
280+
*
281+
* Used to describe the query and set selection target on a video device
282+
*/
283+
struct video_selection {
284+
/** buffer type, allow to select for device having both input and output */
285+
enum video_buf_type type;
286+
/** selection target enum */
287+
enum video_selection_target target;
288+
/** selection target rectangle */
289+
struct video_rect rect;
290+
};
291+
240292
/**
241293
* @typedef video_api_format_t
242294
* @brief Function pointer type for video_set/get_format()
@@ -327,6 +379,14 @@ typedef int (*video_api_get_caps_t)(const struct device *dev, struct video_caps
327379
*/
328380
typedef int (*video_api_set_signal_t)(const struct device *dev, struct k_poll_signal *sig);
329381

382+
/**
383+
* @typedef video_api_selection_t
384+
* @brief Get/Set video selection (crop / compose)
385+
*
386+
* See @ref video_set_selection and @ref video_get_selection for argument descriptions.
387+
*/
388+
typedef int (*video_api_selection_t)(const struct device *dev, struct video_selection *sel);
389+
330390
__subsystem struct video_driver_api {
331391
/* mandatory callbacks */
332392
video_api_format_t set_format;
@@ -343,6 +403,8 @@ __subsystem struct video_driver_api {
343403
video_api_frmival_t set_frmival;
344404
video_api_frmival_t get_frmival;
345405
video_api_enum_frmival_t enum_frmival;
406+
video_api_selection_t set_selection;
407+
video_api_selection_t get_selection;
346408
};
347409

348410
/**
@@ -756,6 +818,72 @@ static inline int video_set_signal(const struct device *dev, struct k_poll_signa
756818
return api->set_signal(dev, sig);
757819
}
758820

821+
/**
822+
* @brief Set video selection (crop/compose).
823+
*
824+
* Configure the optional crop and compose feature of a video device.
825+
* Crop is first applied on the input frame, and the result of that crop is applied
826+
* to the compose. The result of the compose (width/height) is equal to the format
827+
* width/height given to the @ref video_set_format function.
828+
*
829+
* Some targets are inter-dependents. For instance, setting a @ref VIDEO_SEL_TGT_CROP will
830+
* reset @ref VIDEO_SEL_TGT_COMPOSE to the same size.
831+
*
832+
* @param dev Pointer to the device structure for the driver instance.
833+
* @param sel Pointer to a video selection structure
834+
*
835+
* @retval 0 Is successful.
836+
* @retval -EINVAL If parameters are invalid.
837+
* @retval -ENOTSUP If format is not supported.
838+
* @retval -EIO General input / output error.
839+
*/
840+
static inline int video_set_selection(const struct device *dev, struct video_selection *sel)
841+
{
842+
const struct video_driver_api *api;
843+
844+
__ASSERT_NO_MSG(dev != NULL);
845+
__ASSERT_NO_MSG(sel != NULL);
846+
847+
api = (const struct video_driver_api *)dev->api;
848+
if (api->set_selection == NULL) {
849+
return -ENOSYS;
850+
}
851+
852+
return api->set_selection(dev, sel);
853+
}
854+
855+
/**
856+
* @brief Get video selection (crop/compose).
857+
*
858+
* Retrieve the current settings related to the crop and compose of the video device.
859+
* This can also be used to read the native size of the input stream of the video
860+
* device.
861+
* This function can be used to read crop / compose capabilities of the device prior
862+
* to performing configuration via the @ref video_set_selection api.
863+
*
864+
* @param dev Pointer to the device structure for the driver instance.
865+
* @param sel Pointer to a video selection structure, @c type and @c target set by the caller
866+
*
867+
* @retval 0 Is successful.
868+
* @retval -EINVAL If parameters are invalid.
869+
* @retval -ENOTSUP If format is not supported.
870+
* @retval -EIO General input / output error.
871+
*/
872+
static inline int video_get_selection(const struct device *dev, struct video_selection *sel)
873+
{
874+
const struct video_driver_api *api;
875+
876+
__ASSERT_NO_MSG(dev != NULL);
877+
__ASSERT_NO_MSG(sel != NULL);
878+
879+
api = (const struct video_driver_api *)dev->api;
880+
if (api->get_selection == NULL) {
881+
return -ENOSYS;
882+
}
883+
884+
return api->get_selection(dev, sel);
885+
}
886+
759887
/**
760888
* @brief Allocate aligned video buffer.
761889
*

0 commit comments

Comments
 (0)