]> git.sesse.net Git - vlc/blob - plugins/dummy/input_dummy.c
b0e659cf40ff793915056ca83a31829f745a8e9d
[vlc] / plugins / dummy / input_dummy.c
1 /*****************************************************************************
2  * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: input_dummy.c,v 1.11 2001/12/30 07:09:55 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 #ifdef STRNCASECMP_IN_STRINGS_H
35 #   include <strings.h>
36 #endif
37
38 #include "interface.h"
39 #include "intf_playlist.h"
40
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43 #include "input_ext-dec.h"
44 #include "input_ext-plugins.h"
45
46 /*****************************************************************************
47  * Local prototypes
48  *****************************************************************************/
49 static int  DummyProbe     ( probedata_t * );
50 static void DummyOpen      ( struct input_thread_s * );
51 static void DummyClose     ( struct input_thread_s * );
52
53 /*****************************************************************************
54  * Functions exported as capabilities. They are declared as static so that
55  * we don't pollute the namespace too much.
56  *****************************************************************************/
57 void _M( input_getfunctions )( function_list_t * p_function_list )
58 {
59 #define input p_function_list->functions.input
60     p_function_list->pf_probe = DummyProbe;
61     input.pf_init             = NULL; /* Not needed, open is called first */
62     input.pf_open             = DummyOpen;
63     input.pf_close            = DummyClose;
64     input.pf_end              = NULL;
65     input.pf_set_area         = NULL;
66     input.pf_read             = NULL;
67     input.pf_demux            = NULL;
68     input.pf_new_packet       = NULL;
69     input.pf_new_pes          = NULL;
70     input.pf_delete_packet    = NULL;
71     input.pf_delete_pes       = NULL;
72     input.pf_rewind           = NULL;
73     input.pf_seek             = NULL;
74 #undef input
75 }
76
77 /*
78  * Data reading functions
79  */
80
81 /*****************************************************************************
82  * DummyProbe: verifies that the input is a vlc command
83  *****************************************************************************/
84 static int DummyProbe( probedata_t *p_data )
85 {
86     input_thread_t *p_input = (input_thread_t *)p_data;
87     char *psz_name = p_input->p_source;
88
89     if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "vlc:", 4 ) )
90     {
91         /* If the user specified "vlc:" then it's probably a file */
92         return( 100 );
93     }
94
95     return( 1 );
96 }
97
98 /*****************************************************************************
99  * DummyOpen: open the target, ie. do what the command says
100  *****************************************************************************/
101 static void DummyOpen( input_thread_t * p_input )
102 {
103     char *psz_name = p_input->p_source;
104     int   i_len = strlen( psz_name );
105     int   i_arg;
106     
107     /* XXX: Tell the input layer to quit immediately, there must
108      * be a nicer way to do this. */
109     p_input->b_error = 1;
110
111     if( ( i_len <= 4 ) || strncasecmp( psz_name, "vlc:", 4 ) )
112     {
113         /* If the command doesn't start with "vlc:" then it's not for us */
114         return;
115     }
116
117     /* We don't need the "vlc:" stuff any more */
118     psz_name += 4;
119     i_len -= 4;
120
121     /* Check for a "vlc:quit" command */
122     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
123     {
124         intf_WarnMsg( 2, "input: command `quit'" );
125         p_main->p_intf->b_die = 1;
126         return;
127     }
128
129     /* Check for a "vlc:loop" command */
130     if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
131     {
132         intf_WarnMsg( 2, "input: command `loop'" );
133         intf_PlaylistJumpto( p_main->p_playlist, -1 );
134         return;
135     }
136
137     /* Check for a "vlc:pause:***" command */
138     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
139     {
140         i_arg = atoi( psz_name + 6 );
141
142         intf_WarnMsgImm( 2, "input: command `pause %i'", i_arg );
143
144         msleep( i_arg * 1000000 );
145         return;
146     }
147
148     intf_ErrMsg( "input error: unknown command `%s'", psz_name );
149
150 }
151
152 /*****************************************************************************
153  * DummyClose: close the target, ie. do nothing
154  *****************************************************************************/
155 static void DummyClose( input_thread_t * p_input )
156 {
157     return;
158 }
159