瀏覽代碼

mac-virtualcam: Fix virtualcam video on Intel-based Macs

This issue primarily seems to affect Intel-based Macs without unified
memory: While an IOSurface is supposed to be shared via a mach port
with other processes, each process needs to lock the surface during
access (as is common with other shared resources).

Apple Silicon-based Macs seem to be less affected as a switch between
GPU and CPU memory (which can happen dynamically for IOSurfaces) would
still point to the same unified memory.
PatTheMav 3 年之前
父節點
當前提交
ee34d8fbfe

+ 3 - 0
plugins/mac-virtualcam/src/dal-plugin/OBSDALMachClient.mm

@@ -10,6 +10,7 @@
 #import "Logging.h"
 
 @interface OBSDALMachClient () <NSPortDelegate> {
+	uint32_t _seed;
 	NSPort *_receivePort;
 }
 @end
@@ -121,9 +122,11 @@
 				return;
 			}
 
+			IOSurfaceLock(surface, 0, &_seed);
 			CVPixelBufferRef frame;
 			CVPixelBufferCreateWithIOSurface(kCFAllocatorDefault,
 							 surface, NULL, &frame);
+			IOSurfaceUnlock(surface, 0, &_seed);
 			CFRelease(surface);
 
 			uint64_t timestamp;

+ 3 - 0
plugins/mac-virtualcam/src/obs-plugin/OBSDALMachServer.mm

@@ -15,6 +15,7 @@
 @property NSPort *port;
 @property NSMutableSet *clientPorts;
 @property NSRunLoop *runLoop;
+@property uint32_t seed;
 @end
 
 @implementation OBSDALMachServer
@@ -155,6 +156,7 @@
 			return;
 		}
 
+		IOSurfaceLock(surface, 0, &_seed);
 		mach_port_t framePort = IOSurfaceCreateMachPort(surface);
 
 		if (!framePort) {
@@ -174,6 +176,7 @@
 					 ]];
 
 		mach_port_deallocate(mach_task_self(), framePort);
+		IOSurfaceUnlock(surface, 0, &_seed);
 	}
 }