1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
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"
30 #include <vlc/libvlc.h>
31 #include <vlc_input.h>
35 * Remember to release the returned vout_thread_t.
37 static vout_thread_t *GetVout( libvlc_media_player_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_player_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_vout = GetVout( p_mi, p_e );
65 /* GetVout will raise the exception for us */
68 var_SetBool( p_vout, "fullscreen", b_fullscreen );
70 vlc_object_release( p_vout );
73 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
74 libvlc_exception_t *p_e )
76 /* We only work on the first vout */
77 vout_thread_t *p_vout = GetVout( p_mi, p_e );
80 /* GetVout will raise the exception for us */
84 i_ret = var_GetBool( p_vout, "fullscreen" );
86 vlc_object_release( p_vout );
91 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
92 libvlc_exception_t *p_e )
94 /* We only work on the first vout */
95 vout_thread_t *p_vout = GetVout( p_mi, p_e );
98 /* GetVout will raise the exception for us */
101 ret = var_GetBool( p_vout, "fullscreen" );
102 var_SetBool( p_vout, "fullscreen", !ret );
104 vlc_object_release( p_vout );
108 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, char *psz_filepath,
109 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
111 vout_thread_t *p_vout = GetVout( p_mi, p_e );
112 input_thread_t *p_input_thread;
114 /* GetVout will raise the exception for us */
122 libvlc_exception_raise( p_e, "filepath is null" );
126 var_SetInteger( p_vout, "snapshot-width", i_width );
127 var_SetInteger( p_vout, "snapshot-height", i_height );
129 p_input_thread = p_mi->p_input_thread;
130 if( !p_mi->p_input_thread )
132 libvlc_exception_raise( p_e, "Input does not exist" );
136 var_SetString( p_vout, "snapshot-path", psz_filepath );
137 var_SetString( p_vout, "snapshot-format", "png" );
139 vout_Control( p_vout, VOUT_SNAPSHOT );
140 vlc_object_release( p_vout );
143 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
144 libvlc_exception_t *p_e )
146 vout_thread_t *p_vout = GetVout( p_mi, p_e );
150 vlc_object_release( p_vout );
152 return p_vout->i_window_height;
155 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
156 libvlc_exception_t *p_e )
158 vout_thread_t *p_vout = GetVout( p_mi, p_e );
162 vlc_object_release( p_vout );
164 return p_vout->i_window_width;
167 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
168 libvlc_exception_t *p_e )
170 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
171 bool has_vout = false;
175 vout_thread_t *p_vout;
177 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
181 vlc_object_release( p_vout );
183 vlc_object_release( p_input_thread );
188 int libvlc_video_reparent( libvlc_media_player_t *p_mi, libvlc_drawable_t d,
189 libvlc_exception_t *p_e )
191 vout_thread_t *p_vout = GetVout( p_mi, p_e );
195 vout_Control( p_vout , VOUT_REPARENT, d);
196 vlc_object_release( p_vout );
201 void libvlc_video_resize( libvlc_media_player_t *p_mi, int width, int height, libvlc_exception_t *p_e )
203 vout_thread_t *p_vout = GetVout( p_mi, p_e );
206 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
207 vlc_object_release( p_vout );
211 void libvlc_video_redraw_rectangle( libvlc_media_player_t *p_mi,
212 const libvlc_rectangle_t *area,
213 libvlc_exception_t *p_e )
216 && ((area->bottom - area->top) > 0)
217 && ((area->right - area->left) > 0) )
219 vout_thread_t *p_vout = GetVout( p_mi, p_e );
222 /* tell running vout to redraw area */
223 vout_Control( p_vout , VOUT_REDRAW_RECT,
224 area->top, area->left, area->bottom, area->right );
225 vlc_object_release( p_vout );
230 /* global video settings */
232 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
233 libvlc_exception_t *p_e )
235 /* set as default for future vout instances */
236 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
238 if( libvlc_playlist_isplaying(p_instance, p_e) )
240 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
243 vout_thread_t *p_vout = GetVout( p_mi, p_e );
246 /* tell running vout to re-parent */
247 vout_Control( p_vout , VOUT_REPARENT, d);
248 vlc_object_release( p_vout );
250 libvlc_media_player_release(p_mi);
255 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
259 libvlc_drawable_t result;
261 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
267 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
268 libvlc_exception_t *p_e )
270 /* set as default for future vout instances */
271 config_PutInt(p_instance->p_libvlc_int, "width", width);
272 config_PutInt(p_instance->p_libvlc_int, "height", height);
274 if( libvlc_playlist_isplaying(p_instance, p_e) )
276 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
279 vout_thread_t *p_vout = GetVout( p_mi, p_e );
282 /* tell running vout to re-size */
283 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
284 vlc_object_release( p_vout );
286 libvlc_media_player_release(p_mi);
291 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
292 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
293 libvlc_exception_t *p_e )
297 libvlc_exception_raise( p_e, "viewport is NULL" );
301 /* if clip is NULL, then use view rectangle as clip */
305 /* set as default for future vout instances */
306 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
307 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
308 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
309 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
310 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
311 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
312 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
313 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
315 if( libvlc_playlist_isplaying(p_instance, p_e) )
317 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
320 vout_thread_t *p_vout = GetVout( p_mi, p_e );
323 /* change viewport for running vout */
324 vout_Control( p_vout , VOUT_SET_VIEWPORT,
325 view->top, view->left, view->bottom, view->right,
326 clip->top, clip->left, clip->bottom, clip->right );
327 vlc_object_release( p_vout );
329 libvlc_media_player_release(p_mi);
334 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
335 libvlc_exception_t *p_e )
337 char *psz_aspect = 0;
338 vout_thread_t *p_vout = GetVout( p_mi, p_e );
340 if( !p_vout ) return 0;
342 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
343 vlc_object_release( p_vout );
344 return psz_aspect ? psz_aspect : strdup("");
347 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
348 char *psz_aspect, libvlc_exception_t *p_e )
350 vout_thread_t *p_vout = GetVout( p_mi, p_e );
353 if( !p_vout ) return;
355 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
357 libvlc_exception_raise( p_e,
358 "Unexpected error while setting aspect-ratio value" );
360 vlc_object_release( p_vout );
363 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
364 libvlc_exception_t *p_e )
366 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
367 vlc_value_t val_list;
373 if( !p_input_thread ) return -1;
375 i_ret = var_Get( p_input_thread, "spu-es", &val );
378 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
379 vlc_object_release( p_input_thread );
383 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
384 for( i = 0; i < val_list.p_list->i_count; i++ )
386 vlc_value_t spu_val = val_list.p_list->p_values[i];
387 if( val.i_int == spu_val.i_int )
393 vlc_object_release( p_input_thread );
397 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
398 libvlc_exception_t *p_e )
400 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
401 vlc_value_t val_list;
405 if( !p_input_thread ) return;
407 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
408 for( i = 0; i < val_list.p_list->i_count; i++ )
410 vlc_value_t val = val_list.p_list->p_values[i];
415 new_val.i_int = val.i_int;
416 i_ret = var_Set( p_input_thread, "spu-es", new_val );
419 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
421 vlc_object_release( p_input_thread );
425 libvlc_exception_raise( p_e, "Subtitle value out of range" );
426 vlc_object_release( p_input_thread );
429 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
431 libvlc_exception_t *p_e )
433 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
438 if( input_AddSubtitles( p_input_thread, psz_subtitle, true ) )
440 vlc_object_release( p_input_thread );
445 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
446 libvlc_exception_t *p_e )
448 char *psz_geometry = 0;
449 vout_thread_t *p_vout = GetVout( p_mi, p_e );
451 if( !p_vout ) return 0;
453 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
454 vlc_object_release( p_vout );
455 return psz_geometry ? psz_geometry : strdup("");
458 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
459 char *psz_geometry, libvlc_exception_t *p_e )
461 vout_thread_t *p_vout = GetVout( p_mi, p_e );
464 if( !p_vout ) return;
466 i_ret = var_SetString( p_vout, "crop", psz_geometry );
468 libvlc_exception_raise( p_e,
469 "Unexpected error while setting crop geometry" );
471 vlc_object_release( p_vout );
474 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
475 libvlc_exception_t *p_e )
477 vout_thread_t *p_vout = GetVout( p_mi, p_e );
481 if( !p_vout ) return i_ret;
483 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
487 i_ret = var_GetInteger( p_vbi, "vbi-page" );
488 vlc_object_release( p_vbi );
491 vlc_object_release( p_vout );
495 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
496 libvlc_exception_t *p_e )
498 vout_thread_t *p_vout = GetVout( p_mi, p_e );
502 if( !p_vout ) return;
504 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
508 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
509 vlc_object_release( p_vbi );
512 libvlc_exception_raise( p_e,
513 "Unexpected error while setting teletext page" );
514 vlc_object_release( p_vout );
517 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
518 libvlc_exception_t *p_e )
520 /* We only work on the first vout */
521 vout_thread_t *p_vout = GetVout( p_mi, p_e );
522 bool opaque; int i_ret;
524 /* GetVout will raise the exception for us */
525 if( !p_vout ) return;
527 opaque = var_GetBool( p_vout, "vbi-opaque" );
528 i_ret = var_SetBool( p_vout, "vbi-opaque", !opaque );
530 libvlc_exception_raise( p_e,
531 "Unexpected error while setting teletext value" );
533 vlc_object_release( p_vout );
536 int libvlc_video_destroy( libvlc_media_player_t *p_mi,
537 libvlc_exception_t *p_e )
539 vout_thread_t *p_vout = GetVout( p_mi, p_e );
540 vlc_object_detach( p_vout );
541 vlc_object_release( p_vout );
542 vlc_object_release( p_vout );