Browse Source

decklink: Use audio/video timestamps from SDK

System timestamps were being used instead of timestamps from the
audio/video input.  This would cause potential desync as well as
incremental buffering when using devices with the blackmagic video
source.  Using the timestamps direct from the SDK itself fixes those
issues, and causes audio/video to play back properly and in sync.
jp9000 10 years ago
parent
commit
ae733230b7
1 changed files with 12 additions and 3 deletions
  1. 12 3
      plugins/decklink/decklink-device-instance.cpp

+ 12 - 3
plugins/decklink/decklink-device-instance.cpp

@@ -126,14 +126,23 @@ bool DeckLinkDeviceInstance::StopCapture(void)
 	return true;
 }
 
+#define TIME_BASE 1000000000
+
 HRESULT STDMETHODCALLTYPE DeckLinkDeviceInstance::VideoInputFrameArrived(
 		IDeckLinkVideoInputFrame *videoFrame,
 		IDeckLinkAudioInputPacket *audioPacket)
 {
-	const uint64_t timestamp = os_gettime_ns();
+	BMDTimeValue videoTS = 0;
+	BMDTimeValue videoDur = 0;
+	BMDTimeValue audioTS = 0;
+
+	videoFrame->GetStreamTime(&videoTS, &videoDur, TIME_BASE);
+	audioPacket->GetPacketTime(&audioTS, TIME_BASE);
 
-	HandleVideoFrame(videoFrame, timestamp);
-	HandleAudioPacket(audioPacket, timestamp);
+	if (videoTS >= 0)
+		HandleVideoFrame(videoFrame, (uint64_t)videoTS);
+	if (audioTS >= 0)
+		HandleAudioPacket(audioPacket, (uint64_t)audioTS);
 
 	return S_OK;
 }