1 /*****************************************************************************
2 * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: input_dummy.c,v 1.19 2002/06/07 16:06:09 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>
34 #include <vlc/input.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 static int DummyInit ( input_thread_t * );
40 static int DummyOpen ( input_thread_t * );
41 static void DummyClose ( input_thread_t * );
42 static void DummyEnd ( input_thread_t * );
43 static int DummyDemux ( input_thread_t * );
45 /*****************************************************************************
46 * access_sys_t: private input data
47 *****************************************************************************/
50 /* The real command */
53 /* Used for the pause command */
58 #define COMMAND_QUIT 1
59 #define COMMAND_LOOP 2
60 #define COMMAND_PAUSE 3
62 /*****************************************************************************
63 * Functions exported as capabilities. They are declared as static so that
64 * we don't pollute the namespace too much.
65 *****************************************************************************/
66 void _M( access_getfunctions )( function_list_t * p_function_list )
68 #define input p_function_list->functions.access
69 input.pf_open = DummyOpen;
71 input.pf_close = DummyClose;
72 input.pf_set_program = NULL;
73 input.pf_set_area = NULL;
78 void _M( demux_getfunctions )( function_list_t * p_function_list )
80 #define input p_function_list->functions.demux
81 input.pf_init = DummyInit;
82 input.pf_end = DummyEnd;
83 input.pf_demux = DummyDemux;
84 input.pf_rewind = NULL;
88 /*****************************************************************************
89 * DummyOpen: open the target, ie. do nothing
90 *****************************************************************************/
91 static int DummyOpen( input_thread_t * p_input )
93 p_input->stream.i_method = INPUT_METHOD_NONE;
95 /* Force dummy demux plug-in */
96 p_input->psz_demux = "vlc";
100 /*****************************************************************************
101 * DummyClose: close the target, ie. do nothing
102 *****************************************************************************/
103 static void DummyClose( input_thread_t * p_input )
107 /*****************************************************************************
108 * DummyInit: initialize the target, ie. parse the command
109 *****************************************************************************/
110 static int DummyInit( input_thread_t *p_input )
112 char * psz_name = p_input->psz_name;
113 int i_len = strlen( psz_name );
114 struct demux_sys_s * p_method;
117 p_input->stream.b_seekable = 0;
119 p_method = malloc( sizeof( struct demux_sys_s ) );
120 if( p_method == NULL )
122 msg_Err( p_input, "out of memory" );
126 p_input->p_demux_data = p_method;
127 p_input->stream.p_demux_data = NULL;
129 /* Check for a "vlc:nop" command */
130 if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
132 msg_Info( p_input, "command `nop'" );
133 p_method->i_command = COMMAND_NOP;
137 /* Check for a "vlc:quit" command */
138 if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
140 msg_Info( p_input, "command `quit'" );
141 p_method->i_command = COMMAND_QUIT;
145 /* Check for a "vlc:loop" command */
146 if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
148 msg_Info( p_input, "command `loop'" );
149 p_method->i_command = COMMAND_LOOP;
153 /* Check for a "vlc:pause:***" command */
154 if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
156 i_arg = atoi( psz_name + 6 );
157 msg_Info( p_input, "command `pause %i'", i_arg );
158 p_method->i_command = COMMAND_PAUSE;
159 p_method->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
163 msg_Err( p_input, "unknown command `%s'", psz_name );
164 free( p_input->p_demux_data );
165 p_input->b_error = 1;
170 /*****************************************************************************
171 * DummyEnd: end the target, ie. do nothing
172 *****************************************************************************/
173 static void DummyEnd( input_thread_t *p_input )
175 free( p_input->p_demux_data );
178 /*****************************************************************************
179 * DummyDemux: do what the command says
180 *****************************************************************************/
181 static int DummyDemux( input_thread_t *p_input )
183 struct demux_sys_s * p_method = p_input->p_demux_data;
184 playlist_t *p_playlist;
186 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
188 if( p_playlist == NULL )
190 msg_Err( p_input, "we are not attached to a playlist" );
191 p_input->b_error = 1;
195 switch( p_method->i_command )
198 p_input->p_vlc->b_die = 1;
202 playlist_Goto( p_playlist, 0 );
206 if( mdate() < p_method->expiration )
222 vlc_object_release( p_playlist );