+ +
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 | * src/avx_dal_sink.c - 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 | |
| 18 | #include "openavx.h" |
| 19 | #include "avx_dal_sink.h" |
| 20 | #include "avx_virtcam_ipc.h" |
| 21 | #include "avx_platform.h" |
| 22 | |
| 23 | #if defined(AVX_OS_MACOS) |
| 24 | #include <sys/stat.h> |
| 25 | #include <unistd.h> |
| 26 | #include <pwd.h> |
| 27 | |
| 28 | static bool get_user_dal_dir(char *out_path, size_t out_max) { |
| 29 | const char *home = getenv("HOME"); |
| 30 | if (!home) { |
| 31 | struct passwd *pw = getpwuid(getuid()); |
| 32 | if (pw) home = pw->pw_dir; |
| 33 | } |
| 34 | if (!home) return false; |
| 35 | snprintf(out_path, out_max, "%s/Library/CoreMediaIO/Plug-Ins/DAL", home); |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | /* Deploys user-space CoreMediaIO DAL bundle structure and Info.plist into ~/Library. */ |
| 40 | bool avx_dal_install_plugin(void) { |
| 41 | char dal_dir[512]; |
| 42 | if (!get_user_dal_dir(dal_dir, sizeof(dal_dir))) return false; |
| 43 | |
| 44 | char cmd[1024]; |
| 45 | snprintf(cmd, sizeof(cmd), "mkdir -p \"%s/OpenAVX.plugin/Contents/MacOS\"", dal_dir); |
| 46 | if (system(cmd) != 0) return false; |
| 47 | |
| 48 | /* Write minimal Info.plist defining the CoreMediaIO DAL Assistant bundle */ |
| 49 | char plist_path[512]; |
| 50 | snprintf(plist_path, sizeof(plist_path), "%s/OpenAVX.plugin/Contents/Info.plist", dal_dir); |
| 51 | FILE *f = fopen(plist_path, "w"); |
| 52 | if (!f) return false; |
| 53 | |
| 54 | fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 55 | "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" |
| 56 | "<plist version=\"1.0\">\n<dict>\n" |
| 57 | " <key>CFBundleName</key><string>OpenAVX</string>\n" |
| 58 | " <key>CFBundleIdentifier</key><string>org.openavx.dal</string>\n" |
| 59 | " <key>CFBundleVersion</key><string>1.0</string>\n" |
| 60 | " <key>CMIOHardwarePlugInFactory</key><string>OpenAVXDALPluginFactory</string>\n" |
| 61 | "</dict>\n</plist>\n"); |
| 62 | fclose(f); |
| 63 | |
| 64 | oavx_log_write(OAVX_LOG_INFO, "dal", "Installed user CoreMediaIO DAL virtual camera plugin into %s/OpenAVX.plugin", dal_dir); |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | bool avx_dal_uninstall_plugin(void) { |
| 69 | char dal_dir[512]; |
| 70 | if (!get_user_dal_dir(dal_dir, sizeof(dal_dir))) return false; |
| 71 | |
| 72 | char cmd[1024]; |
| 73 | snprintf(cmd, sizeof(cmd), "rm -rf \"%s/OpenAVX.plugin\"", dal_dir); |
| 74 | return (system(cmd) == 0); |
| 75 | } |
| 76 | |
| 77 | bool avx_dal_is_installed(void) { |
| 78 | char dal_dir[512]; |
| 79 | if (!get_user_dal_dir(dal_dir, sizeof(dal_dir))) return false; |
| 80 | |
| 81 | char plugin_path[512]; |
| 82 | snprintf(plugin_path, sizeof(plugin_path), "%s/OpenAVX.plugin", dal_dir); |
| 83 | struct stat st; |
| 84 | return (stat(plugin_path, &st) == 0 && S_ISDIR(st.st_mode)); |
| 85 | } |
| 86 | |
| 87 | #else /* Non-macOS Stubs */ |
| 88 | |
| 89 | bool avx_dal_install_plugin(void) { return false; } |
| 90 | bool avx_dal_uninstall_plugin(void) { return false; } |
| 91 | bool avx_dal_is_installed(void) { return false; } |
| 92 | |
| 93 | #endif |