1 /*****************************************************************************
2 * lirc.c : lirc plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: lirc.c,v 1.15 2002/07/31 20:56:51 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 int Open ( vlc_object_t * );
53 static void Close ( vlc_object_t * );
54 static void Run ( intf_thread_t * );
56 /*****************************************************************************
58 *****************************************************************************/
60 set_description( _("infrared remote control module") );
61 set_capability( "interface", 0 );
62 set_callbacks( Open, Close );
65 /*****************************************************************************
66 * Open: initialize interface
67 *****************************************************************************/
68 static int Open( vlc_object_t *p_this )
70 intf_thread_t *p_intf = (intf_thread_t *)p_this;
73 /* Allocate instance and initialize some members */
74 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
75 if( p_intf->p_sys == NULL )
77 msg_Err( p_intf, "out of memory" );
83 i_fd = lirc_init( "vlc", 1 );
86 msg_Err( p_intf, "lirc_init failed" );
87 free( p_intf->p_sys );
92 fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
94 if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
96 msg_Err( p_intf, "lirc_readconfig failed" );
98 free( p_intf->p_sys );
102 p_intf->p_sys->p_input = NULL;
107 /*****************************************************************************
108 * Close: destroy interface
109 *****************************************************************************/
110 static void Close( vlc_object_t *p_this )
112 intf_thread_t *p_intf = (intf_thread_t *)p_this;
114 if( p_intf->p_sys->p_input )
116 vlc_object_release( p_intf->p_sys->p_input );
119 /* Destroy structure */
120 lirc_freeconfig( p_intf->p_sys->config );
122 free( p_intf->p_sys );
125 /*****************************************************************************
127 *****************************************************************************/
128 static void Run( intf_thread_t *p_intf )
131 playlist_t *p_playlist;
132 input_thread_t *p_input;
134 while( !p_intf->b_die )
137 msleep( INTF_IDLE_SLEEP );
139 /* Update the input */
140 if( p_intf->p_sys->p_input == NULL )
142 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
145 else if( p_intf->p_sys->p_input->b_dead )
147 vlc_object_release( p_intf->p_sys->p_input );
148 p_intf->p_sys->p_input = NULL;
151 /* We poll the lircsocket */
152 if( lirc_nextcode(&code) != 0 )
162 while( !p_intf->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 = VLC_TRUE;
172 if( !strcmp( c, "FULLSCREEN" ) )
174 vout_thread_t *p_vout;
175 p_vout = vlc_object_find( p_intf->p_sys->p_input,
176 VLC_OBJECT_VOUT, FIND_CHILD );
179 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
180 vlc_object_release( p_vout );
185 if( !strcmp( c, "PLAY" ) )
187 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
191 vlc_mutex_lock( &p_playlist->object_lock );
192 if( p_playlist->i_size )
194 vlc_mutex_unlock( &p_playlist->object_lock );
195 playlist_Play( p_playlist );
196 vlc_object_release( p_playlist );
200 else if( p_intf->p_sys->p_input )
202 p_input = p_intf->p_sys->p_input;
204 if( !strcmp( c, "PAUSE" ) )
206 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
208 else if( !strcmp( c, "NEXT" ) )
210 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
214 playlist_Next( p_playlist );
215 vlc_object_release( p_playlist );
218 else if( !strcmp( c, "PREV" ) )
220 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
224 playlist_Prev( p_playlist );
225 vlc_object_release( p_playlist );
228 else if( !strcmp( c, "STOP" ) )
230 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
234 playlist_Stop( p_playlist );
235 vlc_object_release( p_playlist );
238 else if( !strcmp( c, "FAST" ) )
240 input_SetStatus( p_input, INPUT_STATUS_FASTER );
242 else if( !strcmp( c, "SLOW" ) )
244 input_SetStatus( p_input, INPUT_STATUS_SLOWER );