]> git.sesse.net Git - vlc/blob - modules/misc/dummy/input.c
de4aa613594e5a8b3bfc6aa82aa9291ea065fee1
[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 VideoLAN
5  * $Id: input.c,v 1.3 2003/04/16 11:47:08 gbazin 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 <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/intf.h>
32 #include <vlc/input.h>
33
34 /*****************************************************************************
35  * Local prototypes
36  *****************************************************************************/
37 static int Demux ( input_thread_t * );
38
39 /*****************************************************************************
40  * access_sys_t: private input data
41  *****************************************************************************/
42 struct demux_sys_t
43 {
44     /* The real command */
45     int i_command;
46
47     /* Used for the pause command */
48     mtime_t expiration;
49 };
50
51 #define COMMAND_NOP   0
52 #define COMMAND_QUIT  1
53 #define COMMAND_LOOP  2
54 #define COMMAND_PAUSE 3
55
56 /*****************************************************************************
57  * OpenAccess: open the target, ie. do nothing
58  *****************************************************************************/
59 int E_(OpenAccess) ( vlc_object_t *p_this )
60 {
61     input_thread_t *p_input = (input_thread_t *)p_this;
62
63     p_input->stream.i_method = INPUT_METHOD_NONE;
64
65     /* Force dummy demux plug-in */
66     p_input->psz_demux = "vlc";
67
68     return VLC_SUCCESS;
69 }
70
71 /*****************************************************************************
72  * OpenDemux: initialize the target, ie. parse the command
73  *****************************************************************************/
74 int E_(OpenDemux) ( vlc_object_t *p_this )
75 {
76     input_thread_t *p_input = (input_thread_t *)p_this;
77     char * psz_name = p_input->psz_name;
78     int i_len = strlen( psz_name );
79     struct demux_sys_t * p_method;
80     int   i_arg;
81     
82     p_input->stream.b_seekable = 0;
83     p_input->pf_demux = Demux;
84     p_input->pf_rewind = NULL;
85
86     p_method = malloc( sizeof( struct demux_sys_t ) );
87     if( p_method == NULL )
88     {
89         msg_Err( p_input, "out of memory" );
90         return -1;
91     }
92
93     p_input->p_demux_data = p_method;
94     p_input->stream.p_demux_data = NULL;
95
96     /* Check for a "vlc:nop" command */
97     if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
98     {
99         msg_Info( p_input, "command `nop'" );
100         p_method->i_command = COMMAND_NOP;
101         return 0;
102     }
103
104     /* Check for a "vlc:quit" command */
105     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
106     {
107         msg_Info( p_input, "command `quit'" );
108         p_method->i_command = COMMAND_QUIT;
109         return 0;
110     }
111
112     /* Check for a "vlc:loop" command */
113     if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
114     {
115         msg_Info( p_input, "command `loop'" );
116         p_method->i_command = COMMAND_LOOP;
117         return 0;
118     }
119
120     /* Check for a "vlc:pause:***" command */
121     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
122     {
123         i_arg = atoi( psz_name + 6 );
124         msg_Info( p_input, "command `pause %i'", i_arg );
125         p_method->i_command = COMMAND_PAUSE;
126         p_method->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
127         return 0;
128     }
129
130     msg_Err( p_input, "unknown command `%s'", psz_name );
131     free( p_input->p_demux_data );
132     p_input->b_error = 1;
133
134     return -1;
135 }
136
137 /*****************************************************************************
138  * CloseDemux: initialize the target, ie. parse the command
139  *****************************************************************************/
140 void E_(CloseDemux) ( vlc_object_t *p_this )
141 {
142     input_thread_t *p_input = (input_thread_t *)p_this;
143
144     free( p_input->p_demux_data );
145 }
146
147 /*****************************************************************************
148  * Demux: do what the command says
149  *****************************************************************************/
150 static int Demux( input_thread_t *p_input )
151 {
152     struct demux_sys_t * p_method = p_input->p_demux_data;
153     playlist_t *p_playlist;
154
155     p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
156
157     if( p_playlist == NULL )
158     {
159         msg_Err( p_input, "we are not attached to a playlist" );
160         p_input->b_error = 1;
161         return 1;
162     }
163
164     switch( p_method->i_command )
165     {
166         case COMMAND_QUIT:
167             p_input->p_vlc->b_die = 1;
168             break;
169
170         case COMMAND_LOOP:
171             playlist_Goto( p_playlist, 0 );
172             break;
173
174         case COMMAND_PAUSE:
175             if( mdate() < p_method->expiration )
176             {
177                 msleep( 10000 );
178             }
179             else
180             {
181                 p_input->b_eof = 1;
182             }
183             break;
184
185         case COMMAND_NOP:
186         default:
187             p_input->b_eof = 1;
188             break;
189     }
190
191     vlc_object_release( p_playlist );
192
193     return 1;
194 }
195