decklink: Add workaround for audio timestamp jump issue
This commit is contained in:
parent
c459ade360
commit
b63e4b055e
2 changed files with 26 additions and 4 deletions
|
|
@ -94,6 +94,9 @@ void DeckLinkDeviceInstance::HandleAudioPacket(
|
|||
currentPacket.data[0] = (uint8_t *)bytes;
|
||||
}
|
||||
|
||||
nextAudioTS = timestamp +
|
||||
((uint64_t)frameCount * 1000000000ULL / 48000ULL) + 1;
|
||||
|
||||
obs_source_output_audio(decklink->GetSource(), ¤tPacket);
|
||||
}
|
||||
|
||||
|
|
@ -219,10 +222,27 @@ HRESULT STDMETHODCALLTYPE DeckLinkDeviceInstance::VideoInputFrameArrived(
|
|||
BMDTimeValue videoDur = 0;
|
||||
BMDTimeValue audioTS = 0;
|
||||
|
||||
if (videoFrame)
|
||||
if (videoFrame) {
|
||||
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)
|
||||
HandleVideoFrame(videoFrame, (uint64_t)videoTS);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue