Commit 7055051d authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/wxwindows/playlist.cpp: don't update the GUI from different threads!

* src/playlist/playlist.c: vout/sout garbage collection improvements.
parent 8b55f113
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* playlist.cpp : wxWindows plugin for vlc * playlist.cpp : wxWindows plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2004 VideoLAN * Copyright (C) 2000-2004 VideoLAN
* $Id: playlist.cpp,v 1.41 2004/02/16 17:14:39 zorglub Exp $ * $Id: playlist.cpp,v 1.42 2004/02/23 12:17:24 gbazin Exp $
* *
* Authors: Olivier Teulire <ipkiss@via.ecp.fr> * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* *
...@@ -88,8 +88,13 @@ enum ...@@ -88,8 +88,13 @@ enum
ListView_Event, ListView_Event,
Browse_Event, /* For export playlist */ Browse_Event, /* For export playlist */
/* custom events */
UpdateItem_Event
}; };
DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );
BEGIN_EVENT_TABLE(Playlist, wxFrame) BEGIN_EVENT_TABLE(Playlist, wxFrame)
/* Menu events */ /* Menu events */
EVT_MENU(AddFile_Event, Playlist::OnAddFile) EVT_MENU(AddFile_Event, Playlist::OnAddFile)
...@@ -143,6 +148,9 @@ BEGIN_EVENT_TABLE(Playlist, wxFrame) ...@@ -143,6 +148,9 @@ BEGIN_EVENT_TABLE(Playlist, wxFrame)
EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange) EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)
/* Custom events */
EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent)
/* Special events : we don't want to destroy the window when the user /* Special events : we don't want to destroy the window when the user
* clicks on (X) */ * clicks on (X) */
EVT_CLOSE(Playlist::OnClose) EVT_CLOSE(Playlist::OnClose)
...@@ -973,6 +981,7 @@ void Playlist::OnRandom( wxCommandEvent& event ) ...@@ -973,6 +981,7 @@ void Playlist::OnRandom( wxCommandEvent& event )
var_Set( p_playlist , "random", val); var_Set( p_playlist , "random", val);
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
} }
void Playlist::OnLoop ( wxCommandEvent& event ) void Playlist::OnLoop ( wxCommandEvent& event )
{ {
vlc_value_t val; vlc_value_t val;
...@@ -1014,6 +1023,7 @@ void Playlist::OnActivateItem( wxListEvent& event ) ...@@ -1014,6 +1023,7 @@ void Playlist::OnActivateItem( wxListEvent& event )
{ {
return; return;
} }
playlist_Goto( p_playlist, event.GetIndex() ); playlist_Goto( p_playlist, event.GetIndex() );
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
...@@ -1158,6 +1168,19 @@ void Playlist::OnPopupInfo( wxMenuEvent& event ) ...@@ -1158,6 +1168,19 @@ void Playlist::OnPopupInfo( wxMenuEvent& event )
ShowInfos( i_popup_item ); ShowInfos( i_popup_item );
} }
/*****************************************************************************
* Custom events management
*****************************************************************************/
void Playlist::OnPlaylistEvent( wxCommandEvent& event )
{
switch( event.GetId() )
{
case UpdateItem_Event:
UpdateItem( event.GetInt() );
break;
}
}
/***************************************************************************** /*****************************************************************************
* PlaylistChanged: callback triggered by the intf-change playlist variable * PlaylistChanged: callback triggered by the intf-change playlist variable
* We don't rebuild the playlist directly here because we don't want the * We don't rebuild the playlist directly here because we don't want the
...@@ -1180,12 +1203,16 @@ int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, ...@@ -1180,12 +1203,16 @@ int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param ) vlc_value_t old_val, vlc_value_t new_val, void *param )
{ {
Playlist *p_playlist_dialog = (Playlist *)param; Playlist *p_playlist_dialog = (Playlist *)param;
p_playlist_dialog->UpdateItem( old_val.i_int );
p_playlist_dialog->UpdateItem( new_val.i_int ); wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
event.SetInt( old_val.i_int );
p_playlist_dialog->AddPendingEvent( event );
event.SetInt( new_val.i_int );
p_playlist_dialog->AddPendingEvent( event );
return 0; return 0;
} }
/***************************************************************************** /*****************************************************************************
* ItemChanged: callback triggered by the item-change playlist variable * ItemChanged: callback triggered by the item-change playlist variable
*****************************************************************************/ *****************************************************************************/
...@@ -1193,11 +1220,14 @@ int ItemChanged( vlc_object_t *p_this, const char *psz_variable, ...@@ -1193,11 +1220,14 @@ int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param ) vlc_value_t old_val, vlc_value_t new_val, void *param )
{ {
Playlist *p_playlist_dialog = (Playlist *)param; Playlist *p_playlist_dialog = (Playlist *)param;
p_playlist_dialog->UpdateItem( new_val.i_int );
wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
event.SetInt( new_val.i_int );
p_playlist_dialog->AddPendingEvent( event );
return 0; return 0;
} }
/*************************************************************************** /***************************************************************************
* NewGroup Class * NewGroup Class
***************************************************************************/ ***************************************************************************/
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* wxwindows.h: private wxWindows interface description * wxwindows.h: private wxWindows interface description
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2004 VideoLAN * Copyright (C) 1999-2004 VideoLAN
* $Id: wxwindows.h,v 1.90 2004/02/22 15:03:33 gbazin Exp $ * $Id: wxwindows.h,v 1.91 2004/02/23 12:17:24 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -799,6 +799,9 @@ private: ...@@ -799,6 +799,9 @@ private:
void OnPopupInfo( wxMenuEvent& event ); void OnPopupInfo( wxMenuEvent& event );
void Rebuild(); void Rebuild();
/* Custom events */
void OnPlaylistEvent( wxCommandEvent& event );
wxTextCtrl *search_text; wxTextCtrl *search_text;
wxButton *search_button; wxButton *search_button;
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* playlist.c : Playlist management functions * playlist.c : Playlist management functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2004 VideoLAN * Copyright (C) 1999-2004 VideoLAN
* $Id: playlist.c,v 1.79 2004/01/29 17:51:08 zorglub Exp $ * $Id: playlist.c,v 1.80 2004/02/23 12:17:24 gbazin Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -162,7 +162,7 @@ void playlist_Destroy( playlist_t * p_playlist ) ...@@ -162,7 +162,7 @@ void playlist_Destroy( playlist_t * p_playlist )
* \param i_command the command to do * \param i_command the command to do
* \param i_arg the argument to the command. See playlist_command_t for details * \param i_arg the argument to the command. See playlist_command_t for details
*/ */
void playlist_Command( playlist_t * p_playlist, playlist_command_t i_command, void playlist_Command( playlist_t * p_playlist, playlist_command_t i_command,
int i_arg ) int i_arg )
{ {
vlc_value_t val; vlc_value_t val;
...@@ -262,36 +262,31 @@ void playlist_Destroy( playlist_t * p_playlist ) ...@@ -262,36 +262,31 @@ void playlist_Destroy( playlist_t * p_playlist )
} }
static void ObjectGarbageCollector( playlist_t *p_playlist, static mtime_t ObjectGarbageCollector( playlist_t *p_playlist, int i_type,
int i_type, mtime_t destroy_date )
mtime_t *pi_obj_destroyed_date )
{ {
vlc_object_t *p_obj; vlc_object_t *p_obj;
if( *pi_obj_destroyed_date > mdate() )
{
return;
}
if( *pi_obj_destroyed_date == 0 ) if( destroy_date > mdate() ) return;
if( destroy_date == 0 )
{ {
/* give a little time */ /* give a little time */
*pi_obj_destroyed_date = mdate() + I64C(300000); return mdate() + I64C(1000000);
} }
else else
{ {
while( ( p_obj = vlc_object_find( p_playlist, while( ( p_obj = vlc_object_find( p_playlist, i_type, FIND_CHILD ) ) )
i_type,
FIND_CHILD ) ) )
{ {
if( p_obj->p_parent != (vlc_object_t*)p_playlist ) if( p_obj->p_parent != (vlc_object_t*)p_playlist )
{ {
/* only first chiled (ie unused) */ /* only first child (ie unused) */
vlc_object_release( p_obj ); vlc_object_release( p_obj );
break; break;
} }
if( i_type == VLC_OBJECT_VOUT ) if( i_type == VLC_OBJECT_VOUT )
{ {
msg_Dbg( p_playlist, "vout garbage collector destroying 1 vout" ); msg_Dbg( p_playlist, "garbage collector destroying 1 vout" );
vlc_object_detach( p_obj ); vlc_object_detach( p_obj );
vlc_object_release( p_obj ); vlc_object_release( p_obj );
vout_Destroy( (vout_thread_t *)p_obj ); vout_Destroy( (vout_thread_t *)p_obj );
...@@ -302,7 +297,7 @@ static void ObjectGarbageCollector( playlist_t *p_playlist, ...@@ -302,7 +297,7 @@ static void ObjectGarbageCollector( playlist_t *p_playlist,
sout_DeleteInstance( (sout_instance_t*)p_obj ); sout_DeleteInstance( (sout_instance_t*)p_obj );
} }
} }
*pi_obj_destroyed_date = 0; return 0;
} }
} }
...@@ -382,10 +377,12 @@ static void RunThread ( playlist_t *p_playlist ) ...@@ -382,10 +377,12 @@ static void RunThread ( playlist_t *p_playlist )
else if( p_playlist->p_input->stream.control.i_status != INIT_S ) else if( p_playlist->p_input->stream.control.i_status != INIT_S )
{ {
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, i_vout_destroyed_date =
&i_vout_destroyed_date ); ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT,
ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, i_vout_destroyed_date );
&i_sout_destroyed_date ); i_vout_destroyed_date =
ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT,
i_sout_destroyed_date );
vlc_mutex_lock( &p_playlist->object_lock ); vlc_mutex_lock( &p_playlist->object_lock );
} }
} }
...@@ -403,10 +400,10 @@ static void RunThread ( playlist_t *p_playlist ) ...@@ -403,10 +400,10 @@ static void RunThread ( playlist_t *p_playlist )
else if( p_playlist->i_status == PLAYLIST_STOPPED ) else if( p_playlist->i_status == PLAYLIST_STOPPED )
{ {
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, i_sout_destroyed_date =
&i_sout_destroyed_date ); ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, mdate() );
ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, i_vout_destroyed_date =
&i_vout_destroyed_date ); ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, mdate() );
vlc_mutex_lock( &p_playlist->object_lock ); vlc_mutex_lock( &p_playlist->object_lock );
} }
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
...@@ -531,9 +528,7 @@ static void SkipItem( playlist_t *p_playlist, int i_arg ) ...@@ -531,9 +528,7 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
/* Boundary check */ /* Boundary check */
if( p_playlist->i_index >= p_playlist->i_size ) if( p_playlist->i_index >= p_playlist->i_size )
{ {
if( p_playlist->i_status == PLAYLIST_STOPPED if( p_playlist->i_status == PLAYLIST_STOPPED || b_random || b_loop )
|| b_random
|| b_loop )
{ {
p_playlist->i_index -= p_playlist->i_size p_playlist->i_index -= p_playlist->i_size
* ( p_playlist->i_index / p_playlist->i_size ); * ( p_playlist->i_index / p_playlist->i_size );
...@@ -551,8 +546,8 @@ static void SkipItem( playlist_t *p_playlist, int i_arg ) ...@@ -551,8 +546,8 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
} }
/* Check that the item is enabled */ /* Check that the item is enabled */
if( p_playlist->pp_items[p_playlist->i_index]->b_enabled == VLC_FALSE && if( p_playlist->pp_items[p_playlist->i_index]->b_enabled == VLC_FALSE &&
p_playlist->i_enabled != 0) p_playlist->i_enabled != 0)
{ {
SkipItem( p_playlist , 1 ); SkipItem( p_playlist , 1 );
} }
......
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