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>
10 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
11 * Damien Fouilleul <damienf a_t videolan dot org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 #include "libvlc_internal.h"
29 #include <vlc/libvlc.h>
30 #include <vlc_input.h>
34 * Remember to release the returned vout_thread_t since it is locked at
35 * the end of this function.
37 static vout_thread_t *GetVout( libvlc_media_instance_t *p_mi,
38 libvlc_exception_t *p_exception )
40 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_exception );
41 vout_thread_t *p_vout = NULL;
45 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
48 libvlc_exception_raise( p_exception, "No active video output" );
50 vlc_object_release( p_input_thread );
55 /**********************************************************************
57 **********************************************************************/
59 void libvlc_set_fullscreen( libvlc_media_instance_t *p_mi, int b_fullscreen,
60 libvlc_exception_t *p_e )
62 /* We only work on the first vout */
63 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
64 vlc_value_t val; int i_ret;
66 /* GetVout will raise the exception for us */
72 if( b_fullscreen ) val.b_bool = VLC_TRUE;
73 else val.b_bool = VLC_FALSE;
75 i_ret = var_Set( p_vout1, "fullscreen", val );
77 libvlc_exception_raise( p_e,
78 "Unexpected error while setting fullscreen value" );
80 vlc_object_release( p_vout1 );
83 int libvlc_get_fullscreen( libvlc_media_instance_t *p_mi,
84 libvlc_exception_t *p_e )
86 /* We only work on the first vout */
87 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
88 vlc_value_t val; int i_ret;
90 /* GetVout will raise the exception for us */
94 i_ret = var_Get( p_vout1, "fullscreen", &val );
96 libvlc_exception_raise( p_e,
97 "Unexpected error while looking up fullscreen value" );
99 return val.b_bool == VLC_TRUE ? 1 : 0;
102 void libvlc_toggle_fullscreen( libvlc_media_instance_t *p_mi,
103 libvlc_exception_t *p_e )
105 /* We only work on the first vout */
106 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
107 vlc_value_t val; int i_ret;
109 /* GetVout will raise the exception for us */
113 i_ret = var_Get( p_vout1, "fullscreen", &val );
115 libvlc_exception_raise( p_e,
116 "Unexpected error while looking up fullscreen value" );
118 val.b_bool = !val.b_bool;
119 i_ret = var_Set( p_vout1, "fullscreen", val );
121 libvlc_exception_raise( p_e,
122 "Unexpected error while setting fullscreen value" );
124 vlc_object_release( p_vout1 );
128 libvlc_video_take_snapshot( libvlc_media_instance_t *p_mi, char *psz_filepath,
129 libvlc_exception_t *p_e )
131 vout_thread_t *p_vout = GetVout( p_mi, p_e );
132 input_thread_t *p_input_thread;
134 /* GetVout will raise the exception for us */
142 libvlc_exception_raise( p_e, "filepath is null" );
147 p_input_thread = (input_thread_t*)vlc_object_get(
148 p_mi->p_libvlc_instance->p_libvlc_int,
150 if( !p_input_thread )
152 libvlc_exception_raise( p_e, "Input does not exist" );
156 var_SetString( p_vout, "snapshot-path", psz_filepath );
157 var_SetString( p_vout, "snapshot-format", "png" );
159 vout_Control( p_vout, VOUT_SNAPSHOT );
160 vlc_object_release( p_vout );
161 vlc_object_release( p_input_thread );
164 int libvlc_video_get_height( libvlc_media_instance_t *p_mi,
165 libvlc_exception_t *p_e )
167 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
171 vlc_object_release( p_vout1 );
173 return p_vout1->i_window_height;
176 int libvlc_video_get_width( libvlc_media_instance_t *p_mi,
177 libvlc_exception_t *p_e )
179 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
183 vlc_object_release( p_vout1 );
185 return p_vout1->i_window_width;
188 vlc_bool_t libvlc_input_has_vout( libvlc_media_instance_t *p_mi,
189 libvlc_exception_t *p_e )
191 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
192 vlc_bool_t has_vout = VLC_FALSE;
196 vout_thread_t *p_vout;
198 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
202 vlc_object_release( p_vout );
204 vlc_object_release( p_input_thread );
209 int libvlc_video_reparent( libvlc_media_instance_t *p_mi, libvlc_drawable_t d,
210 libvlc_exception_t *p_e )
212 vout_thread_t *p_vout = GetVout( p_mi, p_e );
216 vout_Control( p_vout , VOUT_REPARENT, d);
217 vlc_object_release( p_vout );
222 void libvlc_video_resize( libvlc_media_instance_t *p_mi, int width, int height, libvlc_exception_t *p_e )
224 vout_thread_t *p_vout = GetVout( p_mi, p_e );
227 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
228 vlc_object_release( p_vout );
232 void libvlc_video_redraw_rectangle( libvlc_media_instance_t *p_mi,
233 const libvlc_rectangle_t *area,
234 libvlc_exception_t *p_e )
237 && ((area->bottom - area->top) > 0)
238 && ((area->right - area->left) > 0) )
240 vout_thread_t *p_vout = GetVout( p_mi, p_e );
243 /* tell running vout to redraw area */
244 vout_Control( p_vout , VOUT_REDRAW_RECT,
245 area->top, area->left, area->bottom, area->right );
246 vlc_object_release( p_vout );
251 /* global video settings */
253 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
254 libvlc_exception_t *p_e )
256 /* set as default for future vout instances */
257 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
259 if( libvlc_playlist_isplaying(p_instance, p_e) )
261 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
264 vout_thread_t *p_vout = GetVout( p_mi, p_e );
267 /* tell running vout to re-parent */
268 vout_Control( p_vout , VOUT_REPARENT, d);
269 vlc_object_release( p_vout );
271 libvlc_media_instance_destroy_and_detach(p_mi);
276 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
278 libvlc_drawable_t result;
280 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
286 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
287 libvlc_exception_t *p_e )
289 /* set as default for future vout instances */
290 config_PutInt(p_instance->p_libvlc_int, "width", width);
291 config_PutInt(p_instance->p_libvlc_int, "height", height);
293 if( libvlc_playlist_isplaying(p_instance, p_e) )
295 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
298 vout_thread_t *p_vout = GetVout( p_mi, p_e );
301 /* tell running vout to re-size */
302 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
303 vlc_object_release( p_vout );
305 libvlc_media_instance_destroy_and_detach(p_mi);
310 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
311 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
312 libvlc_exception_t *p_e )
316 libvlc_exception_raise( p_e, "viewport is NULL" );
319 /* if clip is NULL, then use view rectangle as clip */
323 /* set as default for future vout instances */
324 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
325 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
326 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
327 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
328 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
329 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
330 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
331 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
333 if( libvlc_playlist_isplaying(p_instance, p_e) )
335 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
338 vout_thread_t *p_vout = GetVout( p_mi, p_e );
341 /* change viewport for running vout */
342 vout_Control( p_vout , VOUT_SET_VIEWPORT,
343 view->top, view->left, view->bottom, view->right,
344 clip->top, clip->left, clip->bottom, clip->right );
345 vlc_object_release( p_vout );
347 libvlc_media_instance_destroy_and_detach(p_mi);
352 char *libvlc_video_get_aspect_ratio( libvlc_media_instance_t *p_mi,
353 libvlc_exception_t *p_e )
355 char *psz_aspect = 0;
356 vout_thread_t *p_vout = GetVout( p_mi, p_e );
361 psz_aspect = var_GetString( p_vout, "aspect-ratio" );
362 vlc_object_release( p_vout );
366 void libvlc_video_set_aspect_ratio( libvlc_media_instance_t *p_mi,
367 char *psz_aspect, libvlc_exception_t *p_e )
369 vout_thread_t *p_vout = GetVout( p_mi, p_e );
375 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
377 libvlc_exception_raise( p_e,
378 "Unexpected error while setting aspect-ratio value" );
380 vlc_object_release( p_vout );
383 int libvlc_video_get_spu( libvlc_media_instance_t *p_mi,
384 libvlc_exception_t *p_e )
386 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
387 vlc_value_t val_list;
393 if( !p_input_thread )
396 i_ret = var_Get( p_input_thread, "spu-es", &val );
399 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
400 vlc_object_release( p_input_thread );
404 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
405 for( i = 0; i < val_list.p_list->i_count; i++ )
407 vlc_value_t spu_val = val_list.p_list->p_values[i];
408 if( val.i_int == spu_val.i_int )
414 vlc_object_release( p_input_thread );
418 void libvlc_video_set_spu( libvlc_media_instance_t *p_mi, int i_spu,
419 libvlc_exception_t *p_e )
421 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
422 vlc_value_t val_list;
426 if( !p_input_thread )
429 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
430 for( i = 0; i < val_list.p_list->i_count; i++ )
432 vlc_value_t val = val_list.p_list->p_values[i];
437 new_val.i_int = val.i_int;
438 i_ret = var_Set( p_input_thread, "spu-es", new_val );
441 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
443 vlc_object_release( p_input_thread );
447 libvlc_exception_raise( p_e, "Subtitle value out of range" );
448 vlc_object_release( p_input_thread );
451 char *libvlc_video_get_crop_geometry( libvlc_media_instance_t *p_mi,
452 libvlc_exception_t *p_e )
454 char *psz_geometry = 0;
455 vout_thread_t *p_vout = GetVout( p_mi, p_e );
460 psz_geometry = var_GetString( p_vout, "crop" );
461 vlc_object_release( p_vout );
465 void libvlc_video_set_crop_geometry( libvlc_media_instance_t *p_mi,
466 char *psz_geometry, libvlc_exception_t *p_e )
468 vout_thread_t *p_vout = GetVout( p_mi, p_e );
474 i_ret = var_SetString( p_vout, "crop", psz_geometry );
476 libvlc_exception_raise( p_e,
477 "Unexpected error while setting crop geometry" );
479 vlc_object_release( p_vout );
482 int libvlc_video_destroy( libvlc_media_instance_t *p_mi,
483 libvlc_exception_t *p_e )
485 vout_thread_t *p_vout = GetVout( p_mi, p_e );
486 vlc_object_detach( p_vout );
487 vlc_object_release( p_vout );
488 vout_Destroy( p_vout );