]> git.sesse.net Git - vlc/blob - src/control/input.c
src/control: a bit of cleanup here and there
[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 ) RAISENULL( "Input is NULL" );
45
46     p_input_thread = (input_thread_t*)vlc_object_get(
47                                                     p_input->p_instance->p_vlc,
48                                                     p_input->i_input_id );
49     if( !p_input_thread ) RAISENULL( "Input does not exist" );
50
51     return p_input_thread;
52 }
53
54     
55
56 /**************************************************************************
57  * Getters for stream information
58  **************************************************************************/
59 vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
60                              libvlc_exception_t *p_e )
61 {
62     input_thread_t *p_input_thread;
63     vlc_value_t val;
64
65     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
66     if( libvlc_exception_raised( p_e ) )  return -1.0;
67        
68     var_Get( p_input_thread, "length", &val );
69     vlc_object_release( p_input_thread );
70
71     return val.i_time / 1000;
72 }
73
74 vlc_int64_t libvlc_input_get_time( libvlc_input_t *p_input,
75                                    libvlc_exception_t *p_e )
76 {
77     input_thread_t *p_input_thread;
78     vlc_value_t val;
79
80     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
81     if( libvlc_exception_raised( p_e ) )  return -1.0;
82
83     var_Get( p_input_thread , "time", &val );
84     vlc_object_release( p_input_thread );
85     return val.i_time / 1000;
86 }
87
88 void libvlc_input_set_time( libvlc_input_t *p_input, vlc_int64_t time,
89                             libvlc_exception_t *p_e )
90 {
91     input_thread_t *p_input_thread;
92     vlc_value_t value;
93
94     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
95     if( libvlc_exception_raised( p_e ) )  return;
96     
97     value.i_time = time;
98     var_Set( p_input_thread, "time", value );
99     vlc_object_release( p_input_thread );
100 }
101
102 void libvlc_input_set_position( libvlc_input_t *p_input, float position,
103                                 libvlc_exception_t *p_e ) 
104 {
105     input_thread_t *p_input_thread;
106     vlc_value_t val;
107     val.f_float = position;
108     
109     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
110     if ( libvlc_exception_raised( p_e ) ) return;
111
112     var_Set( p_input_thread, "position", val );
113     vlc_object_release( p_input_thread );
114 }
115
116 float libvlc_input_get_position( libvlc_input_t *p_input,
117                                  libvlc_exception_t *p_e )
118 {
119     input_thread_t *p_input_thread;
120     vlc_value_t val;
121
122     p_input_thread = libvlc_get_input_thread ( p_input, p_e);
123     if ( libvlc_exception_raised( p_e ) )  return -1.0;
124
125     var_Get( p_input_thread, "position", &val );
126     vlc_object_release( p_input_thread );
127
128     return val.f_float;
129 }
130
131 float libvlc_input_get_fps( libvlc_input_t *p_input,
132                             libvlc_exception_t *p_e) 
133 {
134     double f_fps;
135     input_thread_t *p_input_thread;
136
137     p_input_thread = libvlc_get_input_thread ( p_input, p_e );
138     if ( libvlc_exception_raised( p_e ) )  return 0.0;
139
140     if( demux2_Control( p_input_thread->input.p_demux, DEMUX_GET_FPS, &f_fps )
141         || f_fps < 0.1 ) 
142     {
143         vlc_object_release( p_input_thread );
144         return 0.0;
145     }
146     else
147     {
148         vlc_object_release( p_input_thread );
149         return( f_fps );
150     }
151 }
152
153 vlc_bool_t libvlc_input_will_play( libvlc_input_t *p_input,
154                                    libvlc_exception_t *p_e) 
155 {
156     input_thread_t *p_input_thread =
157                             libvlc_get_input_thread ( p_input, p_e);
158     if ( libvlc_exception_raised( p_e ) ) return VLC_FALSE;
159
160     if ( !p_input_thread->b_die && !p_input_thread->b_dead ) 
161     {
162         vlc_object_release( p_input_thread );
163         return VLC_TRUE;
164     }
165     vlc_object_release( p_input_thread );
166     return VLC_FALSE;
167 }