1 /*****************************************************************************
2 * lirc.c : lirc plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: lirc.c,v 1.8 2002/02/24 20:51:10 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() */
32 #include <videolan/vlc.h>
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
37 #include "interface.h"
38 #include "intf_playlist.h"
41 #include "video_output.h"
43 #include <lirc/lirc_client.h>
45 /*****************************************************************************
46 * intf_sys_t: description and status of FB interface
47 *****************************************************************************/
48 typedef struct intf_sys_s
50 struct lirc_config *config;
51 vlc_mutex_t change_lock;
54 /*****************************************************************************
56 *****************************************************************************/
57 static void intf_getfunctions( function_list_t * p_function_list );
59 static int intf_Open ( intf_thread_t *p_intf );
60 static void intf_Close ( intf_thread_t *p_intf );
61 static void intf_Run ( intf_thread_t *p_intf );
63 /*****************************************************************************
64 * Build configuration tree.
65 *****************************************************************************/
71 SET_DESCRIPTION( "infrared remote control module" )
72 ADD_CAPABILITY( INTF, 8 )
73 ADD_SHORTCUT( "lirc" )
77 intf_getfunctions( &p_module->p_functions->intf );
80 MODULE_DEACTIVATE_START
81 MODULE_DEACTIVATE_STOP
83 /*****************************************************************************
84 * Functions exported as capabilities. They are declared as static so that
85 * we don't pollute the namespace too much.
86 *****************************************************************************/
87 static void intf_getfunctions( function_list_t * p_function_list )
89 p_function_list->functions.intf.pf_open = intf_Open;
90 p_function_list->functions.intf.pf_close = intf_Close;
91 p_function_list->functions.intf.pf_run = intf_Run;
94 /*****************************************************************************
95 * intf_Open: initialize dummy interface
96 *****************************************************************************/
97 static int intf_Open( intf_thread_t *p_intf )
101 /* Allocate instance and initialize some members */
102 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
103 if( p_intf->p_sys == NULL )
105 intf_ErrMsg("no mem?");
109 i_fd = lirc_init( "vlc", 1 );
112 intf_ErrMsg( "intf error: lirc_init failed" );
113 free( p_intf->p_sys );
117 /* We want polling */
118 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
120 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
122 intf_ErrMsg( "intf error: lirc_readconfig failed" );
124 free( p_intf->p_sys );
131 /*****************************************************************************
132 * intf_Close: destroy dummy interface
133 *****************************************************************************/
134 static void intf_Close( intf_thread_t *p_intf )
136 /* Destroy structure */
137 lirc_freeconfig( p_intf->p_sys->config );
139 free( p_intf->p_sys );
142 /*****************************************************************************
143 * intf_Run: main loop
144 *****************************************************************************/
145 static void intf_Run( intf_thread_t *p_intf )
150 /* Manage core vlc functions through the callback */
151 p_intf->pf_manage( p_intf );
154 while( !p_intf->b_die && lirc_nextcode(&code) == 0 )
156 while( !p_intf->b_die )
159 /* Manage core vlc functions through the callback */
160 p_intf->pf_manage( p_intf );
161 msleep( INTF_IDLE_SLEEP );
163 /* We poll the lircsocket */
164 if( lirc_nextcode(&code) != 0 )
174 while( !p_intf->b_die
175 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
178 if( !strcmp( c, "QUIT" ) )
184 if( !strcmp( c, "FULLSCREEN" ) )
186 vlc_mutex_lock( &p_vout_bank->lock );
187 /* XXX: only fullscreen the first video output */
188 if( p_vout_bank->i_count )
190 p_vout_bank->pp_vout[0]->i_changes
191 |= VOUT_FULLSCREEN_CHANGE;
193 vlc_mutex_unlock( &p_vout_bank->lock );
197 vlc_mutex_lock( &p_input_bank->lock );
199 if( !strcmp( c, "PLAY" ) )
201 if( p_input_bank->pp_input[0] != NULL )
203 input_SetStatus( p_input_bank->pp_input[0],
205 p_main->p_playlist->b_stopped = 0;
209 vlc_mutex_lock( &p_main->p_playlist->change_lock );
211 if( p_main->p_playlist->b_stopped )
213 if( p_main->p_playlist->i_size )
215 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
216 intf_PlaylistJumpto( p_main->p_playlist,
217 p_main->p_playlist->i_index );
221 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
226 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
230 else if( p_input_bank->pp_input[0] != NULL )
232 if( !strcmp( c, "PAUSE" ) )
234 input_SetStatus( p_input_bank->pp_input[0],
235 INPUT_STATUS_PAUSE );
237 vlc_mutex_lock( &p_main->p_playlist->change_lock );
238 p_main->p_playlist->b_stopped = 0;
239 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
241 else if( !strcmp( c, "NEXT" ) )
243 p_input_bank->pp_input[0]->b_eof = 1;
245 else if( !strcmp( c, "LAST" ) )
247 /* FIXME: temporary hack */
248 intf_PlaylistPrev( p_main->p_playlist );
249 intf_PlaylistPrev( p_main->p_playlist );
250 p_input_bank->pp_input[0]->b_eof = 1;
252 else if( !strcmp( c, "STOP" ) )
254 /* end playing item */
255 p_input_bank->pp_input[0]->b_eof = 1;
257 /* update playlist */
258 vlc_mutex_lock( &p_main->p_playlist->change_lock );
260 p_main->p_playlist->i_index--;
261 p_main->p_playlist->b_stopped = 1;
263 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
265 else if( !strcmp( c, "FAST" ) )
267 input_SetStatus( p_input_bank->pp_input[0],
268 INPUT_STATUS_FASTER );
270 vlc_mutex_lock( &p_main->p_playlist->change_lock );
271 p_main->p_playlist->b_stopped = 0;
272 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
274 else if( !strcmp( c, "SLOW" ) )
276 input_SetStatus( p_input_bank->pp_input[0],
277 INPUT_STATUS_SLOWER );
279 vlc_mutex_lock( &p_main->p_playlist->change_lock );
280 p_main->p_playlist->b_stopped = 0;
281 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
285 vlc_mutex_unlock( &p_input_bank->lock );