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_virtcam_ipc.h - Cross-platform shared memory IPC for Virtual Camera Plugins
7 */
8  
9 #ifndef AVX_VIRTCAM_IPC_H
10 #define AVX_VIRTCAM_IPC_H
11  
12 #include <stdint.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include "openavx.h"
16  
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20  
21 #define AVX_VIRTCAM_MAGIC 0x5856434DU /* 'MVXC' */
22 #define AVX_VIRTCAM_VERSION 1
23 #define AVX_VIRTCAM_POSIX_SHM_NAME "/openavx_virtcam_shm"
24 #define AVX_VIRTCAM_WIN_SHM_NAME "Local\\OpenAVX_VirtualCamera_Shm"
25 #define AVX_VIRTCAM_MAX_FRAME_SIZE (3840 * 2160 * 4) /* Up to 4K BGRA */
26  
27 /* Memory-mapped shared frame header */
28 typedef struct avx_virtcam_shm_header_t {
29 uint32_t magic; /* AVX_VIRTCAM_MAGIC */
30 uint32_t version; /* AVX_VIRTCAM_VERSION */
31 uint32_t width; /* Video width (e.g. 1920) */
32 uint32_t height; /* Video height (e.g. 1080) */
33 uint32_t fourcc; /* OAVX_FOURCC_VIDEO_TYPE_UYVY, YUYV, BGRA */
34 uint32_t fps_num; /* Framerate numerator (30) */
35 uint32_t fps_den; /* Framerate denominator (1) */
36 uint32_t stride; /* Row stride in bytes */
37 uint32_t data_size; /* Total frame bytes */
38 uint64_t sequence; /* Monotonically increasing frame index */
39 int64_t timestamp_ns; /* Monotonic timestamp in nanoseconds */
40 uint32_t clients_active; /* Counter of active consuming applications (Zoom/Teams/Meet) */
41 uint32_t reserved[7];
42 } avx_virtcam_shm_header_t;
43  
44 /* Total mapped buffer layout: Header + Pixel Buffer */
45 typedef struct avx_virtcam_shm_layout_t {
46 avx_virtcam_shm_header_t header;
47 uint8_t pixels[AVX_VIRTCAM_MAX_FRAME_SIZE];
48 } avx_virtcam_shm_layout_t;
49  
50 /* Opaque IPC Producer Handle (used by openavx-virtcam) */
51 typedef struct avx_virtcam_producer_t avx_virtcam_producer_t;
52  
53 /* Opaque IPC Consumer Handle (used by DirectShow DLL & CoreMediaIO DAL) */
54 typedef struct avx_virtcam_consumer_t avx_virtcam_consumer_t;
55  
56 /**
57 * Creates and initializes the shared memory region as a video producer.
58 */
59 OPENAVX_API avx_virtcam_producer_t *avx_virtcam_producer_create(void);
60  
61 /**
62 * Destroys the shared memory producer and unmaps memory.
63 */
64 OPENAVX_API void avx_virtcam_producer_destroy(avx_virtcam_producer_t *prod);
65  
66 /**
67 * Pushes a video frame into shared memory for consuming camera plugins (DirectShow / DAL).
68 */
69 OPENAVX_API bool avx_virtcam_producer_write_frame(
70 avx_virtcam_producer_t *prod,
71 const uint8_t *data,
72 size_t size,
73 uint32_t width,
74 uint32_t height,
75 uint32_t stride,
76 uint32_t fourcc,
77 uint32_t fps_num,
78 uint32_t fps_den
79 );
80  
81 /**
82 * Checks if at least one consumer (Zoom, Teams, Meet) is actively reading the virtual camera.
83 */
84 OPENAVX_API bool avx_virtcam_producer_has_clients(const avx_virtcam_producer_t *prod);
85  
86 /**
87 * Connects to the shared memory region as a video consumer (plugin side).
88 */
89 OPENAVX_API avx_virtcam_consumer_t *avx_virtcam_consumer_create(void);
90  
91 /**
92 * Disconnects the consumer from the shared memory region.
93 */
94 OPENAVX_API void avx_virtcam_consumer_destroy(avx_virtcam_consumer_t *cons);
95  
96 /**
97 * Reads the latest available frame from the shared memory region.
98 * Returns true if a new frame was available and copied.
99 */
100 OPENAVX_API bool avx_virtcam_consumer_read_frame(
101 avx_virtcam_consumer_t *cons,
102 avx_virtcam_shm_header_t *out_header,
103 uint8_t *out_buffer,
104 size_t buffer_max,
105 uint64_t *inout_last_seq
106 );
107  
108 #ifdef __cplusplus
109 }
110 #endif
111  
112 #endif /* AVX_VIRTCAM_IPC_H */