]> git.sesse.net Git - vlc/blob - modules/misc/dummy/input.c
Merge branch 1.0-bugfix (early part) into master
[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_access.h>
35 #include <vlc_demux.h>
36
37 #include "dummy.h"
38
39 /*****************************************************************************
40  * Access functions.
41  *****************************************************************************/
42 static ssize_t AccessRead( access_t *p_access, uint8_t *p, size_t i_size )
43 {
44     VLC_UNUSED(p_access);
45     memset( p, 0, i_size );
46     return i_size;
47 }
48 static int AccessControl( access_t *p_access, int i_query, va_list args )
49 {
50     bool        *pb_bool;
51     int64_t     *pi_64;
52
53     switch( i_query )
54     {
55         /* */
56         case ACCESS_CAN_SEEK:
57         case ACCESS_CAN_FASTSEEK:
58         case ACCESS_CAN_PAUSE:
59         case ACCESS_CAN_CONTROL_PACE:
60             pb_bool = (bool*)va_arg( args, bool* );
61             *pb_bool = false;
62             break;
63
64         /* */
65         case ACCESS_GET_PTS_DELAY:
66             pi_64 = (int64_t*)va_arg( args, int64_t * );
67             *pi_64 = DEFAULT_PTS_DELAY * 1000;
68             break;
69
70         /* */
71         case ACCESS_SET_PAUSE_STATE:
72         case ACCESS_GET_TITLE_INFO:
73         case ACCESS_GET_META:
74         case ACCESS_SET_TITLE:
75         case ACCESS_SET_SEEKPOINT:
76             return VLC_EGENERIC;
77
78         default:
79             msg_Err( p_access, "unimplemented query in control" );
80             return VLC_EGENERIC;
81     }
82     return VLC_SUCCESS;
83 }
84
85 int OpenAccess( vlc_object_t *p_this )
86 {
87     access_t *p_access = (access_t*)p_this;
88
89     /* Init p_access */
90     p_access->pf_read = AccessRead;
91     p_access->pf_block = NULL;
92     p_access->pf_seek = NULL;
93     p_access->pf_control = AccessControl;
94     p_access->info.i_update = 0;
95     p_access->info.i_size = 0;
96     p_access->info.i_pos = 0;
97     p_access->info.b_eof = false;
98     p_access->info.i_title = 0;
99     p_access->info.i_seekpoint = 0;
100     p_access->p_sys = NULL;
101
102     /* Force dummy demux plug-in */
103     free( p_access->psz_demux );
104     p_access->psz_demux = strdup( "vlc" );
105
106     return VLC_SUCCESS;
107 }
108
109
110 /*****************************************************************************
111  * Demux
112  *****************************************************************************/
113 struct demux_sys_t
114 {
115     /* The real command */
116     int i_command;
117
118     /* Used for the pause command */
119     mtime_t expiration;
120 };
121 enum
122 {
123     COMMAND_NOP  = 0,
124     COMMAND_QUIT = 1,
125     COMMAND_PAUSE= 3,
126 };
127
128 static int Demux( demux_t * );
129 static int DemuxControl( demux_t *, int, va_list );
130
131
132 /*****************************************************************************
133  * OpenDemux: initialize the target, ie. parse the command
134  *****************************************************************************/
135 int OpenDemux ( vlc_object_t *p_this )
136 {
137     demux_t *p_demux = (demux_t*)p_this;
138     char * psz_name = p_demux->psz_path;
139
140     int i_len = strlen( psz_name );
141     demux_sys_t *p_sys;
142     int   i_arg;
143
144     p_demux->pf_demux   = Demux;
145     p_demux->pf_control = DemuxControl;
146     p_demux->p_sys      = p_sys = malloc( sizeof( demux_sys_t ) );
147
148     /* Check for a "vlc://nop" command */
149     if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
150     {
151         msg_Info( p_demux, "command `nop'" );
152         p_sys->i_command = COMMAND_NOP;
153         return VLC_SUCCESS;
154     }
155
156     /* Check for a "vlc://quit" command */
157     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
158     {
159         msg_Info( p_demux, "command `quit'" );
160         p_sys->i_command = COMMAND_QUIT;
161         return VLC_SUCCESS;
162     }
163
164     /* Check for a "vlc://pause:***" command */
165     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
166     {
167         i_arg = atoi( psz_name + 6 );
168         msg_Info( p_demux, "command `pause %i'", i_arg );
169         p_sys->i_command = COMMAND_PAUSE;
170         p_sys->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
171         return VLC_SUCCESS;
172     }
173  
174     msg_Err( p_demux, "unknown command `%s'", psz_name );
175
176     free( p_sys );
177     return VLC_EGENERIC;
178 }
179
180 /*****************************************************************************
181  * CloseDemux: initialize the target, ie. parse the command
182  *****************************************************************************/
183 void CloseDemux ( vlc_object_t *p_this )
184 {
185     demux_t *p_demux = (demux_t*)p_this;
186
187     free( p_demux->p_sys );
188 }
189
190 /*****************************************************************************
191  * Demux: do what the command says
192  *****************************************************************************/
193 static int Demux( demux_t *p_demux )
194 {
195     demux_sys_t *p_sys = p_demux->p_sys;
196     bool b_eof = false;
197
198     switch( p_sys->i_command )
199     {
200         case COMMAND_QUIT:
201             b_eof = true;
202             libvlc_Quit( p_demux->p_libvlc );
203             break;
204
205         case COMMAND_PAUSE:
206             if( mdate() >= p_sys->expiration )
207                 b_eof = true;
208             else
209                 msleep( 10000 );
210             break;
211  
212         case COMMAND_NOP:
213         default:
214             b_eof = true;
215             break;
216     }
217
218     return b_eof ? 0 : 1;
219 }
220
221 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
222 {
223     return demux_vaControlHelper( p_demux->s,
224                                    0, 0, 0, 1,
225                                    i_query, args );
226 }