decklink: Add workaround for audio timestamp jump issue
This commit is contained in:
parent
c459ade360
commit
b63e4b055e
@ -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);
|
||||
|
@ -14,7 +14,9 @@ protected:
|
||||
BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
|
||||
ComPtr<IDeckLinkInput> input;
|
||||
volatile long refCount = 1;
|
||||
|
||||
int64_t audioOffset = 0;
|
||||
uint64_t nextAudioTS = 0;
|
||||
uint64_t lastVideoTS = 0;
|
||||
AudioRepacker *audioRepacker = nullptr;
|
||||
speaker_layout channelFormat = SPEAKERS_STEREO;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user