Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
video.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2019 Linaro Limited.
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12#ifndef ZEPHYR_INCLUDE_VIDEO_H_
13#define ZEPHYR_INCLUDE_VIDEO_H_
14
24#include <zephyr/device.h>
25#include <stddef.h>
26#include <zephyr/kernel.h>
27
28#include <zephyr/types.h>
29
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36
58};
59
60
82};
83
90struct video_caps {
97};
98
119};
120
131};
132
142};
143
150typedef int (*video_api_set_format_t)(const struct device *dev,
151 enum video_endpoint_id ep,
152 struct video_format *fmt);
153
160typedef int (*video_api_get_format_t)(const struct device *dev,
161 enum video_endpoint_id ep,
162 struct video_format *fmt);
163
170typedef int (*video_api_enqueue_t)(const struct device *dev,
171 enum video_endpoint_id ep,
172 struct video_buffer *buf);
173
180typedef int (*video_api_dequeue_t)(const struct device *dev,
181 enum video_endpoint_id ep,
182 struct video_buffer **buf,
183 k_timeout_t timeout);
184
192typedef int (*video_api_flush_t)(const struct device *dev,
193 enum video_endpoint_id ep,
194 bool cancel);
195
202typedef int (*video_api_stream_start_t)(const struct device *dev);
203
210typedef int (*video_api_stream_stop_t)(const struct device *dev);
211
218typedef int (*video_api_set_ctrl_t)(const struct device *dev,
219 unsigned int cid,
220 void *value);
221
228typedef int (*video_api_get_ctrl_t)(const struct device *dev,
229 unsigned int cid,
230 void *value);
231
238typedef int (*video_api_get_caps_t)(const struct device *dev,
239 enum video_endpoint_id ep,
240 struct video_caps *caps);
241
248typedef int (*video_api_set_signal_t)(const struct device *dev,
249 enum video_endpoint_id ep,
250 struct k_poll_signal *signal);
251
252__subsystem struct video_driver_api {
253 /* mandatory callbacks */
259 /* optional callbacks */
266};
267
282static inline int video_set_format(const struct device *dev,
283 enum video_endpoint_id ep,
284 struct video_format *fmt)
285{
286 const struct video_driver_api *api =
287 (const struct video_driver_api *)dev->api;
288
289 if (api->set_format == NULL) {
290 return -ENOSYS;
291 }
292
293 return api->set_format(dev, ep, fmt);
294}
295
307static inline int video_get_format(const struct device *dev,
308 enum video_endpoint_id ep,
309 struct video_format *fmt)
310{
311 const struct video_driver_api *api =
312 (const struct video_driver_api *)dev->api;
313
314 if (api->get_format == NULL) {
315 return -ENOSYS;
316 }
317
318 return api->get_format(dev, ep, fmt);
319}
320
335static inline int video_enqueue(const struct device *dev,
336 enum video_endpoint_id ep,
337 struct video_buffer *buf)
338{
339 const struct video_driver_api *api =
340 (const struct video_driver_api *)dev->api;
341
342 if (api->enqueue == NULL) {
343 return -ENOSYS;
344 }
345
346 return api->enqueue(dev, ep, buf);
347}
348
364static inline int video_dequeue(const struct device *dev,
365 enum video_endpoint_id ep,
366 struct video_buffer **buf,
367 k_timeout_t timeout)
368{
369 const struct video_driver_api *api =
370 (const struct video_driver_api *)dev->api;
371
372 if (api->dequeue == NULL) {
373 return -ENOSYS;
374 }
375
376 return api->dequeue(dev, ep, buf, timeout);
377}
378
379
394static inline int video_flush(const struct device *dev,
395 enum video_endpoint_id ep,
396 bool cancel)
397{
398 const struct video_driver_api *api =
399 (const struct video_driver_api *)dev->api;
400
401 if (api->flush == NULL) {
402 return -ENOSYS;
403 }
404
405 return api->flush(dev, ep, cancel);
406}
407
420static inline int video_stream_start(const struct device *dev)
421{
422 const struct video_driver_api *api =
423 (const struct video_driver_api *)dev->api;
424
425 if (api->stream_start == NULL) {
426 return -ENOSYS;
427 }
428
429 return api->stream_start(dev);
430}
431
441static inline int video_stream_stop(const struct device *dev)
442{
443 const struct video_driver_api *api =
444 (const struct video_driver_api *)dev->api;
445 int ret;
446
447 if (api->stream_stop == NULL) {
448 return -ENOSYS;
449 }
450
451 ret = api->stream_stop(dev);
452 video_flush(dev, VIDEO_EP_ANY, true);
453
454 return ret;
455}
456
466static inline int video_get_caps(const struct device *dev,
467 enum video_endpoint_id ep,
468 struct video_caps *caps)
469{
470 const struct video_driver_api *api =
471 (const struct video_driver_api *)dev->api;
472
473 if (api->get_caps == NULL) {
474 return -ENOSYS;
475 }
476
477 return api->get_caps(dev, ep, caps);
478}
479
495static inline int video_set_ctrl(const struct device *dev, unsigned int cid,
496 void *value)
497{
498 const struct video_driver_api *api =
499 (const struct video_driver_api *)dev->api;
500
501 if (api->set_ctrl == NULL) {
502 return -ENOSYS;
503 }
504
505 return api->set_ctrl(dev, cid, value);
506}
507
523static inline int video_get_ctrl(const struct device *dev, unsigned int cid,
524 void *value)
525{
526 const struct video_driver_api *api =
527 (const struct video_driver_api *)dev->api;
528
529 if (api->get_ctrl == NULL) {
530 return -ENOSYS;
531 }
532
533 return api->get_ctrl(dev, cid, value);
534}
535
549static inline int video_set_signal(const struct device *dev,
550 enum video_endpoint_id ep,
551 struct k_poll_signal *signal)
552{
553 const struct video_driver_api *api =
554 (const struct video_driver_api *)dev->api;
555
556 if (api->set_signal == NULL) {
557 return -ENOSYS;
558 }
559
560 return api->set_signal(dev, ep, signal);
561}
562
571struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align);
572
581
588
589
590/* fourcc - four-character-code */
591#define video_fourcc(a, b, c, d)\
592 ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
593
594
606#define VIDEO_PIX_FMT_BGGR8 video_fourcc('B', 'G', 'G', 'R') /* 8 BGBG.. GRGR.. */
608#define VIDEO_PIX_FMT_GBRG8 video_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
610#define VIDEO_PIX_FMT_GRBG8 video_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
612#define VIDEO_PIX_FMT_RGGB8 video_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
613
624#define VIDEO_PIX_FMT_RGB565 video_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
625
627#define VIDEO_PIX_FMT_XRGB32 video_fourcc('B', 'X', '2', '4') /* 32 XRGB-8-8-8-8 */
628
639#define VIDEO_PIX_FMT_YUYV video_fourcc('Y', 'U', 'Y', 'V') /* 16 Y0-Cb0 Y1-Cr0 */
640
642#define VIDEO_PIX_FMT_XYUV32 video_fourcc('X', 'Y', 'U', 'V') /* 32 XYUV-8-8-8-8 */
643
655#define VIDEO_PIX_FMT_JPEG video_fourcc('J', 'P', 'E', 'G') /* 8 JPEG */
656
665#ifdef __cplusplus
666}
667#endif
668
673#endif /* ZEPHYR_INCLUDE_VIDEO_H_ */
#define ENOSYS
Function not implemented.
Definition: errno.h:82
int(* video_api_stream_start_t)(const struct device *dev)
Start the capture or output process.
Definition: video.h:202
int(* video_api_set_format_t)(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Set video format.
Definition: video.h:150
video_signal_result
video_event enum
Definition: video.h:138
int(* video_api_enqueue_t)(const struct device *dev, enum video_endpoint_id ep, struct video_buffer *buf)
Enqueue a buffer in the driver’s incoming queue.
Definition: video.h:170
int(* video_api_set_signal_t)(const struct device *dev, enum video_endpoint_id ep, struct k_poll_signal *signal)
Register/Unregister poll signal for buffer events.
Definition: video.h:248
int(* video_api_stream_stop_t)(const struct device *dev)
Stop the capture or output process.
Definition: video.h:210
int(* video_api_get_format_t)(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Get current video format.
Definition: video.h:160
static int video_get_caps(const struct device *dev, enum video_endpoint_id ep, struct video_caps *caps)
Get the capabilities of a video endpoint.
Definition: video.h:466
static int video_stream_stop(const struct device *dev)
Stop the video device function.
Definition: video.h:441
static int video_get_ctrl(const struct device *dev, unsigned int cid, void *value)
Get the current value of a control.
Definition: video.h:523
static int video_stream_start(const struct device *dev)
Start the video device function.
Definition: video.h:420
struct video_buffer * video_buffer_alloc(size_t size)
Allocate video buffer.
static int video_set_ctrl(const struct device *dev, unsigned int cid, void *value)
Set the value of a control.
Definition: video.h:495
int(* video_api_flush_t)(const struct device *dev, enum video_endpoint_id ep, bool cancel)
Flush endpoint buffers, buffer are moved from incoming queue to outgoing queue.
Definition: video.h:192
int(* video_api_get_caps_t)(const struct device *dev, enum video_endpoint_id ep, struct video_caps *caps)
Get capabilities of a video endpoint.
Definition: video.h:238
static int video_dequeue(const struct device *dev, enum video_endpoint_id ep, struct video_buffer **buf, k_timeout_t timeout)
Dequeue a video buffer.
Definition: video.h:364
struct video_buffer * video_buffer_aligned_alloc(size_t size, size_t align)
Allocate aligned video buffer.
int(* video_api_dequeue_t)(const struct device *dev, enum video_endpoint_id ep, struct video_buffer **buf, k_timeout_t timeout)
Dequeue a buffer from the driver’s outgoing queue.
Definition: video.h:180
static int video_set_signal(const struct device *dev, enum video_endpoint_id ep, struct k_poll_signal *signal)
Register/Unregister k_poll signal for a video endpoint.
Definition: video.h:549
static int video_get_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Get video format.
Definition: video.h:307
static int video_enqueue(const struct device *dev, enum video_endpoint_id ep, struct video_buffer *buf)
Enqueue a video buffer.
Definition: video.h:335
void video_buffer_release(struct video_buffer *buf)
Release a video buffer.
int(* video_api_get_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
Get a video control value.
Definition: video.h:228
static int video_set_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Set video format.
Definition: video.h:282
static int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
Flush endpoint buffers.
Definition: video.h:394
video_endpoint_id
video_endpoint_id enum
Definition: video.h:126
int(* video_api_set_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
Set a video control value.
Definition: video.h:218
@ VIDEO_BUF_ABORTED
Definition: video.h:140
@ VIDEO_BUF_DONE
Definition: video.h:139
@ VIDEO_BUF_ERROR
Definition: video.h:141
@ VIDEO_EP_IN
Definition: video.h:129
@ VIDEO_EP_NONE
Definition: video.h:127
@ VIDEO_EP_ANY
Definition: video.h:128
@ VIDEO_EP_OUT
Definition: video.h:130
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition: device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
Definition: kernel.h:5691
Kernel timeout type.
Definition: sys_clock.h:65
Video buffer structure.
Definition: video.h:105
uint32_t bytesused
number of bytes occupied by the valid data in the buffer.
Definition: video.h:113
uint32_t size
size of the buffer in bytes.
Definition: video.h:111
uint8_t * buffer
pointer to the start of the buffer.
Definition: video.h:109
void * driver_data
pointer to driver specific data.
Definition: video.h:107
uint32_t timestamp
time reference in milliseconds at which the last data byte was actually received for input endpoints ...
Definition: video.h:118
Video format capabilities.
Definition: video.h:90
uint8_t min_vbuf_count
minimal count of video buffers to enqueue before being able to start the stream.
Definition: video.h:96
const struct video_format_cap * format_caps
list of video format capabilities (zero terminated).
Definition: video.h:92
Definition: video.h:252
video_api_stream_stop_t stream_stop
Definition: video.h:257
video_api_set_ctrl_t set_ctrl
Definition: video.h:263
video_api_stream_start_t stream_start
Definition: video.h:256
video_api_set_ctrl_t get_ctrl
Definition: video.h:264
video_api_enqueue_t enqueue
Definition: video.h:260
video_api_set_signal_t set_signal
Definition: video.h:265
video_api_get_format_t get_format
Definition: video.h:255
video_api_get_caps_t get_caps
Definition: video.h:258
video_api_set_format_t set_format
Definition: video.h:254
video_api_flush_t flush
Definition: video.h:262
video_api_dequeue_t dequeue
Definition: video.h:261
Video format capability.
Definition: video.h:67
uint16_t height_step
height step size in pixels.
Definition: video.h:81
uint32_t width_min
minimum supported frame width in pixels.
Definition: video.h:71
uint32_t width_max
maximum supported frame width in pixels.
Definition: video.h:73
uint16_t width_step
width step size in pixels.
Definition: video.h:79
uint32_t height_max
maximum supported frame height in pixels.
Definition: video.h:77
uint32_t height_min
minimum supported frame height in pixels.
Definition: video.h:75
uint32_t pixelformat
FourCC pixel format value (Video pixel formats).
Definition: video.h:69
Video format structure.
Definition: video.h:43
uint32_t height
frame height in pixels.
Definition: video.h:49
uint32_t width
frame width in pixels.
Definition: video.h:47
uint32_t pitch
line stride.
Definition: video.h:57
uint32_t pixelformat
FourCC pixel format value (Video pixel formats)
Definition: video.h:45
Public APIs for Video.