+ mtime_t i_pts_delay;
+
+ assert( pi_ts0 );
+ vlc_mutex_lock( &cl->lock );
+
+ if( pi_rate )
+ *pi_rate = cl->i_rate;
+
+ if( !cl->b_has_reference )
+ {
+ vlc_mutex_unlock( &cl->lock );
+ *pi_ts0 = 0;
+ if( pi_ts1 )
+ *pi_ts1 = 0;
+ return VLC_EGENERIC;
+ }
+
+ /* */
+ if( *pi_ts0 > 0 )
+ {
+ *pi_ts0 = ClockStreamToSystem( cl, *pi_ts0 + AvgGet( &cl->drift ) );
+ if( *pi_ts0 > cl->i_ts_max )
+ cl->i_ts_max = *pi_ts0;
+ *pi_ts0 += cl->i_pts_delay;
+ }
+
+ /* XXX we do not ipdate i_ts_max on purpose */
+ if( pi_ts1 && *pi_ts1 > 0 )
+ {
+ *pi_ts1 = ClockStreamToSystem( cl, *pi_ts1 + AvgGet( &cl->drift ) ) +
+ cl->i_pts_delay;
+ }
+
+ i_pts_delay = cl->i_pts_delay;
+ vlc_mutex_unlock( &cl->lock );
+
+ /* Check ts validity */
+ if( i_ts_bound != INT64_MAX &&
+ *pi_ts0 > 0 && *pi_ts0 >= mdate() + cl->i_pts_delay + i_ts_bound )
+ return VLC_EGENERIC;
+
+ return VLC_SUCCESS;
+}
+/*****************************************************************************
+ * input_clock_GetRate: Return current rate
+ *****************************************************************************/
+int input_clock_GetRate( input_clock_t *cl )
+{
+ int i_rate;
+
+ vlc_mutex_lock( &cl->lock );
+ i_rate = cl->i_rate;
+ vlc_mutex_unlock( &cl->lock );
+
+ return i_rate;
+}
+
+int input_clock_GetState( input_clock_t *cl,
+ mtime_t *pi_stream_start, mtime_t *pi_system_start,
+ mtime_t *pi_stream_duration, mtime_t *pi_system_duration )
+{
+ vlc_mutex_lock( &cl->lock );
+
+ if( !cl->b_has_reference )
+ {
+ vlc_mutex_unlock( &cl->lock );
+ return VLC_EGENERIC;
+ }
+
+ *pi_stream_start = cl->ref.i_stream;
+ *pi_system_start = cl->ref.i_system;
+
+ *pi_stream_duration = cl->last.i_stream - cl->ref.i_stream;
+ *pi_system_duration = cl->last.i_system - cl->ref.i_system;
+
+ vlc_mutex_unlock( &cl->lock );
+
+ return VLC_SUCCESS;
+}
+
+void input_clock_ChangeSystemOrigin( input_clock_t *cl, mtime_t i_system )
+{
+ vlc_mutex_lock( &cl->lock );
+
+ assert( cl->b_has_reference );
+ const mtime_t i_offset = i_system - cl->ref.i_system;
+
+ cl->ref.i_system += i_offset;
+ cl->last.i_system += i_offset;
+
+ vlc_mutex_unlock( &cl->lock );
+}
+
+#warning "input_clock_SetJitter needs more work"
+void input_clock_SetJitter( input_clock_t *cl,
+ mtime_t i_pts_delay, int i_cr_average )
+{
+ vlc_mutex_lock( &cl->lock );
+
+ /* TODO always save the value, and when rebuffering use the new one if smaller
+ * TODO when increasing -> force rebuffering
+ */
+ if( cl->i_pts_delay < i_pts_delay )
+ cl->i_pts_delay = i_pts_delay;
+
+ /* */
+ if( i_cr_average < 10 )
+ i_cr_average = 10;
+
+ if( cl->drift.i_divider != i_cr_average )
+ AvgRescale( &cl->drift, i_cr_average );
+
+ vlc_mutex_unlock( &cl->lock );