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/openavx_stream_sender.c - Test Stream Sender Utility
7 */
8  
9 #include "openavx.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <time.h>
15  
16 int main(void) {
17 printf("[*] Starting OpenAVX Stream Sender...\n");
18 oavx_context_t *ctx = oavx_context_create();
19 if (!ctx) {
20 fprintf(stderr, "[-] Failed to initialize OpenAVX context\n");
21 return 1;
22 }
23  
24 oavx_stream_config_t config = {
25 .name = "OpenAVX (Probe Stream)",
26 .direction = OAVX_DIR_TRANSMIT,
27 .clock_sync = true
28 };
29  
30 oavx_stream_t *p_send = oavx_stream_open(ctx, &config);
31 if (!p_send) {
32 fprintf(stderr, "[-] Failed to create OpenAVX stream transmitter\n");
33 oavx_context_destroy(ctx);
34 return 1;
35 }
36 printf("[+] OpenAVX Sender online on port 7960!\n");
37  
38 /* Allocate a 1920x1080 UYVY test pattern (2 bytes per pixel) */
39 int xres = 1920;
40 int yres = 1080;
41 size_t frame_size = (size_t)xres * yres * 2;
42 uint8_t* p_frame = (uint8_t*)malloc(frame_size);
43 if (!p_frame) {
44 oavx_stream_close(p_send);
45 oavx_context_destroy(ctx);
46 return 1;
47 }
48  
49 /* Fill with test pattern: Y=128, U=128, V=128 (Neutral grey) */
50 for (size_t i = 0; i < frame_size; i += 4) {
51 p_frame[i + 0] = 0x80; /* U */
52 p_frame[i + 1] = 0xeb; /* Y0 (white bar) */
53 p_frame[i + 2] = 0x80; /* V */
54 p_frame[i + 3] = 0xeb; /* Y1 */
55 }
56  
57 oavx_video_frame_t video_frame = {
58 .width = (uint32_t)xres,
59 .height = (uint32_t)yres,
60 .fourcc = OAVX_FOURCC_VIDEO_TYPE_UYVY,
61 .scan_type = OAVX_SCAN_PROGRESSIVE,
62 .planes = { p_frame, NULL, NULL, NULL },
63 .strides = { (size_t)xres * 2, 0, 0, 0 },
64 .framerate = { 60000, 1000 },
65 .aspect_ratio = { 16, 9 },
66 .pts_ns = 1000000,
67 .dts_ns = 0,
68 .metadata = NULL,
69 .metadata_len = 0,
70 .user_ctx = NULL
71 };
72  
73 /* Allocate a 48kHz stereo test tone buffer */
74 float audio_buf[2 * 1024];
75 for (int i = 0; i < 2 * 1024; ++i) audio_buf[i] = 0.5f;
76 oavx_audio_frame_t audio_frame = {
77 .sample_rate = 48000,
78 .channels = 2,
79 .frames = 1024,
80 .format = OAVX_AUDIO_FMT_FLT_PLANAR,
81 .planes = { audio_buf, audio_buf + 1024, NULL, NULL, NULL, NULL, NULL, NULL },
82 .stride_bytes = 1024 * sizeof(float),
83 .pts_ns = 1000000,
84 .metadata = NULL,
85 .metadata_len = 0,
86 .user_ctx = NULL
87 };
88  
89 printf("[*] Streaming video and audio frames for 3 seconds...\n");
90 for (int frame_idx = 1; frame_idx <= 60; ++frame_idx) {
91 video_frame.pts_ns = frame_idx * 16666666LL;
92 oavx_stream_send_video(p_send, &video_frame);
93
94 audio_frame.pts_ns = frame_idx * 16666666LL;
95 oavx_stream_send_audio(p_send, &audio_frame);
96
97 struct timespec ts = { .tv_sec = 0, .tv_nsec = 16666666L }; /* ~60 FPS */
98 nanosleep(&ts, NULL);
99 }
100  
101 printf("[+] Finished streaming 60 frames.\n");
102 free(p_frame);
103 oavx_stream_close(p_send);
104 oavx_context_destroy(ctx);
105 printf("[+] Sender shutdown cleanly.\n");
106 return 0;
107 }