Raw ↗
+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
1 /*
2 * SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0
3 * Copyright (c) 2026 Saif Mukhtar
4 *
5 * OpenAVX - Open Audio-Video eXchange
6 * include/avx_v4l2_sink.h - Linux V4L2 Virtual Camera Loopback Sink
7 */
8  
9 #ifndef AVX_V4L2_SINK_H
10 #define AVX_V4L2_SINK_H
11  
12 #include <stdint.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include "avx_platform.h"
16 #include "openavx.h"
17  
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21  
22 typedef struct avx_v4l2_sink_t avx_v4l2_sink_t;
23  
24 typedef struct {
25 const char *device_path; /* Target device, e.g. "/dev/video10", or NULL for auto-probe */
26 uint32_t width; /* Frame width (e.g. 1920) */
27 uint32_t height; /* Frame height (e.g. 1080) */
28 uint32_t pixelformat; /* V4L2 FourCC (e.g. 'YUYV', 'UYVY', 'BGR3') - 0 for default YUYV */
29 uint32_t fps_num; /* Target FPS numerator (e.g. 30, 60, 0 = default 30) */
30 uint32_t fps_den; /* Target FPS denominator (e.g. 1, 0 = default 1) */
31 } avx_v4l2_sink_config_t;
32  
33 /**
34 * Probes the system for available V4L2 loopback devices (e.g. created by v4l2loopback).
35 * Returns true if a valid loopback device was found and writes path to out_path.
36 */
37 OPENAVX_API bool avx_v4l2_sink_probe_loopback(char *out_path, size_t out_path_len);
38  
39 /**
40 * Creates and initializes a V4L2 Virtual Camera loopback sink.
41 * If cfg->device_path is NULL or empty, automatically probes for an available loopback device.
42 * Returns NULL on failure (e.g. device does not exist or permission denied).
43 */
44 OPENAVX_API avx_v4l2_sink_t* avx_v4l2_sink_create(const avx_v4l2_sink_config_t *cfg);
45  
46 /**
47 * Dynamically reconfigures the output resolution or pixel format.
48 */
49 OPENAVX_API int avx_v4l2_sink_set_format(avx_v4l2_sink_t *sink, uint32_t width, uint32_t height, uint32_t pixelformat);
50  
51 /**
52 * Writes an uncompressed frame buffer directly to the V4L2 device.
53 */
54 OPENAVX_API int avx_v4l2_sink_write_raw(avx_v4l2_sink_t *sink, const void *data, size_t size);
55  
56 /**
57 * Writes an OpenAVX video frame, performing high-speed SIMD pixel format conversion
58 * (e.g. UYVY -> YUYV or RGBA -> YUYV) if the frame format differs from the sink format.
59 */
60 OPENAVX_API int avx_v4l2_sink_write_frame(avx_v4l2_sink_t *sink, const oavx_video_frame_t *frame);
61  
62 /**
63 * Returns the currently active V4L2 device path (e.g. "/dev/video10").
64 */
65 OPENAVX_API const char* avx_v4l2_sink_get_device_path(const avx_v4l2_sink_t *sink);
66  
67 /**
68 * Closes the V4L2 device and frees all allocated buffers.
69 */
70 OPENAVX_API void avx_v4l2_sink_destroy(avx_v4l2_sink_t *sink);
71  
72 #ifdef __cplusplus
73 }
74 #endif
75  
76 #endif /* AVX_V4L2_SINK_H */