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>
47 #include "stream_control.h"
48 #include "input_ext-intf.h"
51 #include "intf_playlist.h"
52 #include "interface.h"
55 #include "video_output.h"
58 #include "modules_export.h"
60 /*****************************************************************************
61 * intf_sys_t: description and status of rc interface
62 *****************************************************************************/
63 typedef struct intf_sys_s
65 vlc_mutex_t change_lock;
69 #define MAX_LINE_LENGTH 256
71 /*****************************************************************************
73 *****************************************************************************/
74 static int intf_Probe ( probedata_t *p_data );
75 static int intf_Open ( intf_thread_t *p_intf );
76 static void intf_Close ( intf_thread_t *p_intf );
77 static void intf_Run ( intf_thread_t *p_intf );
79 /*****************************************************************************
80 * Functions exported as capabilities. They are declared as static so that
81 * we don't pollute the namespace too much.
82 *****************************************************************************/
83 void _M( intf_getfunctions )( function_list_t * p_function_list )
85 p_function_list->pf_probe = intf_Probe;
86 p_function_list->functions.intf.pf_open = intf_Open;
87 p_function_list->functions.intf.pf_close = intf_Close;
88 p_function_list->functions.intf.pf_run = intf_Run;
91 /*****************************************************************************
92 * intf_Probe: probe the interface and return a score
93 *****************************************************************************
94 * This function tries to initialize rc and returns a score to the
95 * plugin manager so that it can select the best plugin.
96 *****************************************************************************/
97 static int intf_Probe( probedata_t *p_data )
99 if( TestMethod( INTF_METHOD_VAR, "rc" ) )
107 /*****************************************************************************
108 * intf_Open: initialize and create stuff
109 *****************************************************************************/
110 static int intf_Open( intf_thread_t *p_intf )
112 /* Non-buffered stdout */
113 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
115 /* Allocate instance and initialize some members */
116 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
117 if( p_intf->p_sys == NULL )
119 intf_ErrMsg( "intf error: %s", strerror(ENOMEM) );
126 /*****************************************************************************
127 * intf_Close: destroy interface stuff
128 *****************************************************************************/
129 static void intf_Close( intf_thread_t *p_intf )
131 /* Destroy structure */
132 free( p_intf->p_sys );
135 /*****************************************************************************
136 * intf_Run: rc thread
137 *****************************************************************************
138 * This part of the interface is in a separate thread so that we can call
139 * exec() from within it without annoying the rest of the program.
140 *****************************************************************************/
141 static void intf_Run( intf_thread_t *p_intf )
143 char p_cmd[ MAX_LINE_LENGTH + 1 ];
145 boolean_t b_complete = 0;
150 fd_set fds; /* stdin changed? */
151 struct timeval tv; /* how long to wait */
156 while( !p_intf->b_die )
158 #define S p_intf->p_input->stream
159 if( p_intf->p_input != NULL )
164 f_ratio = 1.0 / ( 50 * S.i_mux_rate );
165 i_newpos = S.p_selected_area->i_tell * f_ratio;
167 if( i_oldpos != i_newpos )
170 intf_Msg( "rc: pos: %li s / %li s", (long int)i_newpos,
171 (long int)( f_ratio *
172 S.p_selected_area->i_size ) );
185 FD_SET( STDIN_FILENO, &fds );
187 if( select( 32, &fds, NULL, NULL, &tv ) )
189 while( !p_intf->b_die
190 && i_cmd_pos < MAX_LINE_LENGTH
191 && read( STDIN_FILENO, p_cmd + i_cmd_pos, 1 ) > 0
192 && p_cmd[ i_cmd_pos ] != '\r'
193 && p_cmd[ i_cmd_pos ] != '\n' )
198 if( i_cmd_pos == MAX_LINE_LENGTH
199 || p_cmd[ i_cmd_pos ] == '\r'
200 || p_cmd[ i_cmd_pos ] == '\n' )
202 p_cmd[ i_cmd_pos ] = 0;
207 /* Is there something to do? */
208 if( b_complete == 1 )
214 if( p_intf->p_input != NULL )
216 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
222 vlc_mutex_lock( &p_vout_bank->lock );
223 /* XXX: only fullscreen the first video output */
224 if( p_vout_bank->i_count )
226 p_vout_bank->pp_vout[0]->i_changes
227 |= VOUT_FULLSCREEN_CHANGE;
229 vlc_mutex_unlock( &p_vout_bank->lock );
235 double picratio = p_intf->p_input->p_default_vout->i_width
236 / p_intf->p_input->p_default_vout->i_height;
238 p_intf->p_input->p_default_vout->i_width=800
239 p_intf->p_input->p_default_vout->i_changes |=
240 VOUT_FULLSCREEN_CHANGE;
256 if( p_intf->p_input != NULL )
259 i_dummy < MAX_LINE_LENGTH && p_cmd[ i_dummy ] >= '0'
260 && p_cmd[ i_dummy ] <= '9';
266 p_cmd[ i_dummy ] = 0;
267 f_cpos = atof( p_cmd + 1 );
268 input_Seek( p_intf->p_input, (off_t) (f_cpos / f_ratio) );
269 /* rcreseek(f_cpos); */
274 intf_Msg( "rc: unknown command `%s'", p_cmd );
279 p_intf->pf_manage( p_intf );
280 msleep( INTF_IDLE_SLEEP );