瀏覽代碼

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 年之前
父節點
當前提交
970c284a65
共有 1 個文件被更改,包括 2 次插入3 次删除
  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;
 	timing.duration =
 		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;
 	return timing;
 }