Skip to content

Commit 49f066c

Browse files
Alain Volmatdkalowsk
authored andcommitted
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 88eda71 commit 49f066c

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
*/
@@ -239,6 +240,57 @@ enum video_signal_result {
239240
VIDEO_BUF_ERROR,
240241
};
241242

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

384+
/**
385+
* @typedef video_api_selection_t
386+
* @brief Get/Set video selection (crop / compose)
387+
*
388+
* See @ref video_set_selection and @ref video_get_selection for argument descriptions.
389+
*/
390+
typedef int (*video_api_selection_t)(const struct device *dev, struct video_selection *sel);
391+
332392
__subsystem struct video_driver_api {
333393
/* mandatory callbacks */
334394
video_api_format_t set_format;
@@ -345,6 +405,8 @@ __subsystem struct video_driver_api {
345405
video_api_frmival_t set_frmival;
346406
video_api_frmival_t get_frmival;
347407
video_api_enum_frmival_t enum_frmival;
408+
video_api_selection_t set_selection;
409+
video_api_selection_t get_selection;
348410
};
349411

350412
/**
@@ -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)