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