]> git.sesse.net Git - vlc/blob - src/control/input.c
Forward port of [17351]. Report input error condition to JavaScript
[vlc] / src / control / input.c
1 /*****************************************************************************
2  * input.c: Libvlc new API input management functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <libvlc_internal.h>
25 #include <vlc_demux.h>
26 #include <vlc/libvlc.h>
27
28 #include <vlc/intf.h>
29
30 void libvlc_input_free( libvlc_input_t *p_input )
31 {
32     if( p_input ) free( p_input );
33 }
34
35 /*
36  * Retrieve the input thread. Be sure to release the object
37  * once you are done with it.
38  */
39 input_thread_t *libvlc_get_input_thread( libvlc_input_t *p_input,
40                                          libvlc_exception_t *p_e ) 
41 {
42     input_thread_t *p_input_thread;
43
44     if( !p_input )
45         RAISENULL( "Input is NULL" );
46
47     p_input_thread = (input_thread_t*)vlc_object_get(
48                                              p_input->p_instance->p_libvlc_int,
49                                              p_input->i_input_id );
50     if( !p_input_thread )
51         RAISENULL( "Input does not exist" );
52
53     return p_input_thread;
54 }
55
56
57 /**************************************************************************
58  * Getters for stream information
59  **************************************************************************/
60 vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
61                              libvlc_exception_t *p_e )
62 {
63     input_thread_t *p_input_thread;
64     vlc_value_t val;
65
66     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
67     if( libvlc_exception_raised( p_e ) )
68         return -1;
69
70     var_Get( p_input_thread, "length", &val );
71     vlc_object_release( p_input_thread );
72
73     return (val.i_time+500LL)/1000LL;
74 }
75
76 vlc_int64_t libvlc_input_get_time( libvlc_input_t *p_input,
77                                    libvlc_exception_t *p_e )
78 {
79     input_thread_t *p_input_thread;
80     vlc_value_t val;
81
82     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
83     if( libvlc_exception_raised( p_e ) )
84         return -1;
85
86     var_Get( p_input_thread , "time", &val );
87     vlc_object_release( p_input_thread );
88     return (val.i_time+500LL)/1000LL;
89 }
90
91 void libvlc_input_set_time( libvlc_input_t *p_input, vlc_int64_t time,
92                             libvlc_exception_t *p_e )
93 {
94     input_thread_t *p_input_thread;
95     vlc_value_t value;
96
97     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
98     if( libvlc_exception_raised( p_e ) )
99         return;
100
101     value.i_time = time*1000LL;
102     var_Set( p_input_thread, "time", value );
103     vlc_object_release( p_input_thread );
104 }
105
106 void libvlc_input_set_position( libvlc_input_t *p_input, float position,
107                                 libvlc_exception_t *p_e ) 
108 {
109     input_thread_t *p_input_thread;
110     vlc_value_t val;
111     val.f_float = position;
112
113     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
114     if ( libvlc_exception_raised( p_e ) )
115         return;
116
117     var_Set( p_input_thread, "position", val );
118     vlc_object_release( p_input_thread );
119 }
120
121 float libvlc_input_get_position( libvlc_input_t *p_input,
122                                  libvlc_exception_t *p_e )
123 {
124     input_thread_t *p_input_thread;
125     vlc_value_t val;
126
127     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
128     if ( libvlc_exception_raised( p_e ) )
129         return -1.0;
130
131     var_Get( p_input_thread, "position", &val );
132     vlc_object_release( p_input_thread );
133
134     return val.f_float;
135 }
136
137 float libvlc_input_get_fps( libvlc_input_t *p_input,
138                             libvlc_exception_t *p_e) 
139 {
140     double f_fps;
141     input_thread_t *p_input_thread;
142
143     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
144     if ( libvlc_exception_raised( p_e ) )
145         return 0.0;
146
147     if( demux2_Control( p_input_thread->input.p_demux, DEMUX_GET_FPS, &f_fps )
148         || f_fps < 0.1 ) 
149     {
150         vlc_object_release( p_input_thread );
151         return 0.0;
152     }
153     else
154     {
155         vlc_object_release( p_input_thread );
156         return( f_fps );
157     }
158 }
159
160 vlc_bool_t libvlc_input_will_play( libvlc_input_t *p_input,
161                                    libvlc_exception_t *p_e) 
162 {
163     input_thread_t *p_input_thread =
164                             libvlc_get_input_thread ( p_input, p_e);
165     if ( libvlc_exception_raised( p_e ) )
166         return VLC_FALSE;
167
168     if ( !p_input_thread->b_die && !p_input_thread->b_dead ) 
169     {
170         vlc_object_release( p_input_thread );
171         return VLC_TRUE;
172     }
173     vlc_object_release( p_input_thread );
174     return VLC_FALSE;
175 }
176
177 void libvlc_input_set_rate( libvlc_input_t *p_input, float rate,
178                                 libvlc_exception_t *p_e ) 
179 {
180     input_thread_t *p_input_thread;
181     vlc_value_t val;
182
183     if( rate <= 0 )
184         RAISEVOID( "Rate value is invalid" );
185
186     val.i_int = 1000.0f/rate;
187
188     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
189     if ( libvlc_exception_raised( p_e ) )
190         return;
191
192     var_Set( p_input_thread, "rate", val );
193     vlc_object_release( p_input_thread );
194 }
195
196 float libvlc_input_get_rate( libvlc_input_t *p_input,
197                                  libvlc_exception_t *p_e )
198 {
199     input_thread_t *p_input_thread;
200     vlc_value_t val;
201
202     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
203     if ( libvlc_exception_raised( p_e ) )
204         return -1.0;
205
206     var_Get( p_input_thread, "rate", &val );
207     vlc_object_release( p_input_thread );
208
209     return (float)1000.0f/val.i_int;
210 }
211
212 int libvlc_input_get_state( libvlc_input_t *p_input,
213                                  libvlc_exception_t *p_e )
214 {
215     input_thread_t *p_input_thread;
216     vlc_value_t val;
217
218     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
219     if ( libvlc_exception_raised( p_e ) )
220         return 6; /* Return ERROR_S (see include/vlc_input.c) */
221
222     var_Get( p_input_thread, "state", &val );
223     vlc_object_release( p_input_thread );
224
225     return val.i_int;
226 }
227