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_pipewire_sink_test.c - Unit & integration tests for PipeWire virtual camera sink
7 */
8  
9 #define _DEFAULT_SOURCE
10 #define _POSIX_C_SOURCE 200809L
11  
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdint.h>
15 #include <stdbool.h>
16 #include <string.h>
17 #include <assert.h>
18 #include <unistd.h>
19  
20 #include "openavx.h"
21 #include "avx_pipewire_sink.h"
22  
23 static void test_pipewire_availability(void)
24 {
25 printf("[test] Testing PipeWire availability check...\n");
26 bool avail = avx_pipewire_is_available();
27 printf(" -> PipeWire available: %s\n", avail ? "YES" : "NO (graceful fallback)");
28 }
29  
30 static void test_pipewire_sink_null_defensive(void)
31 {
32 printf("[test] Testing PipeWire sink defensive null checks...\n");
33 avx_pipewire_sink_destroy(NULL);
34 assert(!avx_pipewire_sink_push_frame(NULL, NULL, 0, 0, 0, 0));
35 assert(!avx_pipewire_sink_is_active(NULL));
36 printf(" -> Defensive checks passed.\n");
37 }
38  
39 static void test_pipewire_sink_lifecycle(void)
40 {
41 printf("[test] Testing PipeWire virtual camera sink lifecycle...\n");
42 if (!avx_pipewire_is_available()) {
43 printf(" -> Skipping lifecycle test (PipeWire library not available).\n");
44 return;
45 }
46  
47 avx_pipewire_sink_config_t config = {
48 .node_name = "OpenAVX Test Camera",
49 .node_description = "OpenAVX Automated Test Camera Source",
50 .width = 640,
51 .height = 360,
52 .fps_num = 30,
53 .fps_den = 1,
54 .preferred_fourcc = OAVX_FOURCC_VIDEO_TYPE_UYVY,
55 };
56  
57 avx_pipewire_sink_t *sink = avx_pipewire_sink_create(&config);
58 if (!sink) {
59 printf(" -> Warning: Could not connect to PipeWire daemon (headless/container environment). Skipping live graph test.\n");
60 return;
61 }
62  
63 assert(sink != NULL);
64  
65 /* Allocate dummy 640x360 UYVY test frame */
66 size_t frame_bytes = 640 * 360 * 2;
67 uint8_t *dummy_uyvy = (uint8_t*)malloc(frame_bytes);
68 assert(dummy_uyvy != NULL);
69 memset(dummy_uyvy, 0x80, frame_bytes); // neutral gray UYVY (Y=128, U=128, V=128)
70  
71 /* Allow background thread-loop to connect to daemon */
72 usleep(100000); // 100ms
73  
74 /* Push several frames */
75 for (int i = 0; i < 5; i++) {
76 avx_pipewire_sink_push_frame(sink, dummy_uyvy, frame_bytes, 640, 360, OAVX_FOURCC_VIDEO_TYPE_UYVY);
77 usleep(10000); // 10ms
78 }
79  
80 free(dummy_uyvy);
81 avx_pipewire_sink_destroy(sink);
82 printf(" -> Lifecycle test passed cleanly.\n");
83 }
84  
85 int main(void)
86 {
87 printf("===================================================\n");
88 printf("OpenAVX PipeWire Virtual Camera Sink Test Suite\n");
89 printf("===================================================\n");
90  
91 test_pipewire_availability();
92 test_pipewire_sink_null_defensive();
93 test_pipewire_sink_lifecycle();
94  
95 printf("===================================================\n");
96 printf("All PipeWire Virtual Camera Tests Passed!\n");
97 printf("===================================================\n");
98 return 0;
99 }