1 /*****************************************************************************
2 * lirc.c : lirc plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: lirc.c,v 1.11 2002/06/01 12:31:59 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() */
36 #include <lirc/lirc_client.h>
38 /*****************************************************************************
39 * intf_sys_t: description and status of FB interface
40 *****************************************************************************/
43 struct lirc_config *config;
44 vlc_mutex_t change_lock;
47 /*****************************************************************************
49 *****************************************************************************/
50 static void intf_getfunctions( function_list_t * p_function_list );
52 static int intf_Open ( intf_thread_t *p_intf );
53 static void intf_Close ( intf_thread_t *p_intf );
54 static void intf_Run ( intf_thread_t *p_intf );
56 /*****************************************************************************
57 * Build configuration tree.
58 *****************************************************************************/
64 SET_DESCRIPTION( _("infrared remote control module") )
65 ADD_CAPABILITY( INTF, 8 )
69 intf_getfunctions( &p_module->p_functions->intf );
72 MODULE_DEACTIVATE_START
73 MODULE_DEACTIVATE_STOP
75 /*****************************************************************************
76 * Functions exported as capabilities. They are declared as static so that
77 * we don't pollute the namespace too much.
78 *****************************************************************************/
79 static void intf_getfunctions( function_list_t * p_function_list )
81 p_function_list->functions.intf.pf_open = intf_Open;
82 p_function_list->functions.intf.pf_close = intf_Close;
83 p_function_list->functions.intf.pf_run = intf_Run;
86 /*****************************************************************************
87 * intf_Open: initialize dummy interface
88 *****************************************************************************/
89 static int intf_Open( intf_thread_t *p_intf )
93 /* Allocate instance and initialize some members */
94 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
95 if( p_intf->p_sys == NULL )
97 msg_Err( p_intf, "out of memory" );
101 i_fd = lirc_init( "vlc", 1 );
104 msg_Err( p_intf, "lirc_init failed" );
105 free( p_intf->p_sys );
109 /* We want polling */
110 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
112 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
114 msg_Err( p_intf, "lirc_readconfig failed" );
116 free( p_intf->p_sys );
123 /*****************************************************************************
124 * intf_Close: destroy dummy interface
125 *****************************************************************************/
126 static void intf_Close( intf_thread_t *p_intf )
128 /* Destroy structure */
129 lirc_freeconfig( p_intf->p_sys->config );
131 free( p_intf->p_sys );
134 /*****************************************************************************
135 * intf_Run: main loop
136 *****************************************************************************/
137 static void intf_Run( intf_thread_t *p_intf )
142 /* Manage core vlc functions through the callback */
143 p_intf->pf_manage( p_intf );
145 while( !p_intf->p_vlc->b_die )
147 /* Manage core vlc functions through the callback */
148 p_intf->pf_manage( p_intf );
149 msleep( INTF_IDLE_SLEEP );
151 /* We poll the lircsocket */
152 if( lirc_nextcode(&code) != 0 )
162 while( !p_intf->p_vlc->b_die
163 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
166 if( !strcmp( c, "QUIT" ) )
168 p_intf->p_vlc->b_die = 1;
172 if( !strcmp( c, "FULLSCREEN" ) )
174 vlc_mutex_lock( &p_intf->p_vlc->p_vout_bank->lock );
175 /* XXX: only fullscreen the first video output */
176 if( p_intf->p_vlc->p_vout_bank->i_count )
178 p_intf->p_vlc->p_vout_bank->pp_vout[0]->i_changes
179 |= VOUT_FULLSCREEN_CHANGE;
181 vlc_mutex_unlock( &p_intf->p_vlc->p_vout_bank->lock );
185 vlc_mutex_lock( &p_intf->p_vlc->p_input_bank->lock );
187 if( !strcmp( c, "PLAY" ) )
189 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
191 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0],
193 p_intf->p_vlc->p_playlist->b_stopped = 0;
197 vlc_mutex_lock( &p_intf->p_vlc->p_playlist->change_lock );
199 if( p_intf->p_vlc->p_playlist->b_stopped
200 && p_intf->p_vlc->p_playlist->i_size )
202 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
203 intf_PlaylistJumpto( p_intf->p_vlc->p_playlist,
204 p_intf->p_vlc->p_playlist->i_index );
208 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
212 else if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
214 if( !strcmp( c, "PAUSE" ) )
216 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0],
217 INPUT_STATUS_PAUSE );
219 vlc_mutex_lock( &p_intf->p_vlc->p_playlist->change_lock );
220 p_intf->p_vlc->p_playlist->b_stopped = 0;
221 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
223 else if( !strcmp( c, "NEXT" ) )
225 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
227 else if( !strcmp( c, "LAST" ) )
229 /* FIXME: temporary hack */
230 intf_PlaylistPrev( p_intf->p_vlc->p_playlist );
231 intf_PlaylistPrev( p_intf->p_vlc->p_playlist );
232 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
234 else if( !strcmp( c, "STOP" ) )
236 /* end playing item */
237 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
239 /* update playlist */
240 vlc_mutex_lock( &p_intf->p_vlc->p_playlist->change_lock );
242 p_intf->p_vlc->p_playlist->i_index--;
243 p_intf->p_vlc->p_playlist->b_stopped = 1;
245 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
247 else if( !strcmp( c, "FAST" ) )
249 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0],
250 INPUT_STATUS_FASTER );
252 vlc_mutex_lock( &p_intf->p_vlc->p_playlist->change_lock );
253 p_intf->p_vlc->p_playlist->b_stopped = 0;
254 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
256 else if( !strcmp( c, "SLOW" ) )
258 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0],
259 INPUT_STATUS_SLOWER );
261 vlc_mutex_lock( &p_intf->p_vlc->p_playlist->change_lock );
262 p_intf->p_vlc->p_playlist->b_stopped = 0;
263 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
267 vlc_mutex_unlock( &p_intf->p_vlc->p_input_bank->lock );