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 * test/oavx_stream_test.c - Verification Suite for Modern Native Media Pipeline (oavx_*)
7 */
8  
9 #define _DEFAULT_SOURCE
10 #define _POSIX_C_SOURCE 200809L
11 #include "openavx.h"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <assert.h>
16 #include <unistd.h>
17  
18 int main(void) {
19 printf("=== OpenAVX Stream Pipeline Tests (oavx_*) ===\n\n");
20  
21 /* 1. Initialize Context */
22 printf("[*] 1. Creating oavx_context_t runtime engine...\n");
23 oavx_context_t *ctx = oavx_context_create();
24 assert(ctx != NULL);
25 printf(" [+] Context created: %p\n", (void*)ctx);
26 printf(" [+] Engine Version: %s\n", oavx_version());
27 printf(" [+] CPU Supported: %s\n", oavx_is_supported_cpu() ? "YES" : "NO");
28 assert(oavx_is_supported_cpu());
29  
30 /* 2. Open Transmit Stream */
31 printf("[*] 2. Opening Transmit Stream: 'OAVX_PROD_FEED' on port 7960...\n");
32 oavx_stream_config_t tx_cfg = {
33 .name = "OAVX_PROD_FEED",
34 .direction = OAVX_DIR_TRANSMIT,
35 .clock_sync = false,
36 .groups = "Public"
37 };
38 oavx_stream_t *tx = oavx_stream_open(ctx, &tx_cfg);
39 assert(tx != NULL);
40 printf(" [+] Transmit stream handle initialized: %p\n", (void*)tx);
41  
42 /* 3. Open Receive Stream & Connect */
43 printf("[*] 3. Opening Receive Stream connecting to 127.0.0.1:7960...\n");
44 oavx_stream_config_t rx_cfg = {
45 .name = "OAVX_PROD_FEED",
46 .endpoint = "127.0.0.1:7960",
47 .direction = OAVX_DIR_RECEIVE,
48 .color_format = OAVX_COLOR_FORMAT_UYVY_RGBA,
49 .bandwidth = OAVX_BANDWIDTH_HIGHEST,
50 .groups = "Public"
51 };
52 oavx_stream_t *rx = oavx_stream_open(ctx, &rx_cfg);
53 assert(rx != NULL);
54 printf(" [+] Receive stream handle initialized: %p\n", (void*)rx);
55  
56 /* Wait briefly for TCP handshake */
57 usleep(50000);
58  
59 /* 4. Transmit and Receive Planar Video Frame */
60 printf("[*] 4. Transmitting 1080p60 planar-aware video frame over stream...\n");
61 const uint32_t width = 640;
62 const uint32_t height = 360;
63 size_t line_stride = (size_t)width * 2;
64 size_t frame_bytes = line_stride * height;
65 uint8_t *video_buf = (uint8_t*)malloc(frame_bytes);
66 assert(video_buf != NULL);
67 memset(video_buf, 0x5A, frame_bytes);
68  
69 oavx_video_frame_t tx_v = {
70 .width = width,
71 .height = height,
72 .fourcc = OAVX_FOURCC_VIDEO_TYPE_UYVY,
73 .scan_type = OAVX_SCAN_PROGRESSIVE,
74 .planes = { video_buf, NULL, NULL, NULL },
75 .strides = { line_stride, 0, 0, 0 },
76 .framerate = { .num = 60000, .den = 1000 },
77 .aspect_ratio = { .num = 16, .den = 9 },
78 .pts_ns = 1000000000LL /* 1.0 second */
79 };
80  
81 int tx_res = oavx_stream_send_video(tx, &tx_v);
82 assert(tx_res == 0);
83 printf(" [+] Dispatched video frame via oavx_stream_send_video (640x360 UYVY)\n");
84  
85 oavx_video_frame_t rx_v = {0};
86 oavx_frame_type_t ftype = oavx_stream_receive(rx, &rx_v, NULL, NULL, 500);
87 assert(ftype == OAVX_FRAME_TYPE_VIDEO);
88 assert(rx_v.width == width);
89 assert(rx_v.height == height);
90 assert(rx_v.fourcc == OAVX_FOURCC_VIDEO_TYPE_UYVY);
91 assert(rx_v.planes[0] != NULL);
92 assert(((uint8_t*)rx_v.planes[0])[0] == 0x5A);
93 printf(" [+] Successfully received video frame over oavx_stream_receive!\n");
94 printf(" - Resolution: %ux%u | Stride: %zu bytes\n", rx_v.width, rx_v.height, rx_v.strides[0]);
95 printf(" - PTS: %ld ns | Signature match: 100%%\n", (long)rx_v.pts_ns);
96 oavx_stream_release_video(rx, &rx_v);
97  
98 /* 5. Transmit and Receive Planar Audio Frame */
99 printf("[*] 5. Transmitting 48kHz stereo float audio frame over stream...\n");
100 const uint32_t sample_rate = 48000;
101 const uint16_t channels = 2;
102 const uint32_t frames = 1024;
103 float *audio_buf = (float*)malloc(frames * channels * sizeof(float));
104 assert(audio_buf != NULL);
105 for (size_t i = 0; i < frames * channels; ++i) {
106 audio_buf[i] = 0.75f;
107 }
108  
109 oavx_audio_frame_t tx_a = {
110 .sample_rate = sample_rate,
111 .channels = channels,
112 .frames = frames,
113 .format = OAVX_AUDIO_FMT_FLT_PLANAR,
114 .planes = { audio_buf, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
115 .stride_bytes = frames * sizeof(float),
116 .pts_ns = 1000000000LL
117 };
118  
119 int a_res = oavx_stream_send_audio(tx, &tx_a);
120 assert(a_res == 0);
121 printf(" [+] Dispatched audio frame via oavx_stream_send_audio (48kHz 2ch 1024 frames)\n");
122  
123 oavx_audio_frame_t rx_a = {0};
124 ftype = oavx_stream_receive(rx, NULL, &rx_a, NULL, 500);
125 assert(ftype == OAVX_FRAME_TYPE_AUDIO);
126 assert(rx_a.sample_rate == sample_rate);
127 assert(rx_a.channels == channels);
128 assert(rx_a.frames == frames);
129 assert(rx_a.planes[0] != NULL);
130 assert(((float*)rx_a.planes[0])[0] == 0.75f);
131 printf(" [+] Successfully received audio frame over oavx_stream_receive!\n");
132 printf(" - Sample Rate: %u Hz | Channels: %u | Samples: %u\n", rx_a.sample_rate, rx_a.channels, rx_a.frames);
133 oavx_stream_release_audio(rx, &rx_a);
134  
135 /* 6. Test Stream Device & Camera Controls (Tally & PTZ) */
136 printf("[*] 6. Testing Device & Camera Controls (Tally, PTZ)...\n");
137 oavx_tally_t tally = { .flags = OAVX_TALLY_PROGRAM | OAVX_TALLY_PREVIEW };
138 bool tally_set = oavx_stream_set_tally(rx, &tally);
139 assert(tally_set);
140 printf(" [+] Set Program + Preview tally state via oavx_stream_set_tally\n");
141  
142 oavx_tally_t query_tally = {0};
143 bool tally_got = oavx_stream_get_tally(tx, &query_tally, 200);
144 assert(tally_got);
145 assert((query_tally.flags & OAVX_TALLY_PROGRAM) != 0);
146 assert((query_tally.flags & OAVX_TALLY_PREVIEW) != 0);
147 printf(" [+] Queried tally on sender: flags=0x%x (Program=YES, Preview=YES)\n", query_tally.flags);
148  
149 oavx_ptz_state_t ptz = {
150 .pan = 0.25f,
151 .tilt = -0.5f,
152 .zoom = 0.75f,
153 .focus = 0.5f
154 };
155 bool ptz_ok = oavx_stream_set_ptz(rx, &ptz);
156 assert(ptz_ok);
157 printf(" [+] Transmitted PTZ positioning command via oavx_stream_set_ptz\n");
158  
159 /* 7. Test Discovery Grid */
160 printf("[*] 7. Testing Network Discovery Grid (oavx_discovery_t)...\n");
161 oavx_discovery_t *disc = oavx_discovery_create(ctx, "Public");
162 assert(disc != NULL);
163 oavx_endpoint_t sources[16];
164 size_t count = oavx_discovery_get_sources(disc, sources, 16);
165 printf(" [+] Discovery grid active, enumerated %zu initial endpoints\n", count);
166 oavx_discovery_destroy(disc);
167  
168 /* 8. Teardown Streams and Context */
169 printf("[*] 8. Cleanly closing stream pipelines and destroying context...\n");
170 oavx_stream_close(rx);
171 oavx_stream_close(tx);
172 oavx_context_destroy(ctx);
173  
174 free(video_buf);
175 free(audio_buf);
176  
177 printf("\n[PASS] oavx_stream_test\n");
178  
179 return 0;
180 }