|
@@ -94,6 +94,9 @@ void DeckLinkDeviceInstance::HandleAudioPacket(
|
|
currentPacket.data[0] = (uint8_t *)bytes;
|
|
currentPacket.data[0] = (uint8_t *)bytes;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ nextAudioTS = timestamp +
|
|
|
|
+ ((uint64_t)frameCount * 1000000000ULL / 48000ULL) + 1;
|
|
|
|
+
|
|
obs_source_output_audio(decklink->GetSource(), ¤tPacket);
|
|
obs_source_output_audio(decklink->GetSource(), ¤tPacket);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -219,10 +222,27 @@ HRESULT STDMETHODCALLTYPE DeckLinkDeviceInstance::VideoInputFrameArrived(
|
|
BMDTimeValue videoDur = 0;
|
|
BMDTimeValue videoDur = 0;
|
|
BMDTimeValue audioTS = 0;
|
|
BMDTimeValue audioTS = 0;
|
|
|
|
|
|
- if (videoFrame)
|
|
|
|
|
|
+ if (videoFrame) {
|
|
videoFrame->GetStreamTime(&videoTS, &videoDur, TIME_BASE);
|
|
videoFrame->GetStreamTime(&videoTS, &videoDur, TIME_BASE);
|
|
- if (audioPacket)
|
|
|
|
- audioPacket->GetPacketTime(&audioTS, TIME_BASE);
|
|
|
|
|
|
+ lastVideoTS = (uint64_t)videoTS;
|
|
|
|
+ }
|
|
|
|
+ if (audioPacket) {
|
|
|
|
+ BMDTimeValue newAudioTS = 0;
|
|
|
|
+ int64_t diff;
|
|
|
|
+
|
|
|
|
+ audioPacket->GetPacketTime(&newAudioTS, TIME_BASE);
|
|
|
|
+ audioTS = newAudioTS + audioOffset;
|
|
|
|
+
|
|
|
|
+ diff = (int64_t)audioTS - (int64_t)nextAudioTS;
|
|
|
|
+ if (diff > 10000000LL) {
|
|
|
|
+ audioOffset -= diff;
|
|
|
|
+ audioTS = newAudioTS + audioOffset;
|
|
|
|
+
|
|
|
|
+ } else if (diff < -1000000) {
|
|
|
|
+ audioOffset = 0;
|
|
|
|
+ audioTS = newAudioTS;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
if (videoFrame && videoTS >= 0)
|
|
if (videoFrame && videoTS >= 0)
|
|
HandleVideoFrame(videoFrame, (uint64_t)videoTS);
|
|
HandleVideoFrame(videoFrame, (uint64_t)videoTS);
|