demux: mkv: simplify block handling
[vlc.git] / modules / access / idummy.c
blobf4c37b73f96b5221cf65990fd34ec12d5a48bf76
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", 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 vlc_tick_sleep( VLC_HARD_MIN_SLEEP ); /* FIXME!!! */
60 return 1;
63 typedef struct
65 vlc_tick_t end;
66 vlc_tick_t length;
67 } demux_sys_t;
69 static int DemuxPause( demux_t *demux )
71 demux_sys_t *p_sys = demux->p_sys;
72 vlc_tick_t now = vlc_tick_now();
74 if( now >= p_sys->end )
75 return 0;
77 vlc_tick_sleep( VLC_HARD_MIN_SLEEP ); /* 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 vlc_tick_t now = vlc_tick_now();
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 vlc_tick_t now = vlc_tick_now();
103 p_sys->end = now + (p_sys->length * (1. - pos));
104 break;
107 case DEMUX_GET_LENGTH:
109 vlc_tick_t *plen = va_arg( args, vlc_tick_t * );
110 *plen = p_sys->length;
111 break;
114 case DEMUX_GET_TIME:
116 vlc_tick_t *ppos = va_arg( args, vlc_tick_t * );
117 *ppos = vlc_tick_now() + p_sys->length - p_sys->end;
118 break;
121 case DEMUX_SET_TIME:
123 vlc_tick_t pos = va_arg( args, vlc_tick_t );
124 p_sys->end = vlc_tick_now() + 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 vlc_tick_t length = vlc_tick_from_sec( f );
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 = vlc_tick_now() + 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 *va_arg( args, vlc_tick_t * ) = DEFAULT_PTS_DELAY;
212 return VLC_SUCCESS;
214 default:
215 return VLC_EGENERIC;