X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fclock.c;h=dd07adb71461510829db5ebd0ac89b2ac23d7848;hb=5fed39358294c743eaaaa0e8b439c7ca21622463;hp=4bd82b44c7e12c0a2b508ddf2d666f35251e2e61;hpb=b72b3e538b7844b05d01857139eb9a1ba3a8b705;p=vlc diff --git a/src/input/clock.c b/src/input/clock.c index 4bd82b44c7..dd07adb714 100644 --- a/src/input/clock.c +++ b/src/input/clock.c @@ -30,8 +30,8 @@ #endif #include - -#include "input_internal.h" +#include +#include "input_clock.h" /* * DISCUSSION : SYNCHRONIZATION METHOD @@ -99,7 +99,8 @@ struct input_clock_t mtime_t i_system; } last; - mtime_t last_pts; + /* Maixmal timestamp returned by input_clock_GetTS (in system unit) */ + mtime_t i_ts_max; /* Clock drift */ mtime_t i_delta_update; /* System time to wait for drift update */ @@ -114,40 +115,9 @@ struct input_clock_t int i_cr_average; }; -/***************************************************************************** - * ClockStreamToSystem: converts a movie clock to system date - *****************************************************************************/ -static mtime_t ClockStreamToSystem( input_clock_t *cl, mtime_t i_clock ) -{ - if( !cl->b_has_reference ) - return 0; - - return (i_clock - cl->ref.i_clock) * cl->i_rate / INPUT_RATE_DEFAULT + - cl->ref.i_system; -} - -/***************************************************************************** - * ClockSystemToStream: converts a system date to movie clock - ***************************************************************************** - * Caution : a valid reference point is needed for this to operate. - *****************************************************************************/ -static mtime_t ClockSystemToStream( input_clock_t *cl, mtime_t i_ck_system ) -{ - assert( cl->b_has_reference ); - return ( i_ck_system - cl->ref.i_system ) * INPUT_RATE_DEFAULT / cl->i_rate + - cl->ref.i_clock; -} - -/***************************************************************************** - * ClockSetReference: writes a new clock reference - *****************************************************************************/ -static void ClockSetReference( input_clock_t *cl, - mtime_t i_clock, mtime_t i_sysdate ) -{ - cl->b_has_reference = true; - cl->ref.i_clock = i_clock; - cl->ref.i_system = i_sysdate ; -} +static mtime_t ClockStreamToSystem( input_clock_t *, mtime_t i_clock ); +static mtime_t ClockSystemToStream( input_clock_t *, mtime_t i_system ); +static void ClockSetReference( input_clock_t *, mtime_t i_clock, mtime_t i_system ); /***************************************************************************** * input_clock_New: create a new clock @@ -164,7 +134,8 @@ input_clock_t *input_clock_New( bool b_master, int i_cr_average, int i_rate ) cl->last.i_clock = 0; cl->last.i_system = 0; - cl->last_pts = 0; + + cl->i_ts_max = 0; cl->i_delta = 0; cl->i_delta_residue = 0; @@ -192,10 +163,10 @@ void input_clock_Delete( input_clock_t *cl ) * i_ck_system: date in system clock *****************************************************************************/ void input_clock_SetPCR( input_clock_t *cl, - input_thread_t *p_input, + vlc_object_t *p_log, bool b_can_pace_control, mtime_t i_ck_stream, mtime_t i_ck_system ) { - const bool b_synchronize = p_input->b_can_pace_control && cl->b_master; + const bool b_synchronize = b_can_pace_control && cl->b_master; bool b_reset_reference = false; if( ( !cl->b_has_reference ) || @@ -206,18 +177,18 @@ void input_clock_SetPCR( input_clock_t *cl, /* */ b_reset_reference= true; } - else if ( cl->last.i_clock != 0 && - ( (cl->last.i_clock - i_ck_stream) > CR_MAX_GAP || - (cl->last.i_clock - i_ck_stream) < - CR_MAX_GAP ) ) + else if( cl->last.i_clock != 0 && + ( (cl->last.i_clock - i_ck_stream) > CR_MAX_GAP || + (cl->last.i_clock - 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_input, "clock gap, unexpected stream discontinuity" ); - cl->last_pts = 0; + msg_Warn( p_log, "clock gap, unexpected stream discontinuity" ); + cl->i_ts_max = 0; /* */ - msg_Warn( p_input, "feeding synchro with a new reference point trying to recover from clock gap" ); + 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 ) @@ -227,7 +198,7 @@ void input_clock_SetPCR( input_clock_t *cl, /* Feed synchro with a new reference point. */ ClockSetReference( cl, i_ck_stream, - __MAX( cl->last_pts + CR_MEAN_PTS_GAP, i_ck_system ) ); + __MAX( cl->i_ts_max + CR_MEAN_PTS_GAP, i_ck_system ) ); } cl->last.i_clock = i_ck_stream; @@ -255,7 +226,7 @@ void input_clock_SetPCR( input_clock_t *cl, void input_clock_ResetPCR( input_clock_t *cl ) { cl->b_has_reference = false; - cl->last_pts = 0; + cl->i_ts_max = 0; } /***************************************************************************** @@ -264,11 +235,17 @@ void input_clock_ResetPCR( input_clock_t *cl ) mtime_t input_clock_GetTS( input_clock_t *cl, mtime_t i_pts_delay, mtime_t i_ts ) { + mtime_t i_converted_ts; + if( !cl->b_has_reference ) return 0; - cl->last_pts = ClockStreamToSystem( cl, i_ts + cl->i_delta ); - return cl->last_pts + i_pts_delay; + /* */ + i_converted_ts = ClockStreamToSystem( cl, i_ts + cl->i_delta ); + if( i_converted_ts > cl->i_ts_max ) + cl->i_ts_max = i_converted_ts; + + return i_converted_ts + i_pts_delay; } /***************************************************************************** @@ -294,7 +271,7 @@ void input_clock_SetMaster( input_clock_t *cl, bool b_master ) /***************************************************************************** * input_clock_GetWakeup *****************************************************************************/ -mtime_t input_clock_GetWakeup( input_clock_t *cl, input_thread_t *p_input ) +mtime_t input_clock_GetWakeup( input_clock_t *cl ) { /* Not synchronized, we cannot wait */ if( !cl->b_has_reference ) @@ -308,3 +285,39 @@ mtime_t input_clock_GetWakeup( input_clock_t *cl, input_thread_t *p_input ) return ClockStreamToSystem( cl, cl->last.i_clock ); } +/***************************************************************************** + * ClockStreamToSystem: converts a movie clock to system date + *****************************************************************************/ +static mtime_t ClockStreamToSystem( input_clock_t *cl, mtime_t i_clock ) +{ + if( !cl->b_has_reference ) + return 0; + + return ( i_clock - cl->ref.i_clock ) * cl->i_rate / INPUT_RATE_DEFAULT + + cl->ref.i_system; +} + +/***************************************************************************** + * ClockSystemToStream: converts a system date to movie clock + ***************************************************************************** + * Caution : a valid reference point is needed for this to operate. + *****************************************************************************/ +static mtime_t ClockSystemToStream( input_clock_t *cl, mtime_t i_system ) +{ + assert( cl->b_has_reference ); + return ( i_system - cl->ref.i_system ) * INPUT_RATE_DEFAULT / cl->i_rate + + cl->ref.i_clock; +} + +/***************************************************************************** + * ClockSetReference: writes a new clock reference + *****************************************************************************/ +static void ClockSetReference( input_clock_t *cl, + mtime_t i_clock, mtime_t i_system ) +{ + cl->b_has_reference = true; + cl->ref.i_clock = i_clock; + cl->ref.i_system = i_system; +} + +