]> git.sesse.net Git - vlc/blob - modules/misc/dummy/input.c
* modules/misc/dummy/input.c: fixed the vlc:quit command.
[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.6 2003/12/16 12:54:29 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,none";
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     p_input->pf_demux_control = demux_vaControlDefault;
86
87     p_method = malloc( sizeof( struct demux_sys_t ) );
88     if( p_method == NULL )
89     {
90         msg_Err( p_input, "out of memory" );
91         return VLC_EGENERIC;
92     }
93
94     p_input->p_demux_data = p_method;
95     p_input->stream.p_demux_data = NULL;
96
97     /* Check for a "vlc:nop" command */
98     if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
99     {
100         msg_Info( p_input, "command `nop'" );
101         p_method->i_command = COMMAND_NOP;
102         return VLC_SUCCESS;
103     }
104
105     /* Check for a "vlc:quit" command */
106     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
107     {
108         msg_Info( p_input, "command `quit'" );
109         p_method->i_command = COMMAND_QUIT;
110         return VLC_SUCCESS;
111     }
112
113     /* Check for a "vlc:loop" command */
114     if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
115     {
116         msg_Info( p_input, "command `loop'" );
117         p_method->i_command = COMMAND_LOOP;
118         return VLC_SUCCESS;
119     }
120
121     /* Check for a "vlc:pause:***" command */
122     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
123     {
124         i_arg = atoi( psz_name + 6 );
125         msg_Info( p_input, "command `pause %i'", i_arg );
126         p_method->i_command = COMMAND_PAUSE;
127         p_method->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
128         return VLC_SUCCESS;
129     }
130
131     msg_Err( p_input, "unknown command `%s'", psz_name );
132     free( p_input->p_demux_data );
133     p_input->b_error = 1;
134
135     return VLC_EGENERIC;
136 }
137
138 /*****************************************************************************
139  * CloseDemux: initialize the target, ie. parse the command
140  *****************************************************************************/
141 void E_(CloseDemux) ( vlc_object_t *p_this )
142 {
143     input_thread_t *p_input = (input_thread_t *)p_this;
144
145     free( p_input->p_demux_data );
146 }
147
148 /*****************************************************************************
149  * Demux: do what the command says
150  *****************************************************************************/
151 static int Demux( input_thread_t *p_input )
152 {
153     struct demux_sys_t * p_method = p_input->p_demux_data;
154     playlist_t *p_playlist;
155
156     p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
157
158     if( p_playlist == NULL )
159     {
160         msg_Err( p_input, "we are not attached to a playlist" );
161         p_input->b_error = 1;
162         return 1;
163     }
164
165     switch( p_method->i_command )
166     {
167         case COMMAND_QUIT:
168             p_input->p_vlc->b_die = 1;
169             p_input->b_eof = 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