]> git.sesse.net Git - vlc/blob - plugins/lirc/lirc.c
This is the first part of the new configuration architecture for vlc.
[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.8 2002/02/24 20:51:10 gbazin 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 <fcntl.h>
31
32 #include <videolan/vlc.h>
33
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
36 #include "intf_msg.h"
37 #include "interface.h"
38 #include "intf_playlist.h"
39
40 #include "video.h"
41 #include "video_output.h"
42
43 #include <lirc/lirc_client.h>
44
45 /*****************************************************************************
46  * intf_sys_t: description and status of FB interface
47  *****************************************************************************/
48 typedef struct intf_sys_s
49 {
50     struct lirc_config *config;
51     vlc_mutex_t         change_lock;
52 } intf_sys_t;
53
54 /*****************************************************************************
55  * Local prototypes.
56  *****************************************************************************/
57 static void intf_getfunctions( function_list_t * p_function_list );
58
59 static int  intf_Open      ( intf_thread_t *p_intf );
60 static void intf_Close     ( intf_thread_t *p_intf );
61 static void intf_Run       ( intf_thread_t *p_intf );
62
63 /*****************************************************************************
64  * Build configuration tree.
65  *****************************************************************************/
66 MODULE_CONFIG_START
67
68 MODULE_CONFIG_STOP
69
70 MODULE_INIT_START
71     SET_DESCRIPTION( "infrared remote control module" )
72     ADD_CAPABILITY( INTF, 8 )
73     ADD_SHORTCUT( "lirc" )
74 MODULE_INIT_STOP
75
76 MODULE_ACTIVATE_START
77     intf_getfunctions( &p_module->p_functions->intf );
78 MODULE_ACTIVATE_STOP
79
80 MODULE_DEACTIVATE_START
81 MODULE_DEACTIVATE_STOP
82
83 /*****************************************************************************
84  * Functions exported as capabilities. They are declared as static so that
85  * we don't pollute the namespace too much.
86  *****************************************************************************/
87 static void intf_getfunctions( function_list_t * p_function_list )
88 {
89     p_function_list->functions.intf.pf_open  = intf_Open;
90     p_function_list->functions.intf.pf_close = intf_Close;
91     p_function_list->functions.intf.pf_run   = intf_Run;
92 }
93
94 /*****************************************************************************
95  * intf_Open: initialize dummy interface
96  *****************************************************************************/
97 static int intf_Open( intf_thread_t *p_intf )
98 {
99     int i_fd;
100
101     /* Allocate instance and initialize some members */
102     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
103     if( p_intf->p_sys == NULL )
104     {
105         intf_ErrMsg("no mem?");
106         return 1;
107     }
108
109     i_fd = lirc_init( "vlc", 1 );
110     if( i_fd == -1 )
111     {
112         intf_ErrMsg( "intf error: lirc_init failed" );
113         free( p_intf->p_sys );
114         return 1;
115     }
116
117     /* We want polling */
118     fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
119
120     if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
121     {
122         intf_ErrMsg( "intf error: lirc_readconfig failed" );
123         lirc_deinit();
124         free( p_intf->p_sys );
125         return 1;
126     }
127
128     return 0;
129 }
130
131 /*****************************************************************************
132  * intf_Close: destroy dummy interface
133  *****************************************************************************/
134 static void intf_Close( intf_thread_t *p_intf )
135 {
136     /* Destroy structure */
137     lirc_freeconfig( p_intf->p_sys->config );
138     lirc_deinit();
139     free( p_intf->p_sys );
140 }
141
142 /*****************************************************************************
143  * intf_Run: main loop
144  *****************************************************************************/
145 static void intf_Run( intf_thread_t *p_intf )
146 {
147     char *code;
148     char *c;
149
150     /* Manage core vlc functions through the callback */
151     p_intf->pf_manage( p_intf );
152
153 <<<<<<< lirc.c
154     while( !p_intf->b_die && lirc_nextcode(&code) == 0 )
155 =======
156     while( !p_intf->b_die )
157 >>>>>>> 1.7
158     {
159         /* Manage core vlc functions through the callback */
160         p_intf->pf_manage( p_intf );
161         msleep( INTF_IDLE_SLEEP );
162
163         /* We poll the lircsocket */
164         if( lirc_nextcode(&code) != 0 )
165         {
166             break;
167         }
168
169         if( code == NULL )
170         {
171             continue;
172         }
173
174         while( !p_intf->b_die 
175                 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
176                 && c != NULL )
177         {
178             if( !strcmp( c, "QUIT" ) )
179             {
180                 p_intf->b_die = 1;
181                 continue;
182             }
183
184             if( !strcmp( c, "FULLSCREEN" ) )
185             {
186                 vlc_mutex_lock( &p_vout_bank->lock );
187                 /* XXX: only fullscreen the first video output */
188                 if( p_vout_bank->i_count )
189                 {
190                     p_vout_bank->pp_vout[0]->i_changes
191                         |= VOUT_FULLSCREEN_CHANGE;
192                 }
193                 vlc_mutex_unlock( &p_vout_bank->lock );
194                 continue;
195             }
196
197             vlc_mutex_lock( &p_input_bank->lock );
198
199             if( !strcmp( c, "PLAY" ) )
200             {
201                 if( p_input_bank->pp_input[0] != NULL )
202                 {
203                     input_SetStatus( p_input_bank->pp_input[0],
204                                      INPUT_STATUS_PLAY );
205                     p_main->p_playlist->b_stopped = 0;
206                 }
207                 else
208                 {
209                     vlc_mutex_lock( &p_main->p_playlist->change_lock );
210
211                     if( p_main->p_playlist->b_stopped )
212                     {
213                         if( p_main->p_playlist->i_size )
214                         {
215                             vlc_mutex_unlock( &p_main->p_playlist->change_lock );
216                             intf_PlaylistJumpto( p_main->p_playlist,
217                                                  p_main->p_playlist->i_index );
218                         }
219                         else
220                         {
221                             vlc_mutex_unlock( &p_main->p_playlist->change_lock );
222                         }
223                     }
224                     else
225                     {
226                         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
227                     }
228                 }
229             }
230             else if( p_input_bank->pp_input[0] != NULL )
231             {
232                 if( !strcmp( c, "PAUSE" ) )
233                 {
234                     input_SetStatus( p_input_bank->pp_input[0],
235                                      INPUT_STATUS_PAUSE );
236
237                     vlc_mutex_lock( &p_main->p_playlist->change_lock );
238                     p_main->p_playlist->b_stopped = 0;
239                     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
240                 }
241                 else if( !strcmp( c, "NEXT" ) )
242                 {
243                     p_input_bank->pp_input[0]->b_eof = 1;
244                 }
245                 else if( !strcmp( c, "LAST" ) )
246                 {
247                     /* FIXME: temporary hack */
248                     intf_PlaylistPrev( p_main->p_playlist );
249                     intf_PlaylistPrev( p_main->p_playlist );
250                     p_input_bank->pp_input[0]->b_eof = 1;
251                 }
252                 else if( !strcmp( c, "STOP" ) )
253                 {
254                     /* end playing item */
255                     p_input_bank->pp_input[0]->b_eof = 1;
256     
257                     /* update playlist */
258                     vlc_mutex_lock( &p_main->p_playlist->change_lock );
259     
260                     p_main->p_playlist->i_index--;
261                     p_main->p_playlist->b_stopped = 1;
262     
263                     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
264                 }
265                 else if( !strcmp( c, "FAST" ) )
266                 {
267                     input_SetStatus( p_input_bank->pp_input[0],
268                                      INPUT_STATUS_FASTER );
269     
270                     vlc_mutex_lock( &p_main->p_playlist->change_lock );
271                     p_main->p_playlist->b_stopped = 0;
272                     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
273                 }
274                 else if( !strcmp( c, "SLOW" ) )
275                 {
276                     input_SetStatus( p_input_bank->pp_input[0],
277                                      INPUT_STATUS_SLOWER );
278     
279                     vlc_mutex_lock( &p_main->p_playlist->change_lock );
280                     p_main->p_playlist->b_stopped = 0;
281                     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
282                 }
283             }
284
285             vlc_mutex_unlock( &p_input_bank->lock );
286         }
287
288         free( code );
289     }
290 }
291