Commit b3bfa5ad authored by Rémi Duraffort's avatar Rémi Duraffort

xosd: use a condition variable instead of a sleep.

parent 60a84269
......@@ -47,6 +47,8 @@ struct intf_sys_t
{
xosd * p_osd; /* libxosd handle */
bool b_need_update; /* Update display ? */
vlc_mutex_t lock; /* lock for the condition variable */
vlc_cond_t cond; /* condition variable to know when to update */
};
#define MAX_LINE_LENGTH 256
......@@ -59,7 +61,7 @@ static void Close ( vlc_object_t * );
static void Run ( intf_thread_t * );
static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
static int PlaylistNext ( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param );
/*****************************************************************************
......@@ -111,7 +113,7 @@ static int Open( vlc_object_t *p_this )
char *psz_font, *psz_colour;
/* Allocate instance and initialize some members */
p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
if( p_intf->p_sys == NULL )
return VLC_ENOMEM;
......@@ -146,13 +148,16 @@ static int Open( vlc_object_t *p_this )
return VLC_EGENERIC;
}
psz_colour = config_GetPsz( p_intf,"xosd-colour" );
psz_colour = config_GetPsz( p_intf, "xosd-colour" );
xosd_set_colour( p_osd, psz_colour );
xosd_set_timeout( p_osd, 3 );
free( psz_colour );
#endif
// Initialize mutex and condition variable before adding the callbacks
vlc_mutex_init( &p_intf->p_sys->lock );
vlc_cond_init( &p_intf->p_sys->cond );
// Add the callbacks
playlist_t *p_playlist = pl_Hold( p_intf );
var_AddCallback( p_playlist, "item-current", PlaylistNext, p_this );
var_AddCallback( p_playlist, "item-change", PlaylistNext, p_this );
......@@ -194,6 +199,7 @@ static int Open( vlc_object_t *p_this )
static void Close( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t *)p_this;
playlist_t *p_playlist = pl_Hold( p_intf );
var_DelCallback( p_playlist, "item-current", PlaylistNext, p_this );
var_DelCallback( p_playlist, "item-change", PlaylistNext, p_this );
......@@ -203,6 +209,8 @@ static void Close( vlc_object_t *p_this )
xosd_destroy( p_intf->p_sys->p_osd );
/* Destroy structure */
vlc_cond_destroy( &p_intf->p_sys->cond );
vlc_mutex_destroy( &p_intf->p_sys->lock );
free( p_intf->p_sys );
}
......@@ -216,26 +224,33 @@ static void Run( intf_thread_t *p_intf )
playlist_t *p_playlist;
playlist_item_t *p_item = NULL;
char *psz_display = NULL;
int cancel = vlc_savecancel();
for( ;; )
{
int canc = vlc_savecancel();
if( p_intf->p_sys->b_need_update == true )
while( true )
{
// Wait for a signal
vlc_restorecancel( cancel );
vlc_mutex_lock( &p_intf->p_sys->lock );
mutex_cleanup_push( &p_intf->p_sys->lock );
while( !p_intf->p_sys->b_need_update )
vlc_cond_wait( &p_intf->p_sys->cond, &p_intf->p_sys->lock );
p_intf->p_sys->b_need_update = false;
vlc_cleanup_run();
// Compute the signal
cancel = vlc_savecancel();
p_playlist = pl_Hold( p_intf );
PL_LOCK;
// If the playlist is empty don't do anything
if( playlist_IsEmpty( p_playlist ) )
{
PL_UNLOCK;
pl_Release( p_intf );
vlc_restorecancel( canc );
continue;
}
free( psz_display );
free( psz_display );
int i_status = playlist_Status( p_playlist );
if( i_status == PLAYLIST_STOPPED )
{
......@@ -256,7 +271,6 @@ static void Run( intf_thread_t *p_intf )
{
PL_UNLOCK;
pl_Release( p_intf );
vlc_restorecancel( canc );
continue;
}
input_item_t *p_input = p_item->p_input;
......@@ -280,22 +294,23 @@ static void Run( intf_thread_t *p_intf )
}
/* Display */
xosd_display( p_intf->p_sys->p_osd,
0, /* first line */
XOSD_string,
psz_display );
}
vlc_restorecancel( canc );
msleep( INTF_IDLE_SLEEP );
xosd_display( p_intf->p_sys->p_osd, 0, /* first line */
XOSD_string, psz_display );
}
}
static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param )
{
(void)p_this; (void)psz_variable; (void)oval; (void)nval;
intf_thread_t *p_intf = (intf_thread_t *)param;
// Send the signal using the condition variable
vlc_mutex_lock( &p_intf->p_sys->lock );
p_intf->p_sys->b_need_update = true;
vlc_cond_signal( &p_intf->p_sys->cond );
vlc_mutex_unlock( &p_intf->p_sys->lock );
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