Zephyr API Documentation 4.1.0-rc1
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
315typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable);
316
323typedef int (*video_api_set_ctrl_t)(const struct device *dev, unsigned int cid, void *value);
324
331typedef int (*video_api_get_ctrl_t)(const struct device *dev, unsigned int cid, void *value);
332
339typedef int (*video_api_get_caps_t)(const struct device *dev, enum video_endpoint_id ep,
340 struct video_caps *caps);
341
348typedef int (*video_api_set_signal_t)(const struct device *dev, enum video_endpoint_id ep,
349 struct k_poll_signal *signal);
350
368
383static inline int video_set_format(const struct device *dev, enum video_endpoint_id ep,
384 struct video_format *fmt)
385{
386 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
387
388 if (api->set_format == NULL) {
389 return -ENOSYS;
390 }
391
392 return api->set_format(dev, ep, fmt);
393}
394
406static inline int video_get_format(const struct device *dev, enum video_endpoint_id ep,
407 struct video_format *fmt)
408{
409 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
410
411 if (api->get_format == NULL) {
412 return -ENOSYS;
413 }
414
415 return api->get_format(dev, ep, fmt);
416}
417
435static inline int video_set_frmival(const struct device *dev, enum video_endpoint_id ep,
436 struct video_frmival *frmival)
437{
438 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
439
440 if (api->set_frmival == NULL) {
441 return -ENOSYS;
442 }
443
444 return api->set_frmival(dev, ep, frmival);
445}
446
461static inline int video_get_frmival(const struct device *dev, enum video_endpoint_id ep,
462 struct video_frmival *frmival)
463{
464 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
465
466 if (api->get_frmival == NULL) {
467 return -ENOSYS;
468 }
469
470 return api->get_frmival(dev, ep, frmival);
471}
472
491static inline int video_enum_frmival(const struct device *dev, enum video_endpoint_id ep,
492 struct video_frmival_enum *fie)
493{
494 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
495
496 if (api->enum_frmival == NULL) {
497 return -ENOSYS;
498 }
499
500 return api->enum_frmival(dev, ep, fie);
501}
502
517static inline int video_enqueue(const struct device *dev, enum video_endpoint_id ep,
518 struct video_buffer *buf)
519{
520 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
521
522 if (api->enqueue == NULL) {
523 return -ENOSYS;
524 }
525
526 return api->enqueue(dev, ep, buf);
527}
528
544static inline int video_dequeue(const struct device *dev, enum video_endpoint_id ep,
545 struct video_buffer **buf, k_timeout_t timeout)
546{
547 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
548
549 if (api->dequeue == NULL) {
550 return -ENOSYS;
551 }
552
553 return api->dequeue(dev, ep, buf, timeout);
554}
555
570static inline int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
571{
572 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
573
574 if (api->flush == NULL) {
575 return -ENOSYS;
576 }
577
578 return api->flush(dev, ep, cancel);
579}
580
593static inline int video_stream_start(const struct device *dev)
594{
595 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
596
597 if (api->set_stream == NULL) {
598 return -ENOSYS;
599 }
600
601 return api->set_stream(dev, true);
602}
603
613static inline int video_stream_stop(const struct device *dev)
614{
615 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
616 int ret;
617
618 if (api->set_stream == NULL) {
619 return -ENOSYS;
620 }
621
622 ret = api->set_stream(dev, false);
623 video_flush(dev, VIDEO_EP_ALL, true);
624
625 return ret;
626}
627
637static inline int video_get_caps(const struct device *dev, enum video_endpoint_id ep,
638 struct video_caps *caps)
639{
640 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
641
642 if (api->get_caps == NULL) {
643 return -ENOSYS;
644 }
645
646 return api->get_caps(dev, ep, caps);
647}
648
664static inline int video_set_ctrl(const struct device *dev, unsigned int cid, void *value)
665{
666 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
667
668 if (api->set_ctrl == NULL) {
669 return -ENOSYS;
670 }
671
672 return api->set_ctrl(dev, cid, value);
673}
674
690static inline int video_get_ctrl(const struct device *dev, unsigned int cid, void *value)
691{
692 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
693
694 if (api->get_ctrl == NULL) {
695 return -ENOSYS;
696 }
697
698 return api->get_ctrl(dev, cid, value);
699}
700
714static inline int video_set_signal(const struct device *dev, enum video_endpoint_id ep,
715 struct k_poll_signal *signal)
716{
717 const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
718
719 if (api->set_signal == NULL) {
720 return -ENOSYS;
721 }
722
723 return api->set_signal(dev, ep, signal);
724}
725
735struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align, k_timeout_t timeout);
736
746
753
764int video_format_caps_index(const struct video_format_cap *fmts, const struct video_format *fmt,
765 size_t *idx);
766
774static inline uint64_t video_frmival_nsec(const struct video_frmival *frmival)
775{
776 return (uint64_t)NSEC_PER_SEC * frmival->numerator / frmival->denominator;
777}
778
787 const struct video_frmival *desired,
788 struct video_frmival *match);
789
808void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
809 struct video_frmival_enum *match);
810
822#define VIDEO_FOURCC(a, b, c, d) \
823 ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
824
834#define VIDEO_FOURCC_FROM_STR(str) VIDEO_FOURCC((str)[0], (str)[1], (str)[2], (str)[3])
835
850#define VIDEO_PIX_FMT_BGGR8 VIDEO_FOURCC('B', 'A', '8', '1')
851
858#define VIDEO_PIX_FMT_GBRG8 VIDEO_FOURCC('G', 'B', 'R', 'G')
859
866#define VIDEO_PIX_FMT_GRBG8 VIDEO_FOURCC('G', 'R', 'B', 'G')
867
874#define VIDEO_PIX_FMT_RGGB8 VIDEO_FOURCC('R', 'G', 'G', 'B')
875
895#define VIDEO_PIX_FMT_RGB565X VIDEO_FOURCC('R', 'G', 'B', 'R')
896
906#define VIDEO_PIX_FMT_RGB565 VIDEO_FOURCC('R', 'G', 'B', 'P')
907
915#define VIDEO_PIX_FMT_XRGB32 VIDEO_FOURCC('B', 'X', '2', '4')
916
935#define VIDEO_PIX_FMT_YUYV VIDEO_FOURCC('Y', 'U', 'Y', 'V')
936
944#define VIDEO_PIX_FMT_XYUV32 VIDEO_FOURCC('X', 'Y', 'U', 'V')
945
958#define VIDEO_PIX_FMT_JPEG VIDEO_FOURCC('J', 'P', 'E', 'G')
959
972static inline unsigned int video_bits_per_pixel(uint32_t pixfmt)
973{
974 switch (pixfmt) {
979 return 8;
982 return 16;
985 return 32;
986 default:
987 /* Variable number of bits per pixel or unknown format */
988 return 0;
989 }
990}
991
996#ifdef __cplusplus
997}
998#endif
999
1004#endif /* ZEPHYR_INCLUDE_VIDEO_H_ */
#define NSEC_PER_SEC
number of nanoseconds per second
Definition sys_clock.h:113
#define ENOSYS
Function not implemented.
Definition errno.h:82
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
struct video_buffer * video_buffer_aligned_alloc(size_t size, size_t align, k_timeout_t timeout)
Allocate aligned video buffer.
int(* video_api_set_stream_t)(const struct device *dev, bool enable)
Start or stop streaming on the video device.
Definition video.h:315
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:637
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:435
static int video_stream_stop(const struct device *dev)
Stop the video device function.
Definition video.h:613
static int video_get_ctrl(const struct device *dev, unsigned int cid, void *value)
Get the current value of a control.
Definition video.h:690
void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep, struct video_frmival_enum *match)
Find the closest match to a frame interval value within a video device.
video_frmival_type
video_frmival_type enum
Definition video.h:150
static uint64_t video_frmival_nsec(const struct video_frmival *frmival)
Compute the difference between two frame intervals.
Definition video.h:774
static int video_stream_start(const struct device *dev)
Start the video device function.
Definition video.h:593
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
static int video_set_ctrl(const struct device *dev, unsigned int cid, void *value)
Set the value of a control.
Definition video.h:664
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:544
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:348
int(* video_api_get_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
Get a video control value.
Definition video.h:331
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:461
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:714
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 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:491
static int video_get_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Get video format.
Definition video.h:406
static int video_enqueue(const struct device *dev, enum video_endpoint_id ep, struct video_buffer *buf)
Enqueue a video buffer.
Definition video.h:517
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_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwise, const struct video_frmival *desired, struct video_frmival *match)
Find the closest match to a frame interval value within a stepwise frame interval.
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:323
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:339
int video_format_caps_index(const struct video_format_cap *fmts, const struct video_format *fmt, size_t *idx)
Search for a format that matches in a list of capabilities.
static int video_set_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Set video format.
Definition video.h:383
static int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
Flush endpoint buffers.
Definition video.h:570
struct video_buffer * video_buffer_alloc(size_t size, k_timeout_t timeout)
Allocate video buffer.
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
The first byte is empty (X) for each pixel.
Definition video.h:944
#define VIDEO_PIX_FMT_RGGB8
Definition video.h:874
#define VIDEO_PIX_FMT_BGGR8
Definition video.h:850
#define VIDEO_PIX_FMT_GRBG8
Definition video.h:866
#define VIDEO_PIX_FMT_XRGB32
The first byte is empty (X) for each pixel.
Definition video.h:915
static unsigned int video_bits_per_pixel(uint32_t pixfmt)
Get number of bits per pixel of a pixel format.
Definition video.h:972
#define VIDEO_PIX_FMT_YUYV
There is either a missing channel per pixel, U or V.
Definition video.h:935
#define VIDEO_PIX_FMT_GBRG8
Definition video.h:858
#define VIDEO_PIX_FMT_RGB565
5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
Definition video.h:906
#define NULL
Definition iar_missing_defs.h:20
sighandler_t signal(int signo, sighandler_t handler)
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__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:453
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:459
Definition kernel.h:5964
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:351
video_api_set_ctrl_t set_ctrl
Definition video.h:361
video_api_enqueue_t enqueue
Definition video.h:358
video_api_set_signal_t set_signal
Definition video.h:363
video_api_get_format_t get_format
Definition video.h:354
video_api_enum_frmival_t enum_frmival
Definition video.h:366
video_api_get_caps_t get_caps
Definition video.h:356
video_api_set_format_t set_format
Definition video.h:353
video_api_flush_t flush
Definition video.h:360
video_api_dequeue_t dequeue
Definition video.h:359
video_api_get_ctrl_t get_ctrl
Definition video.h:362
video_api_get_frmival_t get_frmival
Definition video.h:365
video_api_set_stream_t set_stream
Definition video.h:355
video_api_set_frmival_t set_frmival
Definition video.h:364
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