Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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
22#include <device.h>
23#include <stddef.h>
24#include <zephyr.h>
25
26#include <zephyr/types.h>
27
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34
52};
53
75};
76
86struct video_caps {
89};
90
111};
112
122};
123
132};
133
139typedef int (*video_api_set_format_t)(const struct device *dev,
140 enum video_endpoint_id ep,
141 struct video_format *fmt);
142
148typedef int (*video_api_get_format_t)(const struct device *dev,
149 enum video_endpoint_id ep,
150 struct video_format *fmt);
151
157typedef int (*video_api_enqueue_t)(const struct device *dev,
158 enum video_endpoint_id ep,
159 struct video_buffer *buf);
160
166typedef int (*video_api_dequeue_t)(const struct device *dev,
167 enum video_endpoint_id ep,
168 struct video_buffer **buf,
170
177typedef int (*video_api_flush_t)(const struct device *dev,
178 enum video_endpoint_id ep,
179 bool cancel);
180
186typedef int (*video_api_stream_start_t)(const struct device *dev);
187
193typedef int (*video_api_stream_stop_t)(const struct device *dev);
194
200typedef int (*video_api_set_ctrl_t)(const struct device *dev,
201 unsigned int cid,
202 void *value);
203
209typedef int (*video_api_get_ctrl_t)(const struct device *dev,
210 unsigned int cid,
211 void *value);
212
218typedef int (*video_api_get_caps_t)(const struct device *dev,
219 enum video_endpoint_id ep,
220 struct video_caps *caps);
221
227typedef int (*video_api_set_signal_t)(const struct device *dev,
228 enum video_endpoint_id ep,
229 struct k_poll_signal *signal);
230
232 /* mandatory callbacks */
238 /* optional callbacks */
245};
246
261static inline int video_set_format(const struct device *dev,
262 enum video_endpoint_id ep,
263 struct video_format *fmt)
264{
265 const struct video_driver_api *api =
266 (const struct video_driver_api *)dev->api;
267
268 if (api->set_format == NULL) {
269 return -ENOSYS;
270 }
271
272 return api->set_format(dev, ep, fmt);
273}
274
286static inline int video_get_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->get_format == NULL) {
294 return -ENOSYS;
295 }
296
297 return api->get_format(dev, ep, fmt);
298}
299
314static inline int video_enqueue(const struct device *dev,
315 enum video_endpoint_id ep,
316 struct video_buffer *buf)
317{
318 const struct video_driver_api *api =
319 (const struct video_driver_api *)dev->api;
320
321 if (api->enqueue == NULL) {
322 return -ENOSYS;
323 }
324
325 return api->enqueue(dev, ep, buf);
326}
327
343static inline int video_dequeue(const struct device *dev,
344 enum video_endpoint_id ep,
345 struct video_buffer **buf,
347{
348 const struct video_driver_api *api =
349 (const struct video_driver_api *)dev->api;
350
351 if (api->dequeue == NULL) {
352 return -ENOSYS;
353 }
354
355 return api->dequeue(dev, ep, buf, timeout);
356}
357
358
373static inline int video_flush(const struct device *dev,
374 enum video_endpoint_id ep,
375 bool cancel)
376{
377 const struct video_driver_api *api =
378 (const struct video_driver_api *)dev->api;
379
380 if (api->flush == NULL) {
381 return -ENOSYS;
382 }
383
384 return api->flush(dev, ep, cancel);
385}
386
399static inline int video_stream_start(const struct device *dev)
400{
401 const struct video_driver_api *api =
402 (const struct video_driver_api *)dev->api;
403
404 if (api->stream_start == NULL) {
405 return -ENOSYS;
406 }
407
408 return api->stream_start(dev);
409}
410
420static inline int video_stream_stop(const struct device *dev)
421{
422 const struct video_driver_api *api =
423 (const struct video_driver_api *)dev->api;
424 int ret;
425
426 if (api->stream_stop == NULL) {
427 return -ENOSYS;
428 }
429
430 ret = api->stream_stop(dev);
431 video_flush(dev, VIDEO_EP_ANY, true);
432
433 return ret;
434}
435
445static inline int video_get_caps(const struct device *dev,
446 enum video_endpoint_id ep,
447 struct video_caps *caps)
448{
449 const struct video_driver_api *api =
450 (const struct video_driver_api *)dev->api;
451
452 if (api->get_caps == NULL) {
453 return -ENOSYS;
454 }
455
456 return api->get_caps(dev, ep, caps);
457}
458
474static inline int video_set_ctrl(const struct device *dev, unsigned int cid,
475 void *value)
476{
477 const struct video_driver_api *api =
478 (const struct video_driver_api *)dev->api;
479
480 if (api->set_ctrl == NULL) {
481 return -ENOSYS;
482 }
483
484 return api->set_ctrl(dev, cid, value);
485}
486
502static inline int video_get_ctrl(const struct device *dev, unsigned int cid,
503 void *value)
504{
505 const struct video_driver_api *api =
506 (const struct video_driver_api *)dev->api;
507
508 if (api->get_ctrl == NULL) {
509 return -ENOSYS;
510 }
511
512 return api->get_ctrl(dev, cid, value);
513}
514
528static inline int video_set_signal(const struct device *dev,
529 enum video_endpoint_id ep,
530 struct k_poll_signal *signal)
531{
532 const struct video_driver_api *api =
533 (const struct video_driver_api *)dev->api;
534
535 if (api->set_signal == NULL) {
536 return -ENOSYS;
537 }
538
539 return api->set_signal(dev, ep, signal);
540}
541
550
557
558
559/* fourcc - four-character-code */
560#define video_fourcc(a, b, c, d)\
561 ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
562
563/* Raw bayer formats */
564#define VIDEO_PIX_FMT_BGGR8 video_fourcc('B', 'G', 'G', 'R') /* 8 BGBG.. GRGR.. */
565#define VIDEO_PIX_FMT_GBRG8 video_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
566#define VIDEO_PIX_FMT_GRBG8 video_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
567#define VIDEO_PIX_FMT_RGGB8 video_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
568
569/* RGB formats */
570#define VIDEO_PIX_FMT_RGB565 video_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
571
572/* JPEG formats */
573#define VIDEO_PIX_FMT_JPEG video_fourcc('J', 'P', 'E', 'G') /* 8 JPEG */
574
575/* YUV formats */
576#define VIDEO_PIX_FMT_YUYV video_fourcc('Y', 'U', 'Y', 'V') /* 16 YUYV */
577#define VIDEO_PIX_FMT_YVYU video_fourcc('Y', 'V', 'Y', 'U') /* 16 YVYU */
578#define VIDEO_PIX_FMT_VYVU video_fourcc('V', 'Y', 'V', 'U') /* 16 VYVU */
579#define VIDEO_PIX_FMT_UYVY video_fourcc('U', 'Y', 'V', 'Y') /* 16 UYVY */
580
581#ifdef __cplusplus
582}
583#endif
584
589#endif /* ZEPHYR_INCLUDE_VIDEO_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
#define ENOSYS
Definition: errno.h:83
int(* video_api_stream_start_t)(const struct device *dev)
Start the capture or output process. See video_stream_start() for argument descriptions.
Definition: video.h:186
int(* video_api_set_format_t)(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Set video format See video_set_format() for argument descriptions.
Definition: video.h:139
video_signal_result
video_event enum Identify video event.
Definition: video.h:128
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. See video_enqueue() for argument descriptions.
Definition: video.h:157
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. See video_set_signal() for argument descriptions.
Definition: video.h:227
int(* video_api_stream_stop_t)(const struct device *dev)
Stop the capture or output process. See video_stream_stop() for argument descriptions.
Definition: video.h:193
int(* video_api_get_format_t)(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
get current video format See video_get_format() for argument descriptions.
Definition: video.h:148
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:445
static int video_stream_stop(const struct device *dev)
Stop the video device function.
Definition: video.h:420
static int video_get_ctrl(const struct device *dev, unsigned int cid, void *value)
Get the current value of a control.
Definition: video.h:502
static int video_stream_start(const struct device *dev)
Start the video device function.
Definition: video.h:399
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:474
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. See video_flush() for...
Definition: video.h:177
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. See video_get_caps() for argument descriptions.
Definition: video.h:218
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:343
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. See video_dequeue() for argument descriptions.
Definition: video.h:166
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:528
static int video_get_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Get video format.
Definition: video.h:286
static int video_enqueue(const struct device *dev, enum video_endpoint_id ep, struct video_buffer *buf)
Enqueue a video buffer.
Definition: video.h:314
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. See video_get_ctrl() for argument descriptions.
Definition: video.h:209
static int video_set_format(const struct device *dev, enum video_endpoint_id ep, struct video_format *fmt)
Set video format.
Definition: video.h:261
static int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
Flush endpoint buffers.
Definition: video.h:373
video_endpoint_id
video_endpoint_id enum Identify the video device endpoint.
Definition: video.h:117
int(* video_api_set_ctrl_t)(const struct device *dev, unsigned int cid, void *value)
set a video control value. See video_set_ctrl() for argument descriptions.
Definition: video.h:200
@ VIDEO_BUF_ABORTED
Definition: video.h:130
@ VIDEO_BUF_DONE
Definition: video.h:129
@ VIDEO_BUF_ERROR
Definition: video.h:131
@ VIDEO_EP_IN
Definition: video.h:120
@ VIDEO_EP_NONE
Definition: video.h:118
@ VIDEO_EP_ANY
Definition: video.h:119
@ VIDEO_EP_OUT
Definition: video.h:121
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
Definition: kernel.h:5405
Kernel timeout type.
Definition: sys_clock.h:65
video buffer structure
Definition: video.h:105
uint32_t bytesused
Definition: video.h:109
uint32_t size
Definition: video.h:108
uint8_t * buffer
Definition: video.h:107
void * driver_data
Definition: video.h:106
uint32_t timestamp
Definition: video.h:110
video capabilities
Definition: video.h:86
uint8_t min_vbuf_count
Definition: video.h:88
const struct video_format_cap * format_caps
Definition: video.h:87
Definition: video.h:231
video_api_stream_stop_t stream_stop
Definition: video.h:236
video_api_set_ctrl_t set_ctrl
Definition: video.h:242
video_api_stream_start_t stream_start
Definition: video.h:235
video_api_set_ctrl_t get_ctrl
Definition: video.h:243
video_api_enqueue_t enqueue
Definition: video.h:239
video_api_set_signal_t set_signal
Definition: video.h:244
video_api_get_format_t get_format
Definition: video.h:234
video_api_get_caps_t get_caps
Definition: video.h:237
video_api_set_format_t set_format
Definition: video.h:233
video_api_flush_t flush
Definition: video.h:241
video_api_dequeue_t dequeue
Definition: video.h:240
video format capability
Definition: video.h:67
uint16_t height_step
Definition: video.h:74
uint32_t width_min
Definition: video.h:69
uint32_t width_max
Definition: video.h:70
uint16_t width_step
Definition: video.h:73
uint32_t height_max
Definition: video.h:72
uint32_t height_min
Definition: video.h:71
uint32_t pixelformat
Definition: video.h:68
video format structure
Definition: video.h:47
uint32_t height
Definition: video.h:50
uint32_t width
Definition: video.h:49
uint32_t pitch
Definition: video.h:51
uint32_t pixelformat
Definition: video.h:48
static struct k_poll_signal signal
Definition: test_poll.c:696
Public APIs for Video.