Skip to content

Commit

Permalink
mac-virtualcam: Compare camera UUIDs using CFUUID
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm authored and RytoEX committed Sep 12, 2024
1 parent 4dac849 commit 552a88a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plugins/mac-virtualcam/src/obs-plugin/plugin-main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,10 @@ static bool virtualcam_output_start(void *data)
CMIOObjectGetPropertyData(kCMIOObjectSystemObject, &address, 0, NULL, size, &used, device_data);

vcam->deviceID = 0;
NSString *OBSVirtualCamUUID = [[NSBundle bundleWithIdentifier:@"com.obsproject.mac-virtualcam"]
NSString *OBSVirtualCamUUIDString = [[NSBundle bundleWithIdentifier:@"com.obsproject.mac-virtualcam"]
objectForInfoDictionaryKey:@"OBSCameraDeviceUUID"];
CFUUIDRef OBSVirtualCamUUID =
CFUUIDCreateFromString(kCFAllocatorDefault, (CFStringRef) OBSVirtualCamUUIDString);

size_t num_elements = size / sizeof(CMIOObjectID);
for (size_t i = 0; i < num_elements; i++) {
Expand All @@ -395,15 +397,19 @@ static bool virtualcam_output_start(void *data)
CMIOObjectGetPropertyDataSize(cmioDevice, &address, 0, NULL, &device_name_size);
CFStringRef uid;
CMIOObjectGetPropertyData(cmioDevice, &address, 0, NULL, device_name_size, &used, &uid);
const char *uid_string = CFStringGetCStringPtr(uid, kCFStringEncodingUTF8);
if (uid_string && strcmp(uid_string, OBSVirtualCamUUID.UTF8String) == 0) {
CFUUIDRef deviceUUID = CFUUIDCreateFromString(kCFAllocatorDefault, uid);

if (CFEqual(OBSVirtualCamUUID, deviceUUID)) {
vcam->deviceID = cmioDevice;
CFRelease(uid);
CFRelease(deviceUUID);
break;
} else {
CFRelease(uid);
CFRelease(deviceUUID);
}
}
CFRelease(OBSVirtualCamUUID);

if (!vcam->deviceID) {
obs_output_set_last_error(vcam->output, obs_module_text("Error.SystemExtension.CameraUnavailable"));
Expand Down

0 comments on commit 552a88a

Please sign in to comment.