1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: rc.c,v 1.24 2002/07/31 20:56:52 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 */
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
45 #include <sys/types.h>
48 #include <winsock2.h> /* select() */
51 #define MAX_LINE_LENGTH 256
53 /*****************************************************************************
55 *****************************************************************************/
56 static int Activate ( vlc_object_t * );
57 static void Run ( intf_thread_t *p_intf );
59 /*****************************************************************************
61 *****************************************************************************/
63 set_description( _("remote control interface module") );
64 set_capability( "interface", 20 );
65 set_callbacks( Activate, NULL );
68 /*****************************************************************************
69 * Activate: initialize and create stuff
70 *****************************************************************************/
71 static int Activate( vlc_object_t *p_this )
73 intf_thread_t *p_intf = (intf_thread_t*)p_this;
76 /* Check that stdin is a TTY */
79 msg_Warn( p_intf, "fd 0 is not a TTY" );
84 /* Non-buffered stdout */
85 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
91 freopen( "CONOUT$", "w", stdout );
92 freopen( "CONOUT$", "w", stderr );
93 freopen( "CONIN$", "r", stdin );
94 printf( VERSION_MESSAGE "\n" );
97 printf( "remote control interface initialized, `h' for help\n" );
101 /*****************************************************************************
103 *****************************************************************************
104 * This part of the interface is in a separate thread so that we can call
105 * exec() from within it without annoying the rest of the program.
106 *****************************************************************************/
107 static void Run( intf_thread_t *p_intf )
109 input_thread_t * p_input;
111 char p_buffer[ MAX_LINE_LENGTH + 1 ];
112 vlc_bool_t b_complete = 0;
113 input_info_category_t * p_category;
114 input_info_t * p_info;
119 fd_set fds; /* stdin changed? */
120 struct timeval tv; /* how long to wait */
125 memset(psz_dashes, '-', 80);
126 psz_dashes[80] = '\0';
130 while( !p_intf->b_die )
138 FD_SET( STDIN_FILENO, &fds );
140 i_dummy = select( 32, &fds, NULL, NULL, &tv );
145 while( !p_intf->b_die
146 && i_size < MAX_LINE_LENGTH
147 && read( STDIN_FILENO, p_buffer + i_size, 1 ) > 0
148 && p_buffer[ i_size ] != '\r'
149 && p_buffer[ i_size ] != '\n' )
154 if( i_size == MAX_LINE_LENGTH
155 || p_buffer[ i_size ] == '\r'
156 || p_buffer[ i_size ] == '\n' )
158 p_buffer[ i_size ] = 0;
163 /* Manage the input part */
164 if( p_input == NULL )
166 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
169 else if( p_input->b_dead )
171 vlc_object_release( p_input );
178 vlc_mutex_lock( &p_input->stream.stream_lock );
179 if( !p_input->b_die && p_input->stream.i_mux_rate )
181 #define A p_input->stream.p_selected_area
182 f_ratio = 1.0 / ( 50 * p_input->stream.i_mux_rate );
183 i_newpos = A->i_tell * f_ratio;
185 if( i_oldpos != i_newpos )
188 printf( "pos: %li s / %li s\n", (long int)i_newpos,
189 (long int)(f_ratio * A->i_size) );
193 vlc_mutex_unlock( &p_input->stream.stream_lock );
196 /* Is there something to do? */
197 if( b_complete == 1 )
199 char *p_cmd = p_buffer;
205 if( p_cmd[1] == ' ' )
207 playlist_t *p_playlist;
208 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
212 playlist_Add( p_playlist, p_cmd + 2,
213 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
214 vlc_object_release( p_playlist );
221 vlc_dumpstructure( p_intf->p_vlc );
228 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
236 vout_thread_t *p_vout;
237 p_vout = vlc_object_find( p_input,
238 VLC_OBJECT_VOUT, FIND_CHILD );
242 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
243 vlc_object_release( p_vout );
255 p_intf->p_vlc->b_die = VLC_TRUE;
263 i_dummy < MAX_LINE_LENGTH && p_cmd[ i_dummy ] >= '0'
264 && p_cmd[ i_dummy ] <= '9';
270 p_cmd[ i_dummy ] = 0;
271 input_Seek( p_input, (off_t)atoi( p_cmd + 1 ),
272 INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
273 /* rcreseek(f_cpos); */
280 printf( "help for remote control commands\n" );
281 printf( "h . . . . . . . . . . . . . . . . . . . . . help\n" );
282 printf( "a XYZ . . . . . . . . . . append XYZ to playlist\n" );
283 printf( "p . . . . . . . . . . . . . . . . . toggle pause\n" );
284 printf( "f . . . . . . . . . . . . . . toggle fullscreen\n" );
285 printf( "r X . . . seek in seconds, for instance `r 3.5'\n" );
286 printf( "q . . . . . . . . . . . . . . . . . . . . . quit\n" );
287 printf( "end of help\n" );
291 printf( "Dumping stream info\n" );
292 vlc_mutex_lock( &p_input->stream.stream_lock );
293 p_category = p_input->stream.p_info;
296 psz_dashes[72 - strlen(p_category->psz_name) ] = '\0';
297 printf( "+--| %s |%s+\n", p_category->psz_name, psz_dashes);
298 psz_dashes[72 - strlen(p_category->psz_name) ] = '-';
299 p_info = p_category->p_info;
302 printf( "| %s: %s\n", p_info->psz_name,
304 p_info = p_info->p_next;
307 p_category = p_category->p_next;
309 psz_dashes[78] = '\0';
310 printf( "+%s+\n", psz_dashes );
311 vlc_mutex_unlock( &p_input->stream.stream_lock );
314 /* Ignore empty lines */
317 printf( "unknown command `%s'\n", p_cmd );
322 msleep( INTF_IDLE_SLEEP );
327 vlc_object_release( p_input );