+ +
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_dal_test.c - Unit & Integration Test for macOS CoreMediaIO DAL Virtual Camera Plugin |
| 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 "cmio/CMIOHardwarePlugIn.h" |
| 22 | |
| 23 | #define kOpenAVXDeviceID 0x41565831 /* 'AVX1' */ |
| 24 | #define kOpenAVXStreamID 0x41565853 /* 'AVXS' */ |
| 25 | |
| 26 | /* Exported factory declaration */ |
| 27 | void* OpenAVXDALPluginFactory(CFAllocatorRef allocator, CFUUIDRef requestedTypeUUID); |
| 28 | |
| 29 | int main(void) |
| 30 | { |
| 31 | printf("[DAL TEST] Testing macOS CoreMediaIO DAL Virtual Camera Plugin Factory...\n"); |
| 32 | |
| 33 | /* 1. Call Plugin Factory */ |
| 34 | CMIOHardwarePlugInRef pluginRef = (CMIOHardwarePlugInRef)OpenAVXDALPluginFactory(NULL, NULL); |
| 35 | assert(pluginRef != NULL); |
| 36 | assert(*pluginRef != NULL); |
| 37 | printf("[PASS] OpenAVXDALPluginFactory returned valid CMIOHardwarePlugInRef\n"); |
| 38 | |
| 39 | CMIOHardwarePlugInInterface *vtbl = *pluginRef; |
| 40 | |
| 41 | /* 2. Test QueryInterface */ |
| 42 | void *queried = NULL; |
| 43 | HRESULT hr = vtbl->QueryInterface(pluginRef, kCMIOHardwarePlugInInterfaceUUID, &queried); |
| 44 | assert(hr == S_OK); |
| 45 | assert(queried == (void*)pluginRef); |
| 46 | printf("[PASS] QueryInterface returned valid interface matching kCMIOHardwarePlugInInterfaceUUID\n"); |
| 47 | vtbl->Release(pluginRef); |
| 48 | |
| 49 | /* 3. Test Initialize */ |
| 50 | OSStatus st = vtbl->Initialize(pluginRef); |
| 51 | assert(st == kCMIOHardwareNoError); |
| 52 | st = vtbl->InitializeWithObjectID(pluginRef, kCMIOObjectSystemObject); |
| 53 | assert(st == kCMIOHardwareNoError); |
| 54 | printf("[PASS] Initialize and InitializeWithObjectID succeeded\n"); |
| 55 | |
| 56 | /* 4. Test System Object Properties (Device Enumeration) */ |
| 57 | CMIOObjectPropertyAddress addrStreams = { kCMIODevicePropertyStreams, kCMIOObjectPropertyScopeGlobal, kCMIOObjectPropertyElementMaster }; |
| 58 | Boolean hasProp = vtbl->ObjectHasProperty(pluginRef, kCMIOObjectSystemObject, &addrStreams); |
| 59 | assert(hasProp == true); |
| 60 | |
| 61 | UInt32 size = 0; |
| 62 | st = vtbl->ObjectGetPropertyDataSize(pluginRef, kCMIOObjectSystemObject, &addrStreams, 0, NULL, &size); |
| 63 | assert(st == kCMIOHardwareNoError && size == sizeof(CMIODeviceID)); |
| 64 | |
| 65 | CMIODeviceID devId = 0; |
| 66 | UInt32 dataUsed = 0; |
| 67 | st = vtbl->ObjectGetPropertyData(pluginRef, kCMIOObjectSystemObject, &addrStreams, 0, NULL, sizeof(devId), &dataUsed, &devId); |
| 68 | assert(st == kCMIOHardwareNoError && dataUsed == sizeof(CMIODeviceID)); |
| 69 | assert(devId == kOpenAVXDeviceID); |
| 70 | printf("[PASS] System Object correctly reports Virtual Camera Device (ID=0x%08x)\n", devId); |
| 71 | |
| 72 | /* 5. Test Device Object Properties */ |
| 73 | CMIOObjectPropertyAddress addrAlive = { kCMIODevicePropertyDeviceIsAlive, kCMIOObjectPropertyScopeGlobal, kCMIOObjectPropertyElementMaster }; |
| 74 | UInt32 isAlive = 0; |
| 75 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXDeviceID, &addrAlive, 0, NULL, sizeof(isAlive), &dataUsed, &isAlive); |
| 76 | assert(st == kCMIOHardwareNoError && isAlive == 1); |
| 77 | |
| 78 | CMIOObjectPropertyAddress addrTransport = { kCMIODevicePropertyTransportType, kCMIOObjectPropertyScopeGlobal, kCMIOObjectPropertyElementMaster }; |
| 79 | UInt32 transport = 0; |
| 80 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXDeviceID, &addrTransport, 0, NULL, sizeof(transport), &dataUsed, &transport); |
| 81 | assert(st == kCMIOHardwareNoError && transport == 0x76697274); /* 'virt' */ |
| 82 | |
| 83 | CMIOStreamID streamId = 0; |
| 84 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXDeviceID, &addrStreams, 0, NULL, sizeof(streamId), &dataUsed, &streamId); |
| 85 | assert(st == kCMIOHardwareNoError && streamId == kOpenAVXStreamID); |
| 86 | printf("[PASS] Device Object confirmed: IsAlive=1, Transport='virt', StreamID=0x%08x\n", streamId); |
| 87 | |
| 88 | /* 6. Test Stream Object Properties */ |
| 89 | CMIOObjectPropertyAddress addrDir = { kCMIOStreamPropertyDirection, kCMIOObjectPropertyScopeGlobal, kCMIOObjectPropertyElementMaster }; |
| 90 | UInt32 dir = 0; |
| 91 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXStreamID, &addrDir, 0, NULL, sizeof(dir), &dataUsed, &dir); |
| 92 | assert(st == kCMIOHardwareNoError && dir == 1); /* 1 = output capture stream */ |
| 93 | |
| 94 | CMIOObjectPropertyAddress addrRates = { kCMIOStreamPropertyFrameRates, kCMIOObjectPropertyScopeGlobal, kCMIOObjectPropertyElementMaster }; |
| 95 | double rates[2] = {0}; |
| 96 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXStreamID, &addrRates, 0, NULL, sizeof(rates), &dataUsed, rates); |
| 97 | assert(st == kCMIOHardwareNoError && rates[0] == 30.0 && rates[1] == 60.0); |
| 98 | printf("[PASS] Stream Object confirmed: Direction=1 (Output), FrameRates=[%.1f, %.1f]\n", rates[0], rates[1]); |
| 99 | |
| 100 | /* 7. Test Streaming Engine Start & Stop */ |
| 101 | CMIOObjectPropertyAddress addrRunning = { kCMIODevicePropertyDeviceIsRunning, kCMIOObjectPropertyScopeGlobal, kCMIOObjectPropertyElementMaster }; |
| 102 | UInt32 isRunning = 0; |
| 103 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXDeviceID, &addrRunning, 0, NULL, sizeof(isRunning), &dataUsed, &isRunning); |
| 104 | assert(st == kCMIOHardwareNoError && isRunning == 0); |
| 105 | |
| 106 | st = vtbl->DeviceStartStream(pluginRef, kOpenAVXDeviceID, kOpenAVXStreamID); |
| 107 | assert(st == kCMIOHardwareNoError); |
| 108 | |
| 109 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXDeviceID, &addrRunning, 0, NULL, sizeof(isRunning), &dataUsed, &isRunning); |
| 110 | assert(st == kCMIOHardwareNoError && isRunning == 1); |
| 111 | printf("[PASS] DeviceStartStream activated stream: DeviceIsRunning=%u\n", isRunning); |
| 112 | |
| 113 | /* Allow background streaming thread to cycle */ |
| 114 | usleep(100000); /* 100ms */ |
| 115 | |
| 116 | st = vtbl->DeviceStopStream(pluginRef, kOpenAVXDeviceID, kOpenAVXStreamID); |
| 117 | assert(st == kCMIOHardwareNoError); |
| 118 | |
| 119 | st = vtbl->ObjectGetPropertyData(pluginRef, kOpenAVXDeviceID, &addrRunning, 0, NULL, sizeof(isRunning), &dataUsed, &isRunning); |
| 120 | assert(st == kCMIOHardwareNoError && isRunning == 0); |
| 121 | printf("[PASS] DeviceStopStream halted stream: DeviceIsRunning=%u\n", isRunning); |
| 122 | |
| 123 | /* 8. Teardown & Release */ |
| 124 | st = vtbl->Teardown(pluginRef); |
| 125 | assert(st == kCMIOHardwareNoError); |
| 126 | ULONG remaining = vtbl->Release(pluginRef); |
| 127 | assert(remaining == 0); |
| 128 | printf("[PASS] Teardown & Release completed with 0 remaining references\n"); |
| 129 | |
| 130 | printf("\n=======================================================\n"); |
| 131 | printf(">>> ALL MACOS COREMEDIAIO DAL PLUGIN TESTS PASSED! <<<\n"); |
| 132 | printf("=======================================================\n"); |
| 133 | return 0; |
| 134 | } |