]> git.sesse.net Git - vlc/blob - src/control/input.c
libvlc input and video update:
[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/libvlc.h>
26
27 #include <vlc/intf.h>
28
29 void libvlc_input_free( libvlc_input_t *p_input )
30 {
31     if( p_input )
32         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     {
46         libvlc_exception_raise( p_e, "Input is NULL" );
47         return -1;
48     }
49
50     p_input_thread = (input_thread_t*)vlc_object_get(
51                                  p_input->p_instance->p_vlc,
52                                  p_input->i_input_id );
53     if( !p_input_thread )
54     {
55         libvlc_exception_raise( p_e, "Input does not exist" );
56         return NULL;
57     }
58
59     return p_input_thread;
60 }
61
62     
63
64 /**************************************************************************
65  * Getters for stream information
66  **************************************************************************/
67 vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
68                              libvlc_exception_t *p_exception )
69 {
70     input_thread_t *p_input_thread;
71     vlc_value_t val;
72
73     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
74
75     if ( libvlc_exception_raised( p_exception ) )
76         return -1.0;
77        
78     var_Get( p_input_thread, "length", &val );
79     vlc_object_release( p_input_thread );
80
81     return val.i_time / 1000;
82 }
83
84 vlc_int64_t libvlc_input_get_time( libvlc_input_t *p_input,
85                            libvlc_exception_t *p_exception )
86 {
87     input_thread_t *p_input_thread;
88     vlc_value_t val;
89
90
91     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
92
93     if ( libvlc_exception_raised( p_exception ) )
94         return -1.0;
95
96     var_Get( p_input_thread , "time", &val );
97     vlc_object_release( p_input_thread );
98
99     return val.i_time / 1000;
100 }
101
102 float libvlc_input_get_position( libvlc_input_t *p_input,
103                                  libvlc_exception_t *p_exception )
104 {
105     input_thread_t *p_input_thread;
106     vlc_value_t val;
107
108     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
109
110     if ( libvlc_exception_raised( p_exception ) )
111         return -1.0;
112
113     var_Get( p_input_thread, "position", &val );
114     vlc_object_release( p_input_thread );
115
116     return val.f_float;
117 }
118
119 vlc_bool_t libvlc_input_will_play( libvlc_input_t *p_input,
120                                    libvlc_exception_t *p_exception) 
121 {
122     input_thread_t *p_input_thread;
123
124     p_input_thread = libvlc_get_input_thread ( p_input, p_exception);
125
126     if ( libvlc_exception_raised( p_exception ) )
127         return VLC_FALSE;
128
129     if ( !p_input_thread->b_die && !p_input_thread->b_dead ) 
130     {
131         vlc_object_release( p_input_thread );
132         return VLC_TRUE;
133     }
134     
135     vlc_object_release( p_input_thread );
136     return VLC_FALSE;
137 }