]> git.sesse.net Git - vlc/blob - src/osd/osd.c
Detach osdmenu object before destroying.
[vlc] / src / osd / osd.c
1 /*****************************************************************************
2  * osd.c - The OSD Menu core code.
3  *****************************************************************************
4  * Copyright (C) 2005-2007 M2X
5  * $Id$
6  *
7  * Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #include <vlc/vlc.h>
29 #include <vlc_keys.h>
30 #include <vlc_osd.h>
31 #include <vlc_image.h>
32
33 #include "libvlc.h"
34
35 #undef OSD_MENU_DEBUG
36
37 /*****************************************************************************
38  * Local prototypes
39  *****************************************************************************/
40
41 static void osd_UpdateState( osd_menu_state_t *, int, int, int, int, picture_t * );
42 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *, int );
43 static int osd_VolumeStep( vlc_object_t *, int, int );
44 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd );
45 static osd_menu_t *osd_ParserLoad( vlc_object_t *, const char * );
46 static void osd_ParserUnload( vlc_object_t *, osd_menu_t * );
47
48 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd )
49 {
50     vlc_value_t val;
51
52     var_Get( p_osd, "osd-menu-visible", &val );
53     return val.b_bool;
54 }
55
56 /*****************************************************************************
57  * Wrappers for loading and unloading osd parser modules.
58  *****************************************************************************/
59 static osd_menu_t *osd_ParserLoad( vlc_object_t *p_this, const char *psz_file )
60 {
61     osd_menu_t *p_menu;
62
63     p_menu = vlc_object_create( p_this, VLC_OBJECT_OSDMENU );
64     if( !p_menu )
65     {
66         msg_Err( p_this, "out of memory" );
67         return NULL;
68     }
69     vlc_object_attach( p_this, p_menu );
70
71     /* Stuff needed for Parser */
72     p_menu->psz_file = strdup( psz_file );
73     p_menu->p_image = image_HandlerCreate( p_this );
74     if( !p_menu->p_image || !p_menu->psz_file )
75     {
76         msg_Err( p_this, "unable to load images, aborting .." );
77         osd_ParserUnload( p_this, p_menu );
78         return NULL;
79     }
80     else
81     {
82         char *psz_type;
83         char *psz_ext = strrchr( p_menu->psz_file, '.' );
84
85         if( psz_ext && !strcmp( psz_ext, ".cfg") )
86             psz_type = "import-osd";
87         else
88             psz_type = "import-osd-xml";
89
90         p_menu->p_parser = module_Need( p_menu, "osd parser",
91                                         psz_type, VLC_TRUE );
92         if( !p_menu->p_parser )
93         {
94             osd_ParserUnload( p_this, p_menu );
95             return NULL;
96         }
97     }
98     return p_menu;
99 }
100
101 static void osd_ParserUnload( vlc_object_t *p_this, osd_menu_t *p_menu )
102 {
103     if( p_menu->p_image )
104         image_HandlerDelete( p_menu->p_image );
105     if( p_menu->psz_file )
106         free( p_menu->psz_file );
107
108     if( p_menu->p_parser )
109         module_Unneed( p_menu, p_menu->p_parser );
110
111     vlc_object_detach( p_menu );
112     vlc_object_destroy( p_menu );
113 }
114
115 /*****************************************************************************
116  * OSD menu Funtions
117  *****************************************************************************/
118 osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
119 {
120     osd_menu_t  *p_osd = NULL;
121     vlc_value_t lockval;
122     int         i_volume = 0;
123     int         i_steps = 0;
124
125     /* to be sure to avoid multiple creation */
126     var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );
127     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
128     vlc_mutex_lock( lockval.p_address );
129
130     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
131     if( p_osd == NULL )
132     {
133         vlc_value_t val;
134
135         /* Parse configuration file */
136         p_osd = osd_ParserLoad( p_this, psz_file );
137         if( !p_osd )
138             goto error;
139
140         /* Setup default button (first button) */
141         p_osd->p_state->p_visible = p_osd->p_button;
142         p_osd->p_state->p_visible->p_current_state =
143             osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );
144         p_osd->i_width  = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch;
145         p_osd->i_height = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines;
146
147         if( p_osd->p_state->p_volume )
148         {
149             /* Update the volume state images to match the current volume */
150             i_volume = config_GetInt( p_this, "volume" );
151             i_steps = osd_VolumeStep( p_this, i_volume, p_osd->p_state->p_volume->i_ranges );
152             p_osd->p_state->p_volume->p_current_state = osd_VolumeStateChange(
153                                     p_osd->p_state->p_volume->p_states, i_steps );
154         }
155         /* Initialize OSD state */
156         osd_UpdateState( p_osd->p_state, p_osd->i_x, p_osd->i_y,
157                          p_osd->i_width, p_osd->i_height, NULL );
158
159         vlc_object_yield( p_osd );
160         vlc_object_attach( p_osd, p_this->p_libvlc );
161
162         /* Signal when an update of OSD menu is needed */
163         var_Create( p_osd, "osd-menu-update", VLC_VAR_BOOL );
164         var_Create( p_osd, "osd-menu-visible", VLC_VAR_BOOL );
165
166         val.b_bool = VLC_FALSE;
167         var_Set( p_osd, "osd-menu-update", val );
168         var_Set( p_osd, "osd-menu-visible", val );
169     }
170     vlc_mutex_unlock( lockval.p_address );
171     return p_osd;
172
173 error:
174     msg_Err( p_this, "creating OSD menu object failed" );
175
176     if( p_osd->p_image )
177         image_HandlerDelete( p_osd->p_image );
178     if( p_osd->psz_file )
179         free( p_osd->psz_file );
180
181     vlc_object_detach( p_osd );
182     vlc_object_destroy( p_osd );
183     vlc_mutex_unlock( lockval.p_address );
184     return NULL;
185 }
186
187 void __osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )
188 {
189     vlc_value_t lockval;
190
191     if( !p_osd || !p_this ) return;
192
193     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
194     vlc_mutex_lock( lockval.p_address );
195
196     vlc_object_release( p_osd );
197     if( p_osd->p_internals->i_refcount > 0 )
198     {
199         vlc_mutex_unlock( lockval.p_address );
200         return;
201     }
202
203     var_Destroy( p_osd, "osd-menu-visible" );
204     var_Destroy( p_osd, "osd-menu-update" );
205
206     osd_ParserUnload( p_this, p_osd );
207     p_osd = NULL;
208     vlc_mutex_unlock( lockval.p_address );
209 }
210
211 osd_state_t *__osd_StateChange( osd_state_t *p_states, const int i_state )
212 {
213     osd_state_t *p_current = p_states;
214     osd_state_t *p_temp = NULL;
215     int i = 0;
216
217     for( i=0; p_current != NULL; i++ )
218     {
219         if( p_current->i_state == i_state )
220             return p_current;
221         p_temp = p_current->p_next;
222         p_current = p_temp;
223     }
224     return p_states;
225 }
226
227 /* The volume can be modified in another interface while the OSD Menu
228  * has not been instantiated yet. This routines updates the "volume OSD menu item"
229  * to reflect the current state of the GUI.
230  */
231 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *p_current, int i_steps )
232 {
233     osd_state_t *p_temp = NULL;
234     int i;
235
236     if( i_steps < 0 ) i_steps = 0;
237
238     for( i=0; (i < i_steps) && (p_current != NULL); i++ )
239     {
240         p_temp = p_current->p_next;
241         if( !p_temp ) return p_current;
242         p_current = p_temp;
243     }
244     return (!p_temp) ? p_current : p_temp;
245 }
246
247 /* Update the state of the OSD Menu */
248 static void osd_UpdateState( osd_menu_state_t *p_state, int i_x, int i_y,
249         int i_width, int i_height, picture_t *p_pic )
250 {
251     p_state->i_x = i_x;
252     p_state->i_y = i_y;
253     p_state->i_width = i_width;
254     p_state->i_height = i_height;
255     p_state->p_pic = p_pic;
256 }
257
258 void __osd_MenuShow( vlc_object_t *p_this )
259 {
260     osd_menu_t *p_osd = NULL;
261     osd_button_t *p_button = NULL;
262     vlc_value_t lockval;
263
264     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
265     if( p_osd == NULL )
266     {
267         msg_Err( p_this, "osd_MenuNext failed" );
268         return;
269     }
270
271     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
272     vlc_mutex_lock( lockval.p_address );
273
274 #if defined(OSD_MENU_DEBUG)
275     msg_Dbg( p_osd, "menu on" );
276 #endif
277     p_button = p_osd->p_state->p_visible;
278     if( p_button )
279     {
280         if( !p_button->b_range )
281             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_UNSELECT );
282         p_osd->p_state->p_visible = p_osd->p_button;
283
284         if( !p_osd->p_state->p_visible->b_range )
285             p_osd->p_state->p_visible->p_current_state =
286                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );
287
288         osd_UpdateState( p_osd->p_state,
289                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
290                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,
291                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,
292                 p_osd->p_state->p_visible->p_current_state->p_pic );
293         osd_SetMenuUpdate( p_osd, VLC_TRUE );
294     }
295     osd_SetMenuVisible( p_osd, VLC_TRUE );
296
297     vlc_object_release( (vlc_object_t*) p_osd );
298     vlc_mutex_unlock( lockval.p_address );
299 }
300
301 void __osd_MenuHide( vlc_object_t *p_this )
302 {
303     osd_menu_t *p_osd = NULL;
304     vlc_value_t lockval;
305
306     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
307     if( p_osd == NULL )
308     {
309         msg_Err( p_this, "osd_MenuNext failed" );
310         return;
311     }
312
313     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
314     vlc_mutex_lock( lockval.p_address );
315
316 #if defined(OSD_MENU_DEBUG)
317     msg_Dbg( p_osd, "menu off" );
318 #endif
319     osd_UpdateState( p_osd->p_state,
320                 p_osd->p_state->i_x, p_osd->p_state->i_y,
321                 0, 0, NULL );
322     osd_SetMenuUpdate( p_osd, VLC_TRUE );
323
324     vlc_object_release( (vlc_object_t*) p_osd );
325     vlc_mutex_unlock( lockval.p_address );
326 }
327
328 void __osd_MenuActivate( vlc_object_t *p_this )
329 {
330     osd_menu_t *p_osd = NULL;
331     osd_button_t *p_button = NULL;
332     vlc_value_t lockval;
333
334     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
335     if( p_osd == NULL )
336     {
337         msg_Err( p_this, "osd_MenuNext failed" );
338         return;
339     }
340
341     if( osd_isVisible( p_osd ) == VLC_FALSE )
342     {
343         vlc_object_release( (vlc_object_t*) p_osd );
344         return;
345     }
346
347     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
348     vlc_mutex_lock( lockval.p_address );
349
350 #if defined(OSD_MENU_DEBUG)
351     msg_Dbg( p_osd, "select" );
352 #endif
353     p_button = p_osd->p_state->p_visible;
354     /*
355      * Is there a menu item above or below? If so, then select it.
356      */
357     if( p_button && p_button->p_up )
358     {
359         vlc_object_release( (vlc_object_t*) p_osd );
360         vlc_mutex_unlock( lockval.p_address );
361         __osd_MenuUp( p_this );   /* "menu select" means go to menu item above. */
362         return;
363     }
364     if( p_button && p_button->p_down )
365     {
366         vlc_object_release( (vlc_object_t*) p_osd );
367         vlc_mutex_unlock( lockval.p_address );
368         __osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */
369         return;
370     }
371
372     if( p_button && !p_button->b_range )
373     {
374         p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_PRESSED );
375         osd_UpdateState( p_osd->p_state,
376                 p_button->i_x, p_button->i_y,
377                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,
378                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,
379                 p_button->p_current_state->p_pic );
380         osd_SetMenuUpdate( p_osd, VLC_TRUE );
381         osd_SetMenuVisible( p_osd, VLC_TRUE );
382         osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt( p_osd, p_button->psz_action ) );
383 #if defined(OSD_MENU_DEBUG)
384         msg_Dbg( p_osd, "select (%d, %s)", config_GetInt( p_osd, p_button->psz_action ), p_button->psz_action );
385 #endif
386     }
387     vlc_object_release( (vlc_object_t*) p_osd );
388     vlc_mutex_unlock( lockval.p_address );
389 }
390
391 void __osd_MenuNext( vlc_object_t *p_this )
392 {
393     osd_menu_t *p_osd = NULL;
394     osd_button_t *p_button = NULL;
395     vlc_value_t lockval;
396
397     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
398     if( p_osd == NULL )
399     {
400         msg_Err( p_this, "osd_MenuNext failed" );
401         return;
402     }
403
404     if( osd_isVisible( p_osd ) == VLC_FALSE )
405     {
406         vlc_object_release( (vlc_object_t*) p_osd );
407         return;
408     }
409
410     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
411     vlc_mutex_lock( lockval.p_address );
412
413     p_button = p_osd->p_state->p_visible;
414     if( p_button )
415     {
416         if( !p_button->b_range )
417             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_UNSELECT );
418         if( p_button->p_next )
419             p_osd->p_state->p_visible = p_button->p_next;
420         else
421             p_osd->p_state->p_visible = p_osd->p_button;
422
423         if( !p_osd->p_state->p_visible->b_range )
424             p_osd->p_state->p_visible->p_current_state =
425                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );
426
427         osd_UpdateState( p_osd->p_state,
428                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
429                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,
430                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,
431                 p_osd->p_state->p_visible->p_current_state->p_pic );
432         osd_SetMenuUpdate( p_osd, VLC_TRUE );
433     }
434 #if defined(OSD_MENU_DEBUG)
435     msg_Dbg( p_osd, "direction right [button %s]", p_osd->p_state->p_visible->psz_action );
436 #endif
437
438     vlc_object_release( (vlc_object_t*) p_osd );
439     vlc_mutex_unlock( lockval.p_address );
440 }
441
442 void __osd_MenuPrev( vlc_object_t *p_this )
443 {
444     osd_menu_t *p_osd = NULL;
445     osd_button_t *p_button = NULL;
446     vlc_value_t lockval;
447
448     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
449     if( p_osd == NULL )
450     {
451         msg_Err( p_this, "osd_MenuPrev failed" );
452         return;
453     }
454
455     if( osd_isVisible( p_osd ) == VLC_FALSE )
456     {
457         vlc_object_release( (vlc_object_t*) p_osd );
458         return;
459     }
460
461     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
462     vlc_mutex_lock( lockval.p_address );
463
464     p_button = p_osd->p_state->p_visible;
465     if( p_button )
466     {
467         if( !p_button->b_range )
468             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_UNSELECT );
469         if( p_button->p_prev )
470             p_osd->p_state->p_visible = p_button->p_prev;
471         else
472             p_osd->p_state->p_visible = p_osd->p_last_button;
473
474         if( !p_osd->p_state->p_visible->b_range )
475             p_osd->p_state->p_visible->p_current_state =
476                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );
477
478         osd_UpdateState( p_osd->p_state,
479                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
480                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,
481                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,
482                 p_osd->p_state->p_visible->p_current_state->p_pic );
483         osd_SetMenuUpdate( p_osd, VLC_TRUE );
484     }
485 #if defined(OSD_MENU_DEBUG)
486     msg_Dbg( p_osd, "direction left [button %s]", p_osd->p_state->p_visible->psz_action );
487 #endif
488
489     vlc_object_release( (vlc_object_t*) p_osd );
490     vlc_mutex_unlock( lockval.p_address );
491 }
492
493 void __osd_MenuUp( vlc_object_t *p_this )
494 {
495     osd_menu_t *p_osd = NULL;
496     osd_button_t *p_button = NULL;
497     vlc_value_t lockval;
498 #if defined(OSD_MENU_DEBUG)
499     vlc_value_t val;
500 #endif
501     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
502     if( p_osd == NULL )
503     {
504         msg_Err( p_this, "osd_MenuDown failed" );
505         return;
506     }
507
508     if( osd_isVisible( p_osd ) == VLC_FALSE )
509     {
510         vlc_object_release( (vlc_object_t*) p_osd );
511         return;
512     }
513
514     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
515     vlc_mutex_lock( lockval.p_address );
516
517     p_button = p_osd->p_state->p_visible;
518     if( p_button )
519     {
520         if( !p_button->b_range )
521         {
522             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_SELECT );
523             if( p_button->p_up )
524                 p_osd->p_state->p_visible = p_button->p_up;
525         }
526
527         if( p_button->b_range && p_osd->p_state->p_visible->b_range )
528         {
529             osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
530             if( p_temp && p_temp->p_next )
531                 p_osd->p_state->p_visible->p_current_state = p_temp->p_next;
532         }
533         else if( !p_osd->p_state->p_visible->b_range )
534         {
535             p_osd->p_state->p_visible->p_current_state =
536                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );
537         }
538
539         osd_UpdateState( p_osd->p_state,
540                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
541                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,
542                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,
543                 p_osd->p_state->p_visible->p_current_state->p_pic );
544         osd_SetMenuUpdate( p_osd, VLC_TRUE );
545         /* If this is a range style action with associated images of only one state,
546             * then perform "menu select" on every menu navigation
547             */
548         if( p_button->b_range )
549         {
550             osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action) );
551 #if defined(OSD_MENU_DEBUG)
552             msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action );
553 #endif
554         }
555     }
556 #if defined(OSD_MENU_DEBUG)
557     msg_Dbg( p_osd, "direction up [button %s]", p_osd->p_state->p_visible->psz_action );
558 #endif
559
560     vlc_object_release( (vlc_object_t*) p_osd );
561     vlc_mutex_unlock( lockval.p_address );
562 }
563
564 void __osd_MenuDown( vlc_object_t *p_this )
565 {
566     osd_menu_t *p_osd = NULL;
567     osd_button_t *p_button = NULL;
568     vlc_value_t lockval;
569 #if defined(OSD_MENU_DEBUG)
570     vlc_value_t val;
571 #endif
572
573     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
574     if( p_osd == NULL )
575     {
576         msg_Err( p_this, "osd_MenuDown failed" );
577         return;
578     }
579
580     if( osd_isVisible( p_osd ) == VLC_FALSE )
581     {
582         vlc_object_release( (vlc_object_t*) p_osd );
583         return;
584     }
585
586     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
587     vlc_mutex_lock( lockval.p_address );
588
589     p_button = p_osd->p_state->p_visible;
590     if( p_button )
591     {
592         if( !p_button->b_range )
593         {
594             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_SELECT );
595             if( p_button->p_down )
596                 p_osd->p_state->p_visible = p_button->p_down;
597         }
598
599         if( p_button->b_range && p_osd->p_state->p_visible->b_range )
600         {
601             osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
602             if( p_temp && p_temp->p_prev )
603                 p_osd->p_state->p_visible->p_current_state = p_temp->p_prev;
604         }
605         else if( !p_osd->p_state->p_visible->b_range )
606         {
607             p_osd->p_state->p_visible->p_current_state =
608                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );
609         }
610
611         osd_UpdateState( p_osd->p_state,
612                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
613                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,
614                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,
615                 p_osd->p_state->p_visible->p_current_state->p_pic );
616         osd_SetMenuUpdate( p_osd, VLC_TRUE );
617         /* If this is a range style action with associated images of only one state,
618          * then perform "menu select" on every menu navigation
619          */
620         if( p_button->b_range )
621         {
622             osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action_down) );
623 #if defined(OSD_MENU_DEBUG)
624             msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action_down );
625 #endif
626         }
627     }
628 #if defined(OSD_MENU_DEBUG)
629     msg_Dbg( p_osd, "direction down [button %s]", p_osd->p_state->p_visible->psz_action );
630 #endif
631
632     vlc_object_release( (vlc_object_t*) p_osd );
633     vlc_mutex_unlock( lockval.p_address );
634 }
635
636 static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )
637 {
638     int i_volume_step = 0;
639     (void)i_steps;
640
641     i_volume_step = config_GetInt( p_this->p_libvlc, "volume-step" );
642     return (i_volume/i_volume_step);
643 }
644
645 /**
646  * Display current audio volume bitmap
647  *
648  * The OSD Menu audio volume bar is updated to reflect the new audio volume. Call this function
649  * when the audio volume is updated outside the OSD menu command "menu up", "menu down" or "menu select".
650  */
651 void __osd_Volume( vlc_object_t *p_this )
652 {
653     osd_menu_t *p_osd = NULL;
654     osd_button_t *p_button = NULL;
655     vlc_value_t lockval;
656     int i_volume = 0;
657     int i_steps = 0;
658
659     p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
660     if( p_osd == NULL )
661     {
662         msg_Err( p_this, "OSD menu volume update failed" );
663         return;
664     }
665
666     if( p_osd->p_state && p_osd->p_state->p_volume )
667     {
668         var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
669         vlc_mutex_lock( lockval.p_address );
670
671         p_button = p_osd->p_state->p_volume;
672         if( p_osd->p_state->p_volume )
673             p_osd->p_state->p_visible = p_osd->p_state->p_volume;
674         if( p_button && p_button->b_range )
675         {
676             /* Update the volume state images to match the current volume */
677             i_volume = config_GetInt( p_this, "volume" );
678             i_steps = osd_VolumeStep( p_this, i_volume, p_button->i_ranges );
679             p_button->p_current_state = osd_VolumeStateChange( p_button->p_states, i_steps );
680
681             osd_UpdateState( p_osd->p_state,
682                     p_button->i_x, p_button->i_y,
683                     p_button->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,
684                     p_button->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,
685                     p_button->p_current_state->p_pic );
686             osd_SetMenuUpdate( p_osd, VLC_TRUE );
687             osd_SetMenuVisible( p_osd, VLC_TRUE );
688         }
689         vlc_object_release( (vlc_object_t*) p_osd );
690         vlc_mutex_unlock( lockval.p_address );
691     }
692 }