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