]> git.sesse.net Git - vlc/blob - src/control/input.c
bb48e8581e9c706caec662bfc13ef01da3ead07e
[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 )
33         free( p_input );
34 }
35
36 /*
37  * Retrieve the input thread. Be sure to release the object
38  * once you are done with it.
39  */
40 input_thread_t *libvlc_get_input_thread( libvlc_input_t *p_input,
41                                          libvlc_exception_t *p_e ) 
42 {
43     input_thread_t *p_input_thread;
44
45     if( !p_input )
46     {
47         libvlc_exception_raise( p_e, "Input is NULL" );
48         return NULL;
49     }
50
51     p_input_thread = (input_thread_t*)vlc_object_get(
52                                  p_input->p_instance->p_vlc,
53                                  p_input->i_input_id );
54     if( !p_input_thread )
55     {
56         libvlc_exception_raise( p_e, "Input does not exist" );
57         return NULL;
58     }
59
60     return p_input_thread;
61 }
62
63     
64
65 /**************************************************************************
66  * Getters for stream information
67  **************************************************************************/
68 vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
69                              libvlc_exception_t *p_exception )
70 {
71     input_thread_t *p_input_thread;
72     vlc_value_t val;
73
74     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
75
76     if ( libvlc_exception_raised( p_exception ) )
77         return -1.0;
78        
79     var_Get( p_input_thread, "length", &val );
80     vlc_object_release( p_input_thread );
81
82     return val.i_time / 1000;
83 }
84
85 vlc_int64_t libvlc_input_get_time( libvlc_input_t *p_input,
86                            libvlc_exception_t *p_exception )
87 {
88     input_thread_t *p_input_thread;
89     vlc_value_t val;
90
91
92     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
93
94     if ( libvlc_exception_raised( p_exception ) )
95         return -1.0;
96
97     var_Get( p_input_thread , "time", &val );
98     vlc_object_release( p_input_thread );
99
100     return val.i_time / 1000;
101 }
102
103 void libvlc_input_set_time( libvlc_input_t *p_input, vlc_int64_t time, libvlc_exception_t *p_exception )
104 {
105     input_thread_t *p_input_thread;
106     vlc_value_t value;
107
108     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
109
110     if ( libvlc_exception_raised( p_exception ) )
111         return;
112     
113     value.i_time = time;
114     var_Set( p_input_thread, "time", value );
115     vlc_object_release( p_input_thread );
116
117     return;
118     
119 }
120
121 void libvlc_input_set_position( libvlc_input_t *p_input, float position, libvlc_exception_t *p_exception ) 
122 {
123     input_thread_t *p_input_thread;
124     vlc_value_t val;
125
126     val.f_float = position;
127     
128     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
129
130     if ( libvlc_exception_raised( p_exception ) )
131         return;
132
133     var_Set( p_input_thread, "position", val );
134     vlc_object_release( p_input_thread );
135
136     return;
137
138 }
139
140
141
142 float libvlc_input_get_position( libvlc_input_t *p_input,
143                                  libvlc_exception_t *p_exception )
144 {
145     input_thread_t *p_input_thread;
146     vlc_value_t val;
147
148     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
149
150     if ( libvlc_exception_raised( p_exception ) )
151         return -1.0;
152
153     var_Get( p_input_thread, "position", &val );
154     vlc_object_release( p_input_thread );
155
156     return val.f_float;
157 }
158
159 float libvlc_input_get_fps( libvlc_input_t *p_input,
160                             libvlc_exception_t *p_exception) 
161 {
162     double f_fps;
163     input_thread_t *p_input_thread;
164
165     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
166
167     if( demux2_Control( p_input_thread->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 ) 
168     {
169         vlc_object_release( p_input_thread );
170         return 0;
171     }
172     else
173     {
174         vlc_object_release( p_input_thread );
175         return( f_fps );
176     }
177 }
178
179 vlc_bool_t libvlc_input_will_play( libvlc_input_t *p_input,
180                                    libvlc_exception_t *p_exception) 
181 {
182     input_thread_t *p_input_thread;
183
184     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
185
186     if ( libvlc_exception_raised( p_exception ) )
187         return VLC_FALSE;
188
189     if ( !p_input_thread->b_die && !p_input_thread->b_dead ) 
190     {
191         vlc_object_release( p_input_thread );
192         return VLC_TRUE;
193     }
194     
195     vlc_object_release( p_input_thread );
196     return VLC_FALSE;
197 }