Commit d2ce7fe9 authored by Laurent Aimar's avatar Laurent Aimar

Simplify a bit main playlist loop.

parent baae4f74
...@@ -86,9 +86,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent ) ...@@ -86,9 +86,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
pl_priv(p_playlist)->i_last_playlist_id = 0; pl_priv(p_playlist)->i_last_playlist_id = 0;
pl_priv(p_playlist)->p_input = NULL; pl_priv(p_playlist)->p_input = NULL;
pl_priv(p_playlist)->gc_date = 0;
pl_priv(p_playlist)->b_cant_sleep = false;
ARRAY_INIT( p_playlist->items ); ARRAY_INIT( p_playlist->items );
ARRAY_INIT( p_playlist->all_items ); ARRAY_INIT( p_playlist->all_items );
ARRAY_INIT( pl_priv(p_playlist)->items_to_delete ); ARRAY_INIT( pl_priv(p_playlist)->items_to_delete );
...@@ -184,23 +181,6 @@ static void playlist_Destructor( vlc_object_t * p_this ) ...@@ -184,23 +181,6 @@ static void playlist_Destructor( vlc_object_t * p_this )
msg_Err( p_this, "Destroyed" ); msg_Err( p_this, "Destroyed" );
} }
/* Destroy remaining objects */
static void ObjectGarbageCollector( playlist_t *p_playlist, bool b_force )
{
if( !b_force )
{
if( mdate() - pl_priv(p_playlist)->gc_date < 1000000 )
{
pl_priv(p_playlist)->b_cant_sleep = true;
return;
}
else if( pl_priv(p_playlist)->gc_date == 0 )
return;
}
pl_priv(p_playlist)->b_cant_sleep = false;
}
/* Input Callback */ /* Input Callback */
static int InputEvent( vlc_object_t *p_this, char const *psz_cmd, static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
...@@ -214,9 +194,6 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd, ...@@ -214,9 +194,6 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
PL_LOCK; PL_LOCK;
if( newval.i_int == INPUT_EVENT_ES )
pl_priv(p_playlist)->gc_date = mdate();
vlc_object_signal_unlocked( p_playlist ); vlc_object_signal_unlocked( p_playlist );
PL_UNLOCK; PL_UNLOCK;
...@@ -331,7 +308,6 @@ void set_current_status_node( playlist_t * p_playlist, ...@@ -331,7 +308,6 @@ void set_current_status_node( playlist_t * p_playlist,
*/ */
void playlist_MainLoop( playlist_t *p_playlist ) void playlist_MainLoop( playlist_t *p_playlist )
{ {
playlist_item_t *p_item = NULL;
bool b_playexit = var_GetBool( p_playlist, "play-and-exit" ); bool b_playexit = var_GetBool( p_playlist, "play-and-exit" );
PL_ASSERT_LOCKED; PL_ASSERT_LOCKED;
...@@ -348,23 +324,21 @@ check_input: ...@@ -348,23 +324,21 @@ check_input:
/* If there is an input, check that it doesn't need to die. */ /* If there is an input, check that it doesn't need to die. */
if( pl_priv(p_playlist)->p_input ) if( pl_priv(p_playlist)->p_input )
{ {
if( pl_priv(p_playlist)->request.b_request && !pl_priv(p_playlist)->p_input->b_die ) input_thread_t *p_input = pl_priv(p_playlist)->p_input;
if( pl_priv(p_playlist)->request.b_request && !p_input->b_die )
{ {
PL_DEBUG( "incoming request - stopping current input" ); PL_DEBUG( "incoming request - stopping current input" );
input_StopThread( pl_priv(p_playlist)->p_input ); input_StopThread( p_input );
} }
/* This input is dead. Remove it ! */ /* This input is dead. Remove it ! */
if( pl_priv(p_playlist)->p_input->b_dead ) if( p_input->b_dead )
{ {
int i_activity;
input_thread_t *p_input;
sout_instance_t **pp_sout = &pl_priv(p_playlist)->p_sout; sout_instance_t **pp_sout = &pl_priv(p_playlist)->p_sout;
PL_DEBUG( "dead input" ); PL_DEBUG( "dead input" );
p_input = pl_priv(p_playlist)->p_input;
assert( *pp_sout == NULL ); assert( *pp_sout == NULL );
if( var_CreateGetBool( p_input, "sout-keep" ) ) if( var_CreateGetBool( p_input, "sout-keep" ) )
*pp_sout = input_DetachSout( p_input ); *pp_sout = input_DetachSout( p_input );
...@@ -372,17 +346,13 @@ check_input: ...@@ -372,17 +346,13 @@ check_input:
/* Destroy input */ /* Destroy input */
playlist_release_current_input( p_playlist ); playlist_release_current_input( p_playlist );
pl_priv(p_playlist)->gc_date = mdate(); int i_activity= var_GetInteger( p_playlist, "activity" );
pl_priv(p_playlist)->b_cant_sleep = true; var_SetInteger( p_playlist, "activity",
i_activity - DEFAULT_INPUT_ACTIVITY );
i_activity= var_GetInteger( p_playlist, "activity" );
var_SetInteger( p_playlist, "activity", i_activity -
DEFAULT_INPUT_ACTIVITY );
goto check_input; goto check_input;
} }
/* This input is dying, let it do */ /* This input is dying, let it do */
else if( pl_priv(p_playlist)->p_input->b_die ) else if( p_input->b_die )
{ {
PL_DEBUG( "dying input" ); PL_DEBUG( "dying input" );
PL_UNLOCK; PL_UNLOCK;
...@@ -391,18 +361,13 @@ check_input: ...@@ -391,18 +361,13 @@ check_input:
goto check_input; goto check_input;
} }
/* This input has finished, ask it to die ! */ /* This input has finished, ask it to die ! */
else if( pl_priv(p_playlist)->p_input->b_error else if( p_input->b_error || p_input->b_eof )
|| pl_priv(p_playlist)->p_input->b_eof )
{ {
PL_DEBUG( "finished input" ); PL_DEBUG( "finished input" );
input_StopThread( pl_priv(p_playlist)->p_input ); input_StopThread( p_input );
/* No need to wait here, we'll wait in the p_input->b_die case */ /* No need to wait here, we'll wait in the p_input->b_die case */
goto check_input; goto check_input;
} }
else if( pl_priv(p_playlist)->p_input->i_state != INIT_S )
{
ObjectGarbageCollector( p_playlist, false );
}
} }
else else
{ {
...@@ -417,7 +382,7 @@ check_input: ...@@ -417,7 +382,7 @@ check_input:
if( i_status != PLAYLIST_STOPPED ) if( i_status != PLAYLIST_STOPPED )
{ {
msg_Dbg( p_playlist, "starting new item" ); msg_Dbg( p_playlist, "starting new item" );
p_item = playlist_NextItem( p_playlist ); playlist_item_t *p_item = playlist_NextItem( p_playlist );
if( p_item == NULL ) if( p_item == NULL )
{ {
...@@ -429,7 +394,6 @@ check_input: ...@@ -429,7 +394,6 @@ check_input:
msg_Info( p_playlist, "end of playlist, exiting" ); msg_Info( p_playlist, "end of playlist, exiting" );
vlc_object_kill( p_playlist->p_libvlc ); vlc_object_kill( p_playlist->p_libvlc );
} }
ObjectGarbageCollector( p_playlist, true );
return; return;
} }
playlist_PlayItem( p_playlist, p_item ); playlist_PlayItem( p_playlist, p_item );
...@@ -438,64 +402,8 @@ check_input: ...@@ -438,64 +402,8 @@ check_input:
} }
else else
{ {
const bool b_gc_forced = pl_priv(p_playlist)->status.i_status != PLAYLIST_STOPPED;
pl_priv(p_playlist)->status.i_status = PLAYLIST_STOPPED; pl_priv(p_playlist)->status.i_status = PLAYLIST_STOPPED;
/* Collect garbage */
ObjectGarbageCollector( p_playlist, b_gc_forced );
}
}
}
/**
* Last loop
*
* The playlist is dying so do the last loop
* \param p_playlist the playlist object
* \return nothing
*/
void playlist_LastLoop( playlist_t *p_playlist )
{
/* If there is an input, kill it */
while( 1 )
{
PL_LOCK;
if( pl_priv(p_playlist)->p_input == NULL )
{
PL_UNLOCK;
break;
}
if( pl_priv(p_playlist)->p_input->b_dead )
{
/* remove input */
playlist_release_current_input( p_playlist );
/* sout-keep: no need to anything here.
* The last input will destroy its sout, if any, by itself */
PL_UNLOCK;
continue;
}
else if( pl_priv(p_playlist)->p_input->b_die )
{
/* This input is dying, leave it alone */
;
}
else if( pl_priv(p_playlist)->p_input->b_error || pl_priv(p_playlist)->p_input->b_eof )
{
input_StopThread( pl_priv(p_playlist)->p_input );
PL_UNLOCK;
continue;
} }
else
{
pl_priv(p_playlist)->p_input->b_eof = 1;
}
PL_UNLOCK;
msleep( INTF_IDLE_SLEEP );
} }
} }
...@@ -540,6 +448,7 @@ static void VariablesInit( playlist_t *p_playlist ) ...@@ -540,6 +448,7 @@ static void VariablesInit( playlist_t *p_playlist )
int playlist_CurrentId( playlist_t * p_playlist ) int playlist_CurrentId( playlist_t * p_playlist )
{ {
return pl_priv(p_playlist)->status.p_item->i_id; return pl_priv(p_playlist)->status.p_item->i_id;
} }
bool playlist_IsPlaying( playlist_t * p_playlist ) bool playlist_IsPlaying( playlist_t * p_playlist )
......
...@@ -85,8 +85,6 @@ typedef struct playlist_private_t ...@@ -85,8 +85,6 @@ typedef struct playlist_private_t
bool b_tree; /**< Display as a tree */ bool b_tree; /**< Display as a tree */
bool b_doing_ml; /**< Doing media library stuff get quicker */ bool b_doing_ml; /**< Doing media library stuff get quicker */
bool b_auto_preparse; bool b_auto_preparse;
bool b_cant_sleep;
mtime_t gc_date;
mtime_t last_rebuild_date; mtime_t last_rebuild_date;
bool b_reset_currently_playing; /** Reset current item array */ bool b_reset_currently_playing; /** Reset current item array */
int i_last_playlist_id; /**< Last id to an item */ int i_last_playlist_id; /**< Last id to an item */
...@@ -112,9 +110,6 @@ playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist, ...@@ -112,9 +110,6 @@ playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist,
/* Engine */ /* Engine */
void playlist_MainLoop( playlist_t * ); void playlist_MainLoop( playlist_t * );
void playlist_LastLoop( playlist_t * );
void *playlist_PreparseLoop( void * );
void *playlist_FetcherLoop( void * );
void ResetCurrentlyPlaying( playlist_t *, bool, playlist_item_t * ); void ResetCurrentlyPlaying( playlist_t *, bool, playlist_item_t * );
......
...@@ -143,26 +143,14 @@ static void* RunControlThread ( vlc_object_t *p_this ) ...@@ -143,26 +143,14 @@ static void* RunControlThread ( vlc_object_t *p_this )
/* The playlist lock has been unlocked, so we can't tell if /* The playlist lock has been unlocked, so we can't tell if
* someone has killed us in the meantime. Check now. */ * someone has killed us in the meantime. Check now. */
if( !vlc_object_alive( p_playlist ) ) if( !vlc_object_alive( p_playlist ) && !pl_priv(p_playlist)->p_input )
break; break;
if( pl_priv(p_playlist)->b_cant_sleep ) vlc_object_wait( p_playlist );
{
/* 100 ms is an acceptable delay for playlist operations */
vlc_object_unlock( p_playlist );
msleep( INTF_IDLE_SLEEP*2 );
vlc_object_lock( p_playlist );
}
else
{
vlc_object_wait( p_playlist );
}
} }
vlc_object_unlock( p_playlist ); vlc_object_unlock( p_playlist );
playlist_LastLoop( p_playlist );
vlc_restorecancel (canc); vlc_restorecancel (canc);
return NULL; return NULL;
} }
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