1 /*****************************************************************************
2 * lirc.c : lirc plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: lirc.c,v 1.4 2003/02/16 10:25:57 sigmunau 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() */
37 #include <lirc/lirc_client.h>
39 /*****************************************************************************
40 * intf_sys_t: description and status of FB interface
41 *****************************************************************************/
44 struct lirc_config *config;
45 vlc_mutex_t change_lock;
47 input_thread_t * p_input;
50 /*****************************************************************************
52 *****************************************************************************/
53 static int Open ( vlc_object_t * );
54 static void Close ( vlc_object_t * );
55 static void Run ( intf_thread_t * );
57 /*****************************************************************************
59 *****************************************************************************/
61 set_description( _("infrared remote control module") );
62 set_capability( "interface", 0 );
63 set_callbacks( Open, Close );
66 /*****************************************************************************
67 * Open: initialize interface
68 *****************************************************************************/
69 static int Open( vlc_object_t *p_this )
71 intf_thread_t *p_intf = (intf_thread_t *)p_this;
74 /* Allocate instance and initialize some members */
75 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
76 if( p_intf->p_sys == NULL )
78 msg_Err( p_intf, "out of memory" );
84 i_fd = lirc_init( "vlc", 1 );
87 msg_Err( p_intf, "lirc_init failed" );
88 free( p_intf->p_sys );
93 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
95 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
97 msg_Err( p_intf, "lirc_readconfig failed" );
99 free( p_intf->p_sys );
103 p_intf->p_sys->p_input = NULL;
108 /*****************************************************************************
109 * Close: destroy interface
110 *****************************************************************************/
111 static void Close( vlc_object_t *p_this )
113 intf_thread_t *p_intf = (intf_thread_t *)p_this;
115 if( p_intf->p_sys->p_input )
117 vlc_object_release( p_intf->p_sys->p_input );
120 /* Destroy structure */
121 lirc_freeconfig( p_intf->p_sys->config );
123 free( p_intf->p_sys );
126 /*****************************************************************************
128 *****************************************************************************/
129 static void Run( intf_thread_t *p_intf )
132 playlist_t *p_playlist;
133 input_thread_t *p_input;
135 while( !p_intf->b_die )
138 msleep( INTF_IDLE_SLEEP );
140 /* Update the input */
141 if( p_intf->p_sys->p_input == NULL )
143 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
146 else if( p_intf->p_sys->p_input->b_dead )
148 vlc_object_release( p_intf->p_sys->p_input );
149 p_intf->p_sys->p_input = NULL;
151 p_input = p_intf->p_sys->p_input;
153 /* We poll the lircsocket */
154 if( lirc_nextcode(&code) != 0 )
164 while( !p_intf->b_die
165 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
168 if( !strcmp( c, "QUIT" ) )
170 p_intf->p_vlc->b_die = VLC_TRUE;
173 if( !strcmp( c, "VOL_UP" ) )
175 aout_VolumeUp( p_intf, 1, NULL );
177 if( !strcmp( c, "VOL_DOWN" ) )
179 aout_VolumeDown( p_intf, 1, NULL );
181 if( !strcmp( c, "FULLSCREEN" ) )
183 vout_thread_t *p_vout;
184 p_vout = vlc_object_find( p_intf->p_sys->p_input,
185 VLC_OBJECT_VOUT, FIND_CHILD );
188 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
189 vlc_object_release( p_vout );
193 if( !strcmp( c, "ACTIVATE" ) )
195 vout_thread_t *p_vout;
196 p_vout = vlc_object_find( p_intf->p_sys->p_input,
197 VLC_OBJECT_VOUT, FIND_CHILD );
201 val.psz_string = "ENTER";
202 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
204 msg_Warn( p_intf, "key-press failed" );
206 vlc_object_release( p_vout );
211 if( !strcmp( c, "LEFT" ) )
213 vout_thread_t *p_vout;
214 p_vout = vlc_object_find( p_intf->p_sys->p_input,
215 VLC_OBJECT_VOUT, FIND_CHILD );
219 val.psz_string = "LEFT";
220 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
222 msg_Warn( p_intf, "key-press failed" );
224 vlc_object_release( p_vout );
229 if( !strcmp( c, "RIGHT" ) )
231 vout_thread_t *p_vout;
232 p_vout = vlc_object_find( p_intf->p_sys->p_input,
233 VLC_OBJECT_VOUT, FIND_CHILD );
237 val.psz_string = "RIGHT";
238 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
240 msg_Warn( p_intf, "key-press failed" );
242 vlc_object_release( p_vout );
247 if( !strcmp( c, "UP" ) )
249 vout_thread_t *p_vout;
250 p_vout = vlc_object_find( p_intf->p_sys->p_input,
251 VLC_OBJECT_VOUT, FIND_CHILD );
255 val.psz_string = "UP";
256 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
258 msg_Warn( p_intf, "key-press failed" );
260 vlc_object_release( p_vout );
265 if( !strcmp( c, "DOWN" ) )
267 vout_thread_t *p_vout;
268 p_vout = vlc_object_find( p_intf->p_sys->p_input,
269 VLC_OBJECT_VOUT, FIND_CHILD );
273 val.psz_string = "DOWN";
274 if (var_Set( p_vout, "key-pressed", val ) != VLC_SUCCESS)
276 msg_Warn( p_intf, "key-press failed" );
278 vlc_object_release( p_vout );
283 if( !strcmp( c, "PLAY" ) )
285 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
289 vlc_mutex_lock( &p_playlist->object_lock );
290 if( p_playlist->i_size )
292 vlc_mutex_unlock( &p_playlist->object_lock );
293 playlist_Play( p_playlist );
294 vlc_object_release( p_playlist );
298 if( !strcmp( c, "PLAYPAUSE" ) )
301 p_input->stream.control.i_status != PAUSE_S )
303 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
307 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
311 vlc_mutex_lock( &p_playlist->object_lock );
312 if( p_playlist->i_size )
314 vlc_mutex_unlock( &p_playlist->object_lock );
315 playlist_Play( p_playlist );
316 vlc_object_release( p_playlist );
323 if( !strcmp( c, "PAUSE" ) )
325 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
327 else if( !strcmp( c, "NEXT" ) )
329 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
333 playlist_Next( p_playlist );
334 vlc_object_release( p_playlist );
337 else if( !strcmp( c, "PREV" ) )
339 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
343 playlist_Prev( p_playlist );
344 vlc_object_release( p_playlist );
347 else if( !strcmp( c, "STOP" ) )
349 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
353 playlist_Stop( p_playlist );
354 vlc_object_release( p_playlist );
357 else if( !strcmp( c, "FAST" ) )
359 input_SetStatus( p_input, INPUT_STATUS_FASTER );
361 else if( !strcmp( c, "SLOW" ) )
363 input_SetStatus( p_input, INPUT_STATUS_SLOWER );