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 Library
6 * test/openavx_ptz_compat_test.c
7 * Comprehensive test suite for PTZ & Recording extensions
8 */
9  
10 #include "openavx.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <assert.h>
15 #include <time.h>
16 #include <unistd.h>
17  
18 static void sleep_ms(int ms) {
19 struct timespec ts = {
20 .tv_sec = ms / 1000,
21 .tv_nsec = (long)(ms % 1000) * 1000000L
22 };
23 nanosleep(&ts, NULL);
24 }
25  
26 static void test_ptz_and_recording_extensions(void) {
27 printf("[*] 1. Testing Receiver PTZ, Remote Recording & Web Control Extensions...\n");
28  
29 oavx_context_t *ctx = oavx_context_create();
30 assert(ctx != NULL);
31  
32 /* Create Sender (representing a PTZ camera) */
33 oavx_stream_config_t send_create = {
34 .name = "Studio_PTZ_Camera",
35 .groups = NULL,
36 .direction = OAVX_DIR_TRANSMIT,
37 .clock_sync = false
38 };
39 oavx_stream_t *p_send = oavx_stream_open(ctx, &send_create);
40 assert(p_send != NULL);
41  
42 /* Create Receiver connected to sender */
43 oavx_stream_config_t recv_create = {
44 .name = "PTZ_Controller_Recv",
45 .endpoint = "127.0.0.1:7960",
46 .direction = OAVX_DIR_RECEIVE,
47 .color_format = OAVX_COLOR_FORMAT_UYVY_RGBA,
48 .bandwidth = OAVX_BANDWIDTH_HIGHEST,
49 .clock_sync = false
50 };
51 oavx_stream_t *p_recv = oavx_stream_open(ctx, &recv_create);
52 assert(p_recv != NULL);
53  
54 /* Wait for connection handshake */
55 for (int wait = 0; wait < 30; ++wait) {
56 if (oavx_stream_get_connection_count(p_send, 50) > 0) break;
57 sleep_ms(20);
58 }
59 assert(oavx_stream_get_connection_count(p_send, 0) > 0);
60  
61 /* Check Web Control URL */
62 const char* web_url = oavx_stream_get_web_control(p_recv);
63 assert(web_url != NULL);
64 assert(strstr(web_url, "http://127.0.0.1") != NULL);
65 printf(" [+] Web Control URL: %s\n", web_url);
66  
67 /* 1.1 Test PTZ Movement Commands */
68 oavx_ptz_state_t ptz = {
69 .pan = 0.35f,
70 .tilt = -0.20f,
71 .zoom = 0.75f,
72 .focus = 0.82f
73 };
74 assert(oavx_stream_set_ptz(p_recv, &ptz));
75 printf(" [+] PTZ Pan/Tilt and Zoom commands transmitted successfully\n");
76  
77 /* 1.2 Test Remote Recording Commands & State */
78 bool is_rec = false;
79 assert(oavx_stream_record_status(p_recv, &is_rec, NULL, NULL));
80 assert(!is_rec);
81  
82 assert(oavx_stream_record_trigger(p_recv, "start", "take_01_scene_04.mov"));
83 const char* active_file = NULL;
84 assert(oavx_stream_record_status(p_recv, &is_rec, &active_file, NULL));
85 assert(is_rec);
86 assert(active_file != NULL);
87 assert(strcmp(active_file, "take_01_scene_04.mov") == 0);
88 printf(" [+] Remote Recording started: '%s'\n", active_file);
89  
90 assert(oavx_stream_record_set_audio_level(p_recv, -6.0f));
91 assert(oavx_stream_record_trigger(p_recv, "stop", NULL));
92 assert(oavx_stream_record_status(p_recv, &is_rec, NULL, NULL));
93 assert(!is_rec);
94 printf(" [+] Remote Recording stopped successfully\n");
95  
96 /* Allow reverse socket pipeline to flush */
97 sleep_ms(50);
98  
99 oavx_stream_close(p_recv);
100 oavx_stream_close(p_send);
101 oavx_context_destroy(ctx);
102 }
103  
104 int main(void) {
105 printf("=== OpenAVX PTZ & Recording Extension Tests ===\n");
106  
107 test_ptz_and_recording_extensions();
108  
109 printf("\n[PASS] openavx_ptz_compat_test\n");
110 return 0;
111 }