1 /*****************************************************************************
2 * idummy.c: dummy input plugin, to manage "vlc://" special options
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
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 /*****************************************************************************
26 *****************************************************************************/
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
* );
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" )
48 static int DemuxControl( demux_t
*, int, va_list );
50 static int DemuxNoOp( demux_t
*demux
)
56 static int DemuxHold( demux_t
*demux
)
59 vlc_tick_sleep( VLC_HARD_MIN_SLEEP
); /* FIXME!!! */
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
)
77 vlc_tick_sleep( VLC_HARD_MIN_SLEEP
); /* FIXME!!! */
81 static int ControlPause( demux_t
*demux
, int query
, va_list args
)
83 demux_sys_t
*p_sys
= demux
->p_sys
;
87 case DEMUX_GET_POSITION
:
89 double *ppos
= va_arg( args
, double * );
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.;
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
));
107 case DEMUX_GET_LENGTH
:
109 vlc_tick_t
*plen
= va_arg( args
, vlc_tick_t
* );
110 *plen
= p_sys
->length
;
116 vlc_tick_t
*ppos
= va_arg( args
, vlc_tick_t
* );
117 *ppos
= vlc_tick_now() + p_sys
->length
- p_sys
->end
;
123 vlc_tick_t pos
= va_arg( args
, vlc_tick_t
);
124 p_sys
->end
= vlc_tick_now() + p_sys
->length
- pos
;
129 *va_arg( args
, bool * ) = true;
133 return DemuxControl( demux
, query
, args
);
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" ) )
152 msg_Info( p_demux
, "command `nop'" );
153 p_demux
->pf_demux
= DemuxNoOp
;
154 p_demux
->pf_control
= DemuxControl
;
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
);
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
;
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
);
185 goto nop
; /* avoid division by zero */
187 demux_sys_t
*p_sys
= vlc_obj_malloc( p_this
, sizeof( *p_sys
) );
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
;
200 msg_Err( p_demux
, "unknown command `%s'", psz_name
);
204 static int DemuxControl( demux_t
*p_demux
, int i_query
, va_list args
)
206 (void)p_demux
; (void)i_query
; (void)args
;
209 case DEMUX_GET_PTS_DELAY
:
211 *va_arg( args
, vlc_tick_t
* ) = DEFAULT_PTS_DELAY
;