1 /*****************************************************************************
2 * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: input_dummy.c,v 1.14 2002/01/10 04:11:25 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
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 *****************************************************************************/
28 #include <sys/types.h>
32 #include <videolan/vlc.h>
34 #ifdef STRNCASECMP_IN_STRINGS_H
38 #include "interface.h"
39 #include "intf_playlist.h"
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43 #include "input_ext-dec.h"
44 #include "input_ext-plugins.h"
46 /*****************************************************************************
48 *****************************************************************************/
49 static int DummyProbe ( probedata_t * );
50 static void DummyInit ( struct input_thread_s * );
51 static void DummyOpen ( struct input_thread_s * );
52 static void DummyClose ( struct input_thread_s * );
53 static void DummyEnd ( struct input_thread_s * );
54 static int DummyRead ( struct input_thread_s *, data_packet_t ** );
56 /*****************************************************************************
57 * dummy_data_t: private input data
58 *****************************************************************************/
59 typedef struct dummy_data_s
61 /* The real command */
64 /* Used for the pause command */
70 #define COMMAND_QUIT 1
71 #define COMMAND_LOOP 2
72 #define COMMAND_PAUSE 3
74 /*****************************************************************************
75 * Functions exported as capabilities. They are declared as static so that
76 * we don't pollute the namespace too much.
77 *****************************************************************************/
78 void _M( input_getfunctions )( function_list_t * p_function_list )
80 #define input p_function_list->functions.input
81 p_function_list->pf_probe = DummyProbe;
82 input.pf_init = DummyInit;
83 input.pf_open = DummyOpen;
84 input.pf_close = DummyClose;
85 input.pf_end = DummyEnd;
86 input.pf_set_area = NULL;
87 input.pf_read = DummyRead;
88 input.pf_demux = NULL;
89 input.pf_new_packet = NULL;
90 input.pf_new_pes = NULL;
91 input.pf_delete_packet = NULL;
92 input.pf_delete_pes = NULL;
93 input.pf_rewind = NULL;
98 /*****************************************************************************
99 * DummyProbe: verifies that the input is a vlc command
100 *****************************************************************************/
101 static int DummyProbe( probedata_t *p_data )
103 input_thread_t *p_input = (input_thread_t *)p_data;
104 char *psz_name = p_input->p_source;
106 if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "vlc:", 4 ) )
108 /* If the user specified "vlc:" then it's probably a file */
115 /*****************************************************************************
116 * DummyOpen: open the target, ie. do nothing
117 *****************************************************************************/
118 static void DummyOpen( input_thread_t * p_input )
120 p_input->stream.i_method = INPUT_METHOD_NONE;
123 /*****************************************************************************
124 * DummyClose: close the target, ie. do nothing
125 *****************************************************************************/
126 static void DummyClose( input_thread_t * p_input )
131 /*****************************************************************************
132 * DummyOpen: initialize the target, ie. parse the command
133 *****************************************************************************/
134 static void DummyInit( struct input_thread_s *p_input )
136 dummy_data_t* p_method;
137 char *psz_name = p_input->p_source;
138 int i_len = strlen( psz_name );
141 p_input->stream.b_seekable = 0;
143 if( ( i_len <= 4 ) || strncasecmp( psz_name, "vlc:", 4 ) )
145 /* If the command doesn't start with "vlc:" then it's not for us */
146 p_input->b_error = 1;
150 /* We don't need the "vlc:" stuff any more */
154 p_method = malloc( sizeof( dummy_data_t ) );
155 if( p_method == NULL )
157 intf_ErrMsg( "input: out of memory" );
158 p_input->b_error = 1;
162 p_input->p_plugin_data = (void *)p_method;
163 p_input->stream.p_demux_data = NULL;
165 /* Check for a "vlc:nop" command */
166 if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
168 intf_WarnMsg( 2, "input: command `nop'" );
169 p_method->i_command = COMMAND_NOP;
173 /* Check for a "vlc:quit" command */
174 if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
176 intf_WarnMsg( 2, "input: command `quit'" );
177 p_method->i_command = COMMAND_QUIT;
181 /* Check for a "vlc:loop" command */
182 if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
184 intf_WarnMsg( 2, "input: command `loop'" );
185 p_method->i_command = COMMAND_LOOP;
189 /* Check for a "vlc:pause:***" command */
190 if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
192 i_arg = atoi( psz_name + 6 );
193 intf_WarnMsg( 2, "input: command `pause %i'", i_arg );
194 p_method->i_command = COMMAND_PAUSE;
195 p_method->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
199 intf_ErrMsg( "input error: unknown command `%s'", psz_name );
200 free( p_input->p_plugin_data );
201 p_input->b_error = 1;
206 /*****************************************************************************
207 * DummyEnd: end the target, ie. do nothing
208 *****************************************************************************/
209 static void DummyEnd( struct input_thread_s *p_input )
211 free( p_input->p_plugin_data );
214 /*****************************************************************************
215 * DummyRead: do what the command says
216 *****************************************************************************/
217 static int DummyRead( struct input_thread_s *p_input, data_packet_t **pp_data )
219 dummy_data_t* p_method = (dummy_data_t *)p_input->p_plugin_data;
221 switch( p_method->i_command )
228 intf_PlaylistJumpto( p_main->p_playlist, -1 );
233 if( mdate() < p_method->expiration )