clock: check condition before calculation
authorZhao Zhili <quinkblack@foxmail.com>
Wed, 20 May 2020 15:28:04 +0000 (23:28 +0800)
committerThomas Guillem <thomas@gllm.fr>
Fri, 22 May 2020 06:57:03 +0000 (08:57 +0200)
Signed-off-by: Thomas Guillem <thomas@gllm.fr>
src/clock/clock.c

index f373460..26e380b 100644 (file)
@@ -132,12 +132,12 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
         if (main_clock->offset != VLC_TICK_INVALID
          && ts != main_clock->last.stream)
         {
-            /* We have a reference so we can update coeff */
-            double instant_coeff = (system_now - main_clock->last.system)
-                                 / (double)(ts - main_clock->last.stream);
             if (rate == main_clock->rate)
             {
-                instant_coeff *= rate;
+                /* We have a reference so we can update coeff */
+                double instant_coeff = (system_now - main_clock->last.system)
+                                     / (double)(ts - main_clock->last.stream)
+                                     * rate;
                 AvgUpdate(&main_clock->coeff_avg, instant_coeff);
                 main_clock->coeff = AvgGet(&main_clock->coeff_avg);
             }