1 /*****************************************************************************
2 * lirc.c : lirc plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: lirc.c,v 1.5 2002/02/20 01:47:01 sam 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() */
30 #include <videolan/vlc.h>
32 #include "stream_control.h"
33 #include "input_ext-intf.h"
35 #include "interface.h"
36 #include "intf_playlist.h"
39 #include "video_output.h"
41 #include <lirc/lirc_client.h>
43 /*****************************************************************************
44 * intf_sys_t: description and status of FB interface
45 *****************************************************************************/
46 typedef struct intf_sys_s
48 struct lirc_config *config;
49 vlc_mutex_t change_lock;
52 /*****************************************************************************
54 *****************************************************************************/
55 static void intf_getfunctions( function_list_t * p_function_list );
57 static int intf_Open ( intf_thread_t *p_intf );
58 static void intf_Close ( intf_thread_t *p_intf );
59 static void intf_Run ( intf_thread_t *p_intf );
61 /*****************************************************************************
62 * Build configuration tree.
63 *****************************************************************************/
65 ADD_WINDOW( "Configuration for lirc module" )
66 ADD_COMMENT( "use ~/.lircrc" )
70 SET_DESCRIPTION( "infrared remote control module" )
71 ADD_CAPABILITY( INTF, 8 )
72 ADD_SHORTCUT( "lirc" )
76 intf_getfunctions( &p_module->p_functions->intf );
79 MODULE_DEACTIVATE_START
80 MODULE_DEACTIVATE_STOP
82 /*****************************************************************************
83 * Functions exported as capabilities. They are declared as static so that
84 * we don't pollute the namespace too much.
85 *****************************************************************************/
86 static void intf_getfunctions( function_list_t * p_function_list )
88 p_function_list->functions.intf.pf_open = intf_Open;
89 p_function_list->functions.intf.pf_close = intf_Close;
90 p_function_list->functions.intf.pf_run = intf_Run;
93 /*****************************************************************************
94 * intf_Open: initialize dummy interface
95 *****************************************************************************/
96 static int intf_Open( intf_thread_t *p_intf )
98 /* Allocate instance and initialize some members */
99 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
100 if( p_intf->p_sys == NULL )
102 intf_ErrMsg("no mem?");
106 if( lirc_init("vlc", 1) == -1 )
108 intf_ErrMsg( "intf error: lirc_init failed" );
109 free( p_intf->p_sys );
113 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
115 intf_ErrMsg( "intf error: lirc_readconfig failed" );
117 free( p_intf->p_sys );
124 /*****************************************************************************
125 * intf_Close: destroy dummy interface
126 *****************************************************************************/
127 static void intf_Close( intf_thread_t *p_intf )
129 /* Destroy structure */
130 lirc_freeconfig( p_intf->p_sys->config );
132 free( p_intf->p_sys );
135 /*****************************************************************************
136 * intf_Run: main loop
137 *****************************************************************************/
138 static void intf_Run( intf_thread_t *p_intf )
143 /* Manage core vlc functions through the callback */
144 p_intf->pf_manage( p_intf );
146 while( !p_intf->b_die && lirc_nextcode(&code) == 0 )
154 while( !p_intf->b_die
155 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
158 if( !strcmp( c, "QUIT" ) )
164 if( !strcmp( c, "FULLSCREEN" ) )
166 vlc_mutex_lock( &p_vout_bank->lock );
167 /* XXX: only fullscreen the first video output */
168 if( p_vout_bank->i_count )
170 p_vout_bank->pp_vout[0]->i_changes
171 |= VOUT_FULLSCREEN_CHANGE;
173 vlc_mutex_unlock( &p_vout_bank->lock );
177 vlc_mutex_lock( &p_input_bank->lock );
179 if( !strcmp( c, "PLAY" ) )
181 if( p_input_bank->pp_input[0] != NULL )
183 input_SetStatus( p_input_bank->pp_input[0],
185 p_main->p_playlist->b_stopped = 0;
189 vlc_mutex_lock( &p_main->p_playlist->change_lock );
191 if( p_main->p_playlist->b_stopped )
193 if( p_main->p_playlist->i_size )
195 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
196 intf_PlaylistJumpto( p_main->p_playlist,
197 p_main->p_playlist->i_index );
201 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
206 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
210 else if( p_input_bank->pp_input[0] != NULL )
212 if( !strcmp( c, "PAUSE" ) )
214 input_SetStatus( p_input_bank->pp_input[0],
215 INPUT_STATUS_PAUSE );
217 vlc_mutex_lock( &p_main->p_playlist->change_lock );
218 p_main->p_playlist->b_stopped = 0;
219 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
221 else if( !strcmp( c, "NEXT" ) )
223 p_input_bank->pp_input[0]->b_eof = 1;
225 else if( !strcmp( c, "LAST" ) )
227 /* FIXME: temporary hack */
228 intf_PlaylistPrev( p_main->p_playlist );
229 intf_PlaylistPrev( p_main->p_playlist );
230 p_input_bank->pp_input[0]->b_eof = 1;
232 else if( !strcmp( c, "STOP" ) )
234 /* end playing item */
235 p_input_bank->pp_input[0]->b_eof = 1;
237 /* update playlist */
238 vlc_mutex_lock( &p_main->p_playlist->change_lock );
240 p_main->p_playlist->i_index--;
241 p_main->p_playlist->b_stopped = 1;
243 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
245 else if( !strcmp( c, "FAST" ) )
247 input_SetStatus( p_input_bank->pp_input[0],
248 INPUT_STATUS_FASTER );
250 vlc_mutex_lock( &p_main->p_playlist->change_lock );
251 p_main->p_playlist->b_stopped = 0;
252 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
254 else if( !strcmp( c, "SLOW" ) )
256 input_SetStatus( p_input_bank->pp_input[0],
257 INPUT_STATUS_SLOWER );
259 vlc_mutex_lock( &p_main->p_playlist->change_lock );
260 p_main->p_playlist->b_stopped = 0;
261 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
265 vlc_mutex_unlock( &p_input_bank->lock );
270 /* Manage core vlc functions through the callback */
271 p_intf->pf_manage( p_intf );
273 printf("end of intf\n");