1 /*****************************************************************************
2 * lirc.c : lirc plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: lirc.c,v 1.14 2002/07/20 18:01:42 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;
46 input_thread_t * p_input;
49 /*****************************************************************************
51 *****************************************************************************/
52 static void intf_getfunctions( function_list_t * p_function_list );
54 static int intf_Open ( intf_thread_t *p_intf );
55 static void intf_Close ( intf_thread_t *p_intf );
56 static void intf_Run ( intf_thread_t *p_intf );
58 /*****************************************************************************
59 * Build configuration tree.
60 *****************************************************************************/
66 SET_DESCRIPTION( _("infrared remote control module") )
67 ADD_CAPABILITY( INTF, 8 )
71 intf_getfunctions( &p_module->p_functions->intf );
74 MODULE_DEACTIVATE_START
75 MODULE_DEACTIVATE_STOP
77 /*****************************************************************************
78 * Functions exported as capabilities. They are declared as static so that
79 * we don't pollute the namespace too much.
80 *****************************************************************************/
81 static void intf_getfunctions( function_list_t * p_function_list )
83 p_function_list->functions.intf.pf_open = intf_Open;
84 p_function_list->functions.intf.pf_close = intf_Close;
85 p_function_list->functions.intf.pf_run = intf_Run;
88 /*****************************************************************************
89 * intf_Open: initialize dummy interface
90 *****************************************************************************/
91 static int intf_Open( intf_thread_t *p_intf )
95 /* Allocate instance and initialize some members */
96 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
97 if( p_intf->p_sys == NULL )
99 msg_Err( p_intf, "out of memory" );
103 i_fd = lirc_init( "vlc", 1 );
106 msg_Err( p_intf, "lirc_init failed" );
107 free( p_intf->p_sys );
111 /* We want polling */
112 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
114 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
116 msg_Err( p_intf, "lirc_readconfig failed" );
118 free( p_intf->p_sys );
122 p_intf->p_sys->p_input = NULL;
127 /*****************************************************************************
128 * intf_Close: destroy dummy interface
129 *****************************************************************************/
130 static void intf_Close( intf_thread_t *p_intf )
132 if( p_intf->p_sys->p_input )
134 vlc_object_release( p_intf->p_sys->p_input );
137 /* Destroy structure */
138 lirc_freeconfig( p_intf->p_sys->config );
140 free( p_intf->p_sys );
143 /*****************************************************************************
144 * intf_Run: main loop
145 *****************************************************************************/
146 static void intf_Run( intf_thread_t *p_intf )
149 playlist_t *p_playlist;
150 input_thread_t *p_input;
152 while( !p_intf->b_die )
155 msleep( INTF_IDLE_SLEEP );
157 /* Update the input */
158 if( p_intf->p_sys->p_input == NULL )
160 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
163 else if( p_intf->p_sys->p_input->b_dead )
165 vlc_object_release( p_intf->p_sys->p_input );
166 p_intf->p_sys->p_input = NULL;
169 /* We poll the lircsocket */
170 if( lirc_nextcode(&code) != 0 )
180 while( !p_intf->b_die
181 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
184 if( !strcmp( c, "QUIT" ) )
186 p_intf->p_vlc->b_die = VLC_TRUE;
190 if( !strcmp( c, "FULLSCREEN" ) )
192 vout_thread_t *p_vout;
193 p_vout = vlc_object_find( p_intf->p_sys->p_input,
194 VLC_OBJECT_VOUT, FIND_CHILD );
197 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
198 vlc_object_release( p_vout );
203 if( !strcmp( c, "PLAY" ) )
205 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
209 vlc_mutex_lock( &p_playlist->object_lock );
210 if( p_playlist->i_size )
212 vlc_mutex_unlock( &p_playlist->object_lock );
213 playlist_Play( p_playlist );
214 vlc_object_release( p_playlist );
218 else if( p_intf->p_sys->p_input )
220 p_input = p_intf->p_sys->p_input;
222 if( !strcmp( c, "PAUSE" ) )
224 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
226 else if( !strcmp( c, "NEXT" ) )
228 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
232 playlist_Next( p_playlist );
233 vlc_object_release( p_playlist );
236 else if( !strcmp( c, "PREV" ) )
238 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
242 playlist_Prev( p_playlist );
243 vlc_object_release( p_playlist );
246 else if( !strcmp( c, "STOP" ) )
248 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
252 playlist_Stop( p_playlist );
253 vlc_object_release( p_playlist );
256 else if( !strcmp( c, "FAST" ) )
258 input_SetStatus( p_input, INPUT_STATUS_FASTER );
260 else if( !strcmp( c, "SLOW" ) )
262 input_SetStatus( p_input, INPUT_STATUS_SLOWER );