Skip to content

Commit c48b390

Browse files
committed
include: video: Add frame interval APIs
Add set/get/enum frame intervals APIs to support frame rate changing. Signed-off-by: Phi Bang Nguyen <[email protected]>
1 parent 45727b5 commit c48b390

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

include/zephyr/drivers/video.h

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,66 @@ struct video_buffer {
118118
uint32_t timestamp;
119119
};
120120

121+
/**
122+
* @brief video_frmival_type enum
123+
*
124+
* Supported frame interval type of a video device.
125+
*/
126+
enum video_frmival_type {
127+
/** discrete frame interval type */
128+
VIDEO_FRMIVAL_TYPE_DISCRETE = 1,
129+
/** stepwise frame interval type */
130+
VIDEO_FRMIVAL_TYPE_STEPWISE = 2,
131+
};
132+
133+
/**
134+
* @struct video_frmival
135+
* @brief Video frame interval structure
136+
*
137+
* Used to describe a video frame interval.
138+
*/
139+
struct video_frmival {
140+
/** numerator of the frame interval */
141+
uint32_t numerator;
142+
/** denominator of the frame interval */
143+
uint32_t denominator;
144+
};
145+
146+
/**
147+
* @struct video_frmival_stepwise
148+
* @brief Video frame interval stepwise structure
149+
*
150+
* Used to describe the video frame interval stepwise type.
151+
*/
152+
struct video_frmival_stepwise {
153+
/** minimum frame interval in seconds */
154+
struct video_frmival min;
155+
/** maximum frame interval in seconds */
156+
struct video_frmival max;
157+
/** frame interval step size in seconds */
158+
struct video_frmival step;
159+
};
160+
161+
/**
162+
* @struct video_frmival_enum
163+
* @brief Video frame interval enumeration structure
164+
*
165+
* Used to describe the supported video frame intervals of a given video format.
166+
*/
167+
struct video_frmival_enum {
168+
/** frame interval index during enumeration */
169+
uint32_t index;
170+
/** video format for which the query is made */
171+
const struct video_format *format;
172+
/** frame interval type the device supports */
173+
enum video_frmival_type type;
174+
/** the actual frame interval */
175+
union {
176+
struct video_frmival discrete;
177+
struct video_frmival_stepwise stepwise;
178+
};
179+
};
180+
121181
/**
122182
* @brief video_endpoint_id enum
123183
*
@@ -165,6 +225,33 @@ typedef int (*video_api_get_format_t)(const struct device *dev,
165225
enum video_endpoint_id ep,
166226
struct video_format *fmt);
167227

228+
/**
229+
* @typedef video_api_set_frmival_t
230+
* @brief Set video frame interval
231+
*
232+
* See video_set_frmival() for argument descriptions.
233+
*/
234+
typedef int (*video_api_set_frmival_t)(const struct device *dev, enum video_endpoint_id ep,
235+
struct video_frmival *frmival);
236+
237+
/**
238+
* @typedef video_api_get_frmival_t
239+
* @brief Get current video frame interval
240+
*
241+
* See video_get_frmival() for argument descriptions.
242+
*/
243+
typedef int (*video_api_get_frmival_t)(const struct device *dev, enum video_endpoint_id ep,
244+
struct video_frmival *frmival);
245+
246+
/**
247+
* @typedef video_api_enum_frmival_t
248+
* @brief List all supported frame intervals of a given format
249+
*
250+
* See video_enum_frmival() for argument descriptions.
251+
*/
252+
typedef int (*video_api_enum_frmival_t)(const struct device *dev, enum video_endpoint_id ep,
253+
struct video_frmival_enum *fie);
254+
168255
/**
169256
* @typedef video_api_enqueue_t
170257
* @brief Enqueue a buffer in the driver’s incoming queue.
@@ -267,6 +354,9 @@ __subsystem struct video_driver_api {
267354
video_api_set_ctrl_t set_ctrl;
268355
video_api_set_ctrl_t get_ctrl;
269356
video_api_set_signal_t set_signal;
357+
video_api_set_frmival_t set_frmival;
358+
video_api_get_frmival_t get_frmival;
359+
video_api_enum_frmival_t enum_frmival;
270360
};
271361

272362
/**
@@ -322,6 +412,91 @@ static inline int video_get_format(const struct device *dev,
322412
return api->get_format(dev, ep, fmt);
323413
}
324414

415+
/**
416+
* @brief Set video frame interval.
417+
*
418+
* Configure video device with a specific frame interval.
419+
*
420+
* Drivers must not return an error solely because the requested interval doesn’t match the device
421+
* capabilities. They must instead modify the interval to match what the hardware can provide.
422+
*
423+
* @param dev Pointer to the device structure for the driver instance.
424+
* @param ep Endpoint ID.
425+
* @param frmival Pointer to a video frame interval struct.
426+
*
427+
* @retval 0 If successful.
428+
* @retval -ENOSYS If API is not implemented.
429+
* @retval -EINVAL If parameters are invalid.
430+
* @retval -EIO General input / output error.
431+
*/
432+
static inline int video_set_frmival(const struct device *dev, enum video_endpoint_id ep,
433+
struct video_frmival *frmival)
434+
{
435+
const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
436+
437+
if (api->set_frmival == NULL) {
438+
return -ENOSYS;
439+
}
440+
441+
return api->set_frmival(dev, ep, frmival);
442+
}
443+
444+
/**
445+
* @brief Get video frame interval.
446+
*
447+
* Get current frame interval of the video device.
448+
*
449+
* @param dev Pointer to the device structure for the driver instance.
450+
* @param ep Endpoint ID.
451+
* @param frmival Pointer to a video frame interval struct.
452+
*
453+
* @retval 0 If successful.
454+
* @retval -ENOSYS If API is not implemented.
455+
* @retval -EINVAL If parameters are invalid.
456+
* @retval -EIO General input / output error.
457+
*/
458+
static inline int video_get_frmival(const struct device *dev, enum video_endpoint_id ep,
459+
struct video_frmival *frmival)
460+
{
461+
const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
462+
463+
if (api->get_frmival == NULL) {
464+
return -ENOSYS;
465+
}
466+
467+
return api->get_frmival(dev, ep, frmival);
468+
}
469+
470+
/**
471+
* @brief List video frame intervals.
472+
*
473+
* List all supported video frame intervals of a given format.
474+
*
475+
* Applications should fill the pixelformat, width and height fields of the
476+
* video_frmival_enum struct first to form a query. Then, the index field is
477+
* used to iterate through the supported frame intervals list.
478+
*
479+
* @param dev Pointer to the device structure for the driver instance.
480+
* @param ep Endpoint ID.
481+
* @param fie Pointer to a video frame interval enumeration struct.
482+
*
483+
* @retval 0 If successful.
484+
* @retval -ENOSYS If API is not implemented.
485+
* @retval -EINVAL If parameters are invalid.
486+
* @retval -EIO General input / output error.
487+
*/
488+
static inline int video_enum_frmival(const struct device *dev, enum video_endpoint_id ep,
489+
struct video_frmival_enum *fie)
490+
{
491+
const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
492+
493+
if (api->enum_frmival == NULL) {
494+
return -ENOSYS;
495+
}
496+
497+
return api->enum_frmival(dev, ep, fie);
498+
}
499+
325500
/**
326501
* @brief Enqueue a video buffer.
327502
*

0 commit comments

Comments
 (0)