Commit a48799e7 authored by Laurent Aimar's avatar Laurent Aimar

Auto detect when we need to buffer again.

As it is part of a critical section for playback, becareful about any
regressions.
parent a4087f06
......@@ -197,8 +197,9 @@ void input_clock_Delete( input_clock_t *cl )
* i_ck_stream: date in stream clock
* i_ck_system: date in system clock
*****************************************************************************/
void input_clock_Update( input_clock_t *cl,
vlc_object_t *p_log, bool b_can_pace_control,
void input_clock_Update( input_clock_t *cl, vlc_object_t *p_log,
bool *pb_late,
bool b_can_pace_control,
mtime_t i_ck_stream, mtime_t i_ck_system )
{
bool b_reset_reference = false;
......@@ -247,6 +248,11 @@ void input_clock_Update( input_clock_t *cl,
}
cl->last = clock_point_Create( i_ck_stream, i_ck_system );
/* It does not take the decoder latency into account but it is not really
* the goal of the clock here */
const mtime_t i_system_expected = ClockStreamToSystem( cl, i_ck_stream + AvgGet( &cl->drift ) );
*pb_late = i_system_expected < i_ck_system - cl->i_pts_delay;
vlc_mutex_unlock( &cl->lock );
}
......
......@@ -52,8 +52,10 @@ void input_clock_Delete( input_clock_t * );
/**
* This function will update a input_clock_t with a new clock reference point.
* It will also tell if the clock point is late regarding our buffering.
*/
void input_clock_Update( input_clock_t *, vlc_object_t *p_log,
bool *pb_late,
bool b_can_pace_control, mtime_t i_clock, mtime_t i_system );
/**
* This function will reset the drift of a input_clock_t.
......
......@@ -2212,6 +2212,7 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
int i_group = 0;
int64_t i_pcr;
/* Search program */
if( i_query == ES_OUT_SET_PCR )
{
p_pgrm = p_sys->p_pgrm;
......@@ -2233,14 +2234,28 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
return VLC_EGENERIC;
}
/* search program
* TODO do not use mdate() but proper stream acquisition date */
/* TODO do not use mdate() but proper stream acquisition date */
bool b_late;
input_clock_Update( p_pgrm->p_clock, VLC_OBJECT(p_sys->p_input),
&b_late,
p_sys->p_input->p->b_can_pace_control || p_sys->b_buffering, i_pcr, mdate() );
/* Check buffering state on master clock update */
if( p_sys->b_buffering && p_pgrm == p_sys->p_pgrm )
EsOutDecodersStopBuffering( out, false );
if( p_pgrm == p_sys->p_pgrm )
{
if( p_sys->b_buffering )
{
/* Check buffering state on master clock update */
EsOutDecodersStopBuffering( out, false );
}
else if( b_late )
{
/* Force a rebufferization when we are too late */
msg_Err( p_sys->p_input, "ES_OUT_SET_(GROUP_)PCR is called too late" );
/* It is not really good, as we throw away already buffered data
* TODO have a mean to correctly reenter bufferization */
EsOutChangePosition( out );
}
}
return VLC_SUCCESS;
}
......
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