X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Fnotify%2Fxosd.c;h=edaa72494c8f693d561614e3e62e981095b81b81;hb=f222f159c3fb5f256fb878aa900236945c41391c;hp=ee31cc592becd2758dd3c150784e99b04989d022;hpb=13ae40b0efc4f1b1ce205d9a057537047fcab3f4;p=vlc diff --git a/modules/misc/notify/xosd.c b/modules/misc/notify/xosd.c index ee31cc592b..edaa72494c 100644 --- a/modules/misc/notify/xosd.c +++ b/modules/misc/notify/xosd.c @@ -30,7 +30,7 @@ # include "config.h" #endif -#include +#include #include #include #include @@ -45,8 +45,10 @@ *****************************************************************************/ struct intf_sys_t { - xosd * p_osd; /* libxosd handle */ - bool b_need_update; /* Update display ? */ + 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 @@ -54,13 +56,13 @@ struct intf_sys_t /***************************************************************************** * Local prototypes. *****************************************************************************/ -static int Open ( vlc_object_t * ); -static void Close ( vlc_object_t * ); +static int Open ( vlc_object_t * ); +static void Close ( vlc_object_t * ); -static void Run ( intf_thread_t * ); +static void Run ( intf_thread_t * ); -static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, - vlc_value_t oval, vlc_value_t nval, void *param ); +static int PlaylistNext ( vlc_object_t *p_this, const char *psz_variable, + vlc_value_t oval, vlc_value_t nval, void *param ); /***************************************************************************** * Module descriptor @@ -83,23 +85,23 @@ static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, #define COLOUR_TEXT N_("Color") #define COLOUR_LONGTEXT N_("Color used to display text in the XOSD output.") -vlc_module_begin(); - set_category( CAT_INTERFACE ); - set_subcategory( SUBCAT_INTERFACE_CONTROL ); - set_description( N_("XOSD interface") ); - set_shortname( "XOSD" ); - add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, true ); - add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, true ); +vlc_module_begin () + set_category( CAT_INTERFACE ) + set_subcategory( SUBCAT_INTERFACE_CONTROL ) + set_description( N_("XOSD interface") ) + set_shortname( "XOSD" ) + add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, true ) + add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, true ) add_integer( "xosd-shadow-offset", 2, NULL, - SHD_OFS_TEXT, SHD_OFS_LONGTEXT, true ); + SHD_OFS_TEXT, SHD_OFS_LONGTEXT, true ) add_string( "xosd-font", "-adobe-helvetica-bold-r-normal-*-*-160-*-*-p-*-iso8859-1", - NULL, FONT_TEXT, FONT_LONGTEXT, true ); + NULL, FONT_TEXT, FONT_LONGTEXT, true ) add_string( "xosd-colour", "LawnGreen", - NULL, COLOUR_TEXT, COLOUR_LONGTEXT, true ); - set_capability( "interface", 10 ); - set_callbacks( Open, Close ); -vlc_module_end(); + NULL, COLOUR_TEXT, COLOUR_LONGTEXT, true ) + set_capability( "interface", 10 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Open: initialize and create stuff @@ -108,30 +110,33 @@ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; xosd *p_osd; + 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 ) - { - msg_Err( p_intf, "out of memory" ); return VLC_ENOMEM; - } if( getenv( "DISPLAY" ) == NULL ) { msg_Err( p_intf, "no display, please set the DISPLAY variable" ); + free( p_intf->p_sys ); return VLC_EGENERIC; } /* Initialize library */ #if defined(HAVE_XOSD_VERSION_0) || defined(HAVE_XOSD_VERSION_1) - p_osd = p_intf->p_sys->p_osd = - xosd_init( config_GetPsz( p_intf, "xosd-font" ), - config_GetPsz( p_intf,"xosd-colour" ), 3, - XOSD_top, 0, 1 ); + psz_font = config_GetPsz( p_intf, "xosd-font" ); + psz_colour = config_GetPsz( p_intf,"xosd-colour" ); + p_osd = p_intf->p_sys->p_osd = xosd_init( psz_font, psz_colour, 3, + XOSD_top, 0, 1 ); + free( psz_font ); + free( psz_colour ); + if( p_intf->p_sys->p_osd == NULL ) { msg_Err( p_intf, "couldn't initialize libxosd" ); + free( p_intf->p_sys ); return VLC_EGENERIC; } #else @@ -139,21 +144,29 @@ static int Open( vlc_object_t *p_this ) if( p_osd == NULL ) { msg_Err( p_intf, "couldn't initialize libxosd" ); + free( p_intf->p_sys ); return VLC_EGENERIC; } - xosd_set_colour( p_osd, 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 - - playlist_t *p_playlist = pl_Yield( p_intf ); - var_AddCallback( p_playlist, "playlist-current", PlaylistNext, p_this ); + // 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 ); pl_Release( p_intf ); /* Set user preferences */ - xosd_set_font( p_intf->p_sys->p_osd, - config_GetPsz( p_intf, "xosd-font" ) ); + psz_font = config_GetPsz( p_intf, "xosd-font" ); + xosd_set_font( p_intf->p_sys->p_osd, psz_font ); + free( psz_font ); xosd_set_outline_colour( p_intf->p_sys->p_osd,"black" ); #ifdef HAVE_XOSD_VERSION_2 xosd_set_horizontal_offset( p_intf->p_sys->p_osd, @@ -186,8 +199,9 @@ 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_Yield( p_intf ); - var_DelCallback( p_playlist, "playlist-current", PlaylistNext, 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 ); pl_Release( p_intf ); @@ -195,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 ); } @@ -207,82 +223,91 @@ static void Run( intf_thread_t *p_intf ) { playlist_t *p_playlist; playlist_item_t *p_item = NULL; - input_item_t *p_input; - char psz_duration[MSTRTIME_MAX_SIZE+2]; char *psz_display = NULL; + int cancel = vlc_savecancel(); - while( !p_intf->b_die ) + while( true ) { - if( p_intf->p_sys->b_need_update == 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 ) ) { - p_intf->p_sys->b_need_update = false; - p_playlist = pl_Yield( p_intf ); + PL_UNLOCK; + pl_Release( p_intf ); + continue; + } - if( playlist_IsEmpty( p_playlist ) ) + free( psz_display ); + int i_status = playlist_Status( p_playlist ); + if( i_status == PLAYLIST_STOPPED ) + { + psz_display = strdup(_("Stop")); + PL_UNLOCK; + pl_Release( p_intf ); + } + else if( i_status == PLAYLIST_PAUSED ) + { + psz_display = strdup(_("Pause")); + PL_UNLOCK; + pl_Release( p_intf ); + } + else + { + p_item = playlist_CurrentPlayingItem( p_playlist ); + if( !p_item ) { - vlc_object_release( p_playlist ); + PL_UNLOCK; + pl_Release( p_intf ); continue; } - free( psz_display ); - psz_display = NULL; - if( p_playlist->status.i_status == PLAYLIST_STOPPED ) - { - psz_display = strdup(_("Stop")); - vlc_object_release( p_playlist ); - } - else if( p_playlist->status.i_status == PLAYLIST_PAUSED ) + input_item_t *p_input = p_item->p_input; + + mtime_t i_duration = input_item_GetDuration( p_input ); + if( i_duration != -1 ) { - psz_display = strdup(_("Pause")); - vlc_object_release( p_playlist ); + char psz_durationstr[MSTRTIME_MAX_SIZE]; + secstotimestr( psz_durationstr, i_duration / 1000000 ); + if( asprintf( &psz_display, "%s (%s)", p_input->psz_name, psz_durationstr ) == -1 ) + psz_display = NULL; } else - { - p_item = p_playlist->status.p_item; - p_input = p_item->p_input; - if( !p_item ) - { - vlc_object_release( p_playlist ); - continue; - } - - vlc_object_release( p_playlist ); - - mtime_t i_duration = input_item_GetDuration( p_input ); - if( i_duration != -1 ) - { - char psz_durationstr[MSTRTIME_MAX_SIZE]; - secstotimestr( psz_durationstr, i_duration / 1000000 ); - sprintf( psz_duration, "(%s)", psz_durationstr ); - } - else - { - sprintf( psz_duration," " ); - } - - psz_display = (char *)malloc( sizeof(char )* - (strlen( p_input->psz_name ) + - MSTRTIME_MAX_SIZE + 2+6 + 10 +10 )); - sprintf( psz_display,"%s %s", - p_input->psz_name, psz_duration); - } + psz_display = strdup( p_input->psz_name ); - /* Display */ - xosd_display( p_intf->p_sys->p_osd, - 0, /* first line */ - XOSD_string, - psz_display ); + PL_UNLOCK; + pl_Release( p_intf ); } - msleep( INTF_IDLE_SLEEP ); + /* Display */ + 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; }