1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: rc.c,v 1.10 2002/02/15 13:32:53 sam Exp $
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 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <errno.h> /* ENOMEM */
35 #include <sys/types.h>
37 #include <videolan/vlc.h>
40 #include <winsock2.h> /* select() */
43 #include "stream_control.h"
44 #include "input_ext-intf.h"
46 #include "intf_playlist.h"
47 #include "interface.h"
50 #include "video_output.h"
52 /*****************************************************************************
53 * intf_sys_t: description and status of rc interface
54 *****************************************************************************/
55 typedef struct intf_sys_s
57 vlc_mutex_t change_lock;
61 #define MAX_LINE_LENGTH 256
63 /*****************************************************************************
65 *****************************************************************************/
66 static void intf_getfunctions ( function_list_t * p_function_list );
67 static int intf_Open ( intf_thread_t *p_intf );
68 static void intf_Close ( intf_thread_t *p_intf );
69 static void intf_Run ( intf_thread_t *p_intf );
71 /*****************************************************************************
72 * Build configuration tree.
73 *****************************************************************************/
78 SET_DESCRIPTION( "remote control interface module" )
79 ADD_CAPABILITY( INTF, 20 )
84 intf_getfunctions( &p_module->p_functions->intf );
87 MODULE_DEACTIVATE_START
88 MODULE_DEACTIVATE_STOP
90 /*****************************************************************************
91 * Functions exported as capabilities. They are declared as static so that
92 * we don't pollute the namespace too much.
93 *****************************************************************************/
94 static void intf_getfunctions( function_list_t * p_function_list )
96 p_function_list->functions.intf.pf_open = intf_Open;
97 p_function_list->functions.intf.pf_close = intf_Close;
98 p_function_list->functions.intf.pf_run = intf_Run;
101 /*****************************************************************************
102 * intf_Open: initialize and create stuff
103 *****************************************************************************/
104 static int intf_Open( intf_thread_t *p_intf )
106 /* Non-buffered stdout */
107 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
109 /* Allocate instance and initialize some members */
110 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
111 if( p_intf->p_sys == NULL )
113 intf_ErrMsg( "intf error: %s", strerror(ENOMEM) );
117 intf_Msg( "rc: remote control interface initialized, `h' for help" );
121 /*****************************************************************************
122 * intf_Close: destroy interface stuff
123 *****************************************************************************/
124 static void intf_Close( intf_thread_t *p_intf )
126 /* Destroy structure */
127 free( p_intf->p_sys );
130 /*****************************************************************************
131 * intf_Run: rc thread
132 *****************************************************************************
133 * This part of the interface is in a separate thread so that we can call
134 * exec() from within it without annoying the rest of the program.
135 *****************************************************************************/
136 static void intf_Run( intf_thread_t *p_intf )
138 char p_cmd[ MAX_LINE_LENGTH + 1 ];
140 boolean_t b_complete = 0;
145 fd_set fds; /* stdin changed? */
146 struct timeval tv; /* how long to wait */
151 while( !p_intf->b_die )
153 vlc_mutex_lock( &p_input_bank->lock );
154 #define S p_input_bank->pp_input[0]->stream
155 if( p_input_bank->pp_input[0] != NULL )
160 f_ratio = 1.0 / ( 50 * S.i_mux_rate );
161 i_newpos = S.p_selected_area->i_tell * f_ratio;
163 if( 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 ) );
173 vlc_mutex_unlock( &p_input_bank->lock );
182 FD_SET( STDIN_FILENO, &fds );
184 if( select( 32, &fds, NULL, NULL, &tv ) )
186 while( !p_intf->b_die
187 && i_cmd_pos < MAX_LINE_LENGTH
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' )
195 if( i_cmd_pos == MAX_LINE_LENGTH
196 || p_cmd[ i_cmd_pos ] == '\r'
197 || p_cmd[ i_cmd_pos ] == '\n' )
199 p_cmd[ i_cmd_pos ] = 0;
204 vlc_mutex_lock( &p_input_bank->lock );
206 /* Is there something to do? */
207 if( b_complete == 1 )
213 if( p_cmd[ 1 ] == ' ' )
215 intf_PlaylistAdd( p_main->p_playlist,
216 PLAYLIST_END, p_cmd + 2 );
217 if( p_input_bank->pp_input[0] != NULL )
219 p_input_bank->pp_input[0]->b_eof = 1;
221 intf_PlaylistJumpto( p_main->p_playlist,
222 p_main->p_playlist->i_size - 2 );
228 if( p_input_bank->pp_input[0] != NULL )
230 input_SetStatus( p_input_bank->pp_input[0],
231 INPUT_STATUS_PAUSE );
237 vlc_mutex_lock( &p_vout_bank->lock );
238 /* XXX: only fullscreen the first video output */
239 if( p_vout_bank->i_count )
241 p_vout_bank->pp_vout[0]->i_changes
242 |= VOUT_FULLSCREEN_CHANGE;
244 vlc_mutex_unlock( &p_vout_bank->lock );
250 double picratio = p_intf->p_input->p_default_vout->i_width
251 / p_intf->p_input->p_default_vout->i_height;
253 p_intf->p_input->p_default_vout->i_width=800
254 p_intf->p_input->p_default_vout->i_changes |=
255 VOUT_FULLSCREEN_CHANGE;
271 if( p_input_bank->pp_input[0] != NULL )
274 i_dummy < MAX_LINE_LENGTH && p_cmd[ i_dummy ] >= '0'
275 && p_cmd[ i_dummy ] <= '9';
281 p_cmd[ i_dummy ] = 0;
282 f_cpos = atof( p_cmd + 1 );
283 input_Seek( p_input_bank->pp_input[0],
284 (off_t) (f_cpos / f_ratio) );
285 /* rcreseek(f_cpos); */
292 intf_Msg( "rc: help for remote control commands" );
293 intf_Msg( "rc: h help" );
294 intf_Msg( "rc: a XYZ append XYZ to playlist" );
295 intf_Msg( "rc: p toggle pause" );
296 intf_Msg( "rc: f toggle fullscreen" );
297 intf_Msg( "rc: r X seek in seconds, for instance `r 3.5'" );
298 intf_Msg( "rc: q quit" );
299 intf_Msg( "rc: end of help" );
303 intf_Msg( "rc: unknown command `%s'", p_cmd );
308 vlc_mutex_unlock( &p_input_bank->lock );
310 p_intf->pf_manage( p_intf );
311 msleep( INTF_IDLE_SLEEP );