Commit 20821641 authored by Laurent Aimar's avatar Laurent Aimar

Cosmetics (split MainLoop in smaller functions).

parent dcaafd94
...@@ -553,27 +553,19 @@ exit: ...@@ -553,27 +553,19 @@ exit:
/***************************************************************************** /*****************************************************************************
* Main loop: Fill buffers from access, and demux * Main loop: Fill buffers from access, and demux
*****************************************************************************/ *****************************************************************************/
static void MainLoop( input_thread_t *p_input )
{
int64_t i_start_mdate = mdate();
int64_t i_intf_update = 0;
int i_updates = 0;
/* Stop the timer */ /**
stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING ); * MainLoopDemux
* It asks the demuxer to demux some data
while( !p_input->b_die && !p_input->b_error && !p_input->p->input.b_eof ) */
{ static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *pi_start_mdate )
bool b_force_update = false; {
int i_ret; int i_ret;
int i_type;
vlc_value_t val;
/* Do the read */ *pb_changed = false;
if( p_input->i_state != PAUSE_S )
{
if( ( p_input->p->i_stop > 0 && p_input->i_time >= p_input->p->i_stop ) || if( ( p_input->p->i_stop > 0 && p_input->i_time >= p_input->p->i_stop ) ||
( p_input->p->i_run > 0 && i_start_mdate+p_input->p->i_run < mdate() ) ) ( p_input->p->i_run > 0 && *pi_start_mdate+p_input->p->i_run < mdate() ) )
i_ret = 0; /* EOF */ i_ret = 0; /* EOF */
else else
i_ret = p_input->p->input.p_demux->pf_demux(p_input->p->input.p_demux); i_ret = p_input->p->input.p_demux->pf_demux(p_input->p->input.p_demux);
...@@ -585,14 +577,14 @@ static void MainLoop( input_thread_t *p_input ) ...@@ -585,14 +577,14 @@ static void MainLoop( input_thread_t *p_input )
p_input->p->input.p_demux->info.i_update ) p_input->p->input.p_demux->info.i_update )
{ {
i_ret = UpdateFromDemux( p_input ); i_ret = UpdateFromDemux( p_input );
b_force_update = true; *pb_changed = true;
} }
else if( !p_input->p->input.b_title_demux && else if( !p_input->p->input.b_title_demux &&
p_input->p->input.p_access && p_input->p->input.p_access &&
p_input->p->input.p_access->info.i_update ) p_input->p->input.p_access->info.i_update )
{ {
i_ret = UpdateFromAccess( p_input ); i_ret = UpdateFromAccess( p_input );
b_force_update = true; *pb_changed = true;
} }
} }
...@@ -610,6 +602,8 @@ static void MainLoop( input_thread_t *p_input ) ...@@ -610,6 +602,8 @@ static void MainLoop( input_thread_t *p_input )
} }
else else
{ {
vlc_value_t val;
msg_Dbg( p_input, "repeating the same input (%d)", msg_Dbg( p_input, "repeating the same input (%d)",
repeat.i_int ); repeat.i_int );
if( repeat.i_int > 0 ) if( repeat.i_int > 0 )
...@@ -647,7 +641,7 @@ static void MainLoop( input_thread_t *p_input ) ...@@ -647,7 +641,7 @@ static void MainLoop( input_thread_t *p_input )
} }
/* */ /* */
i_start_mdate = mdate(); *pi_start_mdate = mdate();
} }
} }
else if( i_ret < 0 ) else if( i_ret < 0 )
...@@ -659,29 +653,18 @@ static void MainLoop( input_thread_t *p_input ) ...@@ -659,29 +653,18 @@ static void MainLoop( input_thread_t *p_input )
{ {
SlaveDemux( p_input ); SlaveDemux( p_input );
} }
} }
else
{
/* Small wait */
msleep( 10*1000 );
}
/* Handle control */
vlc_mutex_lock( &p_input->p->lock_control );
ControlReduce( p_input );
while( !ControlPopNoLock( p_input, &i_type, &val ) )
{
msg_Dbg( p_input, "control type=%d", i_type );
if( Control( p_input, i_type, val ) )
b_force_update = true;
}
vlc_mutex_unlock( &p_input->p->lock_control );
if( b_force_update || i_intf_update < mdate() ) /**
{ * MainLoopInterface
* It update the variables used by the interfaces
*/
static void MainLoopInterface( input_thread_t *p_input )
{
vlc_value_t val; vlc_value_t val;
double f_pos; double f_pos;
int64_t i_time, i_length; int64_t i_time, i_length;
/* update input status variables */ /* update input status variables */
if( !demux_Control( p_input->p->input.p_demux, if( !demux_Control( p_input->p->input.p_demux,
DEMUX_GET_POSITION, &f_pos ) ) DEMUX_GET_POSITION, &f_pos ) )
...@@ -711,11 +694,14 @@ static void MainLoop( input_thread_t *p_input ) ...@@ -711,11 +694,14 @@ static void MainLoop( input_thread_t *p_input )
} }
var_SetBool( p_input, "intf-change", true ); var_SetBool( p_input, "intf-change", true );
i_intf_update = mdate() + INT64_C(150000); }
}
/* 150ms * 8 = ~ 1 second */ /**
if( ++i_updates % 8 == 0 ) * MainLoopStatistic
{ * It updates the globals statics
*/
static void MainLoopStatistic( input_thread_t *p_input )
{
stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats ); stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
/* Are we the thread responsible for computing global stats ? */ /* Are we the thread responsible for computing global stats ? */
if( libvlc_priv( p_input->p_libvlc )->p_stats_computer == p_input ) if( libvlc_priv( p_input->p_libvlc )->p_stats_computer == p_input )
...@@ -723,7 +709,59 @@ static void MainLoop( input_thread_t *p_input ) ...@@ -723,7 +709,59 @@ static void MainLoop( input_thread_t *p_input )
stats_ComputeGlobalStats( p_input->p_libvlc, stats_ComputeGlobalStats( p_input->p_libvlc,
p_input->p_libvlc->p_stats ); p_input->p_libvlc->p_stats );
} }
}
/**
* MainLoop
* The main input loop.
*/
static void MainLoop( input_thread_t *p_input )
{
mtime_t i_start_mdate = mdate();
int64_t i_intf_update = 0;
int i_updates = 0;
/* Start the timer */
stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
while( !p_input->b_die && !p_input->b_error && !p_input->p->input.b_eof )
{
bool b_force_update;
int i_type;
vlc_value_t val;
/* Do the read */
if( p_input->i_state != PAUSE_S )
{
MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
} }
else
{
/* Small wait */
b_force_update = false;
msleep( 10*1000 );
}
/* Handle control */
vlc_mutex_lock( &p_input->p->lock_control );
ControlReduce( p_input );
while( !ControlPopNoLock( p_input, &i_type, &val ) )
{
msg_Dbg( p_input, "control type=%d", i_type );
if( Control( p_input, i_type, val ) )
b_force_update = true;
}
vlc_mutex_unlock( &p_input->p->lock_control );
if( b_force_update || i_intf_update < mdate() )
{
MainLoopInterface( p_input );
i_intf_update = mdate() + INT64_C(150000);
}
/* 150ms * 8 = ~ 1 second */
if( ++i_updates % 8 == 0 )
MainLoopStatistic( p_input );
} }
if( !p_input->b_eof && !p_input->b_error && p_input->p->input.b_eof ) if( !p_input->b_eof && !p_input->b_error && p_input->p->input.b_eof )
......
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