1
0
Эх сурвалжийг харах

mac-virtualcam: Fix compiler warnings

CMake build framework 3.0 introduces more strict typing checks, which
require additional code fixes to silence.

* Fixes warnings about implicit casts
* Fixes warnings about weak references used multiple times inside
  blocks
PatTheMav 2 жил өмнө
parent
commit
8c8a44b26a

+ 2 - 1
plugins/mac-virtualcam/src/dal-plugin/CMSampleBufferUtils.mm

@@ -22,7 +22,8 @@ CMSampleTimingInfo CMSampleTimingInfoForTimestamp(uint64_t timestampNanos,
 	timing.duration =
 		CMTimeMake(fpsDenominator * scale, fpsNumerator * scale);
 	timing.presentationTimeStamp = CMTimeMake(
-		(timestampNanos / (double)NSEC_PER_SEC) * scale, scale);
+		((int64_t)(timestampNanos / (double)NSEC_PER_SEC) * scale),
+		scale);
 	timing.decodeTimeStamp = kCMTimeInvalid;
 	return timing;
 }

+ 7 - 5
plugins/mac-virtualcam/src/dal-plugin/OBSDALPlugIn.mm

@@ -81,13 +81,15 @@ typedef enum {
 		uint64_t intervalTime = (int64_t)(1 * NSEC_PER_SEC);
 		dispatch_source_set_timer(_machConnectTimer, startTime,
 					  intervalTime, 0);
+
 		dispatch_source_set_event_handler(_machConnectTimer, ^{
-			if (![[weakSelf machClient] isServerAvailable]) {
+			__strong __typeof(weakSelf) strongSelf = weakSelf;
+			if (![[strongSelf machClient] isServerAvailable]) {
 				DLog(@"Server is not available");
-			} else if (weakSelf.state ==
+			} else if (strongSelf.state ==
 				   PlugInStateWaitingForServer) {
 				DLog(@"Attempting connection");
-				[[weakSelf machClient] connectToServer];
+				[[strongSelf machClient] connectToServer];
 			}
 		});
 	}
@@ -233,8 +235,8 @@ typedef enum {
 	// Add 5 more seconds onto the timeout timer
 	dispatch_source_set_timer(
 		_timeoutTimer,
-		dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC),
-		5.0 * NSEC_PER_SEC, (1ull * NSEC_PER_SEC) / 10);
+		dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)),
+		(uint64_t)(5.0 * NSEC_PER_SEC), (1ull * NSEC_PER_SEC) / 10);
 
 	[self.stream queuePixelBuffer:frame
 			    timestamp:timestamp

+ 19 - 17
plugins/mac-virtualcam/src/dal-plugin/OBSDALStream.mm

@@ -103,7 +103,7 @@
 	if (_queue == NULL) {
 		// Allocate a one-second long queue, which we can use our FPS constant for.
 		OSStatus err = CMSimpleQueueCreate(kCFAllocatorDefault,
-						   self.fps, &_queue);
+						   (int32_t)self.fps, &_queue);
 		if (err != noErr) {
 			DLog(@"Err %d in CMSimpleQueueCreate", err);
 		}
@@ -131,9 +131,9 @@
 	if (NSEqualSizes(_testCardSize, NSZeroSize)) {
 		NSUserDefaults *defaults =
 			[NSUserDefaults standardUserDefaults];
-		int width = [[defaults objectForKey:kTestCardWidthKey]
+		NSInteger width = [[defaults objectForKey:kTestCardWidthKey]
 			integerValue];
-		int height = [[defaults objectForKey:kTestCardHeightKey]
+		NSInteger height = [[defaults objectForKey:kTestCardHeightKey]
 			integerValue];
 		if (width == 0 || height == 0) {
 			_testCardSize =
@@ -183,8 +183,10 @@
 
 		NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
 			initWithBitmapDataPlanes:NULL
-				      pixelsWide:self.testCardSize.width
-				      pixelsHigh:self.testCardSize.height
+				      pixelsWide:(NSInteger)
+							 self.testCardSize.width
+				      pixelsHigh:(NSInteger)self.testCardSize
+							 .height
 				   bitsPerSample:8
 				 samplesPerPixel:4
 					hasAlpha:YES
@@ -194,18 +196,18 @@
 				    bitsPerPixel:0];
 		rep.size = self.testCardSize;
 
-		float hScale =
+		double hScale =
 			placeholderImage.size.width / self.testCardSize.width;
-		float vScale =
+		double vScale =
 			placeholderImage.size.height / self.testCardSize.height;
 
-		float scaling = fmax(hScale, vScale);
+		double scaling = fmax(hScale, vScale);
 
-		float newWidth = placeholderImage.size.width / scaling;
-		float newHeight = placeholderImage.size.height / scaling;
+		double newWidth = placeholderImage.size.width / scaling;
+		double newHeight = placeholderImage.size.height / scaling;
 
-		float leftOffset = (self.testCardSize.width - newWidth) / 2;
-		float topOffset = (self.testCardSize.height - newHeight) / 2;
+		double leftOffset = (self.testCardSize.width - newWidth) / 2;
+		double topOffset = (self.testCardSize.height - newHeight) / 2;
 
 		[NSGraphicsContext saveGraphicsState];
 		[NSGraphicsContext
@@ -249,8 +251,8 @@
 
 - (CVPixelBufferRef)createPixelBufferWithTestAnimation
 {
-	int width = self.testCardSize.width;
-	int height = self.testCardSize.height;
+	int width = (int)self.testCardSize.width;
+	int height = (int)self.testCardSize.height;
 
 	NSDictionary *options = [NSDictionary
 		dictionaryWithObjectsAndKeys:
@@ -316,7 +318,7 @@
 
 	uint64_t hostTime = mach_absolute_time();
 	CMSampleTimingInfo timingInfo =
-		CMSampleTimingInfoForTimestamp(hostTime, self.fps, 1);
+		CMSampleTimingInfoForTimestamp(hostTime, (uint32_t)self.fps, 1);
 
 	OSStatus err = CMIOStreamClockPostTimingEvent(
 		timingInfo.presentationTimeStamp, hostTime, true, self.clock);
@@ -418,8 +420,8 @@
 	OSStatus err = CMVideoFormatDescriptionCreate(
 		kCFAllocatorDefault,
 		kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
-		self.testCardSize.width, self.testCardSize.height, NULL,
-		&formatDescription);
+		(int32_t)self.testCardSize.width,
+		(int32_t)self.testCardSize.height, NULL, &formatDescription);
 	if (err != noErr) {
 		DLog(@"Error %d from CMVideoFormatDescriptionCreate", err);
 	}