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