Zephyr API 3.6.99
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
59
60
83
98
120
136
147
154typedef int (*video_api_set_format_t)(const struct device *dev,
155 enum video_endpoint_id ep,
156 struct video_format *fmt);
157
164typedef int (*video_api_get_format_t)(const struct device *dev,
165 enum video_endpoint_id ep,
166 struct video_format *fmt);
167
174typedef int (*video_api_enqueue_t)(const struct device *dev,
175 enum video_endpoint_id ep,
176 struct video_buffer *buf);
177
184typedef int (*video_api_dequeue_t)(const struct device *dev,
185 enum video_endpoint_id ep,
186 struct video_buffer **buf,
187 k_timeout_t timeout);
188
196typedef int (*video_api_flush_t)(const struct device *dev,
197 enum video_endpoint_id ep,
198 bool cancel);
199
206typedef int (*video_api_stream_start_t)(const struct device *dev);
207
214typedef int (*video_api_stream_stop_t)(const struct device *dev);
215
222typedef int (*video_api_set_ctrl_t)(const struct device *dev,
223 unsigned int cid,
224 void *value);
225
232typedef int (*video_api_get_ctrl_t)(const struct device *dev,
233 unsigned int cid,
234 void *value);
235
242typedef int (*video_api_get_caps_t)(const struct device *dev,
243 enum video_endpoint_id ep,
244 struct video_caps *caps);
245
252typedef int (*video_api_set_signal_t)(const struct device *dev,
253 enum video_endpoint_id ep,
254 struct k_poll_signal *signal);
255
271
286static inline int video_set_format(const struct device *dev,
287 enum video_endpoint_id ep,
288 struct video_format *fmt)
289{
290 const struct video_driver_api *api =
291 (const struct video_driver_api *)dev->api;
292
293 if (api->set_format == NULL) {
294 return -ENOSYS;
295 }
296
297 return api->set_format(dev, ep, fmt);
298}
299
311static inline int video_get_format(const struct device *dev,
312 enum video_endpoint_id ep,
313 struct video_format *fmt)
314{
315 const struct video_driver_api *api =
316 (const struct video_driver_api *)dev->api;
317
318 if (api->get_format == NULL) {
319 return -ENOSYS;
320 }
321
322 return api->get_format(dev, ep, fmt);
323}
324
339static inline int video_enqueue(const struct device *dev,
340 enum video_endpoint_id ep,
341 struct video_buffer *buf)
342{
343 const struct video_driver_api *api =
344 (const struct video_driver_api *)dev->api;
345
346 if (api->enqueue == NULL) {
347 return -ENOSYS;
348 }
349
350 return api->enqueue(dev, ep, buf);
351}
352
368static inline int video_dequeue(const struct device *dev,
369 enum video_endpoint_id ep,
370 struct video_buffer **buf,
371 k_timeout_t timeout)
372{
373 const struct video_driver_api *api =
374 (const struct video_driver_api *)dev->api;
375
376 if (api->dequeue == NULL) {
377 return -ENOSYS;
378 }
379
380 return api->dequeue(dev, ep, buf, timeout);
381}
382
383
398static inline int video_flush(const struct device *dev,
399 enum video_endpoint_id ep,
400 bool cancel)
401{
402 const struct video_driver_api *api =
403 (const struct video_driver_api *)dev->api;
404
405 if (api->flush == NULL) {
406 return -ENOSYS;
407 }
408
409 return api->flush(dev, ep, cancel);
410}
411
424static inline int video_stream_start(const struct device *dev)
425{
426 const struct video_driver_api *api =
427 (const struct video_driver_api *)dev->api;
428
429 if (api->stream_start == NULL) {
430 return -ENOSYS;
431 }
432
433 return api->stream_start(dev);
434}
435
445static inline int video_stream_stop(const struct device *dev)
446{
447 const struct video_driver_api *api =
448 (const struct video_driver_api *)dev->api;
449 int ret;
450
451 if (api->stream_stop == NULL) {
452 return -ENOSYS;
453 }
454
455 ret = api->stream_stop(dev);
456 video_flush(dev, VIDEO_EP_ALL, true);
457
458 return ret;
459}
460
470static inline int video_get_caps(const struct device *dev,
471 enum video_endpoint_id ep,
472 struct video_caps *caps)
473{
474 const struct video_driver_api *api =
475 (const struct video_driver_api *)dev->api;
476
477 if (api->get_caps == NULL) {
478 return -ENOSYS;
479 }
480
481 return api->get_caps(dev, ep, caps);
482}
483
499static inline int video_set_ctrl(const struct device *dev, unsigned int cid,
500 void *value)
501{
502 const struct video_driver_api *api =
503 (const struct video_driver_api *)dev->api;
504
505 if (api->set_ctrl == NULL) {
506 return -ENOSYS;
507 }
508
509 return api->set_ctrl(dev, cid, value);
510}
511
527static inline int video_get_ctrl(const struct device *dev, unsigned int cid,
528 void *value)
529{
530 const struct video_driver_api *api =
531 (const struct video_driver_api *)dev->api;
532
533 if (api->get_ctrl == NULL) {
534 return -ENOSYS;
535 }
536
537 return api->get_ctrl(dev, cid, value);
538}
539
553static inline int video_set_signal(const struct device *dev,
554 enum video_endpoint_id ep,
555 struct k_poll_signal *signal)
556{
557 const struct video_driver_api *api =
558 (const struct video_driver_api *)dev->api;
559
560 if (api->set_signal == NULL) {
561 return -ENOSYS;
562 }
563
564 return api->set_signal(dev, ep, signal);
565}
566
575struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align);
576
585
592
593
594/* fourcc - four-character-code */
595#define video_fourcc(a, b, c, d)\
596 ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
597
598
610#define VIDEO_PIX_FMT_BGGR8 video_fourcc('B', 'G', 'G', 'R') /* 8 BGBG.. GRGR.. */
612#define VIDEO_PIX_FMT_GBRG8 video_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
614#define VIDEO_PIX_FMT_GRBG8 video_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
616#define VIDEO_PIX_FMT_RGGB8 video_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
617
628#define VIDEO_PIX_FMT_RGB565 video_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
629
631#define VIDEO_PIX_FMT_XRGB32 video_fourcc('B', 'X', '2', '4') /* 32 XRGB-8-8-8-8 */
632
643#define VIDEO_PIX_FMT_YUYV video_fourcc('Y', 'U', 'Y', 'V') /* 16 Y0-Cb0 Y1-Cr0 */
644
646#define VIDEO_PIX_FMT_XYUV32 video_fourcc('X', 'Y', 'U', 'V') /* 32 XYUV-8-8-8-8 */
647
659#define VIDEO_PIX_FMT_JPEG video_fourcc('J', 'P', 'E', 'G') /* 8 JPEG */
660
669#ifdef __cplusplus
670}
671#endif
672
677#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:206
video_signal_result
video_event enum
Definition video.h:142
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:174
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:184
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:470
int(* video_api_stream_stop_t)(const struct device *dev)
Stop the capture or output process.
Definition video.h:214
static int video_stream_stop(const struct device *dev)
Stop the video device function.
Definition video.h:445
static int video_get_ctrl(const struct device *dev, unsigned int cid, void *value)
Get the current value of a control.
Definition video.h:527
static int video_stream_start(const struct device *dev)
Start the video device function.
Definition video.h:424
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:164
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:499
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:368
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:252
int(* video_api_get_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
Get a video control value.
Definition video.h:232
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:553
static int video_get_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Get video format.
Definition video.h:311
static int video_enqueue(const struct device *dev, enum video_endpoint_id ep, struct video_buffer *buf)
Enqueue a video buffer.
Definition video.h:339
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:196
int(* video_api_set_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
Set a video control value.
Definition video.h:222
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:242
static int video_set_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Set video format.
Definition video.h:286
static int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
Flush endpoint buffers.
Definition video.h:398
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:154
video_endpoint_id
video_endpoint_id enum
Definition video.h:126
@ VIDEO_BUF_ABORTED
Definition video.h:144
@ VIDEO_BUF_DONE
Definition video.h:143
@ VIDEO_BUF_ERROR
Definition video.h:145
@ VIDEO_EP_IN
Targets all input endpoints of the device: those consuming data.
Definition video.h:132
@ VIDEO_EP_NONE
Targets some part of the video device not bound to an endpoint.
Definition video.h:128
@ VIDEO_EP_OUT
Targets all output endpoints of the device: those producing data.
Definition video.h:134
@ VIDEO_EP_ALL
Targets all input or output endpoints of the device.
Definition video.h:130
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
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:5768
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:256
video_api_stream_stop_t stream_stop
Definition video.h:261
video_api_set_ctrl_t set_ctrl
Definition video.h:267
video_api_stream_start_t stream_start
Definition video.h:260
video_api_set_ctrl_t get_ctrl
Definition video.h:268
video_api_enqueue_t enqueue
Definition video.h:264
video_api_set_signal_t set_signal
Definition video.h:269
video_api_get_format_t get_format
Definition video.h:259
video_api_get_caps_t get_caps
Definition video.h:262
video_api_set_format_t set_format
Definition video.h:258
video_api_flush_t flush
Definition video.h:266
video_api_dequeue_t dequeue
Definition video.h:265
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.