0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00

decklink: Add workaround for audio timestamp jump issue

This commit is contained in:
jp9000 2017-04-07 00:31:16 -07:00
parent c459ade360
commit b63e4b055e
2 changed files with 26 additions and 4 deletions

View File

@ -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(), &currentPacket);
}
@ -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);

View File

@ -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;