1 /*****************************************************************************
2 * hotkeys.c: Hotkey handling for vlc
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8 * Jean-Paul Saman <jpsaman #_at_# m2x.nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
32 #include <vlc/input.h>
39 #define BUFFER_SIZE 10
41 #define CHANNELS_NUMBER 4
42 #define VOLUME_TEXT_CHAN p_intf->p_sys->p_channels[ 0 ]
43 #define VOLUME_WIDGET_CHAN p_intf->p_sys->p_channels[ 1 ]
44 #define POSITION_TEXT_CHAN p_intf->p_sys->p_channels[ 2 ]
45 #define POSITION_WIDGET_CHAN p_intf->p_sys->p_channels[ 3 ]
46 /*****************************************************************************
47 * intf_sys_t: description and status of FB interface
48 *****************************************************************************/
51 vlc_mutex_t change_lock; /* mutex to keep the callback
52 * and the main loop from
53 * stepping on each others
55 int p_keys[ BUFFER_SIZE ]; /* buffer that contains
57 int i_size; /* number of events in buffer */
58 int p_channels[ CHANNELS_NUMBER ]; /* contains registered
60 input_thread_t * p_input; /* pointer to input */
61 vout_thread_t * p_vout; /* pointer to vout object */
64 /*****************************************************************************
66 *****************************************************************************/
67 static int Open ( vlc_object_t * );
68 static void Close ( vlc_object_t * );
69 static void Run ( intf_thread_t * );
70 static int GetKey ( intf_thread_t *);
71 static int KeyEvent( vlc_object_t *, char const *,
72 vlc_value_t, vlc_value_t, void * );
73 static int ActionKeyCB( vlc_object_t *, char const *,
74 vlc_value_t, vlc_value_t, void * );
75 static void PlayBookmark( intf_thread_t *, int );
76 static void SetBookmark ( intf_thread_t *, int );
77 static void DisplayPosition( intf_thread_t *, vout_thread_t *, input_thread_t * );
78 static void DisplayVolume ( intf_thread_t *, vout_thread_t *, audio_volume_t );
79 static void ClearChannels ( intf_thread_t *, vout_thread_t * );
81 /*****************************************************************************
83 *****************************************************************************/
84 #define BOOKMARK1_TEXT N_("Playlist bookmark 1")
85 #define BOOKMARK2_TEXT N_("Playlist bookmark 2")
86 #define BOOKMARK3_TEXT N_("Playlist bookmark 3")
87 #define BOOKMARK4_TEXT N_("Playlist bookmark 4")
88 #define BOOKMARK5_TEXT N_("Playlist bookmark 5")
89 #define BOOKMARK6_TEXT N_("Playlist bookmark 6")
90 #define BOOKMARK7_TEXT N_("Playlist bookmark 7")
91 #define BOOKMARK8_TEXT N_("Playlist bookmark 8")
92 #define BOOKMARK9_TEXT N_("Playlist bookmark 9")
93 #define BOOKMARK10_TEXT N_("Playlist bookmark 10")
94 #define BOOKMARK_LONGTEXT N_( \
95 "This option allows you to define playlist bookmarks.")
98 set_shortname( _("Hotkeys") );
99 set_description( _("Hotkeys management interface") );
100 set_category( CAT_INTERFACE );
101 // set_subcategory( SUBCAT_INTERFACE_GENERAL );
103 add_string( "bookmark1", NULL, NULL,
104 BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
105 add_string( "bookmark2", NULL, NULL,
106 BOOKMARK2_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
107 add_string( "bookmark3", NULL, NULL,
108 BOOKMARK3_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
109 add_string( "bookmark4", NULL, NULL,
110 BOOKMARK4_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
111 add_string( "bookmark5", NULL, NULL,
112 BOOKMARK5_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
113 add_string( "bookmark6", NULL, NULL,
114 BOOKMARK6_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
115 add_string( "bookmark7", NULL, NULL,
116 BOOKMARK7_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
117 add_string( "bookmark8", NULL, NULL,
118 BOOKMARK8_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
119 add_string( "bookmark9", NULL, NULL,
120 BOOKMARK9_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
121 add_string( "bookmark10", NULL, NULL,
122 BOOKMARK10_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
124 set_capability( "interface", 0 );
125 set_callbacks( Open, Close );
128 /*****************************************************************************
129 * Open: initialize interface
130 *****************************************************************************/
131 static int Open( vlc_object_t *p_this )
133 intf_thread_t *p_intf = (intf_thread_t *)p_this;
135 /* Allocate instance and initialize some members */
136 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
137 if( p_intf->p_sys == NULL )
139 msg_Err( p_intf, "out of memory" );
142 vlc_mutex_init( p_intf, &p_intf->p_sys->change_lock );
143 p_intf->p_sys->i_size = 0;
144 p_intf->pf_run = Run;
146 p_intf->p_sys->p_input = NULL;
147 p_intf->p_sys->p_vout = NULL;
149 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
153 /*****************************************************************************
154 * Close: destroy interface
155 *****************************************************************************/
156 static void Close( vlc_object_t *p_this )
158 intf_thread_t *p_intf = (intf_thread_t *)p_this;
160 var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
161 if( p_intf->p_sys->p_input )
163 vlc_object_release( p_intf->p_sys->p_input );
165 if( p_intf->p_sys->p_vout )
167 vlc_object_release( p_intf->p_sys->p_vout );
169 /* Destroy structure */
170 free( p_intf->p_sys );
173 /*****************************************************************************
175 *****************************************************************************/
176 static void Run( intf_thread_t *p_intf )
178 playlist_t *p_playlist = NULL;
179 input_thread_t *p_input = NULL;
180 vout_thread_t *p_vout = NULL;
181 vout_thread_t *p_last_vout = NULL;
182 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
186 /* Initialize hotkey structure */
187 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
189 var_Create( p_intf->p_vlc, p_hotkeys[i].psz_action,
190 VLC_VAR_HOTKEY | VLC_VAR_DOINHERIT );
192 var_AddCallback( p_intf->p_vlc, p_hotkeys[i].psz_action,
194 var_Get( p_intf->p_vlc, p_hotkeys[i].psz_action, &val );
195 var_Set( p_intf->p_vlc, p_hotkeys[i].psz_action, val );
198 while( !p_intf->b_die )
204 msleep( INTF_IDLE_SLEEP );
206 /* Update the input */
207 if( p_intf->p_sys->p_input == NULL )
209 p_playlist = (playlist_t *)vlc_object_find( p_intf,
210 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
213 p_intf->p_sys->p_input = p_playlist->p_input;
214 if( p_intf->p_sys->p_input )
215 vlc_object_yield( p_intf->p_sys->p_input );
216 vlc_object_release( p_playlist );
219 else if( p_intf->p_sys->p_input->b_dead )
221 vlc_object_release( p_intf->p_sys->p_input );
222 p_intf->p_sys->p_input = NULL;
224 p_input = p_intf->p_sys->p_input;
226 /* Update the vout */
227 p_last_vout = p_intf->p_sys->p_vout;
230 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
231 p_intf->p_sys->p_vout = p_vout;
233 else if( p_vout->b_die )
235 vlc_object_release( p_vout );
237 p_intf->p_sys->p_vout = NULL;
240 /* Register OSD channels */
241 if( p_vout && p_vout != p_last_vout )
243 for( i = 0; i < CHANNELS_NUMBER; i++ )
245 spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER,
246 &p_intf->p_sys->p_channels[ i ] );
250 /* Find action triggered by hotkey */
252 i_key = GetKey( p_intf );
253 for( i = 0; i_key != -1 && p_hotkeys[i].psz_action != NULL; i++ )
255 if( p_hotkeys[i].i_key == i_key )
257 i_action = p_hotkeys[i].i_action;
258 i_times = p_hotkeys[i].i_times; /* times key pressed within max. delta time */
259 p_hotkeys[i].i_times = 0;
265 /* No key pressed, sleep a bit more */
266 msleep( INTF_IDLE_SLEEP );
270 if( i_action == ACTIONID_QUIT )
272 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
276 playlist_Stop( p_playlist );
277 vlc_object_release( p_playlist );
279 /* Playlist is stopped now kill vlc. */
280 p_intf->p_vlc->b_die = VLC_TRUE;
281 ClearChannels( p_intf, p_vout );
282 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Quit" ) );
285 else if( i_action == ACTIONID_VOL_UP )
287 audio_volume_t i_newvol;
288 aout_VolumeUp( p_intf, 1, &i_newvol );
289 DisplayVolume( p_intf, p_vout, i_newvol );
291 else if( i_action == ACTIONID_VOL_DOWN )
293 audio_volume_t i_newvol;
294 aout_VolumeDown( p_intf, 1, &i_newvol );
295 DisplayVolume( p_intf, p_vout, i_newvol );
297 else if( i_action == ACTIONID_VOL_MUTE )
299 audio_volume_t i_newvol = -1;
300 aout_VolumeMute( p_intf, &i_newvol );
305 ClearChannels( p_intf, p_vout );
306 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
311 DisplayVolume( p_intf, p_vout, i_newvol );
315 else if( i_action == ACTIONID_INTF_SHOW )
317 val.b_bool = VLC_TRUE;
318 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
322 var_Set( p_playlist, "intf-show", val );
323 vlc_object_release( p_playlist );
326 else if( i_action == ACTIONID_INTF_HIDE )
328 val.b_bool = VLC_FALSE;
329 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
333 var_Set( p_playlist, "intf-show", val );
334 vlc_object_release( p_playlist );
337 else if( i_action == ACTIONID_SNAPSHOT )
339 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
341 else if( i_action == ACTIONID_FULLSCREEN )
345 var_Get( p_vout, "fullscreen", &val ); val.b_bool = !val.b_bool;
346 var_Set( p_vout, "fullscreen", val );
350 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
354 var_Get( p_playlist, "fullscreen", &val ); val.b_bool = !val.b_bool;
355 var_Set( p_playlist, "fullscreen", val );
356 vlc_object_release( p_playlist );
360 else if( i_action == ACTIONID_PLAY_PAUSE )
362 val.i_int = PLAYING_S;
365 var_Get( p_input, "state", &val );
367 if( p_input && val.i_int != PAUSE_S )
369 ClearChannels( p_intf, p_vout );
370 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
373 var_Set( p_input, "state", val );
377 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
381 ClearChannels( p_intf, p_vout );
382 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
384 playlist_Play( p_playlist );
385 vlc_object_release( p_playlist );
392 * How to get a valid value ?
393 * That's not that easy with some special stream
395 vlc_bool_t b_seekable = VLC_TRUE;
398 if( i_action == ACTIONID_PAUSE )
400 ClearChannels( p_intf, p_vout );
401 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
404 var_Set( p_input, "state", val );
406 else if( i_action == ACTIONID_JUMP_BACKWARD_EXTRASHORT && b_seekable )
408 #define SET_TIME( a, b ) \
409 i_interval = config_GetInt( p_input, a "-jump-size" ); \
410 if( i_interval > 0 ) { \
411 val.i_time = ( (mtime_t)(i_interval * b) * 1000000L \
412 * ((mtime_t)(1 << i_times))); \
413 var_Set( p_input, "time-offset", val ); \
414 DisplayPosition( p_intf, p_vout, p_input ); \
416 SET_TIME( "extrashort", -1 );
418 else if( i_action == ACTIONID_JUMP_FORWARD_EXTRASHORT && b_seekable )
420 SET_TIME( "extrashort", 1 );
422 else if( i_action == ACTIONID_JUMP_BACKWARD_SHORT && b_seekable )
424 SET_TIME( "short", -1 );
426 else if( i_action == ACTIONID_JUMP_FORWARD_SHORT && b_seekable )
428 SET_TIME( "short", 1 );
430 else if( i_action == ACTIONID_JUMP_BACKWARD_MEDIUM && b_seekable )
432 SET_TIME( "medium", -1 );
434 else if( i_action == ACTIONID_JUMP_FORWARD_MEDIUM && b_seekable )
436 SET_TIME( "medium", 1 );
438 else if( i_action == ACTIONID_JUMP_BACKWARD_LONG && b_seekable )
440 SET_TIME( "long", -1 );
442 else if( i_action == ACTIONID_JUMP_FORWARD_LONG && b_seekable )
444 SET_TIME( "long", 1 );
447 else if( i_action == ACTIONID_AUDIO_TRACK )
449 vlc_value_t val, list, list2;
451 var_Get( p_input, "audio-es", &val );
452 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
454 i_count = list.p_list->i_count;
459 for( i = 0; i < i_count; i++ )
461 if( val.i_int == list.p_list->p_values[i].i_int )
466 /* value of audio-es was not in choices list */
470 "invalid current audio track, selecting 0" );
471 var_Set( p_input, "audio-es",
472 list.p_list->p_values[0] );
475 else if( i == i_count - 1 )
477 var_Set( p_input, "audio-es",
478 list.p_list->p_values[1] );
483 var_Set( p_input, "audio-es",
484 list.p_list->p_values[i+1] );
487 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
488 _("Audio track: %s"),
489 list2.p_list->p_values[i].psz_string );
491 else if( i_action == ACTIONID_SUBTITLE_TRACK )
493 vlc_value_t val, list, list2;
495 var_Get( p_input, "spu-es", &val );
497 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
499 i_count = list.p_list->i_count;
502 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Subtitle track: %s"), _("N/A") );
505 for( i = 0; i < i_count; i++ )
507 if( val.i_int == list.p_list->p_values[i].i_int )
512 /* value of spu-es was not in choices list */
515 msg_Warn( p_input, "invalid current subtitle track, selecting 0" );
516 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
519 else if( i == i_count - 1 )
521 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
526 var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
529 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
530 _("Subtitle track: %s"),
531 list2.p_list->p_values[i].psz_string );
533 else if( i_action == ACTIONID_ASPECT_RATIO )
535 vlc_value_t val={0}, val_list, text_list;
536 var_Get( p_vout, "aspect-ratio", &val );
537 if( var_Change( p_vout, "aspect-ratio", VLC_VAR_GETLIST,
538 &val_list, &text_list ) >= 0 )
541 for( i = 0; i < val_list.p_list->i_count; i++ )
543 if( !strcmp( val_list.p_list->p_values[i].psz_string,
550 if( i == val_list.p_list->i_count ) i = 0;
551 var_SetString( p_vout, "aspect-ratio",
552 val_list.p_list->p_values[i].psz_string );
553 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
554 _("Aspect ratio: %s"),
555 text_list.p_list->p_values[i].psz_string );
557 free( val.psz_string );
559 else if( i_action == ACTIONID_CROP )
561 vlc_value_t val={0}, val_list, text_list;
562 var_Get( p_vout, "crop", &val );
563 if( var_Change( p_vout, "crop", VLC_VAR_GETLIST,
564 &val_list, &text_list ) >= 0 )
567 for( i = 0; i < val_list.p_list->i_count; i++ )
569 if( !strcmp( val_list.p_list->p_values[i].psz_string,
576 if( i == val_list.p_list->i_count ) i = 0;
577 var_SetString( p_vout, "crop",
578 val_list.p_list->p_values[i].psz_string );
579 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
581 text_list.p_list->p_values[i].psz_string );
583 free( val.psz_string );
585 else if( i_action == ACTIONID_DEINTERLACE )
587 vlc_value_t val={0}, val_list, text_list;
588 var_Get( p_vout, "deinterlace", &val );
589 if( var_Change( p_vout, "deinterlace", VLC_VAR_GETLIST,
590 &val_list, &text_list ) >= 0 )
593 for( i = 0; i < val_list.p_list->i_count; i++ )
595 if( !strcmp( val_list.p_list->p_values[i].psz_string,
602 if( i == val_list.p_list->i_count ) i = 0;
603 var_SetString( p_vout, "deinterlace",
604 val_list.p_list->p_values[i].psz_string );
605 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
606 _("Deinterlace mode: %s"),
607 text_list.p_list->p_values[i].psz_string );
609 free( val.psz_string );
611 else if( i_action == ACTIONID_NEXT )
613 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
617 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Next") );
618 playlist_Next( p_playlist );
619 vlc_object_release( p_playlist );
622 else if( i_action == ACTIONID_PREV )
624 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
628 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Previous") );
629 playlist_Prev( p_playlist );
630 vlc_object_release( p_playlist );
633 else if( i_action == ACTIONID_STOP )
635 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
639 playlist_Stop( p_playlist );
640 vlc_object_release( p_playlist );
643 else if( i_action == ACTIONID_FASTER )
646 val.b_bool = VLC_TRUE;
647 var_Set( p_input, "rate-faster", val );
648 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Faster") );
650 else if( i_action == ACTIONID_SLOWER )
653 val.b_bool = VLC_TRUE;
654 var_Set( p_input, "rate-slower", val );
655 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Slower") );
657 else if( i_action == ACTIONID_POSITION && b_seekable )
659 DisplayPosition( p_intf, p_vout, p_input );
661 else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
662 i_action <= ACTIONID_PLAY_BOOKMARK10 )
664 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
666 else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
667 i_action <= ACTIONID_SET_BOOKMARK10 )
669 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
671 /* Only makes sense with DVD */
672 else if( i_action == ACTIONID_TITLE_PREV )
674 val.b_bool = VLC_TRUE;
675 var_Set( p_input, "prev-title", val );
677 else if( i_action == ACTIONID_TITLE_NEXT )
679 val.b_bool = VLC_TRUE;
680 var_Set( p_input, "next-title", val );
682 else if( i_action == ACTIONID_CHAPTER_PREV )
684 val.b_bool = VLC_TRUE;
685 var_Set( p_input, "prev-chapter", val );
687 else if( i_action == ACTIONID_CHAPTER_NEXT )
689 val.b_bool = VLC_TRUE;
690 var_Set( p_input, "next-chapter", val );
692 else if( i_action == ACTIONID_DISC_MENU )
694 vlc_value_t val; val.i_int = 2;
695 msg_Dbg( p_input, "set dvdmenu" );
696 var_Set( p_input, "title 0", val);
698 else if( i_action == ACTIONID_SUBDELAY_DOWN )
700 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
702 i_delay -= 50000; /* 50 ms */
704 var_SetTime( p_input, "spu-delay", i_delay );
705 ClearChannels( p_intf, p_vout );
706 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
707 (int)(i_delay/1000) );
709 else if( i_action == ACTIONID_SUBDELAY_UP )
711 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
713 i_delay += 50000; /* 50 ms */
715 var_SetTime( p_input, "spu-delay", i_delay );
716 ClearChannels( p_intf, p_vout );
717 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
718 (int)(i_delay/1000) );
720 else if( i_action == ACTIONID_AUDIODELAY_DOWN )
722 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
724 i_delay -= 50000; /* 50 ms */
726 var_SetTime( p_input, "audio-delay", i_delay );
727 ClearChannels( p_intf, p_vout );
728 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
729 (int)(i_delay/1000) );
731 else if( i_action == ACTIONID_AUDIODELAY_UP )
733 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
735 i_delay += 50000; /* 50 ms */
737 var_SetTime( p_input, "audio-delay", i_delay );
738 ClearChannels( p_intf, p_vout );
739 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
740 (int)(i_delay/1000) );
742 else if( i_action == ACTIONID_PLAY )
744 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
748 var_Get( p_input, "rate", &val );
749 msg_Dbg( p_input, "rate %d", val.i_int );
750 if( val.i_int != INPUT_RATE_DEFAULT )
752 /* Return to normal speed */
753 val.i_int = INPUT_RATE_DEFAULT;
754 var_Set( p_input, "rate", val );
758 ClearChannels( p_intf, p_vout );
759 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
761 playlist_Play( p_playlist );
763 vlc_object_release( p_playlist );
770 static int GetKey( intf_thread_t *p_intf)
772 vlc_mutex_lock( &p_intf->p_sys->change_lock );
773 if ( p_intf->p_sys->i_size == 0 )
775 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
780 int i_return = p_intf->p_sys->p_keys[ 0 ];
782 p_intf->p_sys->i_size--;
783 for ( i = 0; i < BUFFER_SIZE - 1; i++)
785 p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ];
787 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
792 /*****************************************************************************
793 * KeyEvent: callback for keyboard events
794 *****************************************************************************/
795 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
796 vlc_value_t oldval, vlc_value_t newval, void *p_data )
798 intf_thread_t *p_intf = (intf_thread_t *)p_data;
799 vlc_mutex_lock( &p_intf->p_sys->change_lock );
800 if ( p_intf->p_sys->i_size == BUFFER_SIZE )
802 msg_Warn( p_intf, "event buffer full, dropping keypress" );
803 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
808 p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int;
809 p_intf->p_sys->i_size++;
811 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
816 static int ActionKeyCB( vlc_object_t *p_this, char const *psz_var,
817 vlc_value_t oldval, vlc_value_t newval, void *p_data )
819 vlc_t *p_vlc = (vlc_t *)p_this;
820 struct hotkey *p_hotkeys = p_vlc->p_hotkeys;
824 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
826 if( !strcmp( p_hotkeys[i].psz_action, psz_var ) )
828 p_hotkeys[i].i_key = newval.i_int;
829 /* do hotkey accounting */
831 if( (p_hotkeys[i].i_delta_date > 0) &&
832 (p_hotkeys[i].i_delta_date <= (i_date - p_hotkeys[i].i_last_date) ) )
833 p_hotkeys[i].i_times = 0;
835 p_hotkeys[i].i_times++;
836 p_hotkeys[i].i_last_date = i_date;
843 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
847 char psz_bookmark_name[11];
848 playlist_t *p_playlist =
849 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
851 sprintf( psz_bookmark_name, "bookmark%i", i_num );
852 var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
853 var_Get( p_intf, psz_bookmark_name, &val );
857 char *psz_bookmark = strdup( val.psz_string );
858 for( i_position = 0; i_position < p_playlist->i_size; i_position++)
860 if( !strcmp( psz_bookmark,
861 p_playlist->pp_items[i_position]->input.psz_uri ) )
863 playlist_Goto( p_playlist, i_position );
867 vlc_object_release( p_playlist );
871 static void SetBookmark( intf_thread_t *p_intf, int i_num )
873 playlist_t *p_playlist =
874 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
877 char psz_bookmark_name[11];
878 sprintf( psz_bookmark_name, "bookmark%i", i_num );
879 var_Create( p_intf, psz_bookmark_name,
880 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
881 if( p_playlist->status.p_item )
883 config_PutPsz( p_intf, psz_bookmark_name,
884 p_playlist->status.p_item->input.psz_uri);
885 msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num,
886 p_playlist->status.p_item->input.psz_uri);
887 config_SaveConfigFile( p_intf, "hotkeys" );
889 vlc_object_release( p_playlist );
893 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
894 input_thread_t *p_input )
896 char psz_duration[MSTRTIME_MAX_SIZE];
897 char psz_time[MSTRTIME_MAX_SIZE];
898 vlc_value_t time, pos;
905 ClearChannels( p_intf, p_vout );
907 var_Get( p_input, "time", &time );
908 i_seconds = time.i_time / 1000000;
909 secstotimestr ( psz_time, i_seconds );
911 var_Get( p_input, "length", &time );
912 if( time.i_time > 0 )
914 secstotimestr( psz_duration, time.i_time / 1000000 );
915 vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s / %s",
916 psz_time, psz_duration );
918 else if( i_seconds > 0 )
920 vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
923 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
925 var_Get( p_input, "position", &pos );
926 vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
927 pos.f_float * 100, OSD_HOR_SLIDER );
931 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
932 audio_volume_t i_vol )
938 ClearChannels( p_intf, p_vout );
940 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
942 vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
943 i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
947 vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, "Volume %d%%",
948 i_vol*400/AOUT_VOLUME_MAX );
952 static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
958 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
959 for( i = 0; i < CHANNELS_NUMBER; i++ )
961 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
962 p_intf->p_sys->p_channels[ i ] );