]> git.sesse.net Git - vlc/blob - plugins/text/intf_rc.c
* Fixed a few warnings with gcc 3.0.
[vlc] / plugins / text / intf_rc.c
1 /*****************************************************************************
2  * intf_rc.cpp: remote control interface
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: intf_rc.cpp,v 0.1 2001/04/27 shurdeek
6  *
7  * Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
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 #define MODULE_NAME rc
25 #include "modules_inner.h"
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <errno.h>                                                 /* ENOMEM */
33 #include <stdlib.h>                                                /* free() */
34 #include <string.h>                                            /* strerror() */
35 #include <stdio.h>
36 #include <ctype.h>
37 #include <unistd.h>
38 #include <sys/time.h>
39 #include <sys/types.h>
40
41 #include "config.h"
42 #include "common.h"
43 #include "threads.h"
44 #include "mtime.h"
45 #include "tests.h"
46 #include "modules.h"
47
48 #include "stream_control.h"
49 #include "input_ext-intf.h"
50
51 #include "intf_msg.h"
52 #include "intf_playlist.h"
53 #include "interface.h"
54
55 #include "video.h"
56 #include "video_output.h"
57
58 /*****************************************************************************
59  * intf_sys_t: description and status of rc interface
60  *****************************************************************************/
61 typedef struct intf_sys_s
62 {
63     vlc_mutex_t         change_lock;
64
65 } intf_sys_t;
66
67 /*****************************************************************************
68  * Local prototypes.
69  *****************************************************************************/
70 static int  intf_Probe     ( probedata_t *p_data );
71 static int  intf_Open      ( intf_thread_t *p_intf );
72 static void intf_Close     ( intf_thread_t *p_intf );
73 static void intf_Run       ( intf_thread_t *p_intf );
74
75 /*****************************************************************************
76  * Functions exported as capabilities. They are declared as static so that
77  * we don't pollute the namespace too much.
78  *****************************************************************************/
79 void _M( intf_getfunctions )( function_list_t * p_function_list )
80 {
81     p_function_list->pf_probe = intf_Probe;
82     p_function_list->functions.intf.pf_open  = intf_Open;
83     p_function_list->functions.intf.pf_close = intf_Close;
84     p_function_list->functions.intf.pf_run   = intf_Run;
85 }
86
87 /*****************************************************************************
88  * intf_Probe: probe the interface and return a score
89  *****************************************************************************
90  * This function tries to initialize rc and returns a score to the
91  * plugin manager so that it can select the best plugin.
92  *****************************************************************************/
93 static int intf_Probe( probedata_t *p_data )
94 {
95     if( TestMethod( INTF_METHOD_VAR, "rc" ) )
96     {
97         return( 999 );
98     }
99
100     return( 2 );
101 }
102
103 /*****************************************************************************
104  * intf_Open: initialize and create stuff
105  *****************************************************************************/
106 static int intf_Open( intf_thread_t *p_intf )
107 {
108     /* Non-buffered stdout */
109     setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
110
111     /* Allocate instance and initialize some members */
112     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
113     if( p_intf->p_sys == NULL )
114     {
115         intf_ErrMsg( "intf error: %s", strerror(ENOMEM) );
116         return( 1 );
117     }
118
119     return( 0 );
120 }
121
122 /*****************************************************************************
123  * intf_Close: destroy interface stuff
124  *****************************************************************************/
125 static void intf_Close( intf_thread_t *p_intf )
126 {
127     /* Destroy structure */
128     free( p_intf->p_sys );
129 }
130
131 /*****************************************************************************
132  * intf_Run: rc thread
133  *****************************************************************************
134  * This part of the interface is in a separate thread so that we can call
135  * exec() from within it without annoying the rest of the program.
136  *****************************************************************************/
137 static void intf_Run( intf_thread_t *p_intf )
138 {
139     char      p_cmd[ 32 ];
140     int       i_cmd_pos;
141     boolean_t b_complete = 0;
142
143     int       i_dummy;
144     off_t     i_oldpos = 0;
145     off_t     i_newpos;
146     fd_set    fds;                                         /* stdin changed? */
147     struct timeval tv;                                   /* how long to wait */
148
149     double    f_cpos;
150     double    f_ratio = 1;
151
152     while( !p_intf->b_die )
153     {
154         if( p_intf->p_input != NULL )
155         {
156             /* Get position */
157 #define S p_intf->p_input->stream
158             if( S.i_mux_rate )
159             {
160                 f_ratio = 1.0 / ( 50 * S.i_mux_rate );
161                 i_newpos = S.p_selected_area->i_tell * f_ratio;
162
163                 if( i_oldpos != i_newpos )
164                 {
165                     i_oldpos = i_newpos;
166                     intf_Msg( "rc: pos: %li s / %li s", (long int)i_newpos,
167                               (long int)( f_ratio *
168                                           S.p_selected_area->i_size ) );
169                 }
170             }
171 #undef S
172
173             b_complete = 0;
174             i_cmd_pos = 0;
175
176             /* Check stdin */
177             tv.tv_sec = 0;
178             tv.tv_usec = 50000;
179             FD_ZERO( &fds );
180             FD_SET( STDIN_FILENO, &fds );
181
182             if( select( 32, &fds, NULL, NULL, &tv ) )
183             {
184                 while( i_cmd_pos < 32
185                        && read( STDIN_FILENO, p_cmd + i_cmd_pos, 1 ) > 0
186                        && p_cmd[ i_cmd_pos ] != '\r'
187                        && p_cmd[ i_cmd_pos ] != '\n' )
188                 {
189                     i_cmd_pos++;
190                 }
191
192                 if( i_cmd_pos == 31 || p_cmd[ i_cmd_pos ] == '\r'
193                                     || p_cmd[ i_cmd_pos ] == '\n' )
194                 {
195                     p_cmd[ i_cmd_pos ] = 0;
196                     b_complete = 1;
197                 }
198             }
199
200             /* Is there something to do? */
201             if( b_complete == 1 )
202             {
203                 switch( p_cmd[ 0 ] )
204                 {
205                 case 'p':
206                 case 'P':
207                     input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
208                     break;
209
210                 case 'f':
211                 case 'F':
212                     vlc_mutex_lock( &p_vout_bank->lock );
213                     /* XXX: only fullscreen the first video output */
214                     if( p_vout_bank->i_count )
215                     {
216                         p_vout_bank->pp_vout[0]->i_changes
217                                           |= VOUT_FULLSCREEN_CHANGE;
218                     }
219                     vlc_mutex_unlock( &p_vout_bank->lock );
220                     break;
221
222                 case 'm':
223                 case 'M':
224 #if 0
225                     double picratio = p_intf->p_input->p_default_vout->i_width 
226                         / p_intf->p_input->p_default_vout->i_height;
227                     if (picratio
228                     p_intf->p_input->p_default_vout->i_width=800
229                     p_intf->p_input->p_default_vout->i_changes |= 
230                         VOUT_FULLSCREEN_CHANGE;
231 #endif
232                     break;
233
234                 case 's':
235                 case 'S':
236                     ;
237                     break;
238
239                 case 'q':
240                 case 'Q':
241                     p_intf->b_die = 1;
242                     break;
243
244                 case 'r':
245                 case 'R':
246                     for( i_dummy = 1; i_dummy < 32 && p_cmd[ i_dummy ] >= '0'
247                          && p_cmd[ i_dummy ] <= '9'; ++i_dummy )
248                     {
249                         ;
250                     }
251
252                     p_cmd[ i_dummy ] = 0;
253                     f_cpos = atof( p_cmd + 1 );
254                     input_Seek( p_intf->p_input, (off_t) (f_cpos / f_ratio) );
255                     /* rcreseek(f_cpos); */
256                     break;
257
258                 default:
259                     intf_Msg( "rc: unknown command: %s", p_cmd );
260                     break;
261                 }
262             }
263         }
264
265         p_intf->pf_manage( p_intf );
266         msleep( INTF_IDLE_SLEEP );
267     }
268 }
269