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�ent 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 );
96 int libvlc_get_fullscreen( libvlc_input_t *p_input,
97 libvlc_exception_t *p_e )
99 /* We only work on the first vout */
100 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
101 vlc_value_t val; int i_ret;
103 /* GetVout will raise the exception for us */
107 i_ret = var_Get( p_vout1, "fullscreen", &val );
109 libvlc_exception_raise( p_e,
110 "Unexpected error while looking up fullscreen value" );
112 return val.b_bool == VLC_TRUE ? 1 : 0;
115 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
116 libvlc_exception_t *p_e )
118 /* We only work on the first vout */
119 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
120 vlc_value_t val; int i_ret;
122 /* GetVout will raise the exception for us */
126 i_ret = var_Get( p_vout1, "fullscreen", &val );
128 libvlc_exception_raise( p_e,
129 "Unexpected error while looking up fullscreen value" );
131 val.b_bool = !val.b_bool;
132 i_ret = var_Set( p_vout1, "fullscreen", val );
134 libvlc_exception_raise( p_e,
135 "Unexpected error while setting fullscreen value" );
137 vlc_object_release( p_vout1 );
141 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
142 libvlc_exception_t *p_e )
144 vout_thread_t *p_vout = GetVout( p_input, p_e );
145 input_thread_t *p_input_thread;
149 /* GetVout will raise the exception for us */
155 p_input_thread = (input_thread_t*)vlc_object_get(
156 p_input->p_instance->p_libvlc_int,
157 p_input->i_input_id );
158 if( !p_input_thread )
160 libvlc_exception_raise( p_e, "Input does not exist" );
164 snprintf( path, 255, "%s", psz_filepath );
165 var_SetString( p_vout, "snapshot-path", path );
166 var_SetString( p_vout, "snapshot-format", "png" );
168 vout_Control( p_vout, VOUT_SNAPSHOT );
169 vlc_object_release( p_vout );
170 vlc_object_release( p_input_thread );
173 int libvlc_video_get_height( libvlc_input_t *p_input,
174 libvlc_exception_t *p_e )
176 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
180 vlc_object_release( p_vout1 );
182 return p_vout1->i_window_height;
185 int libvlc_video_get_width( libvlc_input_t *p_input,
186 libvlc_exception_t *p_e )
188 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
192 vlc_object_release( p_vout1 );
194 return p_vout1->i_window_width;
197 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
198 libvlc_exception_t *p_e )
200 vout_thread_t *p_vout = GetVout( p_input, p_e );
202 /* GetVout will raise the exception for us */
208 vlc_object_release( p_vout );
213 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
214 libvlc_exception_t *p_e )
216 vout_thread_t *p_vout = GetVout( p_input, p_e );
220 /// \todo: set exception
224 vout_Control( p_vout , VOUT_REPARENT, d);
225 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 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
329 libvlc_exception_t *p_e )
331 char *psz_aspect = 0;
332 vout_thread_t *p_vout = GetVout( p_input, p_e );
337 psz_aspect = var_GetString( p_vout, "aspect-ratio" );
338 vlc_object_release( p_vout );
342 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
343 char *psz_aspect, libvlc_exception_t *p_e )
345 vout_thread_t *p_vout = GetVout( p_input, p_e );
351 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
353 libvlc_exception_raise( p_e,
354 "Unexpected error while setting aspect-ratio value" );
356 vlc_object_release( p_vout );
359 int libvlc_video_destroy( libvlc_input_t *p_input,
360 libvlc_exception_t *p_e )
362 vout_thread_t *p_vout = GetVout( p_input, p_e );
363 vlc_object_detach( p_vout );
364 vlc_object_release( p_vout );
365 vout_Destroy( p_vout );