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