From 14c360d834d666ab543bffaf99b6cdfb8c2babac Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 11 Feb 2017 19:22:36 +0100 Subject: [PATCH] Fix an issue with the correction factor locking to 0.95. Basically what was happening is that if the master card lost or corrupted a frame, which we didn't set a timestamp on, causing it to have steady_clock::time_point::min(). This would in turn cause us to assume a latency of trillions of seconds, throwing off the filter and essentially making it be 0.95 forever. The fix is twofold; we always set timestamps, but also make ourselves robust to the ones that are way off (negative uptime). --- decklink_capture.cpp | 7 +++---- mixer.cpp | 1 + resampling_queue.cpp | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/decklink_capture.cpp b/decklink_capture.cpp index a0e890f..eee46c4 100644 --- a/decklink_capture.cpp +++ b/decklink_capture.cpp @@ -358,8 +358,6 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( video_format.width = width; video_format.height = height; - - current_video_frame.received_timestamp = now; } } @@ -376,11 +374,12 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( audio_format.bits_per_sample = 32; audio_format.num_channels = 2; - - current_audio_frame.received_timestamp = now; } } + current_video_frame.received_timestamp = now; + current_audio_frame.received_timestamp = now; + if (current_video_frame.data != nullptr || current_audio_frame.data != nullptr) { // TODO: Put into a queue and put into a dequeue thread, if the // BlackMagic drivers don't already do that for us? diff --git a/mixer.cpp b/mixer.cpp index 1d283e3..26e0095 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -413,6 +413,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, new_frame.length = frame_length; new_frame.interlaced = false; new_frame.dropped_frames = dropped_frames; + new_frame.received_timestamp = video_frame.received_timestamp; card->new_frames.push_back(move(new_frame)); card->new_frames_changed.notify_all(); } diff --git a/resampling_queue.cpp b/resampling_queue.cpp index add0e50..b34e6f5 100644 --- a/resampling_queue.cpp +++ b/resampling_queue.cpp @@ -77,6 +77,11 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam return true; } + // This can happen when we get dropped frames on the master card. + if (duration(ts.time_since_epoch()).count() <= 0.0) { + rate_adjustment_policy = DO_NOT_ADJUST_RATE; + } + if (rate_adjustment_policy == ADJUST_RATE && (a0.good_sample || a1.good_sample)) { // Estimate the current number of input samples produced at // this instant in time, by extrapolating from the last known -- 2.39.2