Typos s/hidding/hiding/g
[vlc/asuraparaju-public.git] / modules / misc / dummy / input.c
blob31b3c5162041b96d3534ca821882a413e839d393
1 /*****************************************************************************
2 * input_dummy.c: dummy input plugin, to manage "vlc://" special options
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 the VideoLAN team
5 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
34 #include <vlc_demux.h>
35 #include <vlc_charset.h>
37 #include "dummy.h"
39 static int DemuxControl( demux_t *, int, va_list );
41 static int DemuxNoOp( demux_t *demux )
43 (void) demux;
44 return 0;
47 static int DemuxHold( demux_t *demux )
49 (void) demux;
50 msleep( 10000 ); /* FIXME!!! */
51 return 1;
54 struct demux_sys_t
56 mtime_t end;
57 mtime_t length;
60 static int DemuxPause( demux_t *demux )
62 demux_sys_t *p_sys = demux->p_sys;
63 mtime_t now = mdate();
65 if( now >= p_sys->end )
66 return 0;
68 msleep( 10000 ); /* FIXME!!! */
69 return 1;
72 static int ControlPause( demux_t *demux, int query, va_list args )
74 demux_sys_t *p_sys = demux->p_sys;
76 switch( query )
78 case DEMUX_GET_POSITION:
80 double *ppos = va_arg( args, double * );
81 double pos;
82 mtime_t now = mdate();
84 pos = 1. + ((double)(now - p_sys->end) / (double)p_sys->length);
85 *ppos = (pos <= 1.) ? pos : 1.;
86 break;
89 case DEMUX_SET_POSITION:
91 double pos = va_arg( args, double );
92 mtime_t now = mdate();
94 p_sys->end = now + (p_sys->length * (1. - pos));
95 break;
98 case DEMUX_GET_LENGTH:
100 mtime_t *plen = va_arg( args, mtime_t * );
101 *plen = p_sys->length;
102 break;
105 case DEMUX_GET_TIME:
107 mtime_t *ppos = va_arg( args, mtime_t * );
108 *ppos = mdate() + p_sys->length - p_sys->end;
109 break;
112 case DEMUX_SET_TIME:
114 mtime_t pos = va_arg( args, mtime_t );
115 p_sys->end = mdate() + p_sys->length - pos;
116 break;
119 case DEMUX_CAN_SEEK:
120 *va_arg( args, bool * ) = true;
121 break;
123 default:
124 return DemuxControl( demux, query, args );
126 return VLC_SUCCESS;
129 /*****************************************************************************
130 * OpenDemux: initialize the target, ie. parse the command
131 *****************************************************************************/
132 int OpenDemux ( vlc_object_t *p_this )
134 demux_t *p_demux = (demux_t*)p_this;
135 char * psz_name = p_demux->psz_location;
137 p_demux->p_sys = NULL;
139 /* Check for a "vlc://nop" command */
140 if( !strcasecmp( psz_name, "nop" ) )
142 nop:
143 msg_Info( p_demux, "command `nop'" );
144 p_demux->pf_demux = DemuxNoOp;
145 p_demux->pf_control = DemuxControl;
146 return VLC_SUCCESS;
149 /* Check for a "vlc://quit" command */
150 if( !strcasecmp( psz_name, "quit" ) )
152 msg_Info( p_demux, "command `quit'" );
153 p_demux->pf_demux = DemuxNoOp;
154 p_demux->pf_control = DemuxControl;
155 libvlc_Quit( p_demux->p_libvlc );
156 return VLC_SUCCESS;
159 if( !strcasecmp( psz_name, "pause" ) )
161 msg_Info( p_demux, "command `pause'" );
163 p_demux->pf_demux = DemuxHold;
164 p_demux->pf_control = DemuxControl;
165 return VLC_SUCCESS;
168 /* Check for a "vlc://pause:***" command */
169 if( !strncasecmp( psz_name, "pause:", 6 ) )
171 double f = us_atof( psz_name + 6 );
172 mtime_t length = f * CLOCK_FREQ;
174 msg_Info( p_demux, "command `pause %f'", f );
175 if( length == 0 )
176 goto nop; /* avoid division by zero */
178 demux_sys_t *p_sys = malloc( sizeof( *p_sys ) );
179 if( p_sys == NULL )
180 return VLC_ENOMEM;
182 p_sys->end = mdate() + length;
183 p_sys->length = length;
185 p_demux->p_sys = p_sys;
186 p_demux->pf_demux = DemuxPause;
187 p_demux->pf_control = ControlPause;
188 return VLC_SUCCESS;
191 msg_Err( p_demux, "unknown command `%s'", psz_name );
192 return VLC_EGENERIC;
195 /*****************************************************************************
196 * CloseDemux: initialize the target, ie. parse the command
197 *****************************************************************************/
198 void CloseDemux ( vlc_object_t *p_this )
200 demux_t *p_demux = (demux_t*)p_this;
202 free( p_demux->p_sys );
205 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
207 (void)p_demux; (void)i_query; (void)args;
208 switch( i_query )
210 case DEMUX_GET_PTS_DELAY:
212 int64_t *pi_pts_delay = va_arg( args, int64_t * );
213 *pi_pts_delay = DEFAULT_PTS_DELAY;
214 return VLC_SUCCESS;
216 default:
217 return VLC_EGENERIC;