Qt: fix build
[vlc.git] / modules / access / idummy.c
blob18ce6d4257f0622ef8a1eef6a340e8d1efea77b6
1 /*****************************************************************************
2 * idummy.c: dummy input plugin, to manage "vlc://" special options
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * 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_plugin.h>
34 #include <vlc_interface.h>
35 #include <vlc_demux.h>
36 #include <vlc_charset.h>
38 static int OpenDemux( vlc_object_t * );
40 vlc_module_begin ()
41 set_shortname( N_("Dummy") )
42 set_description( N_("Dummy input") )
43 set_capability( "access_demux", 0 )
44 set_callbacks( OpenDemux, NULL )
45 add_shortcut( "dummy", "vlc" )
46 vlc_module_end ()
48 static int DemuxControl( demux_t *, int, va_list );
50 static int DemuxNoOp( demux_t *demux )
52 (void) demux;
53 return 0;
56 static int DemuxHold( demux_t *demux )
58 (void) demux;
59 msleep( 10000 ); /* FIXME!!! */
60 return 1;
63 struct demux_sys_t
65 mtime_t end;
66 mtime_t length;
69 static int DemuxPause( demux_t *demux )
71 demux_sys_t *p_sys = demux->p_sys;
72 mtime_t now = mdate();
74 if( now >= p_sys->end )
75 return 0;
77 msleep( 10000 ); /* FIXME!!! */
78 return 1;
81 static int ControlPause( demux_t *demux, int query, va_list args )
83 demux_sys_t *p_sys = demux->p_sys;
85 switch( query )
87 case DEMUX_GET_POSITION:
89 double *ppos = va_arg( args, double * );
90 double pos;
91 mtime_t now = mdate();
93 pos = 1. + ((double)(now - p_sys->end) / (double)p_sys->length);
94 *ppos = (pos <= 1.) ? pos : 1.;
95 break;
98 case DEMUX_SET_POSITION:
100 double pos = va_arg( args, double );
101 mtime_t now = mdate();
103 p_sys->end = now + (p_sys->length * (1. - pos));
104 break;
107 case DEMUX_GET_LENGTH:
109 mtime_t *plen = va_arg( args, mtime_t * );
110 *plen = p_sys->length;
111 break;
114 case DEMUX_GET_TIME:
116 mtime_t *ppos = va_arg( args, mtime_t * );
117 *ppos = mdate() + p_sys->length - p_sys->end;
118 break;
121 case DEMUX_SET_TIME:
123 mtime_t pos = va_arg( args, mtime_t );
124 p_sys->end = mdate() + p_sys->length - pos;
125 break;
128 case DEMUX_CAN_SEEK:
129 *va_arg( args, bool * ) = true;
130 break;
132 default:
133 return DemuxControl( demux, query, args );
135 return VLC_SUCCESS;
138 /*****************************************************************************
139 * OpenDemux: initialize the target, ie. parse the command
140 *****************************************************************************/
141 static int OpenDemux( vlc_object_t *p_this )
143 demux_t *p_demux = (demux_t*)p_this;
144 const char *psz_name = p_demux->psz_location;
146 p_demux->p_sys = NULL;
148 /* Check for a "vlc://nop" command */
149 if( !strcasecmp( psz_name, "nop" ) )
151 nop:
152 msg_Info( p_demux, "command `nop'" );
153 p_demux->pf_demux = DemuxNoOp;
154 p_demux->pf_control = DemuxControl;
155 return VLC_SUCCESS;
158 /* Check for a "vlc://quit" command */
159 if( !strcasecmp( psz_name, "quit" ) )
161 msg_Info( p_demux, "command `quit'" );
162 p_demux->pf_demux = DemuxNoOp;
163 p_demux->pf_control = DemuxControl;
164 libvlc_Quit( p_demux->obj.libvlc );
165 return VLC_SUCCESS;
168 if( !strcasecmp( psz_name, "pause" ) )
170 msg_Info( p_demux, "command `pause'" );
172 p_demux->pf_demux = DemuxHold;
173 p_demux->pf_control = DemuxControl;
174 return VLC_SUCCESS;
177 /* Check for a "vlc://pause:***" command */
178 if( !strncasecmp( psz_name, "pause:", 6 ) )
180 double f = us_atof( psz_name + 6 );
181 mtime_t length = f * CLOCK_FREQ;
183 msg_Info( p_demux, "command `pause %f'", f );
184 if( length == 0 )
185 goto nop; /* avoid division by zero */
187 demux_sys_t *p_sys = vlc_obj_malloc( p_this, sizeof( *p_sys ) );
188 if( p_sys == NULL )
189 return VLC_ENOMEM;
191 p_sys->end = mdate() + length;
192 p_sys->length = length;
194 p_demux->p_sys = p_sys;
195 p_demux->pf_demux = DemuxPause;
196 p_demux->pf_control = ControlPause;
197 return VLC_SUCCESS;
200 msg_Err( p_demux, "unknown command `%s'", psz_name );
201 return VLC_EGENERIC;
204 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
206 (void)p_demux; (void)i_query; (void)args;
207 switch( i_query )
209 case DEMUX_GET_PTS_DELAY:
211 int64_t *pi_pts_delay = va_arg( args, int64_t * );
212 *pi_pts_delay = DEFAULT_PTS_DELAY;
213 return VLC_SUCCESS;
215 default:
216 return VLC_EGENERIC;