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_ANYWHERE );
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_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 = true;
73 else val.b_bool = 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_player_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 == true ? 1 : 0;
102 void libvlc_toggle_fullscreen( libvlc_media_player_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_player_t *p_mi, char *psz_filepath,
129 unsigned int i_width, unsigned int i_height, 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" );
146 var_SetInteger( p_vout, "snapshot-width", i_width );
147 var_SetInteger( p_vout, "snapshot-height", i_height );
149 p_input_thread = p_mi->p_input_thread;
150 if( !p_mi->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 );
163 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
164 libvlc_exception_t *p_e )
166 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
170 vlc_object_release( p_vout1 );
172 return p_vout1->i_window_height;
175 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
176 libvlc_exception_t *p_e )
178 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
182 vlc_object_release( p_vout1 );
184 return p_vout1->i_window_width;
187 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
188 libvlc_exception_t *p_e )
190 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
191 bool has_vout = false;
195 vout_thread_t *p_vout;
197 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
201 vlc_object_release( p_vout );
203 vlc_object_release( p_input_thread );
208 int libvlc_video_reparent( libvlc_media_player_t *p_mi, libvlc_drawable_t d,
209 libvlc_exception_t *p_e )
211 vout_thread_t *p_vout = GetVout( p_mi, p_e );
215 vout_Control( p_vout , VOUT_REPARENT, d);
216 vlc_object_release( p_vout );
221 void libvlc_video_resize( libvlc_media_player_t *p_mi, int width, int height, libvlc_exception_t *p_e )
223 vout_thread_t *p_vout = GetVout( p_mi, p_e );
226 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
227 vlc_object_release( p_vout );
231 void libvlc_video_redraw_rectangle( libvlc_media_player_t *p_mi,
232 const libvlc_rectangle_t *area,
233 libvlc_exception_t *p_e )
236 && ((area->bottom - area->top) > 0)
237 && ((area->right - area->left) > 0) )
239 vout_thread_t *p_vout = GetVout( p_mi, p_e );
242 /* tell running vout to redraw area */
243 vout_Control( p_vout , VOUT_REDRAW_RECT,
244 area->top, area->left, area->bottom, area->right );
245 vlc_object_release( p_vout );
250 /* global video settings */
252 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
253 libvlc_exception_t *p_e )
255 /* set as default for future vout instances */
256 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
258 if( libvlc_playlist_isplaying(p_instance, p_e) )
260 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
263 vout_thread_t *p_vout = GetVout( p_mi, p_e );
266 /* tell running vout to re-parent */
267 vout_Control( p_vout , VOUT_REPARENT, d);
268 vlc_object_release( p_vout );
270 libvlc_media_player_release(p_mi);
275 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
279 libvlc_drawable_t result;
281 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
287 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
288 libvlc_exception_t *p_e )
290 /* set as default for future vout instances */
291 config_PutInt(p_instance->p_libvlc_int, "width", width);
292 config_PutInt(p_instance->p_libvlc_int, "height", height);
294 if( libvlc_playlist_isplaying(p_instance, p_e) )
296 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
299 vout_thread_t *p_vout = GetVout( p_mi, p_e );
302 /* tell running vout to re-size */
303 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
304 vlc_object_release( p_vout );
306 libvlc_media_player_release(p_mi);
311 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
312 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
313 libvlc_exception_t *p_e )
317 libvlc_exception_raise( p_e, "viewport is NULL" );
320 /* if clip is NULL, then use view rectangle as clip */
324 /* set as default for future vout instances */
325 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
326 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
327 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
328 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
329 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
330 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
331 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
332 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
334 if( libvlc_playlist_isplaying(p_instance, p_e) )
336 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
339 vout_thread_t *p_vout = GetVout( p_mi, p_e );
342 /* change viewport for running vout */
343 vout_Control( p_vout , VOUT_SET_VIEWPORT,
344 view->top, view->left, view->bottom, view->right,
345 clip->top, clip->left, clip->bottom, clip->right );
346 vlc_object_release( p_vout );
348 libvlc_media_player_release(p_mi);
353 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
354 libvlc_exception_t *p_e )
356 char *psz_aspect = 0;
357 vout_thread_t *p_vout = GetVout( p_mi, p_e );
362 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
363 vlc_object_release( p_vout );
364 return psz_aspect ? psz_aspect : strdup("");
367 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
368 char *psz_aspect, libvlc_exception_t *p_e )
370 vout_thread_t *p_vout = GetVout( p_mi, p_e );
376 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
378 libvlc_exception_raise( p_e,
379 "Unexpected error while setting aspect-ratio value" );
381 vlc_object_release( p_vout );
384 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
385 libvlc_exception_t *p_e )
387 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
388 vlc_value_t val_list;
394 if( !p_input_thread )
397 i_ret = var_Get( p_input_thread, "spu-es", &val );
400 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
401 vlc_object_release( p_input_thread );
405 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
406 for( i = 0; i < val_list.p_list->i_count; i++ )
408 vlc_value_t spu_val = val_list.p_list->p_values[i];
409 if( val.i_int == spu_val.i_int )
415 vlc_object_release( p_input_thread );
419 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
420 libvlc_exception_t *p_e )
422 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
423 vlc_value_t val_list;
427 if( !p_input_thread )
430 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
431 for( i = 0; i < val_list.p_list->i_count; i++ )
433 vlc_value_t val = val_list.p_list->p_values[i];
438 new_val.i_int = val.i_int;
439 i_ret = var_Set( p_input_thread, "spu-es", new_val );
442 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
444 vlc_object_release( p_input_thread );
448 libvlc_exception_raise( p_e, "Subtitle value out of range" );
449 vlc_object_release( p_input_thread );
452 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
454 libvlc_exception_t *p_e )
456 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
461 if( input_AddSubtitles( p_input_thread, psz_subtitle, true ) )
463 vlc_object_release( p_input_thread );
468 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
469 libvlc_exception_t *p_e )
471 char *psz_geometry = 0;
472 vout_thread_t *p_vout = GetVout( p_mi, p_e );
477 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
478 vlc_object_release( p_vout );
479 return psz_geometry ? psz_geometry : strdup("");
482 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
483 char *psz_geometry, libvlc_exception_t *p_e )
485 vout_thread_t *p_vout = GetVout( p_mi, p_e );
491 i_ret = var_SetString( p_vout, "crop", psz_geometry );
493 libvlc_exception_raise( p_e,
494 "Unexpected error while setting crop geometry" );
496 vlc_object_release( p_vout );
499 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
500 libvlc_exception_t *p_e )
502 vout_thread_t *p_vout = GetVout( p_mi, p_e );
509 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
513 i_ret = var_GetInteger( p_vbi, "vbi-page" );
514 vlc_object_release( p_vbi );
517 vlc_object_release( p_vout );
521 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
522 libvlc_exception_t *p_e )
524 vout_thread_t *p_vout = GetVout( p_mi, p_e );
531 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
535 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
536 vlc_object_release( p_vbi );
539 libvlc_exception_raise( p_e,
540 "Unexpected error while setting teletext page" );
541 vlc_object_release( p_vout );
544 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
545 libvlc_exception_t *p_e )
547 /* We only work on the first vout */
548 vout_thread_t *p_vout = GetVout( p_mi, p_e );
549 vlc_value_t val; int i_ret;
551 /* GetVout will raise the exception for us */
555 i_ret = var_Get( p_vout, "vbi-opaque", &val );
557 libvlc_exception_raise( p_e,
558 "Unexpected error while looking up teletext value" );
560 val.b_bool = !val.b_bool;
561 i_ret = var_Set( p_vout, "vbi-opaque", val );
563 libvlc_exception_raise( p_e,
564 "Unexpected error while setting teletext value" );
566 vlc_object_release( p_vout );
569 int libvlc_video_destroy( libvlc_media_player_t *p_mi,
570 libvlc_exception_t *p_e )
572 vout_thread_t *p_vout = GetVout( p_mi, p_e );
573 vlc_object_detach( p_vout );
574 vlc_object_release( p_vout );
575 vlc_object_release( p_vout );