]> git.sesse.net Git - vlc/blob - modules/misc/dummy/input.c
4b745982b236873126fb0f86e56a0bf0a585ab1d
[vlc] / modules / misc / dummy / input.c
1 /*****************************************************************************
2  * input_dummy.c: dummy input plugin, to manage "vlc://" special options
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
34 #include <vlc_demux.h>
35 #include <vlc_charset.h>
36
37 #include "dummy.h"
38
39 static int DemuxControl( demux_t *, int, va_list );
40
41 static int DemuxNoOp( demux_t *demux )
42 {
43     (void) demux;
44     return 0;
45 }
46
47 struct demux_sys_t
48 {
49     mtime_t end;
50     mtime_t length;
51 };
52
53 static int DemuxPause( demux_t *demux )
54 {
55     demux_sys_t *p_sys = demux->p_sys;
56     mtime_t now = mdate();
57
58     if( now >= p_sys->end )
59         return 0;
60
61     msleep( 10000 ); /* FIXME!!! */
62     return 1;
63 }
64
65 static int ControlPause( demux_t *demux, int query, va_list args )
66 {
67     demux_sys_t *p_sys = demux->p_sys;
68
69     switch( query )
70     {
71         case DEMUX_GET_POSITION:
72         {
73             double *ppos = va_arg( args, double * );
74             double pos;
75             mtime_t now = mdate();
76
77             pos = 1. + ((double)(now - p_sys->end) / (double)p_sys->length);
78             *ppos = (pos <= 1.) ? pos : 1.;
79             break;
80         }
81
82         case DEMUX_SET_POSITION:
83         {
84             double pos = va_arg( args, double );
85             mtime_t now = mdate();
86
87             p_sys->end = now + (p_sys->length * (1. - pos));
88             break;
89         }
90
91         case DEMUX_GET_LENGTH:
92         {
93             mtime_t *plen = va_arg( args, mtime_t * );
94             *plen = p_sys->length;
95             break;
96         }
97
98         case DEMUX_GET_TIME:
99         {
100             mtime_t *ppos = va_arg( args, mtime_t * );
101             *ppos = mdate() + p_sys->length - p_sys->end;
102             break;
103         }
104
105         case DEMUX_SET_TIME:
106         {
107             mtime_t pos = va_arg( args, mtime_t );
108             p_sys->end = mdate() + p_sys->length - pos;
109             break;
110         }
111
112         case DEMUX_CAN_SEEK:
113             *va_arg( args, bool * ) = true;
114             break;
115
116         default:
117             return DemuxControl( demux, query, args );
118     }
119     return VLC_SUCCESS;
120 }
121
122 /*****************************************************************************
123  * OpenDemux: initialize the target, ie. parse the command
124  *****************************************************************************/
125 int OpenDemux ( vlc_object_t *p_this )
126 {
127     demux_t *p_demux = (demux_t*)p_this;
128     char * psz_name = p_demux->psz_location;
129
130     p_demux->p_sys = NULL;
131
132     /* Check for a "vlc://nop" command */
133     if( !strcasecmp( psz_name, "nop" ) )
134     {
135 nop:
136         msg_Info( p_demux, "command `nop'" );
137         p_demux->pf_demux = DemuxNoOp;
138         p_demux->pf_control = DemuxControl;
139         return VLC_SUCCESS;
140     }
141
142     /* Check for a "vlc://quit" command */
143     if( !strcasecmp( psz_name, "quit" ) )
144     {
145         msg_Info( p_demux, "command `quit'" );
146         p_demux->pf_demux = DemuxNoOp;
147         p_demux->pf_control = DemuxControl;
148         libvlc_Quit( p_demux->p_libvlc );
149         return VLC_SUCCESS;
150     }
151
152     /* Check for a "vlc://pause:***" command */
153     if( !strncasecmp( psz_name, "pause:", 6 ) )
154     {
155         double f = us_atof( psz_name + 6 );
156         mtime_t length = f * CLOCK_FREQ;
157
158         msg_Info( p_demux, "command `pause %f'", f );
159         if( length == 0 )
160             goto nop; /* avoid division by zero */
161
162         demux_sys_t *p_sys = malloc( sizeof( *p_sys ) );
163         if( p_sys == NULL )
164             return VLC_ENOMEM;
165
166         p_sys->end = mdate() + length;
167         p_sys->length = length;
168
169         p_demux->p_sys = p_sys;
170         p_demux->pf_demux = DemuxPause;
171         p_demux->pf_control = ControlPause;
172         return VLC_SUCCESS;
173     }
174  
175     msg_Err( p_demux, "unknown command `%s'", psz_name );
176     return VLC_EGENERIC;
177 }
178
179 /*****************************************************************************
180  * CloseDemux: initialize the target, ie. parse the command
181  *****************************************************************************/
182 void CloseDemux ( vlc_object_t *p_this )
183 {
184     demux_t *p_demux = (demux_t*)p_this;
185
186     free( p_demux->p_sys );
187 }
188
189 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
190 {
191     (void)p_demux; (void)i_query; (void)args;
192     switch( i_query )
193     {
194     case DEMUX_GET_PTS_DELAY:
195     {
196         int64_t *pi_pts_delay = va_arg( args, int64_t * );
197         *pi_pts_delay = DEFAULT_PTS_DELAY;
198         return VLC_SUCCESS;
199     }
200     default:
201         return VLC_EGENERIC;
202     }
203 }