]> git.sesse.net Git - nageru/commitdiff
Fix an issue with the correction factor locking to 0.95.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 11 Feb 2017 18:22:36 +0000 (19:22 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 11 Feb 2017 18:22:36 +0000 (19:22 +0100)
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
mixer.cpp
resampling_queue.cpp

index a0e890fcbcdd4fdc7c8bbb55e8212e8039980192..eee46c4454f528db07fd2593129b25949c3cd19d 100644 (file)
@@ -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?
index 1d283e374041ea16da2c880da0584ef5fa614461..26e009595c650461fb92ae4a2d71ad17ba6cb567 100644 (file)
--- 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();
                }
index add0e50ac5bb7bcb065c012a8ba7845798917701..b34e6f58c979bdc8d94b38678ba35e6e8ef63e36 100644 (file)
@@ -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<double>(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