[vlc-commits] [Git][videolan/vlc][master] 5 commits: clock: refactor

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Oct 19 08:26:59 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
94673a39 by Thomas Guillem at 2023-10-19T08:07:22+00:00
clock: refactor

Handle both reset case in the same place.
No functional changes.

- - - - -
cc1a574c by Thomas Guillem at 2023-10-19T08:07:22+00:00
clock: explicit NULL check

- - - - -
a0d91649 by Thomas Guillem at 2023-10-19T08:07:22+00:00
clock: trace when the clock is reset

- - - - -
f8d9f6d7 by Thomas Guillem at 2023-10-19T08:07:22+00:00
es_out: comment the vlc_clock_main_Reset usage while buffering

- - - - -
2a359b21 by Thomas Guillem at 2023-10-19T08:07:22+00:00
es_out: prevent a clock reset after buffering

The clock was very likely reset, just after the buffering step, if the
clock source was the input since input_clock_ChangeSystemOrigin() was
modifying the clock coefficient drastically.

And cf. comment

- - - - -


2 changed files:

- src/clock/clock.c
- src/input/es_out.c


Changes:

=====================================
src/clock/clock.c
=====================================
@@ -115,7 +115,7 @@ static inline void vlc_clock_on_update(vlc_clock_t *clock,
         clock->cbs->on_update(system_now, ts, rate, frame_rate, frame_rate_base,
                               clock->cbs_data);
 
-    if (main_clock->tracer != NULL && clock->track_str_id)
+    if (main_clock->tracer != NULL && clock->track_str_id != NULL)
         vlc_tracer_TraceRender(main_clock->tracer, "RENDER", clock->track_str_id,
                                system_now, ts);
 }
@@ -152,23 +152,29 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
                 double instant_coeff = system_diff / (double) stream_diff * rate;
 
                 /* System and stream ts should be incrementing */
-                if (system_diff < 0 || stream_diff < 0)
-                {
-                    if (main_clock->logger != NULL)
-                        vlc_warning(main_clock->logger, "resetting master clock: "
-                                    "decreasing ts: system: %"PRId64 ", stream: %" PRId64,
-                                    system_diff, stream_diff);
-                    /* Reset and continue (calculate the offset from the
-                     * current point) */
-                    vlc_clock_main_reset(main_clock);
-                }
+                bool decreasing_ts = system_diff < 0 || stream_diff < 0;
                 /* The instant coeff should always be around 1.0 */
-                else if (instant_coeff > 1.0 + COEFF_THRESHOLD
-                      || instant_coeff < 1.0 - COEFF_THRESHOLD)
+                bool coefficient_unstable = instant_coeff > 1.0 + COEFF_THRESHOLD
+                    || instant_coeff < 1.0 - COEFF_THRESHOLD;
+
+                if (decreasing_ts || coefficient_unstable)
                 {
                     if (main_clock->logger != NULL)
-                        vlc_warning(main_clock->logger, "resetting master clock: "
-                                    "coefficient too unstable: %f", instant_coeff);
+                    {
+                        if (decreasing_ts)
+                            vlc_warning(main_clock->logger, "resetting master clock: "
+                                        "decreasing ts: system: %"PRId64 ", stream: %" PRId64,
+                                        system_diff, stream_diff);
+                        else
+                            vlc_warning(main_clock->logger, "resetting master clock: "
+                                        "coefficient too unstable: %f", instant_coeff);
+                    }
+
+                    if (main_clock->tracer != NULL && clock->track_str_id != NULL)
+                        vlc_tracer_TraceEvent(main_clock->tracer, "RENDER",
+                                              clock->track_str_id,
+                                              "reset_bad_source");
+
                     /* Reset and continue (calculate the offset from the
                      * current point) */
                     vlc_clock_main_reset(main_clock);
@@ -190,7 +196,7 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
         main_clock->offset =
             system_now - ((vlc_tick_t) (ts * main_clock->coeff / rate));
 
-        if (main_clock->tracer != NULL && clock->track_str_id)
+        if (main_clock->tracer != NULL && clock->track_str_id != NULL)
             vlc_tracer_Trace(main_clock->tracer,
                              VLC_TRACE("type", "RENDER"),
                              VLC_TRACE("id", clock->track_str_id),
@@ -215,6 +221,9 @@ static void vlc_clock_master_reset(vlc_clock_t *clock)
     vlc_clock_main_t *main_clock = clock->owner;
 
     vlc_mutex_lock(&main_clock->lock);
+    if (main_clock->tracer != NULL && clock->track_str_id != NULL)
+        vlc_tracer_TraceEvent(main_clock->tracer, "RENDER", clock->track_str_id,
+                              "reset_user");
     vlc_clock_main_reset(main_clock);
 
     assert(main_clock->delay <= 0);


=====================================
src/input/es_out.c
=====================================
@@ -1001,12 +1001,6 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
             vlc_input_decoder_Wait( p_es->p_dec_record );
     }
 
-    /* Reset the main clock once all decoders are ready to output their first
-     * frames and not from EsOutChangePosition(), like the input clock. Indeed,
-     * flush is asynchronous and the output used by the decoder may still need
-     * a valid reference of the clock to output their last frames. */
-    vlc_clock_main_Reset( p_sys->p_pgrm->p_main_clock );
-
     msg_Dbg( p_sys->p_input, "Decoder wait done in %d ms",
               (int)MS_FROM_VLC_TICK(vlc_tick_now() - i_decoder_buffering_start) );
 
@@ -1019,13 +1013,38 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
 
     const vlc_tick_t update = i_current_date + i_wakeup_delay - i_buffering_duration;
 
+    /* The call order of these 3 input_clock_t/vlc_clock_main_t functions is
+     * important:
+     *
+     * - vlc_clock_main_Reset() must be called after
+     *   input_clock_ChangeSystemOrigin() since we want to use update points
+     *   after the buffering step. Indeed, in case of an input clock source,
+     *   input_clock_ChangeSystemOrigin() also forward the updated point to the
+     *   output clock.
+     *
+     * - vlc_clock_main_SetFirstPcr() must be called after
+     *   vlc_clock_main_Reset() since the reset function also reset the first
+     *   PCR point.
+     */
+
+    input_clock_ChangeSystemOrigin( p_sys->p_pgrm->p_input_clock, true, update );
+
+    /* Resetting the main_clock here will drop all points that were sent during
+     * the buffering step. Only points coming from the input_clock are dropped
+     * here. Indeed, decoders should not send any output frames while buffering
+     * so outputs could not update the clock while buffering.
+     *
+     * Reset the main clock once all decoders are ready to output their first
+     * frames and not from EsOutChangePosition(), like the input clock. Indeed,
+     * flush is asynchronous and the output used by the decoder may still need
+     * a valid reference of the clock to output their last frames. */
+    vlc_clock_main_Reset( p_sys->p_pgrm->p_main_clock );
+
     /* Send the first PCR to the output clock. This will be used as a reference
      * point for the sync point. */
     vlc_clock_main_SetFirstPcr(p_sys->p_pgrm->p_main_clock, update,
                                i_stream_start);
 
-    input_clock_ChangeSystemOrigin( p_sys->p_pgrm->p_input_clock, true, update );
-
     foreach_es_then_es_slaves(p_es)
     {
         if( !p_es->p_dec )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/33bb2aec271089e1af693080b4f13039a5eacfa7...2a359b21289c7eb6016d7d94b85ea7d2ca98d3ab

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/33bb2aec271089e1af693080b4f13039a5eacfa7...2a359b21289c7eb6016d7d94b85ea7d2ca98d3ab
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list