1 /*****************************************************************************
2 * lirc.c : lirc plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: lirc.c,v 1.6 2003/03/30 18:14:37 gbazin Exp $
7 * Authors: 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;
48 input_thread_t * p_input;
49 vout_thread_t * p_vout;
52 /*****************************************************************************
54 *****************************************************************************/
55 static int Open ( vlc_object_t * );
56 static void Close ( vlc_object_t * );
57 static void Run ( intf_thread_t * );
58 static void Feedback( intf_thread_t *, char * );
60 /*****************************************************************************
62 *****************************************************************************/
64 set_description( _("infrared remote control interface") );
65 set_capability( "interface", 0 );
66 set_callbacks( Open, Close );
69 /*****************************************************************************
70 * Open: initialize interface
71 *****************************************************************************/
72 static int Open( vlc_object_t *p_this )
74 intf_thread_t *p_intf = (intf_thread_t *)p_this;
77 /* Allocate instance and initialize some members */
78 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
79 if( p_intf->p_sys == NULL )
81 msg_Err( p_intf, "out of memory" );
87 i_fd = lirc_init( "vlc", 1 );
90 msg_Err( p_intf, "lirc_init failed" );
91 free( p_intf->p_sys );
96 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
98 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
100 msg_Err( p_intf, "lirc_readconfig failed" );
102 free( p_intf->p_sys );
106 p_intf->p_sys->p_input = NULL;
111 /*****************************************************************************
112 * Close: destroy interface
113 *****************************************************************************/
114 static void Close( vlc_object_t *p_this )
116 intf_thread_t *p_intf = (intf_thread_t *)p_this;
118 if( p_intf->p_sys->p_input )
120 vlc_object_release( p_intf->p_sys->p_input );
122 if( p_intf->p_sys->p_vout )
124 vlc_object_release( p_intf->p_sys->p_vout );
126 /* Destroy structure */
127 lirc_freeconfig( p_intf->p_sys->config );
129 free( p_intf->p_sys );
132 /*****************************************************************************
134 *****************************************************************************/
135 static void Run( intf_thread_t *p_intf )
138 playlist_t *p_playlist;
139 input_thread_t *p_input;
140 vout_thread_t *p_vout = NULL;
142 while( !p_intf->b_die )
145 msleep( INTF_IDLE_SLEEP );
147 /* Update the input */
148 if( p_intf->p_sys->p_input == NULL )
150 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
153 else if( p_intf->p_sys->p_input->b_dead )
155 vlc_object_release( p_intf->p_sys->p_input );
156 p_intf->p_sys->p_input = NULL;
158 p_input = p_intf->p_sys->p_input;
160 /* Update the vout */
163 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
165 p_intf->p_sys->p_vout = p_vout;
167 else if( p_vout->b_die )
169 vlc_object_release( p_vout );
171 p_intf->p_sys->p_vout = NULL;
174 /* We poll the lircsocket */
175 if( lirc_nextcode(&code) != 0 )
185 while( !p_intf->b_die
186 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
190 if( !strcmp( c, "QUIT" ) )
192 p_intf->p_vlc->b_die = VLC_TRUE;
193 Feedback( p_intf, _("Quit" ) );
196 if( !strcmp( c, "VOL_UP" ) )
198 audio_volume_t i_newvol;
200 aout_VolumeUp( p_intf, 1, &i_newvol );
201 sprintf( string, "Vol %%%d", i_newvol*100/AOUT_VOLUME_MAX );
202 Feedback( p_intf, string );
204 if( !strcmp( c, "VOL_DOWN" ) )
206 audio_volume_t i_newvol;
208 aout_VolumeDown( p_intf, 1, &i_newvol );
209 sprintf( string, "Vol %%%d", i_newvol*100/AOUT_VOLUME_MAX );
210 Feedback( p_intf, string );
214 if( !strcmp( c, "FULLSCREEN" ) )
216 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
219 if( !strcmp( c, "ACTIVATE" ) )
222 val.psz_string = "ENTER";
223 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
225 msg_Warn( p_intf, "key-press failed" );
230 if( !strcmp( c, "LEFT" ) )
233 val.psz_string = "LEFT";
234 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
236 msg_Warn( p_intf, "key-press failed" );
241 if( !strcmp( c, "RIGHT" ) )
244 val.psz_string = "RIGHT";
245 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
247 msg_Warn( p_intf, "key-press failed" );
252 if( !strcmp( c, "UP" ) )
255 val.psz_string = "UP";
256 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
258 msg_Warn( p_intf, "key-press failed" );
263 if( !strcmp( c, "DOWN" ) )
266 val.psz_string = "DOWN";
267 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
269 msg_Warn( p_intf, "key-press failed" );
275 if( !strcmp( c, "PLAY" ) )
277 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
281 vlc_mutex_lock( &p_playlist->object_lock );
282 if( p_playlist->i_size )
284 vlc_mutex_unlock( &p_playlist->object_lock );
285 playlist_Play( p_playlist );
286 vlc_object_release( p_playlist );
292 if( !strcmp( c, "PLAYPAUSE" ) )
295 p_input->stream.control.i_status != PAUSE_S )
297 Feedback( p_intf, _( "Pause" ) );
298 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
302 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
306 vlc_mutex_lock( &p_playlist->object_lock );
307 if( p_playlist->i_size )
309 vlc_mutex_unlock( &p_playlist->object_lock );
310 Feedback( p_intf, _( "Play" ) );
311 playlist_Play( p_playlist );
312 vlc_object_release( p_playlist );
321 if( !strcmp( c, "PAUSE" ) )
323 Feedback( p_intf, _( "Pause" ) );
324 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
326 else if( !strcmp( c, "NEXT" ) )
328 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
332 playlist_Next( p_playlist );
333 vlc_object_release( p_playlist );
336 else if( !strcmp( c, "PREV" ) )
338 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
342 playlist_Prev( p_playlist );
343 vlc_object_release( p_playlist );
346 else if( !strcmp( c, "STOP" ) )
348 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
352 playlist_Stop( p_playlist );
353 vlc_object_release( p_playlist );
356 else if( !strcmp( c, "FAST" ) )
358 input_SetStatus( p_input, INPUT_STATUS_FASTER );
360 else if( !strcmp( c, "SLOW" ) )
362 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
371 static void Feedback( intf_thread_t *p_intf, char *psz_string )
373 vlc_value_t val, lockval;
374 if ( p_intf->p_sys->p_vout
375 && var_Get( p_intf->p_sys->p_vout, "lock", &lockval ) == VLC_SUCCESS )
377 vlc_mutex_lock( lockval.p_address );
378 val.i_int = OSD_ALIGN_RIGHT|OSD_ALIGN_BOTTOM;
379 var_Set( p_intf->p_sys->p_vout, "flags", val );
381 var_Set( p_intf->p_sys->p_vout, "duration", val );
383 var_Set( p_intf->p_sys->p_vout, "x-margin", val );
385 var_Set( p_intf->p_sys->p_vout, "y-margin", val );
386 val.psz_string = psz_string;
387 var_Set( p_intf->p_sys->p_vout, "string", val );
388 vlc_mutex_unlock( lockval.p_address );
392 msg_Dbg( p_intf, psz_string );