[vlc-commits] [Git][videolan/vlc][master] vout: improve chrono estimation on start

Romain Vimont (@rom1v) gitlab at videolan.org
Tue Jul 20 12:46:39 UTC 2021



Romain Vimont pushed to branch master at VideoLAN / VLC


Commits:
e6bb48cc by Romain Vimont at 2021-07-20T12:29:00+00:00
vout: improve chrono estimation on start

During a new measurement, the current state of the chrono were always
weighted in the same way, regardless of the number of samples that
contributed in the values. As a consequence, the initial (arbitrary)
value was too impactful.

Instead, until there are enough values (according to the provided
"shift"), weight the average and mean absolute deviation by the number
of contributing samples.

In particular, the first real sample overrides the arbitrary initial
average.

- - - - -


1 changed file:

- src/video_output/chrono.h


Changes:

=====================================
src/video_output/chrono.h
=====================================
@@ -28,20 +28,25 @@
 typedef struct {
     int     shift;
     vlc_tick_t avg;
+    unsigned avg_count;
 
     int     shift_mad;
     vlc_tick_t mad; /* mean absolute deviation */
+    unsigned mad_count;
 
     vlc_tick_t start;
 } vout_chrono_t;
 
 static inline void vout_chrono_Init(vout_chrono_t *chrono, int shift, vlc_tick_t avg_initial)
 {
+    chrono->avg_count   = 0;
+    chrono->mad_count   = 0;
+
     chrono->shift       = shift;
     chrono->avg         = avg_initial;
 
     chrono->shift_mad   = shift+1;
-    chrono->mad         = avg_initial / 2;
+    chrono->mad         = 0;
 
     chrono->start = VLC_TICK_INVALID;
 }
@@ -65,15 +70,31 @@ static inline void vout_chrono_Stop(vout_chrono_t *chrono)
 {
     assert(chrono->start != VLC_TICK_INVALID);
 
-    /* */
     const vlc_tick_t duration = vlc_tick_now() - chrono->start;
-    const vlc_tick_t abs_diff = llabs( duration - chrono->avg );
 
-    /* Update average only if the current point is 'valid' */
-    if( duration < vout_chrono_GetHigh( chrono ) )
-        chrono->avg = (((1 << chrono->shift) - 1) * chrono->avg + duration) >> chrono->shift;
-    /* Always update the mean absolute deviation */
-    chrono->mad = (((1 << chrono->shift_mad) - 1) * chrono->mad + abs_diff) >> chrono->shift_mad;
+    if (chrono->avg_count == 0)
+    {
+        /* Overwrite the arbitrary initial values with the real first sample */
+        chrono->avg = duration;
+        chrono->avg_count = 1;
+    }
+    else
+    {
+        /* Update average only if the current point is 'valid' */
+        if( duration < vout_chrono_GetHigh( chrono ) )
+        {
+            if (chrono->avg_count < (1u << chrono->shift))
+                ++chrono->avg_count;
+            chrono->avg = ((chrono->avg_count - 1) * chrono->avg + duration) / chrono->avg_count;
+        }
+
+        const vlc_tick_t abs_diff = llabs( duration - chrono->avg );
+
+        /* Always update the mean absolute deviation */
+        if (chrono->mad_count < (1u << chrono->shift_mad))
+            ++chrono->mad_count;
+        chrono->mad = ((chrono->mad_count - 1) * chrono->mad + abs_diff) / chrono->mad_count;
+    }
 
     /* For assert */
     chrono->start = VLC_TICK_INVALID;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e6bb48cc1568fdebabba810718c8c235abe0b4ab

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e6bb48cc1568fdebabba810718c8c235abe0b4ab
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list