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
7 * Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
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 #define MODULE_NAME rc
25 #include "modules_inner.h"
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <errno.h> /* ENOMEM */
33 #include <stdlib.h> /* free() */
34 #include <string.h> /* strerror() */
39 #include <sys/types.h>
42 #include <winsock2.h> /* select() */
51 #include "stream_control.h"
52 #include "input_ext-intf.h"
54 #include "intf_playlist.h"
55 #include "interface.h"
58 #include "video_output.h"
61 #include "modules_export.h"
63 /*****************************************************************************
64 * intf_sys_t: description and status of rc interface
65 *****************************************************************************/
66 typedef struct intf_sys_s
68 vlc_mutex_t change_lock;
72 #define MAX_LINE_LENGTH 256
74 /*****************************************************************************
76 *****************************************************************************/
77 static int intf_Probe ( probedata_t *p_data );
78 static int intf_Open ( intf_thread_t *p_intf );
79 static void intf_Close ( intf_thread_t *p_intf );
80 static void intf_Run ( intf_thread_t *p_intf );
82 /*****************************************************************************
83 * Functions exported as capabilities. They are declared as static so that
84 * we don't pollute the namespace too much.
85 *****************************************************************************/
86 void _M( intf_getfunctions )( function_list_t * p_function_list )
88 p_function_list->pf_probe = intf_Probe;
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;
94 /*****************************************************************************
95 * intf_Probe: probe the interface and return a score
96 *****************************************************************************
97 * This function tries to initialize rc and returns a score to the
98 * plugin manager so that it can select the best plugin.
99 *****************************************************************************/
100 static int intf_Probe( probedata_t *p_data )
102 if( TestMethod( INTF_METHOD_VAR, "rc" ) )
110 /*****************************************************************************
111 * intf_Open: initialize and create stuff
112 *****************************************************************************/
113 static int intf_Open( intf_thread_t *p_intf )
115 /* Non-buffered stdout */
116 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
118 /* Allocate instance and initialize some members */
119 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
120 if( p_intf->p_sys == NULL )
122 intf_ErrMsg( "intf error: %s", strerror(ENOMEM) );
129 /*****************************************************************************
130 * intf_Close: destroy interface stuff
131 *****************************************************************************/
132 static void intf_Close( intf_thread_t *p_intf )
134 /* Destroy structure */
135 free( p_intf->p_sys );
138 /*****************************************************************************
139 * intf_Run: rc thread
140 *****************************************************************************
141 * This part of the interface is in a separate thread so that we can call
142 * exec() from within it without annoying the rest of the program.
143 *****************************************************************************/
144 static void intf_Run( intf_thread_t *p_intf )
146 char p_cmd[ MAX_LINE_LENGTH + 1 ];
148 boolean_t b_complete = 0;
153 fd_set fds; /* stdin changed? */
154 struct timeval tv; /* how long to wait */
159 while( !p_intf->b_die )
161 #define S p_intf->p_input->stream
162 if( p_intf->p_input != NULL )
167 f_ratio = 1.0 / ( 50 * S.i_mux_rate );
168 i_newpos = S.p_selected_area->i_tell * f_ratio;
170 if( i_oldpos != i_newpos )
173 intf_Msg( "rc: pos: %li s / %li s", (long int)i_newpos,
174 (long int)( f_ratio *
175 S.p_selected_area->i_size ) );
188 FD_SET( STDIN_FILENO, &fds );
190 if( select( 32, &fds, NULL, NULL, &tv ) )
192 while( !p_intf->b_die
193 && i_cmd_pos < MAX_LINE_LENGTH
194 && read( STDIN_FILENO, p_cmd + i_cmd_pos, 1 ) > 0
195 && p_cmd[ i_cmd_pos ] != '\r'
196 && p_cmd[ i_cmd_pos ] != '\n' )
201 if( i_cmd_pos == MAX_LINE_LENGTH
202 || p_cmd[ i_cmd_pos ] == '\r'
203 || p_cmd[ i_cmd_pos ] == '\n' )
205 p_cmd[ i_cmd_pos ] = 0;
210 /* Is there something to do? */
211 if( b_complete == 1 )
217 if( p_intf->p_input != NULL )
219 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
225 vlc_mutex_lock( &p_vout_bank->lock );
226 /* XXX: only fullscreen the first video output */
227 if( p_vout_bank->i_count )
229 p_vout_bank->pp_vout[0]->i_changes
230 |= VOUT_FULLSCREEN_CHANGE;
232 vlc_mutex_unlock( &p_vout_bank->lock );
238 double picratio = p_intf->p_input->p_default_vout->i_width
239 / p_intf->p_input->p_default_vout->i_height;
241 p_intf->p_input->p_default_vout->i_width=800
242 p_intf->p_input->p_default_vout->i_changes |=
243 VOUT_FULLSCREEN_CHANGE;
259 if( p_intf->p_input != NULL )
262 i_dummy < MAX_LINE_LENGTH && p_cmd[ i_dummy ] >= '0'
263 && p_cmd[ i_dummy ] <= '9';
269 p_cmd[ i_dummy ] = 0;
270 f_cpos = atof( p_cmd + 1 );
271 input_Seek( p_intf->p_input, (off_t) (f_cpos / f_ratio) );
272 /* rcreseek(f_cpos); */
277 intf_Msg( "rc: unknown command `%s'", p_cmd );
282 p_intf->pf_manage( p_intf );
283 msleep( INTF_IDLE_SLEEP );