X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Flirc.c;h=5688c97ab106c2e64038f3d05faf42d113b62ff3;hb=7bf3ee3c5447365e956330b9a3788c7a1b5a3092;hp=7c2a52c17666a7917350b2961fd41ff6bcde60a2;hpb=ec815603a17333bbc9eab5d1d13530836abea47d;p=vlc diff --git a/modules/control/lirc.c b/modules/control/lirc.c index 7c2a52c176..5688c97ab1 100644 --- a/modules/control/lirc.c +++ b/modules/control/lirc.c @@ -1,10 +1,10 @@ /***************************************************************************** * lirc.c : lirc module for vlc ***************************************************************************** - * Copyright (C) 2004 VideoLAN + * Copyright (C) 2003-2005 the VideoLAN team * $Id$ * - * Author: Sigmund Augdal + * Author: Sigmund Augdal Helberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,52 +18,70 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include #include -#include -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include + +#ifdef HAVE_POLL +# include +#endif #include +#define LIRC_TEXT N_("Change the lirc configuration file") +#define LIRC_LONGTEXT N_( \ + "Tell lirc to read this configuration file. By default it " \ + "searches in the users home directory." ) + +/***************************************************************************** + * Module descriptor + *****************************************************************************/ +static int Open ( vlc_object_t * ); +static void Close ( vlc_object_t * ); + +vlc_module_begin () + set_shortname( N_("Infrared") ) + set_category( CAT_INTERFACE ) + set_subcategory( SUBCAT_INTERFACE_CONTROL ) + set_description( N_("Infrared remote control interface") ) + set_capability( "interface", 0 ) + set_callbacks( Open, Close ) + + add_string( "lirc-file", NULL, NULL, + LIRC_TEXT, LIRC_LONGTEXT, true ) +vlc_module_end () + /***************************************************************************** * intf_sys_t: description and status of FB interface *****************************************************************************/ struct intf_sys_t { struct lirc_config *config; - vlc_mutex_t change_lock; - input_thread_t * p_input; - vout_thread_t * p_vout; + int i_fd; }; /***************************************************************************** * Local prototypes *****************************************************************************/ -static int Open ( vlc_object_t * ); -static void Close ( vlc_object_t * ); -static void Run ( intf_thread_t * ); +static void Run( intf_thread_t * ); -/***************************************************************************** - * Module descriptor - *****************************************************************************/ -vlc_module_begin(); - set_description( _("Infrared remote control interface") ); - set_capability( "interface", 0 ); - set_callbacks( Open, Close ); -vlc_module_end(); +static void Process( intf_thread_t * ); /***************************************************************************** * Open: initialize interface @@ -71,40 +89,43 @@ vlc_module_end(); static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; - int i_fd; + intf_sys_t *p_sys; + char *psz_file; /* Allocate instance and initialize some members */ - p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); - if( p_intf->p_sys == NULL ) - { - msg_Err( p_intf, "out of memory" ); - return 1; - } + p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) ); + if( p_sys == NULL ) + return VLC_ENOMEM; p_intf->pf_run = Run; - i_fd = lirc_init( "vlc", 1 ); - if( i_fd == -1 ) + p_sys->i_fd = lirc_init( "vlc", 1 ); + if( p_sys->i_fd == -1 ) { - msg_Err( p_intf, "lirc_init failed" ); - free( p_intf->p_sys ); - return 1; + msg_Err( p_intf, "lirc initialisation failed" ); + goto exit; } /* We want polling */ - fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK ); + fcntl( p_sys->i_fd, F_SETFL, fcntl( p_sys->i_fd, F_GETFL ) | O_NONBLOCK ); - if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 ) + /* Read the configuration file */ + psz_file = var_CreateGetNonEmptyString( p_intf, "lirc-file" ); + if( lirc_readconfig( psz_file, &p_sys->config, NULL ) != 0 ) { - msg_Err( p_intf, "lirc_readconfig failed" ); - lirc_deinit(); - free( p_intf->p_sys ); - return 1; + msg_Err( p_intf, "failure while reading lirc config" ); + free( psz_file ); + goto exit; } + free( psz_file ); - p_intf->p_sys->p_input = NULL; + return VLC_SUCCESS; - return 0; +exit: + if( p_sys->i_fd != -1 ) + lirc_deinit(); + free( p_sys ); + return VLC_EGENERIC; } /***************************************************************************** @@ -113,19 +134,12 @@ static int Open( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; + intf_sys_t *p_sys = p_intf->p_sys; - if( p_intf->p_sys->p_input ) - { - vlc_object_release( p_intf->p_sys->p_input ); - } - if( p_intf->p_sys->p_vout ) - { - vlc_object_release( p_intf->p_sys->p_vout ); - } /* Destroy structure */ - lirc_freeconfig( p_intf->p_sys->config ); + lirc_freeconfig( p_sys->config ); lirc_deinit(); - free( p_intf->p_sys ); + free( p_sys ); } /***************************************************************************** @@ -133,346 +147,78 @@ static void Close( vlc_object_t *p_this ) *****************************************************************************/ static void Run( intf_thread_t *p_intf ) { - char *code, *c; - playlist_t *p_playlist; - input_thread_t *p_input; - vout_thread_t *p_vout = NULL; + intf_sys_t *p_sys = p_intf->p_sys; - while( !p_intf->b_die ) + for( ;; ) { - /* Sleep a bit */ - msleep( INTF_IDLE_SLEEP ); - - /* Update the input */ - if( p_intf->p_sys->p_input == NULL ) - { - p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, - FIND_ANYWHERE ); - } - else if( p_intf->p_sys->p_input->b_dead ) - { - vlc_object_release( p_intf->p_sys->p_input ); - p_intf->p_sys->p_input = NULL; - } - p_input = p_intf->p_sys->p_input; + /* Wait for data */ + struct pollfd ufd = { .fd = p_sys->i_fd, .events = POLLIN, .revents = 0 }; + if( poll( &ufd, 1, -1 ) == -1 ) + break; - /* Update the vout */ - if( p_vout == NULL ) - { - p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, - FIND_ANYWHERE ); - p_intf->p_sys->p_vout = p_vout; - } - else if( p_vout->b_die ) - { - vlc_object_release( p_vout ); - p_vout = NULL; - p_intf->p_sys->p_vout = NULL; - } + /* Process */ + int canc = vlc_savecancel(); + Process( p_intf ); + vlc_restorecancel(canc); + } +} - /* We poll the lircsocket */ - if( lirc_nextcode(&code) != 0 ) - { - break; - } +static void Process( intf_thread_t *p_intf ) +{ + for( ;; ) + { + char *code, *c; + if( lirc_nextcode( &code ) ) + return; if( code == NULL ) - { - continue; - } + return; - while( !p_intf->b_die - && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0 - && c != NULL ) + while( vlc_object_alive( p_intf ) + && (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0) + && (c != NULL) ) { - - if( !strcmp( c, "QUIT" ) ) + if( !strncmp( "key-", c, 4 ) ) { - p_intf->p_vlc->b_die = VLC_TRUE; - vout_OSDMessage( p_intf, SOLO_CHAN, _("Quit" ) ); - continue; - } - else if( !strcmp( c, "VOL_UP" ) ) - { - audio_volume_t i_newvol; - aout_VolumeUp( p_intf, 1, &i_newvol ); - vout_OSDMessage( p_intf, SOLO_CHAN, _("Vol %%%d"), - i_newvol * 100 / AOUT_VOLUME_MAX ); - } - else if( !strcmp( c, "VOL_DOWN" ) ) - { - audio_volume_t i_newvol; - aout_VolumeDown( p_intf, 1, &i_newvol ); - vout_OSDMessage( p_intf, SOLO_CHAN, _("Vol %%%d"), - i_newvol * 100 / AOUT_VOLUME_MAX ); - } - else if( !strcmp( c, "MUTE" ) ) - { - audio_volume_t i_newvol = -1; - aout_VolumeMute( p_intf, &i_newvol ); - if( i_newvol == 0 ) - { - vout_OSDMessage( p_intf, SOLO_CHAN, _( "Mute" ) ); - } + vlc_key_t i_key = vlc_GetActionId( c ); + if( i_key ) + var_SetInteger( p_intf->p_libvlc, "key-action", i_key ); else - { - vout_OSDMessage( p_intf, SOLO_CHAN, _("Vol %d%%"), - i_newvol * 100 / AOUT_VOLUME_MAX ); - } - } - if( p_vout ) - { - if( !strcmp( c, "FULLSCREEN" ) ) - { - p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; - continue; - } - if( !strcmp( c, "ACTIVATE" ) ) - { - vlc_value_t val; - val.psz_string = "ENTER"; - if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS) - { - msg_Warn( p_intf, "key-press failed" ); - } - continue; - } - - if( !strcmp( c, "LEFT" ) ) - { - vlc_value_t val; - val.psz_string = "LEFT"; - if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS) - { - msg_Warn( p_intf, "key-press failed" ); - } - continue; - } - - if( !strcmp( c, "RIGHT" ) ) - { - vlc_value_t val; - val.psz_string = "RIGHT"; - if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS) - { - msg_Warn( p_intf, "key-press failed" ); - } - continue; - } - - if( !strcmp( c, "UP" ) ) - { - vlc_value_t val; - val.psz_string = "UP"; - if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS) - { - msg_Warn( p_intf, "key-press failed" ); - } - continue; - } - - if( !strcmp( c, "DOWN" ) ) - { - vlc_value_t val; - val.psz_string = "DOWN"; - if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS) - { - msg_Warn( p_intf, "key-press failed" ); - } - continue; - } - } - - if( !strcmp( c, "PLAY" ) ) - { - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist ) - { - playlist_Play( p_playlist ); - vlc_object_release( p_playlist ); - } - continue; + msg_Err( p_intf, "Unknown hotkey '%s'", c ); } - - if( !strcmp( c, "PLAYPAUSE" ) ) + else if( !strncmp( "menu ", c, 5) ) { - vlc_value_t val; - val.i_int = PLAYING_S; - if( p_input ) - { - var_Get( p_input, "state", &val ); - } - if( p_input && val.i_int != PAUSE_S ) - { - vout_OSDMessage( VLC_OBJECT(p_intf), SOLO_CHAN, - _( "Pause" ) ); - val.i_int = PAUSE_S; - var_Set( p_input, "state", val ); - } + if( !strncmp( c, "menu on", 7 ) || + !strncmp( c, "menu show", 9 )) + osd_MenuShow( VLC_OBJECT(p_intf) ); + else if( !strncmp( c, "menu off", 8 ) || + !strncmp( c, "menu hide", 9 ) ) + osd_MenuHide( VLC_OBJECT(p_intf) ); + else if( !strncmp( c, "menu up", 7 ) ) + osd_MenuUp( VLC_OBJECT(p_intf) ); + else if( !strncmp( c, "menu down", 9 ) ) + osd_MenuDown( VLC_OBJECT(p_intf) ); + else if( !strncmp( c, "menu left", 9 ) ) + osd_MenuPrev( VLC_OBJECT(p_intf) ); + else if( !strncmp( c, "menu right", 10 ) ) + osd_MenuNext( VLC_OBJECT(p_intf) ); + else if( !strncmp( c, "menu select", 11 ) ) + osd_MenuActivate( VLC_OBJECT(p_intf) ); else { - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist ) - { - vlc_mutex_lock( &p_playlist->object_lock ); - if( p_playlist->i_size ) - { - vlc_mutex_unlock( &p_playlist->object_lock ); - vout_OSDMessage( p_intf, SOLO_CHAN, _( "Play" ) ); - playlist_Play( p_playlist ); - vlc_object_release( p_playlist ); - } - } + msg_Err( p_intf, "Please provide one of the following parameters:" ); + msg_Err( p_intf, "[on|off|up|down|left|right|select]" ); + break; } - continue; } - - else if( p_input ) + else { - if( !strcmp( c, "AUDIO_TRACK" ) ) - { - vlc_value_t val, list, list2; - int i_count, i; - var_Get( p_input, "audio-es", &val ); - var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES, - &list, &list2 ); - i_count = list.p_list->i_count; - for( i = 0; i < i_count; i++ ) - { - if( val.i_int == list.p_list->p_values[i].i_int ) - { - break; - } - } - /* value of audio-es was not in choices list */ - if( i == i_count ) - { - msg_Warn( p_input, - "invalid current audio track, selecting 0" ); - var_Set( p_input, "audio-es", - list.p_list->p_values[0] ); - i = 0; - } - else if( i == i_count - 1 ) - { - var_Set( p_input, "audio-es", - list.p_list->p_values[0] ); - i = 0; - } - else - { - var_Set( p_input, "audio-es", - list.p_list->p_values[i+1] ); - i++; - } - vout_OSDMessage( VLC_OBJECT(p_input), SOLO_CHAN, - _("Audio track: %s"), - list2.p_list->p_values[i].psz_string ); - } - else if( !strcmp( c, "SUBTITLE_TRACK" ) ) - { - vlc_value_t val, list, list2; - int i_count, i; - var_Get( p_input, "spu-es", &val ); - var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES, - &list, &list2 ); - i_count = list.p_list->i_count; - for( i = 0; i < i_count; i++ ) - { - if( val.i_int == list.p_list->p_values[i].i_int ) - { - break; - } - } - /* value of audio-es was not in choices list */ - if( i == i_count ) - { - msg_Warn( p_input, "invalid current subtitle track, selecting 0" ); - var_Set( p_input, "spu-es", list.p_list->p_values[0] ); - i = 0; - } - else if( i == i_count - 1 ) - { - var_Set( p_input, "spu-es", list.p_list->p_values[0] ); - i = 0; - } - else - { - var_Set( p_input, "spu-es", list.p_list->p_values[i+1] ); - i = i + 1; - } - vout_OSDMessage( VLC_OBJECT(p_input), SOLO_CHAN, - _("Subtitle track: %s"), - list2.p_list->p_values[i].psz_string ); - } - else if( !strcmp( c, "PAUSE" ) ) - { - vlc_value_t val; - vout_OSDMessage( p_intf, SOLO_CHAN, _( "Pause" ) ); - val.i_int = PAUSE_S; - var_Set( p_input, "state", val ); - } - else if( !strcmp( c, "NEXT" ) ) - { - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist ) - { - playlist_Next( p_playlist ); - vlc_object_release( p_playlist ); - } - } - else if( !strcmp( c, "PREV" ) ) - { - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist ) - { - playlist_Prev( p_playlist ); - vlc_object_release( p_playlist ); - } - } - else if( !strcmp( c, "STOP" ) ) - { - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist ) - { - playlist_Stop( p_playlist ); - vlc_object_release( p_playlist ); - } - } - else if( !strcmp( c, "FAST" ) ) - { - vlc_value_t val; val.b_bool = VLC_TRUE; - var_Set( p_input, "rate-faster", val ); - } - else if( !strcmp( c, "SLOW" ) ) - { - vlc_value_t val; val.b_bool = VLC_TRUE; - var_Set( p_input, "rate-slower", val ); - } -/* beginning of modifications by stephane Thu Jun 19 15:29:49 CEST 2003 */ - else if ( !strcmp(c, "CHAPTER_N" ) || - !strcmp( c, "CHAPTER_P" ) ) - { - unsigned int i_chapter = 0; - - if( !strcmp( c, "CHAPTER_N" ) ) - { - var_SetVoid( p_input, "next-chapter" ); - } - else if( !strcmp( c, "CHAPTER_P" ) ) - { - var_SetVoid( p_input, "prev-chapter" ); - } - } -/* end of modification by stephane Thu Jun 19 15:29:49 CEST 2003 */ + msg_Err( p_intf, "this doesn't appear to be a valid keycombo " + "lirc sent us. Please look at the " + "doc/lirc/example.lirc file in VLC" ); + break; } } - free( code ); } }