Browse Source

mac-virtualcam: Prevent PTS rounding

All presentation time stamps are rounded to whole seconds during the
conversion from nanoseconds to seconds, because of the immediate cast
to `int64_t`. This results in the same presentation time stamp being
send to consumers for a whole second.

In previews/live streams this isn't super visible as last frame is
often assumed to be the newest and the stream is updated. It's more
problematic when recording since APIs like Apple's AVFoundation don't
allow duplicate presentation time stamps or it can look like frames are
produced in huge bursts once per second.

In this PR `CMTimeMakeWithSeconds` is used instead of `CMTimeMake` to
make sure the conversion is done correctly and simplify the calculation
we have to do a little.
Mathijs Kadijk 2 years ago
parent
commit
970c284a65
1 changed files with 2 additions and 3 deletions
  1. 2 3
      plugins/mac-virtualcam/src/dal-plugin/CMSampleBufferUtils.mm

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

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