Zephyr API Documentation 4.0.0-rc3
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
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/*
35 * Flag used by @ref video_caps structure to indicate endpoint operates on
36 * buffers the size of the video frame
37 */
38#define LINE_COUNT_HEIGHT (-1)
39
62
85
116
144
156
169
184
195 const struct video_format *format;
199 union {
200 struct video_frmival discrete;
201 struct video_frmival_stepwise stepwise;
202 };
203};
204
220
231
238typedef int (*video_api_set_format_t)(const struct device *dev, enum video_endpoint_id ep,
239 struct video_format *fmt);
240
247typedef int (*video_api_get_format_t)(const struct device *dev, enum video_endpoint_id ep,
248 struct video_format *fmt);
249
256typedef int (*video_api_set_frmival_t)(const struct device *dev, enum video_endpoint_id ep,
257 struct video_frmival *frmival);
258
265typedef int (*video_api_get_frmival_t)(const struct device *dev, enum video_endpoint_id ep,
266 struct video_frmival *frmival);
267
274typedef int (*video_api_enum_frmival_t)(const struct device *dev, enum video_endpoint_id ep,
275 struct video_frmival_enum *fie);
276
283typedef int (*video_api_enqueue_t)(const struct device *dev, enum video_endpoint_id ep,
284 struct video_buffer *buf);
285
292typedef int (*video_api_dequeue_t)(const struct device *dev, enum video_endpoint_id ep,
293 struct video_buffer **buf, k_timeout_t timeout);
294
302typedef int (*video_api_flush_t)(const struct device *dev, enum video_endpoint_id ep, bool cancel);
303
310typedef int (*video_api_stream_start_t)(const struct device *dev);
311
318typedef int (*video_api_stream_stop_t)(const struct device *dev);
319
326typedef int (*video_api_set_ctrl_t)(const struct device *dev, unsigned int cid, void *value);
327
334typedef int (*video_api_get_ctrl_t)(const struct device *dev, unsigned int cid, void *value);
335
342typedef int (*video_api_get_caps_t)(const struct device *dev, enum video_endpoint_id ep,
343 struct video_caps *caps);
344
351typedef int (*video_api_set_signal_t)(const struct device *dev, enum video_endpoint_id ep,
352 struct k_poll_signal *signal);
353
372
387static inline int video_set_format(const struct device *dev, enum video_endpoint_id ep,
388 struct video_format *fmt)
389{
390 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
391
392 if (api->set_format == NULL) {
393 return -ENOSYS;
394 }
395
396 return api->set_format(dev, ep, fmt);
397}
398
410static inline int video_get_format(const struct device *dev, enum video_endpoint_id ep,
411 struct video_format *fmt)
412{
413 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
414
415 if (api->get_format == NULL) {
416 return -ENOSYS;
417 }
418
419 return api->get_format(dev, ep, fmt);
420}
421
439static inline int video_set_frmival(const struct device *dev, enum video_endpoint_id ep,
440 struct video_frmival *frmival)
441{
442 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
443
444 if (api->set_frmival == NULL) {
445 return -ENOSYS;
446 }
447
448 return api->set_frmival(dev, ep, frmival);
449}
450
465static inline int video_get_frmival(const struct device *dev, enum video_endpoint_id ep,
466 struct video_frmival *frmival)
467{
468 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
469
470 if (api->get_frmival == NULL) {
471 return -ENOSYS;
472 }
473
474 return api->get_frmival(dev, ep, frmival);
475}
476
495static inline int video_enum_frmival(const struct device *dev, enum video_endpoint_id ep,
496 struct video_frmival_enum *fie)
497{
498 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
499
500 if (api->enum_frmival == NULL) {
501 return -ENOSYS;
502 }
503
504 return api->enum_frmival(dev, ep, fie);
505}
506
521static inline int video_enqueue(const struct device *dev, enum video_endpoint_id ep,
522 struct video_buffer *buf)
523{
524 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
525
526 if (api->enqueue == NULL) {
527 return -ENOSYS;
528 }
529
530 return api->enqueue(dev, ep, buf);
531}
532
548static inline int video_dequeue(const struct device *dev, enum video_endpoint_id ep,
549 struct video_buffer **buf, k_timeout_t timeout)
550{
551 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
552
553 if (api->dequeue == NULL) {
554 return -ENOSYS;
555 }
556
557 return api->dequeue(dev, ep, buf, timeout);
558}
559
574static inline int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
575{
576 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
577
578 if (api->flush == NULL) {
579 return -ENOSYS;
580 }
581
582 return api->flush(dev, ep, cancel);
583}
584
597static inline int video_stream_start(const struct device *dev)
598{
599 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
600
601 if (api->stream_start == NULL) {
602 return -ENOSYS;
603 }
604
605 return api->stream_start(dev);
606}
607
617static inline int video_stream_stop(const struct device *dev)
618{
619 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
620 int ret;
621
622 if (api->stream_stop == NULL) {
623 return -ENOSYS;
624 }
625
626 ret = api->stream_stop(dev);
627 video_flush(dev, VIDEO_EP_ALL, true);
628
629 return ret;
630}
631
641static inline int video_get_caps(const struct device *dev, enum video_endpoint_id ep,
642 struct video_caps *caps)
643{
644 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
645
646 if (api->get_caps == NULL) {
647 return -ENOSYS;
648 }
649
650 return api->get_caps(dev, ep, caps);
651}
652
668static inline int video_set_ctrl(const struct device *dev, unsigned int cid, void *value)
669{
670 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
671
672 if (api->set_ctrl == NULL) {
673 return -ENOSYS;
674 }
675
676 return api->set_ctrl(dev, cid, value);
677}
678
694static inline int video_get_ctrl(const struct device *dev, unsigned int cid, void *value)
695{
696 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
697
698 if (api->get_ctrl == NULL) {
699 return -ENOSYS;
700 }
701
702 return api->get_ctrl(dev, cid, value);
703}
704
718static inline int video_set_signal(const struct device *dev, enum video_endpoint_id ep,
719 struct k_poll_signal *signal)
720{
721 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
722
723 if (api->set_signal == NULL) {
724 return -ENOSYS;
725 }
726
727 return api->set_signal(dev, ep, signal);
728}
729
738struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align);
739
748
755
756/* fourcc - four-character-code */
757#define video_fourcc(a, b, c, d) \
758 ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
759
771#define VIDEO_PIX_FMT_BGGR8 video_fourcc('B', 'G', 'G', 'R') /* 8 BGBG.. GRGR.. */
773#define VIDEO_PIX_FMT_GBRG8 video_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
775#define VIDEO_PIX_FMT_GRBG8 video_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
777#define VIDEO_PIX_FMT_RGGB8 video_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
778
789#define VIDEO_PIX_FMT_RGB565 video_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
790
792#define VIDEO_PIX_FMT_XRGB32 video_fourcc('B', 'X', '2', '4') /* 32 XRGB-8-8-8-8 */
793
804#define VIDEO_PIX_FMT_YUYV video_fourcc('Y', 'U', 'Y', 'V') /* 16 Y0-Cb0 Y1-Cr0 */
805
807#define VIDEO_PIX_FMT_XYUV32 video_fourcc('X', 'Y', 'U', 'V') /* 32 XYUV-8-8-8-8 */
808
820#define VIDEO_PIX_FMT_JPEG video_fourcc('J', 'P', 'E', 'G') /* 8 JPEG */
821
835static inline unsigned int video_pix_fmt_bpp(uint32_t pixfmt)
836{
837 switch (pixfmt) {
842 return 1;
845 return 2;
848 return 4;
849 default:
850 return 0;
851 }
852}
853
854#ifdef __cplusplus
855}
856#endif
857
862#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:310
video_signal_result
video_event enum
Definition video.h:226
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:283
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:292
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:641
static int video_set_frmival(const struct device *dev, enum video_endpoint_id ep, struct video_frmival *frmival)
Set video frame interval.
Definition video.h:439
int(* video_api_stream_stop_t)(const struct device *dev)
Stop the capture or output process.
Definition video.h:318
static int video_stream_stop(const struct device *dev)
Stop the video device function.
Definition video.h:617
static int video_get_ctrl(const struct device *dev, unsigned int cid, void *value)
Get the current value of a control.
Definition video.h:694
video_frmival_type
video_frmival_type enum
Definition video.h:150
static int video_stream_start(const struct device *dev)
Start the video device function.
Definition video.h:597
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:247
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:668
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:548
struct video_buffer * video_buffer_aligned_alloc(size_t size, size_t align)
Allocate aligned video buffer.
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:351
int(* video_api_get_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
Get a video control value.
Definition video.h:334
static int video_get_frmival(const struct device *dev, enum video_endpoint_id ep, struct video_frmival *frmival)
Get video frame interval.
Definition video.h:465
int(* video_api_get_frmival_t)(const struct device *dev, enum video_endpoint_id ep, struct video_frmival *frmival)
Get current video frame interval.
Definition video.h:265
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:718
int(* video_api_enum_frmival_t)(const struct device *dev, enum video_endpoint_id ep, struct video_frmival_enum *fie)
List all supported frame intervals of a given format.
Definition video.h:274
static unsigned int video_pix_fmt_bpp(uint32_t pixfmt)
Get number of bytes per pixel of a pixel format.
Definition video.h:835
static int video_enum_frmival(const struct device *dev, enum video_endpoint_id ep, struct video_frmival_enum *fie)
List video frame intervals.
Definition video.h:495
static int video_get_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Get video format.
Definition video.h:410
static int video_enqueue(const struct device *dev, enum video_endpoint_id ep, struct video_buffer *buf)
Enqueue a video buffer.
Definition video.h:521
int(* video_api_set_frmival_t)(const struct device *dev, enum video_endpoint_id ep, struct video_frmival *frmival)
Set video frame interval.
Definition video.h:256
void video_buffer_release(struct video_buffer *buf)
Release a video buffer.
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:302
int(* video_api_set_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
Set a video control value.
Definition video.h:326
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:342
static int video_set_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Set video format.
Definition video.h:387
static int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
Flush endpoint buffers.
Definition video.h:574
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:238
video_endpoint_id
video_endpoint_id enum
Definition video.h:210
@ VIDEO_BUF_ABORTED
Definition video.h:228
@ VIDEO_BUF_DONE
Definition video.h:227
@ VIDEO_BUF_ERROR
Definition video.h:229
@ VIDEO_FRMIVAL_TYPE_DISCRETE
discrete frame interval type
Definition video.h:152
@ VIDEO_FRMIVAL_TYPE_STEPWISE
stepwise frame interval type
Definition video.h:154
@ VIDEO_EP_IN
Targets all input endpoints of the device: those consuming data.
Definition video.h:216
@ VIDEO_EP_NONE
Targets some part of the video device not bound to an endpoint.
Definition video.h:212
@ VIDEO_EP_OUT
Targets all output endpoints of the device: those producing data.
Definition video.h:218
@ VIDEO_EP_ALL
Targets all input or output endpoints of the device.
Definition video.h:214
#define VIDEO_PIX_FMT_XYUV32
XYUV32 pixel format.
Definition video.h:807
#define VIDEO_PIX_FMT_RGGB8
RGGB8 pixel format.
Definition video.h:777
#define VIDEO_PIX_FMT_BGGR8
BGGR8 pixel format.
Definition video.h:771
#define VIDEO_PIX_FMT_GRBG8
GRBG8 pixel format.
Definition video.h:775
#define VIDEO_PIX_FMT_XRGB32
XRGB32 pixel format.
Definition video.h:792
#define VIDEO_PIX_FMT_YUYV
YUYV pixel format.
Definition video.h:804
#define VIDEO_PIX_FMT_GBRG8
GBRG8 pixel format.
Definition video.h:773
#define VIDEO_PIX_FMT_RGB565
RGB565 pixel format.
Definition video.h:789
sighandler_t signal(int signo, sighandler_t handler)
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
__INT16_TYPE__ int16_t
Definition stdint.h:73
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
Definition kernel.h:5768
Kernel timeout type.
Definition sys_clock.h:65
Video buffer structure.
Definition video.h:123
uint32_t bytesused
number of bytes occupied by the valid data in the buffer.
Definition video.h:131
uint32_t size
size of the buffer in bytes.
Definition video.h:129
uint8_t * buffer
pointer to the start of the buffer.
Definition video.h:127
void * driver_data
pointer to driver specific data.
Definition video.h:125
uint16_t line_offset
Line offset within frame this buffer represents, from the beginning of the frame.
Definition video.h:142
uint32_t timestamp
time reference in milliseconds at which the last data byte was actually received for input endpoints ...
Definition video.h:136
Video format capabilities.
Definition video.h:92
uint8_t min_vbuf_count
minimal count of video buffers to enqueue before being able to start the stream.
Definition video.h:98
int16_t min_line_count
Denotes minimum line count of a video buffer that this endpoint can fill or process.
Definition video.h:107
int16_t max_line_count
Denotes maximum line count of a video buffer that this endpoint can fill or process.
Definition video.h:114
const struct video_format_cap * format_caps
list of video format capabilities (zero terminated).
Definition video.h:94
Definition video.h:354
video_api_stream_stop_t stream_stop
Definition video.h:359
video_api_set_ctrl_t set_ctrl
Definition video.h:365
video_api_stream_start_t stream_start
Definition video.h:358
video_api_enqueue_t enqueue
Definition video.h:362
video_api_set_signal_t set_signal
Definition video.h:367
video_api_get_format_t get_format
Definition video.h:357
video_api_enum_frmival_t enum_frmival
Definition video.h:370
video_api_get_caps_t get_caps
Definition video.h:360
video_api_set_format_t set_format
Definition video.h:356
video_api_flush_t flush
Definition video.h:364
video_api_dequeue_t dequeue
Definition video.h:363
video_api_get_ctrl_t get_ctrl
Definition video.h:366
video_api_get_frmival_t get_frmival
Definition video.h:369
video_api_set_frmival_t set_frmival
Definition video.h:368
Video format capability.
Definition video.h:69
uint16_t height_step
height step size in pixels.
Definition video.h:83
uint32_t width_min
minimum supported frame width in pixels.
Definition video.h:73
uint32_t width_max
maximum supported frame width in pixels.
Definition video.h:75
uint16_t width_step
width step size in pixels.
Definition video.h:81
uint32_t height_max
maximum supported frame height in pixels.
Definition video.h:79
uint32_t height_min
minimum supported frame height in pixels.
Definition video.h:77
uint32_t pixelformat
FourCC pixel format value (Video pixel formats).
Definition video.h:71
Video format structure.
Definition video.h:46
uint32_t height
frame height in pixels.
Definition video.h:52
uint32_t width
frame width in pixels.
Definition video.h:50
uint32_t pitch
line stride.
Definition video.h:60
uint32_t pixelformat
FourCC pixel format value (Video pixel formats)
Definition video.h:48
Video frame interval enumeration structure.
Definition video.h:191
uint32_t index
frame interval index during enumeration
Definition video.h:193
const struct video_format * format
video format for which the query is made
Definition video.h:195
enum video_frmival_type type
frame interval type the device supports
Definition video.h:197
Video frame interval stepwise structure.
Definition video.h:176
struct video_frmival min
minimum frame interval in seconds
Definition video.h:178
struct video_frmival max
maximum frame interval in seconds
Definition video.h:180
struct video_frmival step
frame interval step size in seconds
Definition video.h:182
Video frame interval structure.
Definition video.h:163
uint32_t numerator
numerator of the frame interval
Definition video.h:165
uint32_t denominator
denominator of the frame interval
Definition video.h:167