]> git.sesse.net Git - nageru/commitdiff
Reset jitter history when frame rate changes.
authorSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sun, 30 Aug 2020 22:25:40 +0000 (00:25 +0200)
committerSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sat, 12 Dec 2020 13:55:42 +0000 (14:55 +0100)
This is seemingly especially important when we have input format autodetect
and PAL input rates; it gives us one 59.97 fps frame, then a delay as the
card autodetects and resyncs (might be as much as 30–50 ms; not entirely sure),
and then a steady stream of 50 fps frames. This then causes us to overestimate
the jitter by a lot until we get more than 1000 frames and can reject that
very first event as the outlier it is.

nageru/mixer.cpp
nageru/queue_length_policy.h

index 2fdbf645e876d89cc39022a411d75f2e92016ba3..ce8a73237fd4a838ee85ca0c307663d6e3c9edda 100644 (file)
@@ -234,6 +234,16 @@ void JitterHistory::unregister_metrics(const vector<pair<string, string>> &label
 
 void JitterHistory::frame_arrived(steady_clock::time_point now, int64_t frame_duration, size_t dropped_frames)
 {
+       if (frame_duration != last_duration) {
+               // If the frame rate changed, the input clock is also going to change,
+               // so our historical data doesn't make much sense anymore.
+               // Also, format changes typically introduce blips that are not representative
+               // of the typical frame stream. (We make the assumption that format changes
+               // don't happen all the time in regular use; if they did, we should probably
+               // rather keep the history so that we take jitter they may introduce into account.)
+               clear();
+               last_duration = frame_duration;
+       }
        if (expected_timestamp > steady_clock::time_point::min()) {
                expected_timestamp += dropped_frames * nanoseconds(frame_duration * 1000000000 / TIMEBASE);
                double jitter_seconds = fabs(duration<double>(expected_timestamp - now).count());
index 329eb82983ac15d038e3d5953d4998f274cb4eac..0b8a4204fbcf7893d9f323ac6808fb7d66b04824 100644 (file)
@@ -54,6 +54,7 @@ private:
        std::deque<std::multiset<double>::iterator> history;
 
        std::chrono::steady_clock::time_point expected_timestamp = std::chrono::steady_clock::time_point::min();
+       int64_t last_duration = 0;
 
        // Metrics. There are no direct summaries for jitter, since we already have latency summaries.
        std::atomic<int64_t> metric_input_underestimated_jitter_frames{0};