]> git.sesse.net Git - vlc/blob - modules/misc/dummy/input.c
Fixed dummy input Control function.
[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 static int DemuxPause( demux_t *demux )
48 {
49     const mtime_t *p_end = (void *)demux->p_sys;
50     mtime_t now = mdate();
51
52     if( now >= *p_end )
53         return 0;
54
55     msleep( 10000 ); /* FIXME!!! */
56     return 1;
57 }
58
59 /*****************************************************************************
60  * OpenDemux: initialize the target, ie. parse the command
61  *****************************************************************************/
62 int OpenDemux ( vlc_object_t *p_this )
63 {
64     demux_t *p_demux = (demux_t*)p_this;
65     char * psz_name = p_demux->psz_path;
66
67     p_demux->pf_control = DemuxControl;
68     p_demux->p_sys = NULL;
69
70     /* Check for a "vlc://nop" command */
71     if( !strcasecmp( psz_name, "nop" ) )
72     {
73         msg_Info( p_demux, "command `nop'" );
74         p_demux->pf_demux = DemuxNoOp;
75         return VLC_SUCCESS;
76     }
77
78     /* Check for a "vlc://quit" command */
79     if( !strcasecmp( psz_name, "quit" ) )
80     {
81         msg_Info( p_demux, "command `quit'" );
82         p_demux->pf_demux = DemuxNoOp;
83         libvlc_Quit( p_demux->p_libvlc );
84         return VLC_SUCCESS;
85     }
86
87     /* Check for a "vlc://pause:***" command */
88     if( !strncasecmp( psz_name, "pause:", 6 ) )
89     {
90         double f = us_atof( psz_name + 6 );
91         mtime_t end = mdate() + f * (mtime_t)1000000;
92
93         msg_Info( p_demux, "command `pause %f'", f );
94         p_demux->pf_demux = DemuxPause;
95
96         p_demux->p_sys = malloc( sizeof( end ) );
97         if( p_demux->p_sys == NULL )
98             return VLC_ENOMEM;
99         memcpy( p_demux->p_sys, &end, sizeof( end ) );
100         return VLC_SUCCESS;
101     }
102  
103     msg_Err( p_demux, "unknown command `%s'", psz_name );
104     return VLC_EGENERIC;
105 }
106
107 /*****************************************************************************
108  * CloseDemux: initialize the target, ie. parse the command
109  *****************************************************************************/
110 void CloseDemux ( vlc_object_t *p_this )
111 {
112     demux_t *p_demux = (demux_t*)p_this;
113
114     free( p_demux->p_sys );
115 }
116
117 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
118 {
119     (void)p_demux; (void)i_query; (void)args;
120     switch( i_query )
121     {
122     case DEMUX_GET_PTS_DELAY:
123     {
124         int64_t *pi_pts_delay = va_arg( args, int64_t * );
125         *pi_pts_delay = DEFAULT_PTS_DELAY;
126         return VLC_SUCCESS;
127     }
128     default:
129         return VLC_EGENERIC;
130     }
131 }