]> git.sesse.net Git - vlc/blob - plugins/dummy/input_dummy.c
* ./plugins/dummy/input_dummy.c: fixed `vlc vlc:quit'.
[vlc] / plugins / dummy / input_dummy.c
1 /*****************************************************************************
2  * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id: input_dummy.c,v 1.17 2002/03/02 03:51:23 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 #include "interface.h"
35 #include "intf_playlist.h"
36
37 #include "stream_control.h"
38 #include "input_ext-intf.h"
39 #include "input_ext-dec.h"
40 #include "input_ext-plugins.h"
41
42 /*****************************************************************************
43  * Local prototypes
44  *****************************************************************************/
45 static int  DummyInit      ( struct input_thread_s * );
46 static int  DummyOpen      ( struct input_thread_s * );
47 static void DummyClose     ( struct input_thread_s * );
48 static void DummyEnd       ( struct input_thread_s * );
49 static int  DummyDemux     ( struct input_thread_s * );
50
51 /*****************************************************************************
52  * access_sys_t: private input data
53  *****************************************************************************/
54 struct demux_sys_s
55 {
56     /* The real command */
57     int i_command;
58
59     /* Used for the pause command */
60     mtime_t expiration;
61 };
62
63 #define COMMAND_NOP   0
64 #define COMMAND_QUIT  1
65 #define COMMAND_LOOP  2
66 #define COMMAND_PAUSE 3
67
68 /*****************************************************************************
69  * Functions exported as capabilities. They are declared as static so that
70  * we don't pollute the namespace too much.
71  *****************************************************************************/
72 void _M( access_getfunctions )( function_list_t * p_function_list )
73 {
74 #define input p_function_list->functions.access
75     input.pf_open             = DummyOpen;
76     input.pf_read             = NULL;
77     input.pf_close            = DummyClose;
78     input.pf_set_program      = NULL;
79     input.pf_set_area         = NULL;
80     input.pf_seek             = NULL;
81 #undef input
82 }
83
84 void _M( demux_getfunctions )( function_list_t * p_function_list )
85 {
86 #define input p_function_list->functions.demux
87     input.pf_init             = DummyInit;
88     input.pf_end              = DummyEnd;
89     input.pf_demux            = DummyDemux;
90     input.pf_rewind           = NULL;
91 #undef input
92 }
93
94 /*****************************************************************************
95  * DummyOpen: open the target, ie. do nothing
96  *****************************************************************************/
97 static int DummyOpen( input_thread_t * p_input )
98 {
99     p_input->stream.i_method = INPUT_METHOD_NONE;
100
101     /* Force dummy demux plug-in */
102     p_input->psz_demux = "vlc";
103     return( 0 );
104 }
105
106 /*****************************************************************************
107  * DummyClose: close the target, ie. do nothing
108  *****************************************************************************/
109 static void DummyClose( input_thread_t * p_input )
110 {
111 }
112
113 /*****************************************************************************
114  * DummyInit: initialize the target, ie. parse the command
115  *****************************************************************************/
116 static int DummyInit( struct input_thread_s *p_input )
117 {
118     char * psz_name = p_input->psz_name;
119     int i_len = strlen( psz_name );
120     struct demux_sys_s * p_method;
121     int   i_arg;
122     
123     p_input->stream.b_seekable = 0;
124
125     p_method = malloc( sizeof( struct demux_sys_s ) );
126     if( p_method == NULL )
127     {
128         intf_ErrMsg( "input: out of memory" );
129         return( -1 );
130     }
131
132     p_input->p_demux_data = p_method;
133     p_input->stream.p_demux_data = NULL;
134
135     /* Check for a "vlc:nop" command */
136     if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
137     {
138         intf_WarnMsg( 2, "input: command `nop'" );
139         p_method->i_command = COMMAND_NOP;
140         return( 0 );
141     }
142
143     /* Check for a "vlc:quit" command */
144     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
145     {
146         intf_WarnMsg( 2, "input: command `quit'" );
147         p_method->i_command = COMMAND_QUIT;
148         return( 0 );
149     }
150
151     /* Check for a "vlc:loop" command */
152     if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
153     {
154         intf_WarnMsg( 2, "input: command `loop'" );
155         p_method->i_command = COMMAND_LOOP;
156         return( 0 );
157     }
158
159     /* Check for a "vlc:pause:***" command */
160     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
161     {
162         i_arg = atoi( psz_name + 6 );
163         intf_WarnMsg( 2, "input: command `pause %i'", i_arg );
164         p_method->i_command = COMMAND_PAUSE;
165         p_method->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
166         return( 0 );
167     }
168
169     intf_ErrMsg( "input error: unknown command `%s'", psz_name );
170     free( p_input->p_demux_data );
171     p_input->b_error = 1;
172
173     return( -1 );
174 }
175
176 /*****************************************************************************
177  * DummyEnd: end the target, ie. do nothing
178  *****************************************************************************/
179 static void DummyEnd( struct input_thread_s *p_input )
180 {
181     free( p_input->p_demux_data );
182 }
183
184 /*****************************************************************************
185  * DummyDemux: do what the command says
186  *****************************************************************************/
187 static int DummyDemux( struct input_thread_s *p_input )
188 {
189     struct demux_sys_s * p_method = p_input->p_demux_data;
190
191     switch( p_method->i_command )
192     {
193         case COMMAND_QUIT:
194             p_main->p_intf->b_die = 1;
195             p_input->b_die = 1;
196             break;
197
198         case COMMAND_LOOP:
199             intf_PlaylistJumpto( p_main->p_playlist, -1 );
200             p_input->b_eof = 1;
201             break;
202
203         case COMMAND_PAUSE:
204             if( mdate() < p_method->expiration )
205             {
206                 msleep( 10000 );
207             }
208             else
209             {
210                 p_input->b_eof = 1;
211             }
212             break;
213
214         case COMMAND_NOP:
215         default:
216             p_input->b_eof = 1;
217             break;
218     }
219
220     return 1;
221 }
222