Raw ↗
+ +
5797689 fix(windows): resolve MSVC test linkage, missing unistd, and export declarations
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_rudp_test.c - End-to-end RUDP Media Transport Verification Suite
7 */
8  
9 #define _DEFAULT_SOURCE
10 #define _POSIX_C_SOURCE 200809L
11 #include "openavx.h"
12 #include "avx_platform.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <assert.h>
17  
18 int main(void) {
19 printf("=== OpenAVX End-to-End RUDP Stream Tests ===\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  
27 /* 2. Open Transmit Stream in RUDP Mode */
28 printf("[*] 2. Spawning RUDP Transmit Stream 'RUDP_BROADCAST_FEED'...\n");
29 oavx_stream_config_t tx_cfg = {
30 .name = "RUDP_BROADCAST_FEED",
31 .direction = OAVX_DIR_TRANSMIT,
32 .transport = OAVX_TRANSPORT_RUDP,
33 .clock_sync = false,
34 .groups = "Public"
35 };
36 oavx_stream_t *tx = oavx_stream_open(ctx, &tx_cfg);
37 assert(tx != NULL);
38  
39 const oavx_endpoint_t *ep = oavx_stream_get_endpoint(tx);
40 assert(ep != NULL && ep->address != NULL);
41 printf(" [+] Transmit stream active at endpoint: %s (RUDP)\n", ep->address);
42  
43 /* 3. Open Receive Stream in RUDP Mode */
44 printf("[*] 3. Spawning RUDP Receive Stream connecting to %s...\n", ep->address);
45 oavx_stream_config_t rx_cfg = {
46 .name = "RUDP_RECEIVER_CLIENT",
47 .endpoint = ep->address,
48 .direction = OAVX_DIR_RECEIVE,
49 .transport = OAVX_TRANSPORT_RUDP,
50 .color_format = OAVX_COLOR_FORMAT_UYVY_RGBA,
51 .bandwidth = OAVX_BANDWIDTH_HIGHEST,
52 .groups = "Public"
53 };
54 oavx_stream_t *rx = oavx_stream_open(ctx, &rx_cfg);
55 assert(rx != NULL);
56 printf(" [+] Receive stream active (RUDP session negotiated)\n");
57  
58 /* Allow network session handshake and port negotiation */
59 avx_sleep_ms(80);
60  
61 /* 4. Stream 20 Video Frames over RUDP */
62 printf("[*] 4. Transmitting Video Frames over RUDP...\n");
63 const uint32_t width = 640;
64 const uint32_t height = 360;
65 size_t line_stride = (size_t)width * 2;
66 size_t frame_bytes = line_stride * height;
67 uint8_t *video_buf = (uint8_t*)malloc(frame_bytes);
68 assert(video_buf != NULL);
69  
70 int received_video_count = 0;
71 for (int i = 0; i < 20; ++i) {
72 memset(video_buf, (uint8_t)(0x30 + i), frame_bytes);
73  
74 oavx_video_frame_t tx_v = {
75 .width = width,
76 .height = height,
77 .fourcc = OAVX_FOURCC_VIDEO_TYPE_UYVY,
78 .scan_type = OAVX_SCAN_PROGRESSIVE,
79 .planes = { video_buf, NULL, NULL, NULL },
80 .strides = { line_stride, 0, 0, 0 },
81 .framerate = { .num = 60000, .den = 1000 },
82 .aspect_ratio = { .num = 16, .den = 9 },
83 .pts_ns = 1000000000LL + (int64_t)i * 16666666LL
84 };
85  
86 oavx_status_t s_stat = oavx_stream_send_video(tx, &tx_v);
87 assert(s_stat == OAVX_SUCCESS);
88  
89 oavx_video_frame_t rx_v = {0};
90 oavx_frame_type_t ftype = oavx_stream_receive(rx, &rx_v, NULL, NULL, 200);
91 if (ftype == OAVX_FRAME_TYPE_VIDEO) {
92 assert(rx_v.width == width);
93 assert(rx_v.height == height);
94 assert(rx_v.fourcc == OAVX_FOURCC_VIDEO_TYPE_UYVY);
95 assert(rx_v.planes[0] != NULL);
96 assert(((uint8_t*)rx_v.planes[0])[0] == (uint8_t)(0x30 + i));
97 received_video_count++;
98 oavx_stream_release_video(rx, &rx_v);
99 }
100 }
101 printf(" [+] Successfully received %d/20 video frames over RUDP!\n", received_video_count);
102 assert(received_video_count >= 15); /* High reliability over local loopback */
103  
104 /* 5. Stream 20 Audio Frames over RUDP */
105 printf("[*] 5. Transmitting Audio Frames over RUDP...\n");
106 const uint32_t sample_rate = 48000;
107 const uint16_t channels = 2;
108 const uint32_t num_samples = 480; /* 10 ms at 48kHz */
109 size_t audio_ch_bytes = (size_t)num_samples * sizeof(float);
110 float *left_ch = (float*)malloc(audio_ch_bytes);
111 float *right_ch = (float*)malloc(audio_ch_bytes);
112 assert(left_ch && right_ch);
113  
114 int received_audio_count = 0;
115 for (int i = 0; i < 20; ++i) {
116 for (uint32_t s = 0; s < num_samples; ++s) {
117 left_ch[s] = 0.5f + (float)i * 0.01f;
118 right_ch[s] = -0.5f - (float)i * 0.01f;
119 }
120  
121 oavx_audio_frame_t tx_a = {
122 .sample_rate = sample_rate,
123 .channels = channels,
124 .frames = num_samples,
125 .format = OAVX_AUDIO_FMT_FLT_PLANAR,
126 .planes = { (void*)left_ch, (void*)right_ch, NULL, NULL },
127 .stride_bytes = audio_ch_bytes,
128 .pts_ns = 1000000000LL + (int64_t)i * 10000000LL
129 };
130  
131 oavx_status_t a_stat = oavx_stream_send_audio(tx, &tx_a);
132 assert(a_stat == OAVX_SUCCESS);
133  
134 oavx_audio_frame_t rx_a = {0};
135 oavx_frame_type_t ftype = oavx_stream_receive(rx, NULL, &rx_a, NULL, 200);
136 if (ftype == OAVX_FRAME_TYPE_AUDIO) {
137 assert(rx_a.sample_rate == sample_rate);
138 assert(rx_a.channels == channels);
139 assert(rx_a.frames == num_samples);
140 assert(rx_a.planes[0] != NULL);
141 received_audio_count++;
142 oavx_stream_release_audio(rx, &rx_a);
143 }
144 }
145 printf(" [+] Successfully received %d/20 audio frames over RUDP!\n", received_audio_count);
146 assert(received_audio_count >= 15);
147  
148 /* 6. Verify Tally Control across Session */
149 printf("[*] 6. Verifying Bidirectional Tally Control across session...\n");
150 oavx_tally_t tally_set = { .flags = OAVX_TALLY_PROGRAM | OAVX_TALLY_PREVIEW };
151 bool tally_ok = oavx_stream_set_tally(rx, &tally_set);
152 assert(tally_ok);
153  
154 avx_sleep_ms(50);
155 oavx_tally_t tally_get = {0};
156 bool get_ok = oavx_stream_get_tally(tx, &tally_get, 200);
157 assert(get_ok);
158 assert((tally_get.flags & OAVX_TALLY_PROGRAM) != 0);
159 assert((tally_get.flags & OAVX_TALLY_PREVIEW) != 0);
160 printf(" [+] Tally status successfully reflected: 0x%02X (PROGRAM | PREVIEW)\n", tally_get.flags);
161  
162 /* 7. Teardown */
163 printf("[*] 7. Closing RUDP streams and destroying context...\n");
164 free(video_buf);
165 free(left_ch);
166 free(right_ch);
167 oavx_stream_close(rx);
168 oavx_stream_close(tx);
169 oavx_context_destroy(ctx);
170  
171 printf("\n[PASS] oavx_stream_rudp_test\n");
172 return 0;
173 }