]> git.sesse.net Git - vlc/blob - modules/control/hotkeys.c
* modules/control/hotkeys.c : Display simultaneously time position and slider when...
[vlc] / modules / control / hotkeys.c
1 /*****************************************************************************
2  * hotkeys.c: Hotkey handling for vlc
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28
29 #include <vlc/vlc.h>
30 #include <vlc/intf.h>
31 #include <vlc/input.h>
32 #include <vlc/vout.h>
33 #include <vlc/aout.h>
34 #include <osd.h>
35
36 #include "vlc_keys.h"
37
38 #define BUFFER_SIZE 10
39 /*****************************************************************************
40  * intf_sys_t: description and status of FB interface
41  *****************************************************************************/
42 struct intf_sys_t
43 {
44     vlc_mutex_t         change_lock;  /* mutex to keep the callback
45                                        * and the main loop from
46                                        * stepping on each others
47                                        * toes */
48     int                 p_keys[ BUFFER_SIZE ]; /* buffer that contains
49                                                 * keyevents */
50     int                 i_size;        /* number of events in buffer */
51     input_thread_t *    p_input;       /* pointer to input */
52     vout_thread_t *     p_vout;        /* pointer to vout object */
53 };
54
55 /*****************************************************************************
56  * Local prototypes
57  *****************************************************************************/
58 static int  Open    ( vlc_object_t * );
59 static void Close   ( vlc_object_t * );
60 static void Run     ( intf_thread_t * );
61 static int  GetKey  ( intf_thread_t *);
62 static int  KeyEvent( vlc_object_t *, char const *,
63                       vlc_value_t, vlc_value_t, void * );
64 static int  ActionKeyCB( vlc_object_t *, char const *,
65                          vlc_value_t, vlc_value_t, void * );
66 static void PlayBookmark( intf_thread_t *, int );
67 static void SetBookmark ( intf_thread_t *, int );
68 static int  GetPosition ( intf_thread_t * );
69 static void DisplayPosition( input_thread_t * );
70
71 /*****************************************************************************
72  * Module descriptor
73  *****************************************************************************/
74 #define BOOKMARK1_TEXT N_("Playlist bookmark 1")
75 #define BOOKMARK2_TEXT N_("Playlist bookmark 2")
76 #define BOOKMARK3_TEXT N_("Playlist bookmark 3")
77 #define BOOKMARK4_TEXT N_("Playlist bookmark 4")
78 #define BOOKMARK5_TEXT N_("Playlist bookmark 5")
79 #define BOOKMARK6_TEXT N_("Playlist bookmark 6")
80 #define BOOKMARK7_TEXT N_("Playlist bookmark 7")
81 #define BOOKMARK8_TEXT N_("Playlist bookmark 8")
82 #define BOOKMARK9_TEXT N_("Playlist bookmark 9")
83 #define BOOKMARK10_TEXT N_("Playlist bookmark 10")
84 #define BOOKMARK_LONGTEXT N_( \
85     "This option allows you to define playlist bookmarks.")
86
87 vlc_module_begin();
88     set_description( _("Hotkeys management interface") );
89     add_string( "bookmark1", NULL, NULL,
90                 BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
91     add_string( "bookmark2", NULL, NULL,
92                 BOOKMARK2_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
93     add_string( "bookmark3", NULL, NULL,
94                 BOOKMARK3_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
95     add_string( "bookmark4", NULL, NULL,
96                 BOOKMARK4_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
97     add_string( "bookmark5", NULL, NULL,
98                 BOOKMARK5_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
99     add_string( "bookmark6", NULL, NULL,
100                 BOOKMARK6_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
101     add_string( "bookmark7", NULL, NULL,
102                 BOOKMARK7_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
103     add_string( "bookmark8", NULL, NULL,
104                 BOOKMARK8_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
105     add_string( "bookmark9", NULL, NULL,
106                 BOOKMARK9_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
107     add_string( "bookmark10", NULL, NULL,
108                 BOOKMARK10_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
109
110     set_capability( "interface", 0 );
111     set_callbacks( Open, Close );
112 vlc_module_end();
113
114 /*****************************************************************************
115  * Open: initialize interface
116  *****************************************************************************/
117 static int Open( vlc_object_t *p_this )
118 {
119     intf_thread_t *p_intf = (intf_thread_t *)p_this;
120
121     /* Allocate instance and initialize some members */
122     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
123     if( p_intf->p_sys == NULL )
124     {
125         msg_Err( p_intf, "out of memory" );
126         return 1;
127     }
128     vlc_mutex_init( p_intf, &p_intf->p_sys->change_lock );
129     p_intf->p_sys->i_size = 0;
130     p_intf->pf_run = Run;
131
132     p_intf->p_sys->p_input = NULL;
133     p_intf->p_sys->p_vout = NULL;
134
135     var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
136     return 0;
137 }
138
139 /*****************************************************************************
140  * Close: destroy interface
141  *****************************************************************************/
142 static void Close( vlc_object_t *p_this )
143 {
144     intf_thread_t *p_intf = (intf_thread_t *)p_this;
145
146     if( p_intf->p_sys->p_input )
147     {
148         vlc_object_release( p_intf->p_sys->p_input );
149     }
150     if( p_intf->p_sys->p_vout )
151     {
152         vlc_object_release( p_intf->p_sys->p_vout );
153     }
154     /* Destroy structure */
155     free( p_intf->p_sys );
156 }
157
158 /*****************************************************************************
159  * Run: main loop
160  *****************************************************************************/
161 static void Run( intf_thread_t *p_intf )
162 {
163     playlist_t *p_playlist;
164     input_thread_t *p_input;
165     vout_thread_t *p_vout = NULL;
166     struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
167     vlc_value_t val;
168     int i;
169
170     /* Initialize hotkey structure */
171     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
172     {
173         var_Create( p_intf->p_vlc, p_hotkeys[i].psz_action,
174                     VLC_VAR_HOTKEY | VLC_VAR_DOINHERIT );
175
176         var_AddCallback( p_intf->p_vlc, p_hotkeys[i].psz_action,
177                          ActionKeyCB, NULL );
178         var_Get( p_intf->p_vlc, p_hotkeys[i].psz_action, &val );
179         var_Set( p_intf->p_vlc, p_hotkeys[i].psz_action, val );
180     }
181
182     while( !p_intf->b_die )
183     {
184         int i_key, i_action;
185
186         /* Sleep a bit */
187         msleep( INTF_IDLE_SLEEP );
188
189         /* Update the input */
190         if( p_intf->p_sys->p_input == NULL )
191         {
192             p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
193                                                       FIND_ANYWHERE );
194         }
195         else if( p_intf->p_sys->p_input->b_dead )
196         {
197             vlc_object_release( p_intf->p_sys->p_input );
198             p_intf->p_sys->p_input = NULL;
199         }
200         p_input = p_intf->p_sys->p_input;
201
202         /* Update the vout */
203         if( p_vout == NULL )
204         {
205             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
206             p_intf->p_sys->p_vout = p_vout;
207         }
208         else if( p_vout->b_die )
209         {
210             vlc_object_release( p_vout );
211             p_vout = NULL;
212             p_intf->p_sys->p_vout = NULL;
213         }
214
215         /* Find action triggered by hotkey */
216         i_action = 0;
217         i_key = GetKey( p_intf );
218         for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
219         {
220             if( p_hotkeys[i].i_key == i_key )
221             {
222                  i_action = p_hotkeys[i].i_action;
223             }
224         }
225
226         if( !i_action )
227         {
228             /* No key pressed, sleep a bit more */
229             msleep( INTF_IDLE_SLEEP );
230             continue;
231         }
232
233         if( i_action == ACTIONID_QUIT )
234         {
235             p_intf->p_vlc->b_die = VLC_TRUE;
236             vout_OSDMessage( p_intf, SOLO_CHAN, _( "Quit" ) );
237             continue;
238         }
239         else if( i_action == ACTIONID_VOL_UP )
240         {
241             audio_volume_t i_newvol;
242             aout_VolumeUp( p_intf, 1, &i_newvol );
243             if( p_vout )
244             {
245                 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
246                 {
247                     vout_OSDSlider( VLC_OBJECT( p_intf ), VOLUME_CHAN,
248                         i_newvol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
249                 }
250                 else
251                 {
252                     vout_OSDMessage( p_intf, VOLUME_CHAN, "Vol %d%%",
253                                      2*i_newvol*100/AOUT_VOLUME_MAX );
254                 }
255             }
256         }
257         else if( i_action == ACTIONID_VOL_DOWN )
258         {
259             audio_volume_t i_newvol;
260             aout_VolumeDown( p_intf, 1, &i_newvol );
261             if( p_vout )
262             {
263                 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
264                 {
265                     vout_OSDSlider( VLC_OBJECT( p_intf ), VOLUME_CHAN,
266                         i_newvol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
267                 }
268                 else
269                 {
270                     vout_OSDMessage( p_intf, VOLUME_CHAN, "Vol %d%%",
271                                      2*i_newvol*100/AOUT_VOLUME_MAX );
272                 }
273             }
274
275         }
276         else if( i_action == ACTIONID_VOL_MUTE )
277         {
278             audio_volume_t i_newvol = -1;
279             aout_VolumeMute( p_intf, &i_newvol );
280             if( p_vout )
281             {
282                 if( i_newvol == 0 )
283                 {
284                     vout_OSDMessage( p_intf, SOLO_CHAN, _( "Mute" ) );
285                     vout_OSDIcon( VLC_OBJECT( p_intf ), OSD_MUTE_ICON );
286                 }
287                 else
288                 {
289                     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
290                     {
291                         vout_OSDSlider( VLC_OBJECT( p_intf ), VOLUME_CHAN,
292                             i_newvol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
293                     }
294                     else
295                     {
296                         vout_OSDMessage( p_intf, VOLUME_CHAN, "Vol %d%%",
297                                          i_newvol * 100 / AOUT_VOLUME_MAX );
298                     }
299                 }
300             }
301         }
302
303         else if( i_action == ACTIONID_SUBDELAY_DOWN )
304         {
305             int i_delay;
306             if( input_Control( p_input, INPUT_GET_SUBDELAY, &i_delay ) ==
307                 VLC_SUCCESS )
308             {
309                 i_delay--;
310                 input_Control( p_input, INPUT_SET_SUBDELAY, i_delay );
311                 vout_OSDMessage( p_intf, SOLO_CHAN, "Subtitle delay %i ms",
312                                  i_delay*100);
313             }
314         }
315         else if( i_action == ACTIONID_SUBDELAY_UP )
316         {
317             int i_delay;
318             if( input_Control( p_input, INPUT_GET_SUBDELAY, &i_delay ) ==
319                 VLC_SUCCESS )
320             {
321                 i_delay++;
322                 input_Control( p_input, INPUT_SET_SUBDELAY, i_delay );
323                 vout_OSDMessage( p_intf, SOLO_CHAN, "Subtitle delay %i ms", 
324                                  i_delay*100);
325             }
326         }
327         else if( i_action == ACTIONID_FULLSCREEN && p_vout )
328         {
329             var_Get( p_vout, "fullscreen", &val );
330             var_Set( p_vout, "fullscreen", (vlc_value_t)!val.b_bool );
331         }
332         else if( i_action == ACTIONID_PLAY )
333         {
334             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
335                                           FIND_ANYWHERE );
336             if( p_playlist )
337             {
338                 playlist_Play( p_playlist );
339                 vlc_object_release( p_playlist );
340             }
341         }
342         else if( i_action == ACTIONID_PLAY_PAUSE )
343         {
344             val.i_int = PLAYING_S;
345             if( p_input )
346             {
347                 var_Get( p_input, "state", &val );
348             }
349             if( p_input && val.i_int != PAUSE_S )
350             {
351                 vout_OSDIcon( VLC_OBJECT( p_intf ), OSD_PAUSE_ICON );
352                 val.i_int = PAUSE_S;
353                 var_Set( p_input, "state", val );
354             }
355             else
356             {
357                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
358                                               FIND_ANYWHERE );
359                 if( p_playlist )
360                 {
361                     vout_OSDIcon( VLC_OBJECT( p_intf ), OSD_PLAY_ICON );
362                     playlist_Play( p_playlist );
363                     vlc_object_release( p_playlist );
364                 }
365             }
366         }
367         else if( p_input )
368         {
369             vlc_bool_t b_seekable = p_input->stream.b_seekable;
370
371             if( i_action == ACTIONID_PAUSE )
372             {
373                 vout_OSDMessage( p_intf, SOLO_CHAN, _( "Pause" ) );
374                 val.i_int = PAUSE_S;
375                 var_Set( p_input, "state", val );
376             }
377             else if( i_action == ACTIONID_JUMP_BACKWARD_10SEC && b_seekable )
378             {
379                 val.i_time = -10000000;
380                 var_Set( p_input, "time-offset", val );
381                 if( p_vout )
382                 {
383                     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
384                     {
385                         DisplayPosition( p_input );
386                         vout_OSDSlider( VLC_OBJECT( p_intf ), POSITION_CHAN,
387                                         GetPosition( p_intf ), OSD_HOR_SLIDER );
388                     }
389                     else
390                     {
391                         vout_OSDMessage( p_intf, SOLO_CHAN,
392                                          _( "Jump -10 seconds" ) );
393                     }
394                 }
395             }
396             else if( i_action == ACTIONID_JUMP_FORWARD_10SEC && b_seekable )
397             {
398                 val.i_time = 10000000;
399                 var_Set( p_input, "time-offset", val );
400                 if( p_vout )
401                 {
402                     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
403                     {
404                         DisplayPosition( p_input );
405                         vout_OSDSlider( VLC_OBJECT( p_intf ), POSITION_CHAN,
406                                         GetPosition( p_intf ), OSD_HOR_SLIDER );
407                     }
408                     else
409                     {
410                         vout_OSDMessage( p_intf, POSITION_CHAN,
411                                          _( "Jump +10 seconds" ) );
412                     }
413                 }
414             }
415             else if( i_action == ACTIONID_JUMP_BACKWARD_1MIN && b_seekable )
416             {
417                 val.i_time = -60000000;
418                 var_Set( p_input, "time-offset", val );
419                 if( p_vout )
420                 {
421                     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
422                     {
423                         DisplayPosition( p_input );
424                         vout_OSDSlider( VLC_OBJECT( p_intf ), POSITION_CHAN,
425                                         GetPosition( p_intf ), OSD_HOR_SLIDER );
426                     }
427                     else
428                     {
429                         vout_OSDMessage( p_intf, SOLO_CHAN,
430                                          _( "Jump -1 minute" ) );
431                     }
432                 }
433             }
434             else if( i_action == ACTIONID_JUMP_FORWARD_1MIN && b_seekable )
435             {
436                 val.i_time = 60000000;
437                 var_Set( p_input, "time-offset", val );
438                 if( p_vout )
439                 {
440                     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
441                     {
442                         DisplayPosition( p_input );
443                         vout_OSDSlider( VLC_OBJECT( p_intf ), POSITION_CHAN,
444                                         GetPosition( p_intf ), OSD_HOR_SLIDER );
445                     }
446                     else
447                     {
448                         vout_OSDMessage( p_intf, SOLO_CHAN,
449                                          _( "Jump +1 minute" ) );
450                     }
451                 }
452             }
453             else if( i_action == ACTIONID_JUMP_BACKWARD_5MIN && b_seekable )
454             {
455                 val.i_time = -300000000;
456                 var_Set( p_input, "time-offset", val );
457                 if( p_vout )
458                 {
459                     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
460                     {
461                         DisplayPosition( p_input );
462                         vout_OSDSlider( VLC_OBJECT( p_intf ), POSITION_CHAN,
463                                         GetPosition( p_intf ), OSD_HOR_SLIDER );
464                     }
465                     else
466                     {
467                         vout_OSDMessage( p_intf, SOLO_CHAN,
468                                          _( "Jump -5 minutes" ) );
469                     }
470                 }
471             }
472             else if( i_action == ACTIONID_JUMP_FORWARD_5MIN && b_seekable )
473             {
474                 val.i_time = 300000000;
475                 var_Set( p_input, "time-offset", val );
476                 if( p_vout )
477                 {
478                     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
479                     {
480                         DisplayPosition( p_input );
481                         vout_OSDSlider( VLC_OBJECT( p_intf ), POSITION_CHAN,
482                                         GetPosition( p_intf ), OSD_HOR_SLIDER );
483                     }
484                     else
485                     {
486                         vout_OSDMessage( p_intf, SOLO_CHAN,
487                                          _( "Jump +5 minutes" ) );
488                     }
489                 }
490             }
491             else if( i_action == ACTIONID_NEXT )
492             {
493                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
494                                               FIND_ANYWHERE );
495                 if( p_playlist )
496                 {
497                     playlist_Next( p_playlist );
498                     vlc_object_release( p_playlist );
499                 }
500             }
501             else if( i_action == ACTIONID_PREV )
502             {
503                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
504                                               FIND_ANYWHERE );
505                 if( p_playlist )
506                 {
507                     playlist_Prev( p_playlist );
508                     vlc_object_release( p_playlist );
509                 }
510             }
511             else if( i_action == ACTIONID_STOP )
512             {
513                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
514                                               FIND_ANYWHERE );
515                 if( p_playlist )
516                 {
517                     playlist_Stop( p_playlist );
518                     vlc_object_release( p_playlist );
519                 }
520             }
521             else if( i_action == ACTIONID_FASTER )
522             {
523                 vlc_value_t val; val.b_bool = VLC_TRUE;
524                 var_Set( p_input, "rate-faster", val );
525             }
526             else if( i_action == ACTIONID_SLOWER )
527             {
528                 vlc_value_t val; val.b_bool = VLC_TRUE;
529                 var_Set( p_input, "rate-slower", val );
530             }
531             else if( i_action == ACTIONID_POSITION )
532             {
533                 DisplayPosition( p_input );
534             }
535             else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
536                      i_action <= ACTIONID_PLAY_BOOKMARK10 )
537             {
538                 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
539             }
540             else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
541                      i_action <= ACTIONID_SET_BOOKMARK10 )
542             {
543                 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
544             }
545         }
546     }
547 }
548
549 static int GetKey( intf_thread_t *p_intf)
550 {
551     vlc_mutex_lock( &p_intf->p_sys->change_lock );
552     if ( p_intf->p_sys->i_size == 0 )
553     {
554         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
555         return -1;
556     }
557     else
558     {
559         int i_return = p_intf->p_sys->p_keys[ 0 ];
560         int i;
561         p_intf->p_sys->i_size--;
562         for ( i = 0; i < BUFFER_SIZE - 1; i++)
563         {
564             p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ];
565         }
566         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
567         return i_return;
568     }
569 }
570
571 /*****************************************************************************
572  * KeyEvent: callback for keyboard events
573  *****************************************************************************/
574 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
575                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
576 {
577     intf_thread_t *p_intf = (intf_thread_t *)p_data;
578     vlc_mutex_lock( &p_intf->p_sys->change_lock );
579     if ( p_intf->p_sys->i_size == BUFFER_SIZE )
580     {
581         msg_Warn( p_intf, "event buffer full, dropping keypress" );
582         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
583         return VLC_EGENERIC;
584     }
585     else
586     {
587         p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int;
588         p_intf->p_sys->i_size++;
589     }
590     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
591
592     return VLC_SUCCESS;
593 }
594
595 static int ActionKeyCB( vlc_object_t *p_this, char const *psz_var,
596                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
597 {
598     vlc_t *p_vlc = (vlc_t *)p_this;
599     struct hotkey *p_hotkeys = p_vlc->p_hotkeys;
600     int i;
601
602     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
603     {
604         if( !strcmp( p_hotkeys[i].psz_action, psz_var ) )
605         {
606             p_hotkeys[i].i_key = newval.i_int;
607         }
608     }
609
610     return VLC_SUCCESS;
611 }
612
613 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
614 {
615     vlc_value_t val;
616     int i_position;
617     char psz_bookmark_name[11];
618     playlist_t *p_playlist =
619         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
620
621     sprintf( psz_bookmark_name, "bookmark%i", i_num );
622     var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
623     var_Get( p_intf, psz_bookmark_name, &val );
624
625     if( p_playlist )
626     {
627         char *psz_bookmark = strdup( val.psz_string );
628         for( i_position = 0; i_position < p_playlist->i_size; i_position++)
629         {
630             if( !strcmp( psz_bookmark,
631                          p_playlist->pp_items[i_position]->input.psz_uri ) )
632             {
633                 playlist_Goto( p_playlist, i_position );
634                 break;
635             }
636         }
637         vlc_object_release( p_playlist );
638     }
639 }
640
641 static void SetBookmark( intf_thread_t *p_intf, int i_num )
642 {
643     vlc_value_t val;
644     playlist_t *p_playlist =
645         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
646     if( p_playlist )
647     {
648         char psz_bookmark_name[11];
649         sprintf( psz_bookmark_name, "bookmark%i", i_num );
650         var_Create( p_intf, psz_bookmark_name,
651                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
652         val.psz_string = strdup( p_playlist->pp_items[p_playlist->i_index]->input.psz_uri );
653         var_Set( p_intf, psz_bookmark_name, val );
654         msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num,
655                   val.psz_string );
656         vlc_object_release( p_playlist );
657     }
658 }
659
660 static int GetPosition( intf_thread_t *p_intf )
661 {
662     input_thread_t *p_input =
663         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
664                                                FIND_ANYWHERE );
665     if( p_input )
666     {
667         vlc_value_t pos;
668         var_Get( p_input, "position", &pos );
669         vlc_object_release( p_input );
670         return pos.f_float * 100;
671     }
672     return -1;
673 }
674
675 static void DisplayPosition( input_thread_t *p_input )
676 {
677     char psz_duration[MSTRTIME_MAX_SIZE];
678     char psz_time[MSTRTIME_MAX_SIZE];
679     vlc_value_t time;
680     mtime_t i_seconds;
681
682     var_Get( p_input, "time", &time );
683     i_seconds = time.i_time / 1000000;
684     secstotimestr ( psz_time, i_seconds );
685
686     var_Get( p_input, "length", &time );
687     if( time.i_time > 0 )
688     {
689         secstotimestr( psz_duration, time.i_time / 1000000 );
690         vout_OSDMessage( p_input, POSITION_CHAN, "%s / %s",
691                          psz_time, psz_duration );
692     }
693     else if( i_seconds > 0 )
694     {
695         vout_OSDMessage( p_input, POSITION_CHAN, psz_time );
696     }
697 }