]> git.sesse.net Git - nageru/blobdiff - nageru/mixer.cpp
Reset jitter history when frame rate changes.
[nageru] / nageru / mixer.cpp
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());