1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
8 * Authors: Clément Stenac <zorglub@videolan.org>
9 * Filippo Carone <littlejohn@videolan.org>
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.
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.
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 *****************************************************************************/
26 #include <libvlc_internal.h>
27 #include <vlc/libvlc.h>
33 * Remember to release the returned vout_thread_t since it is locked at
34 * the end of this function.
36 static vout_thread_t *GetVout( libvlc_input_t *p_input,
37 libvlc_exception_t *p_exception )
39 input_thread_t *p_input_thread;
40 vout_thread_t *p_vout;
44 libvlc_exception_raise( p_exception, "Input is NULL" );
48 p_input_thread = (input_thread_t*)vlc_object_get(
49 p_input->p_instance->p_libvlc_int,
50 p_input->i_input_id );
53 libvlc_exception_raise( p_exception, "Input does not exist" );
57 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
60 vlc_object_release( p_input_thread );
61 libvlc_exception_raise( p_exception, "No active video output" );
64 vlc_object_release( p_input_thread );
68 /**********************************************************************
70 **********************************************************************/
72 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
73 libvlc_exception_t *p_e )
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;
79 /* GetVout will raise the exception for us */
85 if( b_fullscreen ) val.b_bool = VLC_TRUE;
86 else val.b_bool = VLC_FALSE;
88 i_ret = var_Set( p_vout1, "fullscreen", val );
90 libvlc_exception_raise( p_e,
91 "Unexpected error while setting fullscreen value" );
93 vlc_object_release( p_vout1 );
97 int libvlc_get_fullscreen( libvlc_input_t *p_input,
98 libvlc_exception_t *p_e )
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;
104 /* GetVout will raise the exception for us */
108 i_ret = var_Get( p_vout1, "fullscreen", &val );
110 libvlc_exception_raise( p_e,
111 "Unexpected error while looking up fullscreen value" );
113 return val.b_bool == VLC_TRUE ? 1 : 0;
116 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
117 libvlc_exception_t *p_e )
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;
123 /* GetVout will raise the exception for us */
127 i_ret = var_Get( p_vout1, "fullscreen", &val );
129 libvlc_exception_raise( p_e,
130 "Unexpected error while looking up fullscreen value" );
132 val.b_bool = !val.b_bool;
133 i_ret = var_Set( p_vout1, "fullscreen", val );
135 libvlc_exception_raise( p_e,
136 "Unexpected error while setting fullscreen value" );
138 vlc_object_release( p_vout1 );
143 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
144 libvlc_exception_t *p_e )
146 vout_thread_t *p_vout = GetVout( p_input, p_e );
147 input_thread_t *p_input_thread;
151 /* GetVout will raise the exception for us */
157 p_input_thread = (input_thread_t*)vlc_object_get(
158 p_input->p_instance->p_libvlc_int,
159 p_input->i_input_id );
160 if( !p_input_thread )
162 libvlc_exception_raise( p_e, "Input does not exist" );
166 snprintf( path, 255, "%s", psz_filepath );
167 var_SetString( p_vout, "snapshot-path", path );
168 var_SetString( p_vout, "snapshot-format", "png" );
170 vout_Control( p_vout, VOUT_SNAPSHOT );
171 vlc_object_release( p_vout );
172 vlc_object_release( p_input_thread );
178 int libvlc_video_get_height( libvlc_input_t *p_input,
179 libvlc_exception_t *p_e )
181 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
185 vlc_object_release( p_vout1 );
187 return p_vout1->i_window_height;
190 int libvlc_video_get_width( libvlc_input_t *p_input,
191 libvlc_exception_t *p_e )
193 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
197 vlc_object_release( p_vout1 );
199 return p_vout1->i_window_width;
202 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
203 libvlc_exception_t *p_e )
205 vout_thread_t *p_vout = GetVout( p_input, p_e );
207 /* GetVout will raise the exception for us */
213 vlc_object_release( p_vout );
219 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
220 libvlc_exception_t *p_e )
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 );
230 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
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 );
237 /* global video settings */
239 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
240 libvlc_exception_t *p_e )
242 /* set as default for future vout instances */
243 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
245 if( libvlc_playlist_isplaying(p_instance, p_e) )
247 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
250 vout_thread_t *p_vout = GetVout( p_input, p_e );
253 /* tell running vout to re-parent */
254 vout_Control( p_vout , VOUT_REPARENT, d);
255 vlc_object_release( p_vout );
257 libvlc_input_free(p_input);
262 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
263 libvlc_exception_t *p_e )
265 /* set as default for future vout instances */
266 config_PutInt(p_instance->p_libvlc_int, "width", width);
267 config_PutInt(p_instance->p_libvlc_int, "height", height);
269 if( libvlc_playlist_isplaying(p_instance, p_e) )
271 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
274 vout_thread_t *p_vout = GetVout( p_input, p_e );
277 /* tell running vout to re-size */
278 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
279 vlc_object_release( p_vout );
281 libvlc_input_free(p_input);
286 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
287 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
288 libvlc_exception_t *p_e )
292 libvlc_exception_raise( p_e, "viewport is NULL" );
295 /* if clip is NULL, then use view rectangle as clip */
299 /* set as default for future vout instances */
300 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
301 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
302 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
303 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
304 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
305 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
306 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
307 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
309 if( libvlc_playlist_isplaying(p_instance, p_e) )
311 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
314 vout_thread_t *p_vout = GetVout( p_input, p_e );
317 /* change viewport for running vout */
318 vout_Control( p_vout , VOUT_SET_VIEWPORT,
319 view->top, view->left, view->bottom, view->right,
320 clip->top, clip->left, clip->bottom, clip->right );
321 vlc_object_release( p_vout );
323 libvlc_input_free(p_input);
328 int libvlc_video_destroy( libvlc_input_t *p_input,
329 libvlc_exception_t *p_e )
331 vout_thread_t *p_vout = GetVout( p_input, p_e );
332 vlc_object_detach( p_vout );
333 vlc_object_release( p_vout );
334 vout_Destroy( p_vout );