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