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