]> git.sesse.net Git - vlc/blob - src/control/video.c
Video resize function added in libvlc.
[vlc] / src / control / video.c
1 /*****************************************************************************
2  * video.c: libvlc new API video functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
7  *
8  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
9  *          Filippo Carone <littlejohn@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #include <libvlc_internal.h>
27 #include <vlc/libvlc.h>
28
29 #include <vlc/vout.h>
30 #include <vlc/intf.h>
31
32 /*
33  * Remember to release the returned vout_thread_t since it is locked at
34  * the end of this function.
35  */
36 static vout_thread_t *GetVout( libvlc_input_t *p_input,
37                                libvlc_exception_t *p_exception )
38 {
39     input_thread_t *p_input_thread;
40     vout_thread_t *p_vout;
41
42     if( !p_input )
43     {
44         libvlc_exception_raise( p_exception, "Input is NULL" );
45         return NULL;
46     }
47
48     p_input_thread = (input_thread_t*)vlc_object_get(
49                                  p_input->p_instance->p_vlc,
50                                  p_input->i_input_id );
51     if( !p_input_thread )
52     {
53         libvlc_exception_raise( p_exception, "Input does not exist" );
54         return NULL;
55     }
56
57     p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
58     if( !p_vout )
59     {
60         vlc_object_release( p_input_thread );
61         libvlc_exception_raise( p_exception, "No active video output" );
62         return NULL;
63     }
64     vlc_object_release( p_input_thread );
65     
66     return p_vout;
67 }
68 /**********************************************************************
69  * Exported functions
70  **********************************************************************/
71
72 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
73                             libvlc_exception_t *p_e )
74 {
75     /* We only work on the first vout */
76     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
77     vlc_value_t val; int i_ret;
78
79     /* GetVout will raise the exception for us */
80     if( !p_vout1 )
81     {
82         return;
83     }
84
85     if( b_fullscreen ) val.b_bool = VLC_TRUE;
86     else               val.b_bool = VLC_FALSE;
87
88     i_ret = var_Set( p_vout1, "fullscreen", val );
89     if( i_ret )
90         libvlc_exception_raise( p_e,
91                         "Unexpected error while setting fullscreen value" );
92
93     vlc_object_release( p_vout1 );
94
95 }
96
97 int libvlc_get_fullscreen( libvlc_input_t *p_input,
98                             libvlc_exception_t *p_e )
99 {
100     /* We only work on the first vout */
101     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
102     vlc_value_t val; int i_ret;
103
104     /* GetVout will raise the exception for us */
105     if( !p_vout1 )
106         return 0;
107
108     i_ret = var_Get( p_vout1, "fullscreen", &val );
109     if( i_ret )
110         libvlc_exception_raise( p_e,
111                         "Unexpected error while looking up fullscreen value" );
112
113     return val.b_bool == VLC_TRUE ? 1 : 0;
114 }
115
116 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
117                                libvlc_exception_t *p_e )
118 {
119     /* We only work on the first vout */
120     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
121     vlc_value_t val; int i_ret;
122
123     /* GetVout will raise the exception for us */
124     if( !p_vout1 )
125         return;
126
127     i_ret = var_Get( p_vout1, "fullscreen", &val );
128     if( i_ret )
129         libvlc_exception_raise( p_e,
130                         "Unexpected error while looking up fullscreen value" );
131
132     val.b_bool = !val.b_bool;
133     i_ret = var_Set( p_vout1, "fullscreen", val );
134     if( i_ret )
135         libvlc_exception_raise( p_e,
136                         "Unexpected error while setting fullscreen value" );
137
138     vlc_object_release( p_vout1 );
139
140 }
141
142 void
143 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
144                        libvlc_exception_t *p_e )
145 {
146     vout_thread_t *p_vout = GetVout( p_input, p_e );
147     input_thread_t *p_input_thread;
148     
149     char path[256];
150
151     /* GetVout will raise the exception for us */
152     if( !p_vout )
153     {
154         return;
155     }
156
157     p_input_thread = (input_thread_t*)vlc_object_get(
158                                  p_input->p_instance->p_vlc,
159                                  p_input->i_input_id );
160     if( !p_input_thread )
161     {
162         libvlc_exception_raise( p_e, "Input does not exist" );
163         return;
164     }
165    
166     snprintf( path, 255, "%s", psz_filepath );
167     var_SetString( p_vout, "snapshot-path", path );
168     var_SetString( p_vout, "snapshot-format", "png" );
169
170     vout_Control( p_vout, VOUT_SNAPSHOT );
171     vlc_object_release( p_vout );
172     vlc_object_release( p_input_thread );
173
174     return;
175     
176 }
177
178 int libvlc_video_get_height( libvlc_input_t *p_input,
179                              libvlc_exception_t *p_e ) 
180 {
181     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
182     if( !p_vout1 )
183         return 0;
184
185     vlc_object_release( p_vout1 );
186
187     return p_vout1->i_window_height;
188 }
189
190 int libvlc_video_get_width( libvlc_input_t *p_input,
191                             libvlc_exception_t *p_e ) 
192 {
193     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
194     if( !p_vout1 )
195         return 0;
196
197     vlc_object_release( p_vout1 );
198
199     return p_vout1->i_window_width;
200 }
201
202 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
203                                   libvlc_exception_t *p_e )
204 {
205     vout_thread_t *p_vout = GetVout( p_input, p_e );
206
207     /* GetVout will raise the exception for us */
208     if( !p_vout )
209     {
210         return VLC_FALSE;
211     }
212
213     vlc_object_release( p_vout );
214     
215     return VLC_TRUE;
216 }
217
218
219 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
220                            libvlc_exception_t *p_e )
221 {
222     vout_thread_t *p_vout = GetVout( p_input, p_e );
223     vout_Control( p_vout , VOUT_REPARENT, d);
224     vlc_object_release( p_vout );
225     
226     return 0;
227     
228 }
229
230 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
231 {
232     vout_thread_t *p_vout = GetVout( p_input, p_e );
233     vout_Control( p_vout, VOUT_SET_SIZE, width, height );
234     vlc_object_release( p_vout );
235 }
236
237
238 int libvlc_video_destroy( libvlc_input_t *p_input,
239                           libvlc_exception_t *p_e )
240 {
241     vout_thread_t *p_vout = GetVout( p_input, p_e );
242     vlc_object_detach( p_vout ); 
243     vlc_object_release( p_vout );
244     vout_Destroy( p_vout );
245     
246     return 0;
247     
248 }