Commit cadfc541 authored by Laurent Aimar's avatar Laurent Aimar

event_thread_t does not need to be an object (msw).

parent c44e1eff
...@@ -499,12 +499,6 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -499,12 +499,6 @@ static int Manage( vout_thread_t *p_vout )
p_vout->p_sys->b_on_top_change = false; p_vout->p_sys->b_on_top_change = false;
} }
/* Check if the event thread is still running */
if( !vlc_object_alive (p_vout->p_sys->p_event) )
{
return VLC_EGENERIC; /* exit */
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -607,12 +607,6 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -607,12 +607,6 @@ static int Manage( vout_thread_t *p_vout )
p_vout->p_sys->b_on_top_change = false; p_vout->p_sys->b_on_top_change = false;
} }
/* Check if the event thread is still running */
if( !vlc_object_alive (p_vout->p_sys->p_event) )
{
return VLC_EGENERIC; /* exit */
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -85,7 +85,7 @@ static void DirectXPopupMenu( event_thread_t *p_event, bool b_open ) ...@@ -85,7 +85,7 @@ static void DirectXPopupMenu( event_thread_t *p_event, bool b_open )
{ {
vlc_value_t val; vlc_value_t val;
val.b_bool = b_open; val.b_bool = b_open;
var_Set( p_event->p_libvlc, "intf-popupmenu", val ); var_Set( p_event->p_vout->p_libvlc, "intf-popupmenu", val );
} }
static int DirectXConvertKey( int i_key ); static int DirectXConvertKey( int i_key );
...@@ -98,9 +98,10 @@ static int DirectXConvertKey( int i_key ); ...@@ -98,9 +98,10 @@ static int DirectXConvertKey( int i_key );
* The main goal of this thread is to isolate the Win32 PeekMessage function * The main goal of this thread is to isolate the Win32 PeekMessage function
* because this one can block for a long time. * because this one can block for a long time.
*****************************************************************************/ *****************************************************************************/
static void* EventThread( vlc_object_t *p_this ) static void *EventThread( void *p_this )
{ {
event_thread_t *p_event = (event_thread_t *)p_this; event_thread_t *p_event = (event_thread_t *)p_this;
vout_thread_t *p_vout = p_event->p_vout;
MSG msg; MSG msg;
POINT old_mouse_pos = {0,0}, mouse_pos; POINT old_mouse_pos = {0,0}, mouse_pos;
vlc_value_t val; vlc_value_t val;
...@@ -108,18 +109,25 @@ static void* EventThread( vlc_object_t *p_this ) ...@@ -108,18 +109,25 @@ static void* EventThread( vlc_object_t *p_this )
HMODULE hkernel32; HMODULE hkernel32;
int canc = vlc_savecancel (); int canc = vlc_savecancel ();
vlc_mutex_lock( &p_event->lock );
/* Create a window for the video */ /* Create a window for the video */
/* Creating a window under Windows also initializes the thread's event /* Creating a window under Windows also initializes the thread's event
* message queue */ * message queue */
if( DirectXCreateWindow( p_event->p_vout ) ) if( DirectXCreateWindow( p_event->p_vout ) )
p_event->b_error = true;
p_event->b_ready = true;
vlc_cond_signal( &p_event->wait );
const bool b_error = p_event->b_error;
vlc_mutex_unlock( &p_event->lock );
if( b_error )
{ {
vlc_restorecancel (canc); vlc_restorecancel( canc );
return NULL; return NULL;
} }
/* Signal the creation of the window */
SetEvent( p_event->window_ready );
#ifndef UNDER_CE #ifndef UNDER_CE
/* Set power management stuff */ /* Set power management stuff */
if( (hkernel32 = GetModuleHandle( _T("KERNEL32") ) ) ) if( (hkernel32 = GetModuleHandle( _T("KERNEL32") ) ) )
...@@ -133,18 +141,30 @@ static void* EventThread( vlc_object_t *p_this ) ...@@ -133,18 +141,30 @@ static void* EventThread( vlc_object_t *p_this )
/* Prevent monitor from powering off */ /* Prevent monitor from powering off */
OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS ); OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
else else
msg_Dbg( p_event, "no support for SetThreadExecutionState()" ); msg_Dbg( p_vout, "no support for SetThreadExecutionState()" );
} }
#endif #endif
/* Main loop */ /* Main loop */
/* GetMessage will sleep if there's no message in the queue */ /* GetMessage will sleep if there's no message in the queue */
while( vlc_object_alive (p_event) && GetMessage( &msg, 0, 0, 0 ) ) for( ;; )
{
if( !GetMessage( &msg, 0, 0, 0 ) )
{ {
vlc_mutex_lock( &p_event->lock );
p_event->b_done = true;
vlc_mutex_unlock( &p_event->lock );
break;
}
/* Check if we are asked to exit */ /* Check if we are asked to exit */
if( !vlc_object_alive (p_event) ) vlc_mutex_lock( &p_event->lock );
const bool b_done = p_event->b_done;
vlc_mutex_unlock( &p_event->lock );
if( b_done )
break; break;
/* */
switch( msg.message ) switch( msg.message )
{ {
...@@ -277,7 +297,7 @@ static void* EventThread( vlc_object_t *p_this ) ...@@ -277,7 +297,7 @@ static void* EventThread( vlc_object_t *p_this )
val.i_int |= KEY_MODIFIER_ALT; val.i_int |= KEY_MODIFIER_ALT;
} }
var_Set( p_event->p_libvlc, "key-pressed", val ); var_Set( p_vout->p_libvlc, "key-pressed", val );
} }
break; break;
...@@ -305,12 +325,12 @@ static void* EventThread( vlc_object_t *p_this ) ...@@ -305,12 +325,12 @@ static void* EventThread( vlc_object_t *p_this )
val.i_int |= KEY_MODIFIER_ALT; val.i_int |= KEY_MODIFIER_ALT;
} }
var_Set( p_event->p_libvlc, "key-pressed", val ); var_Set( p_vout->p_libvlc, "key-pressed", val );
} }
break; break;
case WM_VLC_CHANGE_TEXT: case WM_VLC_CHANGE_TEXT:
var_Get( p_event->p_vout, "video-title", &val ); var_Get( p_vout, "video-title", &val );
if( !val.psz_string || !*val.psz_string ) /* Default video title */ if( !val.psz_string || !*val.psz_string ) /* Default video title */
{ {
free( val.psz_string ); free( val.psz_string );
...@@ -369,11 +389,11 @@ static void* EventThread( vlc_object_t *p_this ) ...@@ -369,11 +389,11 @@ static void* EventThread( vlc_object_t *p_this )
/* Check for WM_QUIT if we created the window */ /* Check for WM_QUIT if we created the window */
if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT ) if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT )
{ {
msg_Warn( p_event, "WM_QUIT... should not happen!!" ); msg_Warn( p_vout, "WM_QUIT... should not happen!!" );
p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */ p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */
} }
msg_Dbg( p_event, "DirectXEventThread terminating" ); msg_Dbg( p_vout, "DirectXEventThread terminating" );
DirectXCloseWindow( p_event->p_vout ); DirectXCloseWindow( p_event->p_vout );
vlc_restorecancel (canc); vlc_restorecancel (canc);
...@@ -878,7 +898,7 @@ static int DirectXConvertKey( int i_key ) ...@@ -878,7 +898,7 @@ static int DirectXConvertKey( int i_key )
return 0; return 0;
} }
int CreateEventThread( vout_thread_t *p_vout ) static event_thread_t *EventThreadCreate( vout_thread_t *p_vout )
{ {
/* Create the Vout EventThread, this thread is created by us to isolate /* Create the Vout EventThread, this thread is created by us to isolate
* the Win32 PeekMessage function calls. We want to do this because * the Win32 PeekMessage function calls. We want to do this because
...@@ -888,29 +908,81 @@ int CreateEventThread( vout_thread_t *p_vout ) ...@@ -888,29 +908,81 @@ int CreateEventThread( vout_thread_t *p_vout )
* window (because PeekMessage has to be called from the same thread which * window (because PeekMessage has to be called from the same thread which
* created the window). */ * created the window). */
msg_Dbg( p_vout, "creating Vout EventThread" ); msg_Dbg( p_vout, "creating Vout EventThread" );
event_thread_t *p_event = p_vout->p_sys->p_event = event_thread_t *p_event = malloc( sizeof(*p_event) );
vlc_object_create( p_vout, sizeof(event_thread_t) ); if( !p_event )
return NULL;
p_event->p_vout = p_vout; p_event->p_vout = p_vout;
p_event->window_ready = CreateEvent( NULL, TRUE, FALSE, NULL ); vlc_mutex_init( &p_event->lock );
if( vlc_thread_create( p_event, "Vout Events Thread", vlc_cond_init( &p_event->wait );
EventThread, 0 ) )
return p_event;
}
static void EventThreadDestroy( event_thread_t *p_event )
{
vlc_cond_destroy( &p_event->wait );
vlc_mutex_destroy( &p_event->lock );
free( p_event );
}
static int EventThreadStart( event_thread_t *p_event )
{
p_event->b_ready = false;
p_event->b_done = false;
p_event->b_error = false;
if( vlc_clone( &p_event->thread, EventThread, p_event,
VLC_THREAD_PRIORITY_LOW ) )
{ {
msg_Err( p_vout, "cannot create Vout EventThread" ); msg_Err( p_event->p_vout, "cannot create Vout EventThread" );
CloseHandle( p_event->window_ready ); return VLC_EGENERIC;
vlc_object_release( p_event );
p_vout->p_sys->p_event = NULL;
return 0;
} }
WaitForSingleObject( p_event->window_ready, INFINITE );
CloseHandle( p_event->window_ready );
if( p_event->b_error ) vlc_mutex_lock( &p_event->lock );
while( !p_event->b_ready )
vlc_cond_wait( &p_event->wait, &p_event->lock );
const bool b_error = p_event->b_error;
vlc_mutex_unlock( &p_event->lock );
if( b_error )
{ {
msg_Err( p_vout, "Vout EventThread failed" ); vlc_join( p_event->thread, NULL );
return 0; p_event->b_ready = false;
return VLC_EGENERIC;
} }
msg_Dbg( p_event->p_vout, "Vout EventThread running" );
return VLC_SUCCESS;
}
static void EventThreadStop( event_thread_t *p_event )
{
if( !p_event->b_ready )
return;
vlc_mutex_lock( &p_event->lock );
p_event->b_done = true;
vlc_mutex_unlock( &p_event->lock );
/* we need to be sure Vout EventThread won't stay stuck in
* GetMessage, so we send a fake message */
if( p_event->p_vout->p_sys->hwnd )
PostMessage( p_event->p_vout->p_sys->hwnd, WM_NULL, 0, 0);
vlc_join( p_event->thread, NULL );
p_event->b_ready = false;
}
/* */
int CreateEventThread( vout_thread_t *p_vout )
{
event_thread_t *p_event =
p_vout->p_sys->p_event = EventThreadCreate( p_vout );
if( !p_event )
return 0;
msg_Dbg( p_vout, "Vout EventThread running" ); if( EventThreadStart( p_event ) )
return 0;
return 1; return 1;
} }
...@@ -924,22 +996,12 @@ void StopEventThread( vout_thread_t *p_vout ) ...@@ -924,22 +996,12 @@ void StopEventThread( vout_thread_t *p_vout )
var_SetBool( p_vout, "fullscreen", true ); var_SetBool( p_vout, "fullscreen", true );
} }
if( p_vout->p_sys->p_event )
{
event_thread_t *p_event = p_vout->p_sys->p_event; event_thread_t *p_event = p_vout->p_sys->p_event;
if( p_event )
/* Kill Vout EventThread */
vlc_object_kill( p_event );
/* we need to be sure Vout EventThread won't stay stuck in
* GetMessage, so we send a fake message */
if( p_vout->p_sys->hwnd )
{ {
PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0); EventThreadStop( p_event );
} EventThreadDestroy( p_event );
p_vout->p_sys->p_event = NULL;
vlc_thread_join( p_event );
vlc_object_release( p_event );
} }
} }
...@@ -336,12 +336,6 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -336,12 +336,6 @@ static int Manage( vout_thread_t *p_vout )
p_vout->p_sys->b_on_top_change = false; p_vout->p_sys->b_on_top_change = false;
} }
/* Check if the event thread is still running */
if( !vlc_object_alive (p_vout->p_sys->p_event) )
{
return VLC_EGENERIC; /* exit */
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -25,12 +25,17 @@ ...@@ -25,12 +25,17 @@
/***************************************************************************** /*****************************************************************************
* event_thread_t: event thread * event_thread_t: event thread
*****************************************************************************/ *****************************************************************************/
typedef struct event_thread_t typedef struct
{ {
VLC_COMMON_MEMBERS vout_thread_t *p_vout;
vout_thread_t * p_vout; /* */
HANDLE window_ready; vlc_thread_t thread;
vlc_mutex_t lock;
vlc_cond_t wait;
bool b_ready;
bool b_done;
bool b_error;
} event_thread_t; } event_thread_t;
......
...@@ -464,12 +464,6 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -464,12 +464,6 @@ static int Manage( vout_thread_t *p_vout )
p_vout->p_sys->b_on_top_change = false; p_vout->p_sys->b_on_top_change = false;
} }
/* Check if the event thread is still running */
if( !vlc_object_alive (p_vout->p_sys->p_event) )
{
return VLC_EGENERIC; /* exit */
}
return VLC_SUCCESS; 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