]> git.sesse.net Git - vlc/blobdiff - src/osd/osd.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / osd / osd.c
index 1dea9bb8ba34ea593d7dc2cf1ec11cf15d3a230a..086abf8c87e3acdbc7c523189aea5e440b64ea62 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * osd.c - The OSD Menu core code.
  *****************************************************************************
- * Copyright (C) 2005-2007 M2X
+ * Copyright (C) 2005-2008 M2X
  * $Id$
  *
  * Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_keys.h>
 #include <vlc_osd.h>
 #include <vlc_image.h>
+#include <vlc_modules.h>
 
 #include "libvlc.h"
 
 #undef OSD_MENU_DEBUG
 
-#if 0
-static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };
-#endif
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -49,85 +46,72 @@ static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };
 static void osd_UpdateState( osd_menu_state_t *, int, int, int, int, picture_t * );
 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *, int );
 static int osd_VolumeStep( vlc_object_t *, int, int );
-static vlc_bool_t osd_isVisible( osd_menu_t *p_osd );
-static osd_menu_t *osd_ParserLoad( vlc_object_t *, const char * );
+static bool osd_ParserLoad( osd_menu_t *, const char * );
 static void osd_ParserUnload( osd_menu_t * );
 
-static vlc_bool_t osd_isVisible( osd_menu_t *p_osd )
+static inline bool osd_isVisible( osd_menu_t *p_osd )
 {
-    vlc_value_t val;
+    return var_GetBool( p_osd, "osd-menu-visible" );
+}
 
-    var_Get( p_osd, "osd-menu-visible", &val );
-    return val.b_bool;
+static vlc_mutex_t *osd_GetMutex( vlc_object_t *p_this )
+{
+    vlc_value_t lockval;
+
+    var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );
+    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
+    return lockval.p_address;
 }
 
 /*****************************************************************************
  * Wrappers for loading and unloading osd parser modules.
  *****************************************************************************/
-static osd_menu_t *osd_ParserLoad( vlc_object_t *p_this, const char *psz_file )
+static bool osd_ParserLoad( osd_menu_t *p_menu, const char *psz_file )
 {
-    osd_menu_t *p_menu;
-    static const char osdmenu_name[] = "osd menu";
-
-    p_menu = vlc_custom_create( p_this, sizeof( *p_menu ), VLC_OBJECT_OSDMENU,
-                                osdmenu_name );
-    if( !p_menu )
-    {
-        msg_Err( p_this, "out of memory" );
-        return NULL;
-    }
-    vlc_object_yield( p_menu );
-    vlc_object_attach( p_menu, p_this->p_libvlc );
-
     /* Stuff needed for Parser */
     p_menu->psz_file = strdup( psz_file );
-    p_menu->p_image = image_HandlerCreate( p_this );
+    p_menu->p_image = image_HandlerCreate( p_menu );
     if( !p_menu->p_image || !p_menu->psz_file )
     {
-        msg_Err( p_this, "unable to load images, aborting .." );
-        osd_ParserUnload( p_menu );
-        return NULL;
+        msg_Err( p_menu, "unable to load images, aborting .." );
+        return false;
     }
     else
     {
-        char *psz_type;
-        char *psz_ext = strrchr( p_menu->psz_file, '.' );
+        const char *psz_type;
+        const char *psz_ext = strrchr( p_menu->psz_file, '.' );
 
         if( psz_ext && !strcmp( psz_ext, ".cfg") )
-            psz_type = (char*)"import-osd";
+            psz_type = "import-osd";
         else
-            psz_type = (char*)"import-osd-xml";
+            psz_type = "import-osd-xml";
 
-        p_menu->p_parser = module_Need( p_menu, "osd parser",
-                                        psz_type, VLC_TRUE );
+        p_menu->p_parser = module_need( p_menu, "osd parser",
+                                        psz_type, true );
         if( !p_menu->p_parser )
         {
-            osd_ParserUnload( p_menu );
-            return NULL;
+            return false;
         }
     }
-    return p_menu;
+    return true;
 }
 
 static void osd_ParserUnload( osd_menu_t *p_menu )
 {
     if( p_menu->p_image )
         image_HandlerDelete( p_menu->p_image );
-    if( p_menu->psz_file )
-        free( p_menu->psz_file );
 
     if( p_menu->p_parser )
-        module_Unneed( p_menu, p_menu->p_parser );
+        module_unneed( p_menu, p_menu->p_parser );
 
-    vlc_object_detach( p_menu );
-    vlc_object_release( p_menu );
+    free( p_menu->psz_file );
 }
 
 /**
  * Change state on an osd_button_t.
  *
- * This function selects the specified state and returns a pointer to it. The
- * following states are currently supported:
+ * This function selects the specified state and returns a pointer
+ * vlc_custom_create to it. The following states are currently supported:
  * \see OSD_BUTTON_UNSELECT
  * \see OSD_BUTTON_SELECT
  * \see OSD_BUTTON_PRESSED
@@ -138,7 +122,7 @@ static osd_state_t *osd_StateChange( osd_button_t *p_button, const int i_state )
     osd_state_t *p_temp = NULL;
     int i = 0;
 
-    for( i=0; p_current != NULL; i++ )
+    for( i= 0; p_current != NULL; i++ )
     {
         if( p_current->i_state == i_state )
         {
@@ -154,29 +138,40 @@ static osd_state_t *osd_StateChange( osd_button_t *p_button, const int i_state )
     return p_button->p_states;
 }
 
+#undef osd_MenuCreate
 /*****************************************************************************
  * OSD menu Funtions
  *****************************************************************************/
-osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
+osd_menu_t *osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
 {
     osd_menu_t  *p_osd = NULL;
-    vlc_value_t lockval;
+    vlc_value_t val;
+    vlc_mutex_t *p_lock;
     int         i_volume = 0;
     int         i_steps = 0;
 
     /* to be sure to avoid multiple creation */
-    var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    p_lock = osd_GetMutex( p_this );
+    vlc_mutex_lock( p_lock );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
+    var_Create( p_this->p_libvlc, "osd-object", VLC_VAR_ADDRESS );
+    var_Get( p_this->p_libvlc, "osd-object", &val );
+    if( val.p_address == NULL )
     {
-        vlc_value_t val;
+        static const char osdmenu_name[] = "osd menu";
 
-        /* Parse configuration file */
-        p_osd = osd_ParserLoad( p_this, psz_file );
+        p_osd = vlc_custom_create( p_this, sizeof( *p_osd ),
+                                   VLC_OBJECT_GENERIC, osdmenu_name );
         if( !p_osd )
+            return NULL;
+
+        p_osd->p_parser = NULL;
+        vlc_object_attach( p_osd, p_this->p_libvlc );
+
+        /* Parse configuration file */
+        if ( !osd_ParserLoad( p_osd, psz_file ) )
+            goto error;
+        if( !p_osd->p_state )
             goto error;
 
         /* Setup default button (first button) */
@@ -202,49 +197,56 @@ osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
         var_Create( p_osd, "osd-menu-update", VLC_VAR_BOOL );
         var_Create( p_osd, "osd-menu-visible", VLC_VAR_BOOL );
 
-        val.b_bool = VLC_FALSE;
-        var_Set( p_osd, "osd-menu-update", val );
-        var_Set( p_osd, "osd-menu-visible", val );
+        var_SetBool( p_osd, "osd-menu-update", false );
+        var_SetBool( p_osd, "osd-menu-visible", false );
+
+        val.p_address = p_osd;
+        var_Set( p_this->p_libvlc, "osd-object", val );
     }
-    vlc_mutex_unlock( lockval.p_address );
+    else
+        p_osd = val.p_address;
+    vlc_object_hold( p_osd );
+    vlc_mutex_unlock( p_lock );
     return p_osd;
 
 error:
-    msg_Err( p_this, "creating OSD menu object failed" );
-
-    if( p_osd->p_image )
-        image_HandlerDelete( p_osd->p_image );
-    if( p_osd->psz_file )
-        free( p_osd->psz_file );
-
-    vlc_object_detach( p_osd );
-    vlc_object_release( p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
+    osd_MenuDelete( p_this, p_osd );
     return NULL;
 }
 
-void __osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )
+#undef osd_MenuDelete
+void osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )
 {
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock;
 
     if( !p_osd || !p_this ) return;
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    p_lock = osd_GetMutex( p_this );
+    vlc_mutex_lock( p_lock );
 
-    vlc_object_release( p_osd );
-    if( p_osd->p_internals->i_refcount > 0 )
+    if( vlc_internals( VLC_OBJECT(p_osd) )->i_refcount == 1 )
     {
-        vlc_mutex_unlock( lockval.p_address );
-        return;
+        vlc_value_t val;
+
+        var_Destroy( p_osd, "osd-menu-visible" );
+        var_Destroy( p_osd, "osd-menu-update" );
+        osd_ParserUnload( p_osd );
+        val.p_address = NULL;
+        var_Set( p_this->p_libvlc, "osd-object", val );
     }
 
-    var_Destroy( p_osd, "osd-menu-visible" );
-    var_Destroy( p_osd, "osd-menu-update" );
+    vlc_object_release( p_osd );
+    vlc_mutex_unlock( p_lock );
+}
 
-    osd_ParserUnload( p_osd );
-    p_osd = NULL;
-    vlc_mutex_unlock( lockval.p_address );
+static osd_menu_t *osd_Find( vlc_object_t *p_this )
+{
+    vlc_value_t val;
+
+    if( var_Get( p_this->p_libvlc, "osd-object", &val ) )
+        return NULL;
+    return val.p_address;
 }
 
 /* The volume can be modified in another interface while the OSD Menu
@@ -278,22 +280,22 @@ static void osd_UpdateState( osd_menu_state_t *p_state, int i_x, int i_y,
     p_state->p_pic = p_pic;
 }
 
-void __osd_MenuShow( vlc_object_t *p_this )
+#undef osd_MenuShow
+void osd_MenuShow( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
+    osd_menu_t *p_osd;
     osd_button_t *p_button = NULL;
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
+    vlc_mutex_lock( p_lock );
+    p_osd = osd_Find( p_this );
     if( p_osd == NULL )
     {
-        msg_Err( p_this, "osd_MenuNext failed" );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_MenuShow failed" );
         return;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
 #if defined(OSD_MENU_DEBUG)
     msg_Dbg( p_osd, "menu on" );
 #endif
@@ -313,63 +315,57 @@ void __osd_MenuShow( vlc_object_t *p_this )
                 p_osd->p_state->p_visible->p_current_state->i_width,
                 p_osd->p_state->p_visible->p_current_state->i_height,
                 p_osd->p_state->p_visible->p_current_state->p_pic );
-        osd_SetMenuUpdate( p_osd, VLC_TRUE );
+        osd_SetMenuUpdate( p_osd, true );
     }
-    osd_SetMenuVisible( p_osd, VLC_TRUE );
+    osd_SetMenuVisible( p_osd, true );
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }
 
-void __osd_MenuHide( vlc_object_t *p_this )
+#undef osd_MenuHide
+void osd_MenuHide( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
-    vlc_value_t lockval;
+    osd_menu_t *p_osd;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
+    vlc_mutex_lock( p_lock );
+
+    p_osd = osd_Find( p_this );
     if( p_osd == NULL )
     {
-        msg_Err( p_this, "osd_MenuNext failed" );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_MenuHide failed" );
         return;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
 #if defined(OSD_MENU_DEBUG)
     msg_Dbg( p_osd, "menu off" );
 #endif
     osd_UpdateState( p_osd->p_state,
                 p_osd->p_state->i_x, p_osd->p_state->i_y,
                 0, 0, NULL );
-    osd_SetMenuUpdate( p_osd, VLC_TRUE );
+    osd_SetMenuUpdate( p_osd, true );
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }
 
-void __osd_MenuActivate( vlc_object_t *p_this )
+#undef osd_MenuActivate
+void osd_MenuActivate( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
+    osd_menu_t *p_osd;
     osd_button_t *p_button = NULL;
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
-    {
-        msg_Err( p_this, "osd_MenuNext failed" );
-        return;
-    }
+    vlc_mutex_lock( p_lock );
 
-    if( osd_isVisible( p_osd ) == VLC_FALSE )
+    p_osd = osd_Find( p_this );
+    if( p_osd == NULL || !osd_isVisible( p_osd ) )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_MenuActivate failed" );
         return;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
 #if defined(OSD_MENU_DEBUG)
     msg_Dbg( p_osd, "select" );
 #endif
@@ -379,16 +375,14 @@ void __osd_MenuActivate( vlc_object_t *p_this )
      */
     if( p_button && p_button->p_up )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
-        vlc_mutex_unlock( lockval.p_address );
-        __osd_MenuUp( p_this );   /* "menu select" means go to menu item above. */
+        vlc_mutex_unlock( p_lock );
+        osd_MenuUp( p_this );   /* "menu select" means go to menu item above. */
         return;
     }
     if( p_button && p_button->p_down )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
-        vlc_mutex_unlock( lockval.p_address );
-        __osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */
+        vlc_mutex_unlock( p_lock );
+        osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */
         return;
     }
 
@@ -400,39 +394,36 @@ void __osd_MenuActivate( vlc_object_t *p_this )
                 p_osd->p_state->p_visible->p_current_state->i_width,
                 p_osd->p_state->p_visible->p_current_state->i_height,
                 p_button->p_current_state->p_pic );
-        osd_SetMenuUpdate( p_osd, VLC_TRUE );
-        osd_SetMenuVisible( p_osd, VLC_TRUE );
-        osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt( p_osd, p_button->psz_action ) );
+        osd_SetMenuUpdate( p_osd, true );
+        osd_SetMenuVisible( p_osd, true );
+        osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc),
+                           var_InheritInteger( p_osd, p_button->psz_action ) );
 #if defined(OSD_MENU_DEBUG)
-        msg_Dbg( p_osd, "select (%d, %s)", config_GetInt( p_osd, p_button->psz_action ), p_button->psz_action );
+        msg_Dbg( p_osd, "select (%d, %s)",
+                 (int)var_InheritInteger( p_osd, p_button->psz_action ),
+                 p_button->psz_action );
 #endif
     }
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }
 
-void __osd_MenuNext( vlc_object_t *p_this )
+#undef osd_MenuNext
+void osd_MenuNext( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
+    osd_menu_t *p_osd;
     osd_button_t *p_button = NULL;
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
-    {
-        msg_Err( p_this, "osd_MenuNext failed" );
-        return;
-    }
+    vlc_mutex_lock( p_lock );
 
-    if( osd_isVisible( p_osd ) == VLC_FALSE )
+    p_osd = osd_Find( p_this );
+    if( p_osd == NULL || !osd_isVisible( p_osd ) )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_MenuNext failed" );
         return;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
     p_button = p_osd->p_state->p_visible;
     if( p_button )
     {
@@ -452,38 +443,31 @@ void __osd_MenuNext( vlc_object_t *p_this )
                 p_osd->p_state->p_visible->p_current_state->i_width,
                 p_osd->p_state->p_visible->p_current_state->i_height,
                 p_osd->p_state->p_visible->p_current_state->p_pic );
-        osd_SetMenuUpdate( p_osd, VLC_TRUE );
+        osd_SetMenuUpdate( p_osd, true );
     }
 #if defined(OSD_MENU_DEBUG)
     msg_Dbg( p_osd, "direction right [button %s]", p_osd->p_state->p_visible->psz_action );
 #endif
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }
 
-void __osd_MenuPrev( vlc_object_t *p_this )
+#undef osd_MenuPrev
+void osd_MenuPrev( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
+    osd_menu_t *p_osd;
     osd_button_t *p_button = NULL;
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
+    vlc_mutex_lock( p_lock );
+    p_osd = osd_Find( p_this );
+    if( p_osd == NULL || !osd_isVisible( p_osd ) )
     {
+        vlc_mutex_unlock( p_lock );
         msg_Err( p_this, "osd_MenuPrev failed" );
         return;
     }
 
-    if( osd_isVisible( p_osd ) == VLC_FALSE )
-    {
-        vlc_object_release( (vlc_object_t*) p_osd );
-        return;
-    }
-
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
     p_button = p_osd->p_state->p_visible;
     if( p_button )
     {
@@ -503,40 +487,34 @@ void __osd_MenuPrev( vlc_object_t *p_this )
                 p_osd->p_state->p_visible->p_current_state->i_width,
                 p_osd->p_state->p_visible->p_current_state->i_height,
                 p_osd->p_state->p_visible->p_current_state->p_pic );
-        osd_SetMenuUpdate( p_osd, VLC_TRUE );
+        osd_SetMenuUpdate( p_osd, true );
     }
 #if defined(OSD_MENU_DEBUG)
     msg_Dbg( p_osd, "direction left [button %s]", p_osd->p_state->p_visible->psz_action );
 #endif
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }
 
-void __osd_MenuUp( vlc_object_t *p_this )
+#undef osd_MenuUp
+void osd_MenuUp( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
+    osd_menu_t *p_osd;
     osd_button_t *p_button = NULL;
-    vlc_value_t lockval;
 #if defined(OSD_MENU_DEBUG)
     vlc_value_t val;
 #endif
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
-    {
-        msg_Err( p_this, "osd_MenuDown failed" );
-        return;
-    }
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    if( osd_isVisible( p_osd ) == VLC_FALSE )
+    vlc_mutex_lock( p_lock );
+    p_osd = osd_Find( p_this );
+    if( p_osd == NULL || !osd_isVisible( p_osd ) )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_MenuActivate failed" );
         return;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
     p_button = p_osd->p_state->p_visible;
     if( p_button )
     {
@@ -564,15 +542,16 @@ void __osd_MenuUp( vlc_object_t *p_this )
                 p_osd->p_state->p_visible->p_current_state->i_width,
                 p_osd->p_state->p_visible->p_current_state->i_height,
                 p_osd->p_state->p_visible->p_current_state->p_pic );
-        osd_SetMenuUpdate( p_osd, VLC_TRUE );
+        osd_SetMenuUpdate( p_osd, true );
         /* If this is a range style action with associated images of only one state,
             * then perform "menu select" on every menu navigation
             */
         if( p_button->b_range )
         {
-            osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action) );
+            osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc),
+                               var_InheritInteger(p_osd, p_button->psz_action) );
 #if defined(OSD_MENU_DEBUG)
-            msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action );
+            msg_Dbg( p_osd, "select (%"PRId64", %s)", val.i_int, p_button->psz_action );
 #endif
         }
     }
@@ -580,35 +559,29 @@ void __osd_MenuUp( vlc_object_t *p_this )
     msg_Dbg( p_osd, "direction up [button %s]", p_osd->p_state->p_visible->psz_action );
 #endif
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }
 
-void __osd_MenuDown( vlc_object_t *p_this )
+#undef osd_MenuDown
+void osd_MenuDown( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
+    osd_menu_t *p_osd;
     osd_button_t *p_button = NULL;
-    vlc_value_t lockval;
 #if defined(OSD_MENU_DEBUG)
     vlc_value_t val;
 #endif
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
-    {
-        msg_Err( p_this, "osd_MenuDown failed" );
-        return;
-    }
+    vlc_mutex_lock( p_lock );
 
-    if( osd_isVisible( p_osd ) == VLC_FALSE )
+    p_osd = osd_Find( p_this );
+    if( p_osd == NULL || !osd_isVisible( p_osd ) )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_MenuActivate failed" );
         return;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
     p_button = p_osd->p_state->p_visible;
     if( p_button )
     {
@@ -636,15 +609,16 @@ void __osd_MenuDown( vlc_object_t *p_this )
                 p_osd->p_state->p_visible->p_current_state->i_width,
                 p_osd->p_state->p_visible->p_current_state->i_height,
                 p_osd->p_state->p_visible->p_current_state->p_pic );
-        osd_SetMenuUpdate( p_osd, VLC_TRUE );
+        osd_SetMenuUpdate( p_osd, true );
         /* If this is a range style action with associated images of only one state,
          * then perform "menu select" on every menu navigation
          */
         if( p_button->b_range )
         {
-            osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action_down) );
+            osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc),
+                               var_InheritInteger(p_osd, p_button->psz_action_down) );
 #if defined(OSD_MENU_DEBUG)
-            msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action_down );
+            msg_Dbg( p_osd, "select (%"PRId64", %s)", val.i_int, p_button->psz_action_down );
 #endif
         }
     }
@@ -652,8 +626,7 @@ void __osd_MenuDown( vlc_object_t *p_this )
     msg_Dbg( p_osd, "direction down [button %s]", p_osd->p_state->p_visible->psz_action );
 #endif
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }
 
 static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )
@@ -665,31 +638,33 @@ static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )
     return (i_volume/i_volume_step);
 }
 
+#undef osd_Volume
 /**
  * Display current audio volume bitmap
  *
  * The OSD Menu audio volume bar is updated to reflect the new audio volume. Call this function
  * when the audio volume is updated outside the OSD menu command "menu up", "menu down" or "menu select".
  */
-void __osd_Volume( vlc_object_t *p_this )
+void osd_Volume( vlc_object_t *p_this )
 {
-    osd_menu_t *p_osd = NULL;
+    osd_menu_t *p_osd;
     osd_button_t *p_button = NULL;
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
     int i_volume = 0;
     int i_steps = 0;
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
+    vlc_mutex_lock( p_lock );
+
+    p_osd = osd_Find( p_this );
     if( p_osd == NULL )
     {
+        vlc_mutex_unlock( p_lock );
         msg_Err( p_this, "OSD menu volume update failed" );
         return;
     }
 
     if( p_osd->p_state && p_osd->p_state->p_volume )
     {
-        var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-        vlc_mutex_lock( lockval.p_address );
 
         p_button = p_osd->p_state->p_volume;
         if( p_osd->p_state->p_volume )
@@ -706,38 +681,32 @@ void __osd_Volume( vlc_object_t *p_this )
                     p_button->p_current_state->i_width,
                     p_button->p_current_state->i_height,
                     p_button->p_current_state->p_pic );
-            osd_SetMenuUpdate( p_osd, VLC_TRUE );
-            osd_SetMenuVisible( p_osd, VLC_TRUE );
+            osd_SetMenuUpdate( p_osd, true );
+            osd_SetMenuVisible( p_osd, true );
         }
-        vlc_object_release( (vlc_object_t*) p_osd );
-        vlc_mutex_unlock( lockval.p_address );
     }
+    vlc_mutex_unlock( p_lock );
 }
 
-osd_button_t *__osd_ButtonFind( vlc_object_t *p_this, int i_x, int i_y,
+#undef osd_ButtonFind
+osd_button_t *osd_ButtonFind( vlc_object_t *p_this, int i_x, int i_y,
     int i_window_height, int i_window_width,
     int i_scale_width, int i_scale_height )
 {
     osd_menu_t *p_osd;
     osd_button_t *p_button;
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
-    {
-        msg_Err( p_this, "OSD menu button find failed" );
-        return NULL;
-    }
+    vlc_mutex_lock( p_lock );
 
-    if( osd_isVisible( p_osd ) == VLC_FALSE )
+    p_osd = osd_Find( p_this );
+    if( p_osd == NULL || !osd_isVisible( p_osd ) )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_ButtonFind failed" );
         return NULL;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
     p_button = p_osd->p_button;
     for( ; p_button != NULL; p_button = p_button->p_next )
     {
@@ -784,42 +753,35 @@ osd_button_t *__osd_ButtonFind( vlc_object_t *p_this, int i_x, int i_y,
         if( ( i_x >= i_x_offset ) && ( i_x <= i_x_offset + i_width ) &&
             ( i_y >= i_y_offset ) && ( i_y <= i_y_offset + i_height ) )
         {
-            vlc_object_release( (vlc_object_t*) p_osd );
-            vlc_mutex_unlock( lockval.p_address );
+            vlc_mutex_unlock( p_lock );
             return p_button;
         }
     }
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
     return NULL;
 }
 
+#undef osd_ButtonSelect
 /**
  * Select the button provided as the new active button
  */
-void __osd_ButtonSelect( vlc_object_t *p_this, osd_button_t *p_button )
+void osd_ButtonSelect( vlc_object_t *p_this, osd_button_t *p_button )
 {
     osd_menu_t *p_osd;
     osd_button_t *p_old;
-    vlc_value_t lockval;
+    vlc_mutex_t *p_lock = osd_GetMutex( p_this );
 
-    p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
-    if( p_osd == NULL )
-    {
-        msg_Err( p_this, "OSD menu button select failed" );
-        return;
-    }
+    vlc_mutex_lock( p_lock );
 
-    if( osd_isVisible( p_osd ) == VLC_FALSE )
+    p_osd = osd_Find( p_this );
+    if( p_osd == NULL || !osd_isVisible( p_osd ) )
     {
-        vlc_object_release( (vlc_object_t*) p_osd );
+        vlc_mutex_unlock( p_lock );
+        msg_Err( p_this, "osd_ButtonSelect failed" );
         return;
     }
 
-    var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-
     p_old = p_osd->p_state->p_visible;
     if( p_old )
     {
@@ -836,12 +798,11 @@ void __osd_ButtonSelect( vlc_object_t *p_this, osd_button_t *p_button )
                 p_osd->p_state->p_visible->p_current_state->i_width,
                 p_osd->p_state->p_visible->p_current_state->i_height,
                 p_osd->p_state->p_visible->p_current_state->p_pic );
-        osd_SetMenuUpdate( p_osd, VLC_TRUE );
+        osd_SetMenuUpdate( p_osd, true );
     }
 #if defined(OSD_MENU_DEBUG)
     msg_Dbg( p_osd, "button selected is [button %s]", p_osd->p_state->p_visible->psz_action );
 #endif
 
-    vlc_object_release( (vlc_object_t*) p_osd );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( p_lock );
 }