]> git.sesse.net Git - vlc/blob - plugins/lirc/lirc.c
* ./plugins/lirc/lirc.c: fixed my mistakes from yesterday.
[vlc] / plugins / lirc / lirc.c
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 $
6  *
7  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <videolan/vlc.h>
31
32 #include "stream_control.h"
33 #include "input_ext-intf.h"
34 #include "intf_msg.h"
35 #include "interface.h"
36 #include "intf_playlist.h"
37
38 #include "video.h"
39 #include "video_output.h"
40
41 #include <lirc/lirc_client.h>
42
43 /*****************************************************************************
44  * intf_sys_t: description and status of FB interface
45  *****************************************************************************/
46 typedef struct intf_sys_s
47 {
48     struct lirc_config *config;
49     vlc_mutex_t         change_lock;
50 } intf_sys_t;
51
52 /*****************************************************************************
53  * Local prototypes.
54  *****************************************************************************/
55 static void intf_getfunctions( function_list_t * p_function_list );
56
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 );
60
61 /*****************************************************************************
62  * Build configuration tree.
63  *****************************************************************************/
64 MODULE_CONFIG_START
65 ADD_WINDOW( "Configuration for lirc module" )
66     ADD_COMMENT( "use ~/.lircrc" )
67 MODULE_CONFIG_STOP
68
69 MODULE_INIT_START
70     SET_DESCRIPTION( "infrared remote control module" )
71     ADD_CAPABILITY( INTF, 8 )
72     ADD_SHORTCUT( "lirc" )
73 MODULE_INIT_STOP
74
75 MODULE_ACTIVATE_START
76     intf_getfunctions( &p_module->p_functions->intf );
77 MODULE_ACTIVATE_STOP
78
79 MODULE_DEACTIVATE_START
80 MODULE_DEACTIVATE_STOP
81
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 )
87 {
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;
91 }
92
93 /*****************************************************************************
94  * intf_Open: initialize dummy interface
95  *****************************************************************************/
96 static int intf_Open( intf_thread_t *p_intf )
97 {
98     /* Allocate instance and initialize some members */
99     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
100     if( p_intf->p_sys == NULL )
101     {
102         intf_ErrMsg("no mem?");
103         return 1;
104     };
105
106     if( lirc_init("vlc", 1) == -1 )
107     {
108         intf_ErrMsg( "intf error: lirc_init failed" );
109         free( p_intf->p_sys );
110         return 1;
111     }
112
113     if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
114     {
115         intf_ErrMsg( "intf error: lirc_readconfig failed" );
116         lirc_deinit();
117         free( p_intf->p_sys );
118         return 1;
119     }
120
121     return 0;
122 }
123
124 /*****************************************************************************
125  * intf_Close: destroy dummy interface
126  *****************************************************************************/
127 static void intf_Close( intf_thread_t *p_intf )
128 {
129     /* Destroy structure */
130     lirc_freeconfig( p_intf->p_sys->config );
131     lirc_deinit();
132     free( p_intf->p_sys );
133 }
134
135 /*****************************************************************************
136  * intf_Run: main loop
137  *****************************************************************************/
138 static void intf_Run( intf_thread_t *p_intf )
139 {
140     char *code;
141     char *c;
142
143     /* Manage core vlc functions through the callback */
144     p_intf->pf_manage( p_intf );
145
146     while( !p_intf->b_die && lirc_nextcode(&code) == 0 )
147     {
148 printf("code\n");
149         if( code == NULL )
150         {
151             continue;
152         }
153
154         while( !p_intf->b_die 
155                 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
156                 && c != NULL )
157         {
158             if( !strcmp( c, "QUIT" ) )
159             {
160                 p_intf->b_die = 1;
161                 continue;
162             }
163
164             if( !strcmp( c, "FULLSCREEN" ) )
165             {
166                 vlc_mutex_lock( &p_vout_bank->lock );
167                 /* XXX: only fullscreen the first video output */
168                 if( p_vout_bank->i_count )
169                 {
170                     p_vout_bank->pp_vout[0]->i_changes
171                         |= VOUT_FULLSCREEN_CHANGE;
172                 }
173                 vlc_mutex_unlock( &p_vout_bank->lock );
174                 continue;
175             }
176
177             vlc_mutex_lock( &p_input_bank->lock );
178
179             if( !strcmp( c, "PLAY" ) )
180             {
181                 if( p_input_bank->pp_input[0] != NULL )
182                 {
183                     input_SetStatus( p_input_bank->pp_input[0],
184                                      INPUT_STATUS_PLAY );
185                     p_main->p_playlist->b_stopped = 0;
186                 }
187                 else
188                 {
189                     vlc_mutex_lock( &p_main->p_playlist->change_lock );
190
191                     if( p_main->p_playlist->b_stopped )
192                     {
193                         if( p_main->p_playlist->i_size )
194                         {
195                             vlc_mutex_unlock( &p_main->p_playlist->change_lock );
196                             intf_PlaylistJumpto( p_main->p_playlist,
197                                                  p_main->p_playlist->i_index );
198                         }
199                         else
200                         {
201                             vlc_mutex_unlock( &p_main->p_playlist->change_lock );
202                         }
203                     }
204                     else
205                     {
206                         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
207                     }
208                 }
209             }
210             else if( p_input_bank->pp_input[0] != NULL )
211             {
212                 if( !strcmp( c, "PAUSE" ) )
213                 {
214                     input_SetStatus( p_input_bank->pp_input[0],
215                                      INPUT_STATUS_PAUSE );
216
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 );
220                 }
221                 else if( !strcmp( c, "NEXT" ) )
222                 {
223                     p_input_bank->pp_input[0]->b_eof = 1;
224                 }
225                 else if( !strcmp( c, "LAST" ) )
226                 {
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;
231                 }
232                 else if( !strcmp( c, "STOP" ) )
233                 {
234                     /* end playing item */
235                     p_input_bank->pp_input[0]->b_eof = 1;
236     
237                     /* update playlist */
238                     vlc_mutex_lock( &p_main->p_playlist->change_lock );
239     
240                     p_main->p_playlist->i_index--;
241                     p_main->p_playlist->b_stopped = 1;
242     
243                     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
244                 }
245                 else if( !strcmp( c, "FAST" ) )
246                 {
247                     input_SetStatus( p_input_bank->pp_input[0],
248                                      INPUT_STATUS_FASTER );
249     
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 );
253                 }
254                 else if( !strcmp( c, "SLOW" ) )
255                 {
256                     input_SetStatus( p_input_bank->pp_input[0],
257                                      INPUT_STATUS_SLOWER );
258     
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 );
262                 }
263             }
264
265             vlc_mutex_unlock( &p_input_bank->lock );
266         }
267
268         free( code );
269
270         /* Manage core vlc functions through the callback */
271         p_intf->pf_manage( p_intf );
272     }
273 printf("end of intf\n");
274 }
275