1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
8 * Authors: Clément 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 = libvlc_get_input_thread( p_mi, p_exception );
41 vout_thread_t *p_vout = NULL;
45 p_vout = input_GetVout( p_input );
48 libvlc_exception_raise( p_exception, "No active video output" );
50 vlc_object_release( p_input );
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 */
81 if( !p_vout ) return 0;
83 i_ret = var_GetBool( p_vout, "fullscreen" );
85 vlc_object_release( p_vout );
90 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
91 libvlc_exception_t *p_e )
93 /* We only work on the first vout */
94 vout_thread_t *p_vout = GetVout( p_mi, p_e );
97 /* GetVout will raise the exception for us */
100 ret = var_GetBool( p_vout, "fullscreen" );
101 var_SetBool( p_vout, "fullscreen", !ret );
103 vlc_object_release( p_vout );
107 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
108 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
110 vout_thread_t *p_vout;
112 /* The filepath must be not NULL */
115 libvlc_exception_raise( p_e, "filepath is null" );
118 /* We must have an input */
119 if( !p_mi->p_input_thread )
121 libvlc_exception_raise( p_e, "Input does not exist" );
125 /* GetVout will raise the exception for us */
126 p_vout = GetVout( p_mi, p_e );
127 if( !p_vout ) return;
129 var_SetInteger( p_vout, "snapshot-width", i_width );
130 var_SetInteger( p_vout, "snapshot-height", i_height );
132 var_SetString( p_vout, "snapshot-path", psz_filepath );
133 var_SetString( p_vout, "snapshot-format", "png" );
135 var_TriggerCallback( p_vout, "video-snapshot" );
136 vlc_object_release( p_vout );
139 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
140 libvlc_exception_t *p_e )
144 vout_thread_t *p_vout = GetVout( p_mi, p_e );
145 if( !p_vout ) return 0;
147 height = p_vout->i_window_height;
149 vlc_object_release( p_vout );
154 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
155 libvlc_exception_t *p_e )
159 vout_thread_t *p_vout = GetVout( p_mi, p_e );
160 if( !p_vout ) return 0;
162 width = p_vout->i_window_width;
164 vlc_object_release( p_vout );
169 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
170 libvlc_exception_t *p_e )
172 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
173 bool has_vout = false;
177 vout_thread_t *p_vout;
179 p_vout = input_GetVout( p_input_thread );
183 vlc_object_release( p_vout );
185 vlc_object_release( p_input_thread );
190 int libvlc_video_reparent( libvlc_media_player_t *p_mi, libvlc_drawable_t d,
191 libvlc_exception_t *p_e )
193 (void) p_mi; (void) d;
194 libvlc_exception_raise(p_e, "Reparenting not supported");
198 void libvlc_video_resize( libvlc_media_player_t *p_mi, int width, int height, libvlc_exception_t *p_e )
200 vout_thread_t *p_vout = GetVout( p_mi, p_e );
203 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
204 vlc_object_release( p_vout );
208 void libvlc_video_redraw_rectangle( libvlc_media_player_t *p_mi,
209 const libvlc_rectangle_t *area,
210 libvlc_exception_t *p_e )
214 && ((area->bottom - area->top) > 0)
215 && ((area->right - area->left) > 0) )
217 vout_thread_t *p_vout = GetVout( p_mi, p_e );
220 /* tell running vout to redraw area */
221 vout_Control( p_vout , VOUT_REDRAW_RECT,
222 area->top, area->left, area->bottom, area->right );
223 vlc_object_release( p_vout );
227 (void) p_mi; (void) area; (void) p_e;
231 /* global video settings */
233 /* Deprecated use libvlc_media_player_set_drawable() */
234 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
235 libvlc_exception_t *p_e )
237 /* set as default for future vout instances */
241 if( sizeof(HWND) > sizeof(libvlc_drawable_t) )
242 return; /* BOOM! we told you not to use this function! */
243 val.p_address = (void *)(uintptr_t)d;
244 var_Set( p_instance->p_libvlc_int, "drawable-hwnd", val );
245 #elif defined(__APPLE__)
246 var_SetInteger( p_instance->p_libvlc_int, "drawable-agl", d );
248 var_SetInteger( p_instance->p_libvlc_int, "drawable-xid", d );
251 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
254 libvlc_media_player_set_drawable( p_mi, d, p_e );
255 libvlc_media_player_release(p_mi);
259 /* Deprecated use libvlc_media_player_get_drawable() */
260 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
267 if( sizeof(HWND) > sizeof(libvlc_drawable_t) )
269 var_Get( p_instance->p_libvlc_int, "drawable-hwnd", &val );
270 return (uintptr_t)val.p_address;
271 #elif defined(__APPLE__)
272 return var_GetInteger( p_instance->p_libvlc_int, "drawable-agl" );
274 return var_GetInteger( p_instance->p_libvlc_int, "drawable-xid" );
278 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
279 libvlc_exception_t *p_e )
281 /* set as default for future vout instances */
282 config_PutInt(p_instance->p_libvlc_int, "width", width);
283 config_PutInt(p_instance->p_libvlc_int, "height", height);
285 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
288 vout_thread_t *p_vout = GetVout( p_mi, p_e );
291 /* tell running vout to re-size */
292 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
293 vlc_object_release( p_vout );
295 libvlc_media_player_release(p_mi);
299 void libvlc_video_set_viewport( libvlc_instance_t *p_instance, libvlc_media_player_t *p_mi,
300 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
301 libvlc_exception_t *p_e )
306 libvlc_exception_raise( p_e, "viewport is NULL" );
310 /* if clip is NULL, then use view rectangle as clip */
314 /* set as default for future vout instances */
315 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
316 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
317 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
318 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
319 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
320 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
321 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
322 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
326 vout_thread_t *p_vout = GetVout( p_mi, p_e );
329 /* change viewport for running vout */
330 vout_Control( p_vout, VOUT_SET_VIEWPORT,
331 view->top, view->left, view->bottom, view->right,
332 clip->top, clip->left, clip->bottom, clip->right );
333 vlc_object_release( p_vout );
337 (void) p_instance; (void) view; (void) clip; (void) p_e;
341 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
342 libvlc_exception_t *p_e )
344 vout_thread_t *p_vout = GetVout( p_mp, p_e );
348 float f_scale = var_GetFloat( p_vout, "scale" );
349 if( var_GetBool( p_vout, "autoscale" ) )
351 vlc_object_release( p_vout );
355 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
356 libvlc_exception_t *p_e )
358 vout_thread_t *p_vout = GetVout( p_mp, p_e );
363 var_SetFloat( p_vout, "scale", f_scale );
364 var_SetBool( p_vout, "autoscale", f_scale != 0. );
365 vlc_object_release( p_vout );
368 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
369 libvlc_exception_t *p_e )
371 char *psz_aspect = 0;
372 vout_thread_t *p_vout = GetVout( p_mi, p_e );
374 if( !p_vout ) return 0;
376 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
377 vlc_object_release( p_vout );
378 return psz_aspect ? psz_aspect : strdup("");
381 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
382 char *psz_aspect, libvlc_exception_t *p_e )
384 vout_thread_t *p_vout = GetVout( p_mi, p_e );
387 if( !p_vout ) return;
389 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
391 libvlc_exception_raise( p_e,
392 "Unexpected error while setting aspect-ratio value" );
394 vlc_object_release( p_vout );
397 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
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;
407 if( !p_input_thread ) return -1;
409 i_ret = var_Get( p_input_thread, "spu-es", &val );
412 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
413 vlc_object_release( p_input_thread );
417 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
418 for( i = 0; i < val_list.p_list->i_count; i++ )
420 vlc_value_t spu_val = val_list.p_list->p_values[i];
421 if( val.i_int == spu_val.i_int )
427 vlc_object_release( p_input_thread );
431 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
432 libvlc_exception_t *p_e )
434 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
435 vlc_value_t val_list;
437 if( !p_input_thread )
440 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
441 vlc_object_release( p_input_thread );
442 return val_list.p_list->i_count;
445 libvlc_track_description_t *
446 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
447 libvlc_exception_t *p_e )
449 return libvlc_get_track_description( p_mi, "spu-es", p_e);
452 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
453 libvlc_exception_t *p_e )
455 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
456 vlc_value_t val_list;
460 if( !p_input_thread ) return;
462 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
464 if( val_list.p_list->i_count == 0 )
466 libvlc_exception_raise( p_e, "Subtitle value out of range" );
467 vlc_object_release( p_input_thread );
471 if( (i_spu < 0) && (i_spu > val_list.p_list->i_count) )
473 libvlc_exception_raise( p_e, "Subtitle value out of range" );
474 vlc_object_release( p_input_thread );
478 newval = val_list.p_list->p_values[i_spu];
479 i_ret = var_Set( p_input_thread, "spu-es", newval );
482 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
484 vlc_object_release( p_input_thread );
487 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
489 libvlc_exception_t *p_e )
491 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
496 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
498 vlc_object_release( p_input_thread );
503 libvlc_track_description_t *
504 libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
505 libvlc_exception_t * p_e )
507 return libvlc_get_track_description( p_mi, "title", p_e);
510 libvlc_track_description_t *
511 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
513 libvlc_exception_t *p_e )
516 sprintf( psz_title, "title %2i", i_title );
517 return libvlc_get_track_description( p_mi, psz_title, p_e);
520 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
521 libvlc_exception_t *p_e )
523 char *psz_geometry = 0;
524 vout_thread_t *p_vout = GetVout( p_mi, p_e );
526 if( !p_vout ) return 0;
528 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
529 vlc_object_release( p_vout );
530 return psz_geometry ? psz_geometry : strdup("");
533 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
534 char *psz_geometry, libvlc_exception_t *p_e )
536 vout_thread_t *p_vout = GetVout( p_mi, p_e );
539 if( !p_vout ) return;
541 i_ret = var_SetString( p_vout, "crop", psz_geometry );
543 libvlc_exception_raise( p_e,
544 "Unexpected error while setting crop geometry" );
546 vlc_object_release( p_vout );
549 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
550 libvlc_exception_t *p_e )
552 vout_thread_t *p_vout = GetVout( p_mi, p_e );
556 if( !p_vout ) return i_ret;
558 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
562 i_ret = var_GetInteger( p_vbi, "vbi-page" );
563 vlc_object_release( p_vbi );
566 vlc_object_release( p_vout );
570 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
571 libvlc_exception_t *p_e )
573 vout_thread_t *p_vout = GetVout( p_mi, p_e );
577 if( !p_vout ) return;
579 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
583 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
584 vlc_object_release( p_vbi );
586 libvlc_exception_raise( p_e,
587 "Unexpected error while setting teletext page" );
589 vlc_object_release( p_vout );
592 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
593 libvlc_exception_t *p_e )
595 input_thread_t *p_input_thread;
599 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
600 if( !p_input_thread ) return;
602 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
604 vlc_object_release( p_input_thread );
607 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
609 p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
615 /* FIXME Gni, why that ? */
616 i_ret = var_SetInteger( p_vbi, "vbi-page",
617 var_GetInteger( p_vbi, "vbi-page" ) );
619 libvlc_exception_raise( p_e,
620 "Unexpected error while setting teletext page" );
625 i_ret = var_SetBool( p_vbi, "vbi-opaque",
626 !var_GetBool( p_vbi, "vbi-opaque" ) );
628 libvlc_exception_raise( p_e,
629 "Unexpected error while setting teletext transparency" );
631 vlc_object_release( p_vbi );
633 else if( b_selected )
635 var_SetInteger( p_input_thread, "spu-es", -1 );
640 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
642 if( list.p_list->i_count > 0 )
643 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
645 var_Change( p_input_thread, "teletext-es", VLC_VAR_FREELIST, &list, NULL );
648 vlc_object_release( p_input_thread );
651 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
652 libvlc_exception_t *p_e )
654 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
655 vlc_value_t val_list;
657 if( !p_input_thread )
660 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
661 vlc_object_release( p_input_thread );
662 return val_list.p_list->i_count;
665 libvlc_track_description_t *
666 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
667 libvlc_exception_t *p_e )
669 return libvlc_get_track_description( p_mi, "video-es", p_e);
672 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
673 libvlc_exception_t *p_e )
675 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
676 vlc_value_t val_list;
682 if( !p_input_thread )
685 i_ret = var_Get( p_input_thread, "video-es", &val );
688 libvlc_exception_raise( p_e, "Getting Video track information failed" );
689 vlc_object_release( p_input_thread );
693 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
694 for( i = 0; i < val_list.p_list->i_count; i++ )
696 vlc_value_t track_val = val_list.p_list->p_values[i];
697 if( track_val.i_int == val.i_int )
703 vlc_object_release( p_input_thread );
707 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
708 libvlc_exception_t *p_e )
710 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
711 vlc_value_t val_list;
715 if( !p_input_thread )
718 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
719 for( i = 0; i < val_list.p_list->i_count; i++ )
721 vlc_value_t val = val_list.p_list->p_values[i];
722 if( i_track == val.i_int )
724 i_ret = var_Set( p_input_thread, "audio-es", val );
726 libvlc_exception_raise( p_e, "Setting video track failed" );
727 vlc_object_release( p_input_thread );
731 libvlc_exception_raise( p_e, "Video track out of range" );
732 vlc_object_release( p_input_thread );
735 int libvlc_video_destroy( libvlc_media_player_t *p_mi,
736 libvlc_exception_t *p_e )
738 vout_thread_t *p_vout = GetVout( p_mi, p_e );
739 vlc_object_detach( p_vout );
740 vlc_object_release( p_vout );
741 vlc_object_release( p_vout );