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 *****************************************************************************/
32 #include <vlc/libvlc.h>
33 #include <vlc/libvlc_media.h>
34 #include <vlc/libvlc_media_player.h>
36 #include <vlc_common.h>
37 #include <vlc_input.h>
40 #include "media_player_internal.h"
45 * Remember to release the returned vout_thread_t.
47 static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
48 libvlc_exception_t *p_exception )
50 input_thread_t *p_input = libvlc_get_input_thread( p_mi, p_exception );
51 vout_thread_t *p_vout = NULL;
55 p_vout = input_GetVout( p_input );
58 libvlc_exception_raise( p_exception );
59 libvlc_printerr( "No active video output" );
61 vlc_object_release( p_input );
66 /**********************************************************************
68 **********************************************************************/
70 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
71 libvlc_exception_t *p_e )
73 /* We only work on the first vout */
74 vout_thread_t *p_vout = GetVout( p_mi, p_e );
76 /* GetVout will raise the exception for us */
79 var_SetBool( p_vout, "fullscreen", b_fullscreen );
81 vlc_object_release( p_vout );
84 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
85 libvlc_exception_t *p_e )
87 /* We only work on the first vout */
88 vout_thread_t *p_vout = GetVout( p_mi, p_e );
91 /* GetVout will raise the exception for us */
92 if( !p_vout ) return 0;
94 i_ret = var_GetBool( p_vout, "fullscreen" );
96 vlc_object_release( p_vout );
101 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
102 libvlc_exception_t *p_e )
104 /* We only work on the first vout */
105 vout_thread_t *p_vout = GetVout( p_mi, p_e );
107 /* GetVout will raise the exception for us */
108 if( !p_vout ) return;
110 var_ToggleBool( p_vout, "fullscreen" );
112 vlc_object_release( p_vout );
116 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
117 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
119 vout_thread_t *p_vout;
121 assert( psz_filepath );
123 /* We must have an input */
124 if( !p_mi->p_input_thread )
126 libvlc_exception_raise( p_e );
127 libvlc_printerr( "Input does not exist" );
131 /* GetVout will raise the exception for us */
132 p_vout = GetVout( p_mi, p_e );
133 if( !p_vout ) return;
135 var_SetInteger( p_vout, "snapshot-width", i_width );
136 var_SetInteger( p_vout, "snapshot-height", i_height );
138 var_SetString( p_vout, "snapshot-path", psz_filepath );
139 var_SetString( p_vout, "snapshot-format", "png" );
141 var_TriggerCallback( p_vout, "video-snapshot" );
142 vlc_object_release( p_vout );
145 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
146 libvlc_exception_t *p_e )
150 vout_thread_t *p_vout = GetVout( p_mi, p_e );
151 if( !p_vout ) return 0;
153 height = p_vout->i_window_height;
155 vlc_object_release( p_vout );
160 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
161 libvlc_exception_t *p_e )
165 vout_thread_t *p_vout = GetVout( p_mi, p_e );
166 if( !p_vout ) return 0;
168 width = p_vout->i_window_width;
170 vlc_object_release( p_vout );
175 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
176 libvlc_exception_t *p_e )
178 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
179 bool has_vout = false;
183 vout_thread_t *p_vout;
185 p_vout = input_GetVout( p_input_thread );
189 vlc_object_release( p_vout );
191 vlc_object_release( p_input_thread );
196 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
197 libvlc_exception_t *p_e )
199 vout_thread_t *p_vout = GetVout( p_mp, p_e );
203 float f_scale = var_GetFloat( p_vout, "scale" );
204 if( var_GetBool( p_vout, "autoscale" ) )
206 vlc_object_release( p_vout );
210 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
211 libvlc_exception_t *p_e )
213 vout_thread_t *p_vout = GetVout( p_mp, p_e );
218 var_SetFloat( p_vout, "scale", f_scale );
219 var_SetBool( p_vout, "autoscale", f_scale != 0. );
220 vlc_object_release( p_vout );
223 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
224 libvlc_exception_t *p_e )
226 char *psz_aspect = NULL;
227 vout_thread_t *p_vout = GetVout( p_mi, p_e );
229 if( !p_vout ) return NULL;
231 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
232 vlc_object_release( p_vout );
233 return psz_aspect ? psz_aspect : strdup("");
236 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
237 const char *psz_aspect, libvlc_exception_t *p_e )
239 vout_thread_t *p_vout = GetVout( p_mi, p_e );
242 if( !p_vout ) return;
244 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
245 vlc_object_release( p_vout );
248 libvlc_exception_raise( p_e );
249 libvlc_printerr( "Bad or unsupported aspect ratio" );
253 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
254 libvlc_exception_t *p_e )
256 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
257 vlc_value_t val_list;
263 if( !p_input_thread ) return -1;
265 i_ret = var_Get( p_input_thread, "spu-es", &val );
268 vlc_object_release( p_input_thread );
269 libvlc_exception_raise( p_e );
270 libvlc_printerr( "Subtitle informations not found" );
274 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
275 for( i = 0; i < val_list.p_list->i_count; i++ )
277 if( val.i_int == val_list.p_list->p_values[i].i_int )
283 var_FreeList( &val_list, NULL );
284 vlc_object_release( p_input_thread );
288 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
289 libvlc_exception_t *p_e )
291 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
294 if( !p_input_thread )
297 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
299 vlc_object_release( p_input_thread );
303 libvlc_track_description_t *
304 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
305 libvlc_exception_t *p_e )
307 return libvlc_get_track_description( p_mi, "spu-es", p_e);
310 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
311 libvlc_exception_t *p_e )
313 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
314 vlc_value_t val_list;
318 if( !p_input_thread ) return;
320 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
322 if( ( val_list.p_list->i_count == 0 )
323 || (i_spu < 0) || (i_spu > val_list.p_list->i_count) )
325 libvlc_exception_raise( p_e );
326 libvlc_printerr( "Subtitle number out of range" );
330 newval = val_list.p_list->p_values[i_spu];
331 i_ret = var_Set( p_input_thread, "spu-es", newval );
334 libvlc_exception_raise( p_e );
335 libvlc_printerr( "Subtitle selection error" );
339 var_FreeList( &val_list, NULL );
340 vlc_object_release( p_input_thread );
343 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
344 const char *psz_subtitle,
345 libvlc_exception_t *p_e )
347 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
352 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
354 vlc_object_release( p_input_thread );
359 libvlc_track_description_t *
360 libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
361 libvlc_exception_t * p_e )
363 return libvlc_get_track_description( p_mi, "title", p_e);
366 libvlc_track_description_t *
367 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
369 libvlc_exception_t *p_e )
372 sprintf( psz_title, "title %2i", i_title );
373 return libvlc_get_track_description( p_mi, psz_title, p_e);
376 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
377 libvlc_exception_t *p_e )
379 char *psz_geometry = 0;
380 vout_thread_t *p_vout = GetVout( p_mi, p_e );
382 if( !p_vout ) return 0;
384 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
385 vlc_object_release( p_vout );
386 return psz_geometry ? psz_geometry : strdup("");
389 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
390 const char *psz_geometry, libvlc_exception_t *p_e )
392 vout_thread_t *p_vout = GetVout( p_mi, p_e );
395 if( !p_vout ) return;
397 i_ret = var_SetString( p_vout, "crop", psz_geometry );
398 vlc_object_release( p_vout );
402 libvlc_exception_raise( p_e );
403 libvlc_printerr( "Bad or unsupported cropping geometry" );
407 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
408 libvlc_exception_t *p_e )
411 vout_thread_t *p_vout = GetVout( p_mi, p_e );
415 if( !p_vout ) return i_ret;
417 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
421 i_ret = var_GetInteger( p_vbi, "vbi-page" );
422 vlc_object_release( p_vbi );
425 vlc_object_release( p_vout );
434 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
435 libvlc_exception_t *p_e )
438 vout_thread_t *p_vout = GetVout( p_mi, p_e );
442 if( !p_vout ) return;
444 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
448 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
449 vlc_object_release( p_vbi );
451 libvlc_exception_raise( p_e,
452 "Unexpected error while setting teletext page" );
454 vlc_object_release( p_vout );
458 VLC_UNUSED( i_page );
462 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
463 libvlc_exception_t *p_e )
465 input_thread_t *p_input_thread;
467 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
468 if( !p_input_thread ) return;
470 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
472 vlc_object_release( p_input_thread );
475 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
479 p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
485 /* FIXME Gni, why that ? */
486 i_ret = var_SetInteger( p_vbi, "vbi-page",
487 var_GetInteger( p_vbi, "vbi-page" ) );
489 libvlc_exception_raise( p_e,
490 "Unexpected error while setting teletext page" );
495 i_ret = var_SetBool( p_vbi, "vbi-opaque",
496 !var_GetBool( p_vbi, "vbi-opaque" ) );
498 libvlc_exception_raise( p_e,
499 "Unexpected error while setting teletext transparency" );
501 vlc_object_release( p_vbi );
507 var_SetInteger( p_input_thread, "spu-es", -1 );
512 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
514 if( list.p_list->i_count > 0 )
515 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
517 var_FreeList( &list, NULL );
520 vlc_object_release( p_input_thread );
523 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
524 libvlc_exception_t *p_e )
526 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
529 if( !p_input_thread )
532 i_track_count = var_CountChoices( p_input_thread, "video-es" );
534 vlc_object_release( p_input_thread );
535 return i_track_count;
538 libvlc_track_description_t *
539 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
540 libvlc_exception_t *p_e )
542 return libvlc_get_track_description( p_mi, "video-es", p_e);
545 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
546 libvlc_exception_t *p_e )
548 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
549 vlc_value_t val_list;
555 if( !p_input_thread )
558 i_ret = var_Get( p_input_thread, "video-es", &val );
561 libvlc_exception_raise( p_e );
562 libvlc_printerr( "Video track information not found" );
563 vlc_object_release( p_input_thread );
567 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
568 for( i = 0; i < val_list.p_list->i_count; i++ )
570 if( val_list.p_list->p_values[i].i_int == val.i_int )
576 var_FreeList( &val_list, NULL );
577 vlc_object_release( p_input_thread );
581 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
582 libvlc_exception_t *p_e )
584 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
585 vlc_value_t val_list;
589 if( !p_input_thread )
592 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
593 for( i = 0; i < val_list.p_list->i_count; i++ )
595 if( i_track == val_list.p_list->p_values[i].i_int )
597 i_ret = var_SetInteger( p_input_thread, "video-es", i_track );
603 libvlc_exception_raise( p_e );
604 libvlc_printerr( "Video track number out of range" );
606 var_FreeList( &val_list, NULL );
607 vlc_object_release( p_input_thread );
610 /******************************************************************************
611 * libvlc_video_set_deinterlace : enable deinterlace
612 *****************************************************************************/
613 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
614 const char *psz_mode,
615 libvlc_exception_t *p_e )
617 vout_thread_t *p_vout = GetVout( p_mi, p_e );
624 /* be sure that the filter name given is supported */
625 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
626 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
627 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x") )
629 /* set deinterlace filter chosen */
630 var_SetString( p_vout, "deinterlace", psz_mode );
634 libvlc_exception_raise( p_e );
635 libvlc_printerr( "Bad or unsuported deinterlacing mode" );
640 /* disable deinterlace filter */
641 var_SetString( p_vout, "deinterlace", "" );
644 vlc_object_release( p_vout );
647 /*****************************************************************************
648 * Marquee: FIXME: That implementation has no persistent state and requires
650 *****************************************************************************/
652 static const char *get_marquee_int_option_identifier(unsigned option)
654 static const char tab[][16] =
666 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
671 static const char *get_marquee_string_option_identifier(unsigned option)
673 static const char tab[][16] =
677 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
683 static vlc_object_t *get_marquee_object( libvlc_media_player_t * p_mi )
685 libvlc_exception_t e;
686 libvlc_exception_init(&e);
687 vout_thread_t * vout = GetVout( p_mi, &e );
688 libvlc_exception_clear(&e);
691 vlc_object_t * object = vlc_object_find_name( vout, "marq", FIND_CHILD );
692 vlc_object_release(vout);
696 /*****************************************************************************
697 * libvlc_video_get_marquee_option_as_int : get a marq option value
698 *****************************************************************************/
699 int libvlc_video_get_marquee_option_as_int( libvlc_media_player_t *p_mi,
700 libvlc_video_marquee_int_option_t option,
701 libvlc_exception_t *p_e )
703 const char * identifier = get_marquee_int_option_identifier(option);
706 libvlc_exception_raise( p_e );
707 libvlc_printerr( "Unknown marquee option" );
710 vlc_object_t * marquee = get_marquee_object(p_mi);
712 /* Handle the libvlc_marquee_Enabled separately */
713 if(option == libvlc_marquee_Enabled)
715 bool isEnabled = marquee != NULL;
716 vlc_object_release(marquee);
723 libvlc_exception_raise( p_e );
724 libvlc_printerr( "Marquee not enabled" );
727 #warning This and the next function may crash due to type checking!
728 int ret = var_GetInteger(marquee, identifier);
729 vlc_object_release(marquee);
733 /*****************************************************************************
734 * libvlc_video_get_marquee_option_as_string : get a marq option value
735 *****************************************************************************/
736 char * libvlc_video_get_marquee_option_as_string( libvlc_media_player_t *p_mi,
737 libvlc_video_marquee_string_option_t option,
738 libvlc_exception_t *p_e )
740 const char * identifier = get_marquee_string_option_identifier(option);
743 libvlc_exception_raise( p_e );
744 libvlc_printerr( "Unknown marquee option" );
748 vlc_object_t * marquee = get_marquee_object(p_mi);
751 libvlc_exception_raise( p_e );
752 libvlc_printerr( "Marquee not enabled" );
755 char *ret = var_GetString(marquee, identifier);
756 vlc_object_release(marquee);
760 /*****************************************************************************
761 * libvlc_video_set_marquee_option_as_int: enable, disable or set an int option
762 *****************************************************************************/
763 void libvlc_video_set_marquee_option_as_int( libvlc_media_player_t *p_mi,
764 libvlc_video_marquee_int_option_t option,
765 int value, libvlc_exception_t *p_e )
767 const char * identifier = get_marquee_int_option_identifier(option);
770 libvlc_exception_raise( p_e );
771 libvlc_printerr( "Unknown marquee option" );
775 /* Handle the libvlc_marquee_Enabled separately */
776 if(option == libvlc_marquee_Enabled)
778 libvlc_exception_t e;
779 libvlc_exception_init(&e);
780 vout_thread_t * vout = GetVout( p_mi, &e );
781 libvlc_exception_clear(&e);
784 vout_EnableFilter(vout, identifier, value, false);
785 vlc_object_release(vout);
790 vlc_object_t * marquee = get_marquee_object(p_mi);
793 libvlc_exception_raise( p_e );
794 libvlc_printerr( "Marquee not enabled" );
797 var_SetInteger(marquee, identifier, value);
798 vlc_object_release(marquee);
801 /*****************************************************************************
802 * libvlc_video_set_marquee_option_as_string: set a string option
803 *****************************************************************************/
804 void libvlc_video_set_marquee_option_as_string( libvlc_media_player_t *p_mi,
805 libvlc_video_marquee_string_option_t option,
807 libvlc_exception_t *p_e )
809 const char * identifier = get_marquee_string_option_identifier(option);
812 libvlc_exception_raise( p_e );
813 libvlc_printerr( "Unknown marquee option" );
816 vlc_object_t * marquee = get_marquee_object(p_mi);
819 libvlc_exception_raise( p_e );
820 libvlc_printerr( "Marquee not enabled" );
823 var_SetString(marquee, identifier, value);
824 vlc_object_release(marquee);