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 );
432 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
433 libvlc_exception_t *p_e )
436 vout_thread_t *p_vout = GetVout( p_mi, p_e );
440 if( !p_vout ) return;
442 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
446 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
447 vlc_object_release( p_vbi );
449 libvlc_exception_raise( p_e,
450 "Unexpected error while setting teletext page" );
452 vlc_object_release( p_vout );
456 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
457 libvlc_exception_t *p_e )
459 input_thread_t *p_input_thread;
462 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
463 if( !p_input_thread ) return;
465 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
467 vlc_object_release( p_input_thread );
470 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
473 p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
479 /* FIXME Gni, why that ? */
480 i_ret = var_SetInteger( p_vbi, "vbi-page",
481 var_GetInteger( p_vbi, "vbi-page" ) );
483 libvlc_exception_raise( p_e,
484 "Unexpected error while setting teletext page" );
489 i_ret = var_SetBool( p_vbi, "vbi-opaque",
490 !var_GetBool( p_vbi, "vbi-opaque" ) );
492 libvlc_exception_raise( p_e,
493 "Unexpected error while setting teletext transparency" );
495 vlc_object_release( p_vbi );
501 var_SetInteger( p_input_thread, "spu-es", -1 );
506 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
508 if( list.p_list->i_count > 0 )
509 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
511 var_FreeList( &list, NULL );
514 vlc_object_release( p_input_thread );
517 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
518 libvlc_exception_t *p_e )
520 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
523 if( !p_input_thread )
526 i_track_count = var_CountChoices( p_input_thread, "video-es" );
528 vlc_object_release( p_input_thread );
529 return i_track_count;
532 libvlc_track_description_t *
533 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
534 libvlc_exception_t *p_e )
536 return libvlc_get_track_description( p_mi, "video-es", p_e);
539 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
540 libvlc_exception_t *p_e )
542 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
543 vlc_value_t val_list;
549 if( !p_input_thread )
552 i_ret = var_Get( p_input_thread, "video-es", &val );
555 libvlc_exception_raise( p_e );
556 libvlc_printerr( "Video track information not found" );
557 vlc_object_release( p_input_thread );
561 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
562 for( i = 0; i < val_list.p_list->i_count; i++ )
564 if( val_list.p_list->p_values[i].i_int == val.i_int )
570 var_FreeList( &val_list, NULL );
571 vlc_object_release( p_input_thread );
575 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
576 libvlc_exception_t *p_e )
578 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
579 vlc_value_t val_list;
583 if( !p_input_thread )
586 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
587 for( i = 0; i < val_list.p_list->i_count; i++ )
589 if( i_track == val_list.p_list->p_values[i].i_int )
591 i_ret = var_SetInteger( p_input_thread, "video-es", i_track );
597 libvlc_exception_raise( p_e );
598 libvlc_printerr( "Video track number out of range" );
600 var_FreeList( &val_list, NULL );
601 vlc_object_release( p_input_thread );
604 /******************************************************************************
605 * libvlc_video_set_deinterlace : enable deinterlace
606 *****************************************************************************/
607 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
608 const char *psz_mode,
609 libvlc_exception_t *p_e )
611 vout_thread_t *p_vout = GetVout( p_mi, p_e );
618 /* be sure that the filter name given is supported */
619 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
620 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
621 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x") )
623 /* set deinterlace filter chosen */
624 var_SetString( p_vout, "deinterlace", psz_mode );
628 libvlc_exception_raise( p_e );
629 libvlc_printerr( "Bad or unsuported deinterlacing mode" );
634 /* disable deinterlace filter */
635 var_SetString( p_vout, "deinterlace", "" );
638 vlc_object_release( p_vout );
641 /*****************************************************************************
642 * Marquee: FIXME: That implementation has no persistent state and requires
644 *****************************************************************************/
646 static const char *get_marquee_int_option_identifier(unsigned option)
648 static const char tab[][16] =
660 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
665 static const char *get_marquee_string_option_identifier(unsigned option)
667 static const char tab[][16] =
671 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
677 static vlc_object_t *get_marquee_object( libvlc_media_player_t * p_mi )
679 libvlc_exception_t e;
680 libvlc_exception_init(&e);
681 vout_thread_t * vout = GetVout( p_mi, &e );
682 libvlc_exception_clear(&e);
685 vlc_object_t * object = vlc_object_find_name( vout, "marq", FIND_CHILD );
686 vlc_object_release(vout);
690 /*****************************************************************************
691 * libvlc_video_get_marquee_option_as_int : get a marq option value
692 *****************************************************************************/
693 int libvlc_video_get_marquee_option_as_int( libvlc_media_player_t *p_mi,
694 libvlc_video_marquee_int_option_t option,
695 libvlc_exception_t *p_e )
697 const char * identifier = get_marquee_int_option_identifier(option);
700 libvlc_exception_raise( p_e );
701 libvlc_printerr( "Unknown marquee option" );
704 vlc_object_t * marquee = get_marquee_object(p_mi);
706 /* Handle the libvlc_marquee_Enabled separately */
707 if(option == libvlc_marquee_Enabled)
709 bool isEnabled = marquee != NULL;
710 vlc_object_release(marquee);
717 libvlc_exception_raise( p_e );
718 libvlc_printerr( "Marquee not enabled" );
721 #warning This and the next function may crash due to type checking!
722 int ret = var_GetInteger(marquee, identifier);
723 vlc_object_release(marquee);
727 /*****************************************************************************
728 * libvlc_video_get_marquee_option_as_string : get a marq option value
729 *****************************************************************************/
730 char * libvlc_video_get_marquee_option_as_string( libvlc_media_player_t *p_mi,
731 libvlc_video_marquee_string_option_t option,
732 libvlc_exception_t *p_e )
734 const char * identifier = get_marquee_string_option_identifier(option);
737 libvlc_exception_raise( p_e );
738 libvlc_printerr( "Unknown marquee option" );
742 vlc_object_t * marquee = get_marquee_object(p_mi);
745 libvlc_exception_raise( p_e );
746 libvlc_printerr( "Marquee not enabled" );
749 char *ret = var_GetString(marquee, identifier);
750 vlc_object_release(marquee);
754 /*****************************************************************************
755 * libvlc_video_set_marquee_option_as_int: enable, disable or set an int option
756 *****************************************************************************/
757 void libvlc_video_set_marquee_option_as_int( libvlc_media_player_t *p_mi,
758 libvlc_video_marquee_int_option_t option,
759 int value, libvlc_exception_t *p_e )
761 const char * identifier = get_marquee_int_option_identifier(option);
764 libvlc_exception_raise( p_e );
765 libvlc_printerr( "Unknown marquee option" );
769 /* Handle the libvlc_marquee_Enabled separately */
770 if(option == libvlc_marquee_Enabled)
772 libvlc_exception_t e;
773 libvlc_exception_init(&e);
774 vout_thread_t * vout = GetVout( p_mi, &e );
775 libvlc_exception_clear(&e);
778 vout_EnableFilter(vout, identifier, value, false);
779 vlc_object_release(vout);
784 vlc_object_t * marquee = get_marquee_object(p_mi);
787 libvlc_exception_raise( p_e );
788 libvlc_printerr( "Marquee not enabled" );
791 var_SetInteger(marquee, identifier, value);
792 vlc_object_release(marquee);
795 /*****************************************************************************
796 * libvlc_video_set_marquee_option_as_string: set a string option
797 *****************************************************************************/
798 void libvlc_video_set_marquee_option_as_string( libvlc_media_player_t *p_mi,
799 libvlc_video_marquee_string_option_t option,
801 libvlc_exception_t *p_e )
803 const char * identifier = get_marquee_string_option_identifier(option);
806 libvlc_exception_raise( p_e );
807 libvlc_printerr( "Unknown marquee option" );
810 vlc_object_t * marquee = get_marquee_object(p_mi);
813 libvlc_exception_raise( p_e );
814 libvlc_printerr( "Marquee not enabled" );
817 var_SetString(marquee, identifier, value);
818 vlc_object_release(marquee);