Commit 8f05427a authored by Laurent Aimar's avatar Laurent Aimar

Reduce locking and mdate count in input clock.

parent e92f2914
......@@ -136,7 +136,7 @@ struct input_clock_t
* It is used to detect unexpected stream discontinuities */
clock_point_t last;
/* Maximal timestamp returned by input_clock_GetTS (in system unit) */
/* Maximal timestamp returned by input_clock_ConvertTS (in system unit) */
mtime_t i_ts_max;
/* Clock drift */
......@@ -325,13 +325,15 @@ mtime_t input_clock_GetWakeup( input_clock_t *cl )
}
/*****************************************************************************
* input_clock_GetTS: manages a PTS or DTS
* input_clock_ConvertTS
*****************************************************************************/
mtime_t input_clock_GetTS( input_clock_t *cl, int *pi_rate,
mtime_t i_ts, mtime_t i_ts_bound )
int input_clock_ConvertTS( input_clock_t *cl,
int *pi_rate, mtime_t *pi_ts0, mtime_t *pi_ts1,
mtime_t i_ts_bound )
{
mtime_t i_converted_ts;
mtime_t i_pts_delay;
assert( pi_ts0 );
vlc_mutex_lock( &cl->lock );
if( pi_rate )
......@@ -340,24 +342,37 @@ mtime_t input_clock_GetTS( input_clock_t *cl, int *pi_rate,
if( !cl->b_has_reference )
{
vlc_mutex_unlock( &cl->lock );
return 0;
*pi_ts0 = 0;
if( pi_ts1 )
*pi_ts1 = 0;
return VLC_EGENERIC;
}
/* */
i_converted_ts = ClockStreamToSystem( cl, i_ts + AvgGet( &cl->drift ) );
if( i_converted_ts > cl->i_ts_max )
cl->i_ts_max = i_converted_ts;
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;
}
vlc_mutex_unlock( &cl->lock );
/* 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_converted_ts += 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 &&
i_converted_ts >= mdate() + cl->i_pts_delay + i_ts_bound )
return 0;
*pi_ts0 > 0 && *pi_ts0 >= mdate() + cl->i_pts_delay + i_ts_bound )
return VLC_EGENERIC;
return i_converted_ts;
return VLC_SUCCESS;
}
/*****************************************************************************
* input_clock_GetRate: Return current rate
......
......@@ -85,14 +85,20 @@ void input_clock_ChangePause( input_clock_t *, bool b_paused, mtime_t i_date
void input_clock_ChangeSystemOrigin( input_clock_t *, mtime_t i_system );
/**
* This function converts a timestamp from stream clock to system clock.
* This function converts a pair of timestamp from stream clock to system clock.
*
* If pi_rate is provided it will be field with the rate value used for
* If pi_rate is provided it will be filled with the rate value used for
* the conversion.
* If i_ts_bound is not INT64_MAX, the value will be invalidated if not
* before mdate() + i_pts_delay + i_ts_bound.
* p_ts0 is a pointer to a timestamp to be converted (in place) and must be non NULL.
* p_ts1 is a pointer to a timestamp to be converted (in place) and can be NULL.
*
* It will return VLC_EGENERIC if i_ts_bound is not INT64_MAX and if the value *p_ts0
* after conversion is not before the deadline mdate() + i_pts_delay + i_ts_bound.
* It will also return VLC_EGENERIC if the conversion cannot be done successfully. In
* this case, *p_ts0 and *p_ts1 will hold an invalid timestamp.
* Otherwise it will return VLC_SUCCESS.
*/
mtime_t input_clock_GetTS( input_clock_t *, int *pi_rate, mtime_t i_ts, mtime_t i_ts_bound );
int input_clock_ConvertTS( input_clock_t *, int *pi_rate, mtime_t *pi_ts0, mtime_t *pi_ts1, mtime_t i_ts_bound );
/**
* This function returns the current rate.
......
......@@ -652,7 +652,10 @@ static mtime_t DecoderGetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
if( !p_owner->p_clock || !i_ts )
return i_ts;
return input_clock_GetTS( p_owner->p_clock, NULL, i_ts, INT64_MAX );
if( input_clock_ConvertTS( p_owner->p_clock, NULL, &i_ts, NULL, INT64_MAX ) )
return 0;
return i_ts;
}
static int DecoderGetDisplayRate( decoder_t *p_dec )
{
......@@ -1039,7 +1042,6 @@ static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
input_clock_t *p_clock = p_owner->p_clock;
int i_rate = 0;
vlc_assert_locked( &p_owner->lock );
......@@ -1048,24 +1050,24 @@ static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
if( p_clock )
{
const bool b_ephemere = pi_ts1 && *pi_ts0 == *pi_ts1;
int i_rate;
if( *pi_ts0 > 0 )
*pi_ts0 = input_clock_GetTS( p_clock, &i_rate, *pi_ts0 + i_es_delay, i_ts_bound );
if( pi_ts1 && *pi_ts1 > 0 )
{
if( *pi_ts0 > 0 )
*pi_ts1 = input_clock_GetTS( p_clock, &i_rate, *pi_ts1 + i_es_delay, INT64_MAX );
else
*pi_ts1 = 0;
*pi_ts0 += i_es_delay;
if( pi_ts1 && *pi_ts1 > 0 )
*pi_ts1 += i_es_delay;
input_clock_ConvertTS( p_clock, &i_rate, pi_ts0, pi_ts1, i_ts_bound );
}
else
{
i_rate = input_clock_GetRate( p_clock );
}
/* Do not create ephemere data because of rounding errors */
if( !b_ephemere && pi_ts1 && *pi_ts0 == *pi_ts1 )
*pi_ts1 += 1;
if( i_rate <= 0 )
i_rate = input_clock_GetRate( p_clock );
if( pi_duration )
*pi_duration = ( *pi_duration * i_rate +
INPUT_RATE_DEFAULT-1 ) / INPUT_RATE_DEFAULT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment