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