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