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