]> git.sesse.net Git - vlc/blob - plugins/dummy/input_dummy.c
* More precise way to retrieve a PTS from the bit stream.
[vlc] / plugins / dummy / input_dummy.c
1 /*****************************************************************************
2  * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: input_dummy.c,v 1.14 2002/01/10 04:11:25 sam Exp $
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 <sys/types.h>
29 #include <string.h>
30 #include <errno.h>
31
32 #include <videolan/vlc.h>
33
34 #ifdef STRNCASECMP_IN_STRINGS_H
35 #   include <strings.h>
36 #endif
37
38 #include "interface.h"
39 #include "intf_playlist.h"
40
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43 #include "input_ext-dec.h"
44 #include "input_ext-plugins.h"
45
46 /*****************************************************************************
47  * Local prototypes
48  *****************************************************************************/
49 static int  DummyProbe     ( probedata_t * );
50 static void DummyInit      ( struct input_thread_s * );
51 static void DummyOpen      ( struct input_thread_s * );
52 static void DummyClose     ( struct input_thread_s * );
53 static void DummyEnd       ( struct input_thread_s * );
54 static int  DummyRead      ( struct input_thread_s *, data_packet_t ** );
55
56 /*****************************************************************************
57  * dummy_data_t: private input data
58  *****************************************************************************/
59 typedef struct dummy_data_s
60 {
61     /* The real command */
62     int i_command;
63
64     /* Used for the pause command */
65     mtime_t expiration;
66
67 } dummy_data_t;
68
69 #define COMMAND_NOP   0
70 #define COMMAND_QUIT  1
71 #define COMMAND_LOOP  2
72 #define COMMAND_PAUSE 3
73
74 /*****************************************************************************
75  * Functions exported as capabilities. They are declared as static so that
76  * we don't pollute the namespace too much.
77  *****************************************************************************/
78 void _M( input_getfunctions )( function_list_t * p_function_list )
79 {
80 #define input p_function_list->functions.input
81     p_function_list->pf_probe = DummyProbe;
82     input.pf_init             = DummyInit;
83     input.pf_open             = DummyOpen;
84     input.pf_close            = DummyClose;
85     input.pf_end              = DummyEnd;
86     input.pf_set_area         = NULL;
87     input.pf_read             = DummyRead;
88     input.pf_demux            = NULL;
89     input.pf_new_packet       = NULL;
90     input.pf_new_pes          = NULL;
91     input.pf_delete_packet    = NULL;
92     input.pf_delete_pes       = NULL;
93     input.pf_rewind           = NULL;
94     input.pf_seek             = NULL;
95 #undef input
96 }
97
98 /*****************************************************************************
99  * DummyProbe: verifies that the input is a vlc command
100  *****************************************************************************/
101 static int DummyProbe( probedata_t *p_data )
102 {
103     input_thread_t *p_input = (input_thread_t *)p_data;
104     char *psz_name = p_input->p_source;
105
106     if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "vlc:", 4 ) )
107     {
108         /* If the user specified "vlc:" then it's probably a file */
109         return( 1 );
110     }
111
112     return( 0 );
113 }
114
115 /*****************************************************************************
116  * DummyOpen: open the target, ie. do nothing
117  *****************************************************************************/
118 static void DummyOpen( input_thread_t * p_input )
119 {
120     p_input->stream.i_method = INPUT_METHOD_NONE;
121 }
122
123 /*****************************************************************************
124  * DummyClose: close the target, ie. do nothing
125  *****************************************************************************/
126 static void DummyClose( input_thread_t * p_input )
127 {
128     ;
129 }
130
131 /*****************************************************************************
132  * DummyOpen: initialize the target, ie. parse the command
133  *****************************************************************************/
134 static void DummyInit( struct input_thread_s *p_input )
135 {
136     dummy_data_t* p_method;
137     char *psz_name = p_input->p_source;
138     int   i_len = strlen( psz_name );
139     int   i_arg;
140     
141     p_input->stream.b_seekable = 0;
142
143     if( ( i_len <= 4 ) || strncasecmp( psz_name, "vlc:", 4 ) )
144     {
145         /* If the command doesn't start with "vlc:" then it's not for us */
146         p_input->b_error = 1;
147         return;
148     }
149
150     /* We don't need the "vlc:" stuff any more */
151     psz_name += 4;
152     i_len -= 4;
153
154     p_method = malloc( sizeof( dummy_data_t ) );
155     if( p_method == NULL )
156     {
157         intf_ErrMsg( "input: out of memory" );
158         p_input->b_error = 1;
159         return;
160     }
161
162     p_input->p_plugin_data = (void *)p_method;
163     p_input->stream.p_demux_data = NULL;
164
165     /* Check for a "vlc:nop" command */
166     if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
167     {
168         intf_WarnMsg( 2, "input: command `nop'" );
169         p_method->i_command = COMMAND_NOP;
170         return;
171     }
172
173     /* Check for a "vlc:quit" command */
174     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
175     {
176         intf_WarnMsg( 2, "input: command `quit'" );
177         p_method->i_command = COMMAND_QUIT;
178         return;
179     }
180
181     /* Check for a "vlc:loop" command */
182     if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
183     {
184         intf_WarnMsg( 2, "input: command `loop'" );
185         p_method->i_command = COMMAND_LOOP;
186         return;
187     }
188
189     /* Check for a "vlc:pause:***" command */
190     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
191     {
192         i_arg = atoi( psz_name + 6 );
193         intf_WarnMsg( 2, "input: command `pause %i'", i_arg );
194         p_method->i_command = COMMAND_PAUSE;
195         p_method->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
196         return;
197     }
198
199     intf_ErrMsg( "input error: unknown command `%s'", psz_name );
200     free( p_input->p_plugin_data );
201     p_input->b_error = 1;
202
203     return;
204 }
205
206 /*****************************************************************************
207  * DummyEnd: end the target, ie. do nothing
208  *****************************************************************************/
209 static void DummyEnd( struct input_thread_s *p_input )
210 {
211     free( p_input->p_plugin_data );
212 }
213
214 /*****************************************************************************
215  * DummyRead: do what the command says
216  *****************************************************************************/
217 static int DummyRead( struct input_thread_s *p_input, data_packet_t **pp_data )
218 {
219     dummy_data_t* p_method = (dummy_data_t *)p_input->p_plugin_data;
220
221     switch( p_method->i_command )
222     {
223         case COMMAND_QUIT:
224             p_input->b_die = 1;
225             break;
226
227         case COMMAND_LOOP:
228             intf_PlaylistJumpto( p_main->p_playlist, -1 );
229             p_input->b_eof = 1;
230             break;
231
232         case COMMAND_PAUSE:
233             if( mdate() < p_method->expiration )
234             {
235                 msleep( 10000 );
236             }
237             else
238             {
239                 p_input->b_eof = 1;
240             }
241             break;
242
243         case COMMAND_NOP:
244         default:
245             p_input->b_eof = 1;
246             break;
247     }
248
249     *pp_data = NULL;
250
251     return 0;
252 }
253