1 /*****************************************************************************
2 * lirc.c : lirc module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Author: Sigmund Augdal <sigmunau@idi.ntnu.no>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
38 #include <lirc/lirc_client.h>
40 /*****************************************************************************
41 * intf_sys_t: description and status of FB interface
42 *****************************************************************************/
45 struct lirc_config *config;
46 vlc_mutex_t change_lock;
50 input_thread_t * p_input;
51 vout_thread_t * p_vout;
54 /*****************************************************************************
56 *****************************************************************************/
57 static int Open ( vlc_object_t * );
58 static void Close ( vlc_object_t * );
59 static void Run ( intf_thread_t * );
61 /*****************************************************************************
63 *****************************************************************************/
65 set_description( _("Infrared remote control interface") );
66 set_capability( "interface", 0 );
67 set_callbacks( Open, Close );
70 /*****************************************************************************
71 * Open: initialize interface
72 *****************************************************************************/
73 static int Open( vlc_object_t *p_this )
75 intf_thread_t *p_intf = (intf_thread_t *)p_this;
78 /* Allocate instance and initialize some members */
79 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
80 if( p_intf->p_sys == NULL )
82 msg_Err( p_intf, "out of memory" );
88 i_fd = lirc_init( "vlc", 1 );
91 msg_Err( p_intf, "lirc_init failed" );
92 free( p_intf->p_sys );
97 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
99 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
101 msg_Err( p_intf, "lirc_readconfig failed" );
103 free( p_intf->p_sys );
107 p_intf->p_sys->p_input = NULL;
112 /*****************************************************************************
113 * Close: destroy interface
114 *****************************************************************************/
115 static void Close( vlc_object_t *p_this )
117 intf_thread_t *p_intf = (intf_thread_t *)p_this;
119 if( p_intf->p_sys->p_input )
121 vlc_object_release( p_intf->p_sys->p_input );
123 if( p_intf->p_sys->p_vout )
125 vlc_object_release( p_intf->p_sys->p_vout );
127 /* Destroy structure */
128 lirc_freeconfig( p_intf->p_sys->config );
130 free( p_intf->p_sys );
133 /*****************************************************************************
135 *****************************************************************************/
136 static void Run( intf_thread_t *p_intf )
139 playlist_t *p_playlist;
140 input_thread_t *p_input;
141 vout_thread_t *p_vout = NULL;
143 while( !p_intf->b_die )
146 msleep( INTF_IDLE_SLEEP );
148 /* Update the input */
149 if( p_intf->p_sys->p_input == NULL )
151 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
154 else if( p_intf->p_sys->p_input->b_dead )
156 vlc_object_release( p_intf->p_sys->p_input );
157 p_intf->p_sys->p_input = NULL;
159 p_input = p_intf->p_sys->p_input;
161 /* Update the vout */
164 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
166 p_intf->p_sys->p_vout = p_vout;
168 else if( p_vout->b_die )
170 vlc_object_release( p_vout );
172 p_intf->p_sys->p_vout = NULL;
175 /* We poll the lircsocket */
176 if( lirc_nextcode(&code) != 0 )
186 while( !p_intf->b_die
187 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
191 if( !strcmp( c, "QUIT" ) )
193 p_intf->p_vlc->b_die = VLC_TRUE;
194 vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Quit" ) );
197 else if( !strcmp( c, "VOL_UP" ) )
199 audio_volume_t i_newvol;
200 aout_VolumeUp( p_intf, 1, &i_newvol );
201 vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Vol %%%d"),
202 i_newvol * 100 / AOUT_VOLUME_MAX );
204 else if( !strcmp( c, "VOL_DOWN" ) )
206 audio_volume_t i_newvol;
207 aout_VolumeDown( p_intf, 1, &i_newvol );
208 vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Vol %%%d"),
209 i_newvol * 100 / AOUT_VOLUME_MAX );
211 else if( !strcmp( c, "MUTE" ) )
213 audio_volume_t i_newvol = -1;
214 aout_VolumeMute( p_intf, &i_newvol );
217 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Mute" ) );
221 vout_OSDMessage( p_intf, DEFAULT_CHAN, _("Vol %d%%"),
222 i_newvol * 100 / AOUT_VOLUME_MAX );
227 if( !strcmp( c, "FULLSCREEN" ) )
229 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
232 if( !strcmp( c, "ACTIVATE" ) )
235 val.psz_string = "ENTER";
236 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
238 msg_Warn( p_intf, "key-press failed" );
243 if( !strcmp( c, "LEFT" ) )
246 val.psz_string = "LEFT";
247 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
249 msg_Warn( p_intf, "key-press failed" );
254 if( !strcmp( c, "RIGHT" ) )
257 val.psz_string = "RIGHT";
258 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
260 msg_Warn( p_intf, "key-press failed" );
265 if( !strcmp( c, "UP" ) )
268 val.psz_string = "UP";
269 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
271 msg_Warn( p_intf, "key-press failed" );
276 if( !strcmp( c, "DOWN" ) )
279 val.psz_string = "DOWN";
280 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
282 msg_Warn( p_intf, "key-press failed" );
288 if( !strcmp( c, "PLAY" ) )
290 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
294 playlist_Play( p_playlist );
295 vlc_object_release( p_playlist );
300 if( !strcmp( c, "PLAYPAUSE" ) )
303 val.i_int = PLAYING_S;
306 var_Get( p_input, "state", &val );
308 if( p_input && val.i_int != PAUSE_S )
310 vout_OSDMessage( VLC_OBJECT(p_intf), DEFAULT_CHAN,
313 var_Set( p_input, "state", val );
317 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
321 vlc_mutex_lock( &p_playlist->object_lock );
322 if( p_playlist->i_size )
324 vlc_mutex_unlock( &p_playlist->object_lock );
325 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Play" ) );
326 playlist_Play( p_playlist );
327 vlc_object_release( p_playlist );
336 if( !strcmp( c, "AUDIO_TRACK" ) )
338 vlc_value_t val, list, list2;
340 var_Get( p_input, "audio-es", &val );
341 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
343 i_count = list.p_list->i_count;
344 for( i = 0; i < i_count; i++ )
346 if( val.i_int == list.p_list->p_values[i].i_int )
351 /* value of audio-es was not in choices list */
355 "invalid current audio track, selecting 0" );
356 var_Set( p_input, "audio-es",
357 list.p_list->p_values[0] );
360 else if( i == i_count - 1 )
362 var_Set( p_input, "audio-es",
363 list.p_list->p_values[0] );
368 var_Set( p_input, "audio-es",
369 list.p_list->p_values[i+1] );
372 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
373 _("Audio track: %s"),
374 list2.p_list->p_values[i].psz_string );
376 else if( !strcmp( c, "SUBTITLE_TRACK" ) )
378 vlc_value_t val, list, list2;
380 var_Get( p_input, "spu-es", &val );
381 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
383 i_count = list.p_list->i_count;
384 for( i = 0; i < i_count; i++ )
386 if( val.i_int == list.p_list->p_values[i].i_int )
391 /* value of audio-es was not in choices list */
394 msg_Warn( p_input, "invalid current subtitle track, selecting 0" );
395 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
398 else if( i == i_count - 1 )
400 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
405 var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
408 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
409 _("Subtitle track: %s"),
410 list2.p_list->p_values[i].psz_string );
412 else if( !strcmp( c, "PAUSE" ) )
415 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Pause" ) );
417 var_Set( p_input, "state", val );
419 else if( !strcmp( c, "NEXT" ) )
421 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
425 playlist_Next( p_playlist );
426 vlc_object_release( p_playlist );
429 else if( !strcmp( c, "PREV" ) )
431 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
435 playlist_Prev( p_playlist );
436 vlc_object_release( p_playlist );
439 else if( !strcmp( c, "STOP" ) )
441 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
445 playlist_Stop( p_playlist );
446 vlc_object_release( p_playlist );
449 else if( !strcmp( c, "FAST" ) )
451 vlc_value_t val; val.b_bool = VLC_TRUE;
452 var_Set( p_input, "rate-faster", val );
454 else if( !strcmp( c, "SLOW" ) )
456 vlc_value_t val; val.b_bool = VLC_TRUE;
457 var_Set( p_input, "rate-slower", val );
459 /* beginning of modifications by stephane Thu Jun 19 15:29:49 CEST 2003 */
460 else if ( !strcmp(c, "CHAPTER_N" ) ||
461 !strcmp( c, "CHAPTER_P" ) )
463 unsigned int i_chapter = 0;
465 if( !strcmp( c, "CHAPTER_N" ) )
467 var_SetVoid( p_input, "next-chapter" );
469 else if( !strcmp( c, "CHAPTER_P" ) )
471 var_SetVoid( p_input, "prev-chapter" );
474 /* end of modification by stephane Thu Jun 19 15:29:49 CEST 2003 */