#endif
#include <vlc_common.h>
-
-#include "input_internal.h"
+#include <vlc_input.h>
+#include "input_clock.h"
/*
* DISCUSSION : SYNCHRONIZATION METHOD
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 */
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
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;
* 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 ) ||
/* */
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 )
/* 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;
void input_clock_ResetPCR( input_clock_t *cl )
{
cl->b_has_reference = false;
- cl->last_pts = 0;
+ cl->i_ts_max = 0;
}
/*****************************************************************************
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;
}
/*****************************************************************************
/*****************************************************************************
* 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 )
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;
+}
+
+