+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 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_api_v3_test.c - Native OpenAVX Modern API Verification Suite |
| 7 | */ |
| 8 | |
| 9 | #define _GNU_SOURCE |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <assert.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | #include "openavx.h" |
| 17 | |
| 18 | int main(void) { |
| 19 | printf("\n=== OpenAVX Public API Tests ===\n\n"); |
| 20 | |
| 21 | /* 1. Initialize Subsystem */ |
| 22 | printf("[*] 1. Initializing OpenAVX Context...\n"); |
| 23 | oavx_context_t *ctx = oavx_context_create(); |
| 24 | assert(ctx != NULL); |
| 25 | |
| 26 | /* 2. Verify Version and CPU Support */ |
| 27 | printf("[*] 2. Verifying oavx_version() and oavx_is_supported_cpu()...\n"); |
| 28 | const char* ver = oavx_version(); |
| 29 | assert(ver != NULL); |
| 30 | assert(oavx_is_supported_cpu()); |
| 31 | printf(" [+] OpenAVX version: %s (CPU supported)\n", ver); |
| 32 | |
| 33 | /* 3. Create Sender & Verify Source Information */ |
| 34 | printf("[*] 3. Creating Sender and verifying oavx_stream_get_endpoint()...\n"); |
| 35 | oavx_stream_config_t send_settings = { |
| 36 | .name = "API_V3_TEST_SOURCE", |
| 37 | .groups = "public", |
| 38 | .direction = OAVX_DIR_TRANSMIT, |
| 39 | .clock_sync = false |
| 40 | }; |
| 41 | oavx_stream_t *p_send = oavx_stream_open(ctx, &send_settings); |
| 42 | assert(p_send != NULL); |
| 43 | |
| 44 | const oavx_endpoint_t* p_src_info = oavx_stream_get_endpoint(p_send); |
| 45 | assert(p_src_info != NULL); |
| 46 | assert(p_src_info->name != NULL); |
| 47 | assert(strstr(p_src_info->name, "API_V3_TEST_SOURCE") != NULL); |
| 48 | assert(p_src_info->address != NULL); |
| 49 | printf(" [+] Sender source info: \"%s\" @ %s\n", p_src_info->name, p_src_info->address); |
| 50 | |
| 51 | /* 4. Create Receiver & Connect */ |
| 52 | printf("[*] 4. Connecting Receiver to %s...\n", p_src_info->address); |
| 53 | oavx_stream_config_t recv_settings = { |
| 54 | .name = "TestReceiver_v3", |
| 55 | .endpoint = p_src_info->address, |
| 56 | .direction = OAVX_DIR_RECEIVE, |
| 57 | .color_format = OAVX_COLOR_FORMAT_UYVY_RGBA, |
| 58 | .bandwidth = OAVX_BANDWIDTH_HIGHEST, |
| 59 | .clock_sync = false |
| 60 | }; |
| 61 | oavx_stream_t *p_recv = oavx_stream_open(ctx, &recv_settings); |
| 62 | assert(p_recv != NULL); |
| 63 | |
| 64 | /* Allow connection establishment */ |
| 65 | usleep(100000); /* 100ms */ |
| 66 | int conns = oavx_stream_get_connection_count(p_send, 200); |
| 67 | assert(conns >= 1); |
| 68 | printf(" [+] Receiver connected (sender active conns: %d)\n", conns); |
| 69 | |
| 70 | /* 5. Transmit & Receive Audio Frame */ |
| 71 | printf("[*] 5. Transmitting Audio Frame via oavx_stream_send_audio()...\n"); |
| 72 | float audio_samples[2048]; |
| 73 | for (int i = 0; i < 2048; ++i) { |
| 74 | audio_samples[i] = 0.75f; |
| 75 | } |
| 76 | |
| 77 | oavx_audio_frame_t tx_audio = { |
| 78 | .sample_rate = 48000, |
| 79 | .channels = 2, |
| 80 | .frames = 1024, |
| 81 | .format = OAVX_AUDIO_FMT_FLT_PLANAR, |
| 82 | .planes = { audio_samples, audio_samples + 1024, NULL, NULL, NULL, NULL, NULL, NULL }, |
| 83 | .stride_bytes = 1024 * sizeof(float), |
| 84 | .pts_ns = 12345678, |
| 85 | .metadata = NULL, |
| 86 | .metadata_len = 0, |
| 87 | .user_ctx = NULL |
| 88 | }; |
| 89 | |
| 90 | oavx_stream_send_audio(p_send, &tx_audio); |
| 91 | |
| 92 | /* Capture via oavx_stream_receive */ |
| 93 | printf("[*] 6. Capturing Audio Frame via oavx_stream_receive()...\n"); |
| 94 | oavx_video_frame_t rx_video = {0}; |
| 95 | oavx_audio_frame_t rx_audio = {0}; |
| 96 | oavx_metadata_frame_t rx_meta = {0}; |
| 97 | |
| 98 | bool got_audio = false; |
| 99 | for (int attempts = 0; attempts < 20 && !got_audio; ++attempts) { |
| 100 | oavx_frame_type_t ft = oavx_stream_receive(p_recv, &rx_video, &rx_audio, &rx_meta, 100); |
| 101 | if (ft == OAVX_FRAME_TYPE_AUDIO) { |
| 102 | got_audio = true; |
| 103 | assert(rx_audio.sample_rate == 48000); |
| 104 | assert(rx_audio.channels == 2); |
| 105 | assert(rx_audio.frames == 1024); |
| 106 | assert(rx_audio.planes[0] != NULL); |
| 107 | |
| 108 | float* samples = (float*)rx_audio.planes[0]; |
| 109 | assert(samples[0] == 0.75f); |
| 110 | assert(samples[1023] == 0.75f); |
| 111 | printf(" [+] Audio captured: 48kHz, 2ch, 1024 samples (verified!)\n"); |
| 112 | |
| 113 | oavx_stream_release_audio(p_recv, &rx_audio); |
| 114 | } |
| 115 | } |
| 116 | assert(got_audio); |
| 117 | |
| 118 | /* 7. Test Upstream Metadata & oavx_stream_capture_metadata() */ |
| 119 | printf("[*] 7. Testing Upstream Metadata via oavx_stream_capture_metadata()...\n"); |
| 120 | oavx_metadata_frame_t upstream_msg = { |
| 121 | .length = 0, |
| 122 | .pts_ns = 9999, |
| 123 | .data = "<openavx_feedback status=\"online\" quality=\"100%\"/>" |
| 124 | }; |
| 125 | int sent_meta = oavx_stream_send_metadata(p_recv, &upstream_msg); |
| 126 | assert(sent_meta == 0); |
| 127 | |
| 128 | oavx_metadata_frame_t captured_upstream = {0}; |
| 129 | oavx_frame_type_t cap_ft = oavx_stream_capture_metadata(p_send, &captured_upstream, 500); |
| 130 | assert(cap_ft == OAVX_FRAME_TYPE_METADATA); |
| 131 | assert(captured_upstream.data != NULL); |
| 132 | assert(strstr(captured_upstream.data, "quality=\"100%\"") != NULL); |
| 133 | printf(" [+] Upstream metadata captured by sender: %s\n", captured_upstream.data); |
| 134 | |
| 135 | oavx_stream_release_metadata(p_send, &captured_upstream); |
| 136 | |
| 137 | /* 8. Verify oavx_stream_get_web_control() */ |
| 138 | printf("[*] 8. Verifying oavx_stream_get_web_control()...\n"); |
| 139 | const char* web_ctrl = oavx_stream_get_web_control(p_recv); |
| 140 | (void)web_ctrl; |
| 141 | printf(" [+] oavx_stream_get_web_control() executed cleanly!\n"); |
| 142 | |
| 143 | /* 9. Clean up */ |
| 144 | printf("[*] 9. Cleaning up instances...\n"); |
| 145 | oavx_stream_close(p_recv); |
| 146 | oavx_stream_close(p_send); |
| 147 | oavx_context_destroy(ctx); |
| 148 | |
| 149 | printf("\n[PASS] openavx_api_v3_test\n\n"); |
| 150 | return 0; |
| 151 | } |