+ bool b_reset_reference = false;
+
+ assert( i_ck_stream > VLC_TS_INVALID && i_ck_system > VLC_TS_INVALID );
+
+ vlc_mutex_lock( &cl->lock );
+
+ if( !cl->b_has_reference )
+ {
+ /* */
+ b_reset_reference= true;
+ }
+ else if( cl->last.i_stream > VLC_TS_INVALID &&
+ ( (cl->last.i_stream - i_ck_stream) > CR_MAX_GAP ||
+ (cl->last.i_stream - i_ck_stream) < -CR_MAX_GAP ) )
+ {
+ /* Stream discontinuity, for which we haven't received a
+ * warning from the stream control facilities (dd-edited
+ * stream ?). */
+ msg_Warn( p_log, "clock gap, unexpected stream discontinuity" );
+ cl->i_ts_max = VLC_TS_INVALID;
+
+ /* */
+ msg_Warn( p_log, "feeding synchro with a new reference point trying to recover from clock gap" );
+ b_reset_reference= true;
+ }
+
+ /* */
+ if( b_reset_reference )
+ {
+ cl->i_next_drift_update = VLC_TS_INVALID;
+ AvgReset( &cl->drift );
+
+ /* Feed synchro with a new reference point. */
+ cl->b_has_reference = true;
+ cl->ref = clock_point_Create( i_ck_stream,
+ __MAX( cl->i_ts_max + CR_MEAN_PTS_GAP, i_ck_system ) );
+ }
+
+ /* Compute the drift between the stream clock and the system clock
+ * when we don't control the source pace */
+ if( !b_can_pace_control && cl->i_next_drift_update < i_ck_system )
+ {
+ const mtime_t i_converted = ClockSystemToStream( cl, i_ck_system );
+
+ AvgUpdate( &cl->drift, i_converted - i_ck_stream );
+
+ cl->i_next_drift_update = i_ck_system + CLOCK_FREQ/5; /* FIXME why that */
+ }