1 /*****************************************************************************
2 * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 the VideoLAN team
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 *****************************************************************************/
32 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int AccessRead( access_t *p_access, uint8_t *p, int i_size )
39 memset( p, 0, i_size );
42 static int AccessControl( access_t *p_access, int i_query, va_list args )
52 case ACCESS_CAN_FASTSEEK:
53 case ACCESS_CAN_PAUSE:
54 case ACCESS_CAN_CONTROL_PACE:
55 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
61 pi_int = (int*)va_arg( args, int * );
65 case ACCESS_GET_PTS_DELAY:
66 pi_64 = (int64_t*)va_arg( args, int64_t * );
67 *pi_64 = DEFAULT_PTS_DELAY * 1000;
71 case ACCESS_SET_PAUSE_STATE:
72 case ACCESS_GET_TITLE_INFO:
73 case ACCESS_SET_TITLE:
74 case ACCESS_SET_SEEKPOINT:
78 msg_Err( p_access, "unimplemented query in control" );
84 int E_(OpenAccess)( vlc_object_t *p_this )
86 access_t *p_access = (access_t*)p_this;
89 p_access->pf_read = AccessRead;
90 p_access->pf_block = NULL;
91 p_access->pf_seek = NULL;
92 p_access->pf_control = AccessControl;
93 p_access->info.i_update = 0;
94 p_access->info.i_size = 0;
95 p_access->info.i_pos = 0;
96 p_access->info.b_eof = VLC_FALSE;
97 p_access->info.i_title = 0;
98 p_access->info.i_seekpoint = 0;
99 p_access->p_sys = NULL;
101 /* Force dummy demux plug-in */
102 p_access->psz_demux = strdup( "vlc" );
108 /*****************************************************************************
110 *****************************************************************************/
113 /* The real command */
116 /* Used for the pause command */
119 /* The command to run */
131 static int Demux( demux_t * );
132 static int DemuxControl( demux_t *, int, va_list );
135 /*****************************************************************************
136 * OpenDemux: initialize the target, ie. parse the command
137 *****************************************************************************/
138 int E_(OpenDemux) ( vlc_object_t *p_this )
140 demux_t *p_demux = (demux_t*)p_this;
141 char * psz_name = p_demux->psz_path;
143 int i_len = strlen( psz_name );
147 p_demux->pf_demux = Demux;
148 p_demux->pf_control = DemuxControl;
149 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
151 /* Check for a "vlc:nop" command */
152 if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
154 msg_Info( p_demux, "command `nop'" );
155 p_sys->i_command = COMMAND_NOP;
159 /* Check for a "vlc:quit" command */
160 if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
162 msg_Info( p_demux, "command `quit'" );
163 p_sys->i_command = COMMAND_QUIT;
167 /* Check for a "vlc:loop" command */
168 if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
170 msg_Info( p_demux, "command `loop'" );
171 p_sys->i_command = COMMAND_LOOP;
175 /* Check for a "vlc:pause:***" command */
176 if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
178 i_arg = atoi( psz_name + 6 );
179 msg_Info( p_demux, "command `pause %i'", i_arg );
180 p_sys->i_command = COMMAND_PAUSE;
181 p_sys->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
185 /* Check for a "vlc:run:***" command */
186 if ( i_len > 4 && !strncasecmp( psz_name, "run:", 4 ) )
188 p_sys->psz_command = malloc( i_len - 4 );
189 strcpy( p_sys->psz_command, psz_name + 4 );
190 msg_Info( p_demux, "command `run program %s'", p_sys->psz_command );
191 p_sys->i_command = COMMAND_RUN;
195 msg_Err( p_demux, "unknown command `%s'", psz_name );
201 /*****************************************************************************
202 * CloseDemux: initialize the target, ie. parse the command
203 *****************************************************************************/
204 void E_(CloseDemux) ( vlc_object_t *p_this )
206 demux_t *p_demux = (demux_t*)p_this;
208 free( p_demux->p_sys );
211 /*****************************************************************************
212 * Demux: do what the command says
213 *****************************************************************************/
214 static int Demux( demux_t *p_demux )
216 demux_sys_t *p_sys = p_demux->p_sys;
217 playlist_t *p_playlist;
218 vlc_bool_t b_eof = VLC_FALSE;
220 p_playlist = vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST, FIND_PARENT );
222 if( p_playlist == NULL )
224 msg_Err( p_demux, "we are not attached to a playlist" );
228 switch( p_sys->i_command )
231 b_eof = p_demux->p_vlc->b_die = VLC_TRUE;
235 playlist_Goto( p_playlist, 0 );
239 if( mdate() >= p_sys->expiration )
246 var_SetString( p_playlist, "run-program-command", p_sys->psz_command );
247 free( p_sys->psz_command );
257 vlc_object_release( p_playlist );
258 return b_eof ? 0 : 1;
261 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
263 return demux2_vaControlHelper( p_demux->s,