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 <vlc/libvlc.h>
29 #include <vlc/libvlc_media.h>
30 #include <vlc/libvlc_media_player.h>
32 #include <vlc_common.h>
33 #include <vlc_input.h>
36 #include "media_player_internal.h"
40 * Remember to release the returned vout_thread_t.
42 static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
43 libvlc_exception_t *p_exception )
45 input_thread_t *p_input = libvlc_get_input_thread( p_mi, p_exception );
46 vout_thread_t *p_vout = NULL;
50 p_vout = input_GetVout( p_input );
53 libvlc_exception_raise( p_exception, "No active video output" );
55 vlc_object_release( p_input );
60 /**********************************************************************
62 **********************************************************************/
64 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
65 libvlc_exception_t *p_e )
67 /* We only work on the first vout */
68 vout_thread_t *p_vout = GetVout( p_mi, p_e );
70 /* GetVout will raise the exception for us */
73 var_SetBool( p_vout, "fullscreen", b_fullscreen );
75 vlc_object_release( p_vout );
78 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
79 libvlc_exception_t *p_e )
81 /* We only work on the first vout */
82 vout_thread_t *p_vout = GetVout( p_mi, p_e );
85 /* GetVout will raise the exception for us */
86 if( !p_vout ) return 0;
88 i_ret = var_GetBool( p_vout, "fullscreen" );
90 vlc_object_release( p_vout );
95 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
96 libvlc_exception_t *p_e )
98 /* We only work on the first vout */
99 vout_thread_t *p_vout = GetVout( p_mi, p_e );
102 /* GetVout will raise the exception for us */
103 if( !p_vout ) return;
105 ret = var_GetBool( p_vout, "fullscreen" );
106 var_SetBool( p_vout, "fullscreen", !ret );
108 vlc_object_release( p_vout );
112 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
113 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
115 vout_thread_t *p_vout;
117 /* The filepath must be not NULL */
120 libvlc_exception_raise( p_e, "filepath is null" );
123 /* We must have an input */
124 if( !p_mi->p_input_thread )
126 libvlc_exception_raise( p_e, "Input does not exist" );
130 /* GetVout will raise the exception for us */
131 p_vout = GetVout( p_mi, p_e );
132 if( !p_vout ) return;
134 var_SetInteger( p_vout, "snapshot-width", i_width );
135 var_SetInteger( p_vout, "snapshot-height", i_height );
137 var_SetString( p_vout, "snapshot-path", psz_filepath );
138 var_SetString( p_vout, "snapshot-format", "png" );
140 var_TriggerCallback( p_vout, "video-snapshot" );
141 vlc_object_release( p_vout );
144 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
145 libvlc_exception_t *p_e )
149 vout_thread_t *p_vout = GetVout( p_mi, p_e );
150 if( !p_vout ) return 0;
152 height = p_vout->i_window_height;
154 vlc_object_release( p_vout );
159 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
160 libvlc_exception_t *p_e )
164 vout_thread_t *p_vout = GetVout( p_mi, p_e );
165 if( !p_vout ) return 0;
167 width = p_vout->i_window_width;
169 vlc_object_release( p_vout );
174 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
175 libvlc_exception_t *p_e )
177 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
178 bool has_vout = false;
182 vout_thread_t *p_vout;
184 p_vout = input_GetVout( p_input_thread );
188 vlc_object_release( p_vout );
190 vlc_object_release( p_input_thread );
195 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
196 libvlc_exception_t *p_e )
198 vout_thread_t *p_vout = GetVout( p_mp, p_e );
202 float f_scale = var_GetFloat( p_vout, "scale" );
203 if( var_GetBool( p_vout, "autoscale" ) )
205 vlc_object_release( p_vout );
209 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
210 libvlc_exception_t *p_e )
212 vout_thread_t *p_vout = GetVout( p_mp, p_e );
217 var_SetFloat( p_vout, "scale", f_scale );
218 var_SetBool( p_vout, "autoscale", f_scale != 0. );
219 vlc_object_release( p_vout );
222 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
223 libvlc_exception_t *p_e )
225 char *psz_aspect = 0;
226 vout_thread_t *p_vout = GetVout( p_mi, p_e );
228 if( !p_vout ) return 0;
230 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
231 vlc_object_release( p_vout );
232 return psz_aspect ? psz_aspect : strdup("");
235 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
236 char *psz_aspect, libvlc_exception_t *p_e )
238 vout_thread_t *p_vout = GetVout( p_mi, p_e );
241 if( !p_vout ) return;
243 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
245 libvlc_exception_raise( p_e,
246 "Unexpected error while setting aspect-ratio value" );
248 vlc_object_release( p_vout );
251 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
252 libvlc_exception_t *p_e )
254 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
255 vlc_value_t val_list;
261 if( !p_input_thread ) return -1;
263 i_ret = var_Get( p_input_thread, "spu-es", &val );
266 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
267 vlc_object_release( p_input_thread );
271 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
272 for( i = 0; i < val_list.p_list->i_count; i++ )
274 if( val.i_int == val_list.p_list->p_values[i].i_int )
280 var_FreeList( &val_list, NULL );
281 vlc_object_release( p_input_thread );
285 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
286 libvlc_exception_t *p_e )
288 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
291 if( !p_input_thread )
294 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
296 vlc_object_release( p_input_thread );
300 libvlc_track_description_t *
301 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
302 libvlc_exception_t *p_e )
304 return libvlc_get_track_description( p_mi, "spu-es", p_e);
307 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
308 libvlc_exception_t *p_e )
310 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
311 vlc_value_t val_list;
315 if( !p_input_thread ) return;
317 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
319 if( val_list.p_list->i_count == 0 )
321 libvlc_exception_raise( p_e, "Subtitle value out of range" );
325 if( (i_spu < 0) && (i_spu > val_list.p_list->i_count) )
327 libvlc_exception_raise( p_e, "Subtitle value out of range" );
331 newval = val_list.p_list->p_values[i_spu];
332 i_ret = var_Set( p_input_thread, "spu-es", newval );
335 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
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,
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 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 );
399 libvlc_exception_raise( p_e,
400 "Unexpected error while setting crop geometry" );
402 vlc_object_release( p_vout );
405 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
406 libvlc_exception_t *p_e )
408 vout_thread_t *p_vout = GetVout( p_mi, p_e );
412 if( !p_vout ) return i_ret;
414 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
418 i_ret = var_GetInteger( p_vbi, "vbi-page" );
419 vlc_object_release( p_vbi );
422 vlc_object_release( p_vout );
426 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
427 libvlc_exception_t *p_e )
429 vout_thread_t *p_vout = GetVout( p_mi, p_e );
433 if( !p_vout ) return;
435 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
439 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
440 vlc_object_release( p_vbi );
442 libvlc_exception_raise( p_e,
443 "Unexpected error while setting teletext page" );
445 vlc_object_release( p_vout );
448 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
449 libvlc_exception_t *p_e )
451 input_thread_t *p_input_thread;
455 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
456 if( !p_input_thread ) return;
458 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
460 vlc_object_release( p_input_thread );
463 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
465 p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
471 /* FIXME Gni, why that ? */
472 i_ret = var_SetInteger( p_vbi, "vbi-page",
473 var_GetInteger( p_vbi, "vbi-page" ) );
475 libvlc_exception_raise( p_e,
476 "Unexpected error while setting teletext page" );
481 i_ret = var_SetBool( p_vbi, "vbi-opaque",
482 !var_GetBool( p_vbi, "vbi-opaque" ) );
484 libvlc_exception_raise( p_e,
485 "Unexpected error while setting teletext transparency" );
487 vlc_object_release( p_vbi );
489 else if( b_selected )
491 var_SetInteger( p_input_thread, "spu-es", -1 );
496 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
498 if( list.p_list->i_count > 0 )
499 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
501 var_FreeList( &list, NULL );
504 vlc_object_release( p_input_thread );
507 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
508 libvlc_exception_t *p_e )
510 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
513 if( !p_input_thread )
516 i_track_count = var_CountChoices( p_input_thread, "video-es" );
518 vlc_object_release( p_input_thread );
519 return i_track_count;
522 libvlc_track_description_t *
523 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
524 libvlc_exception_t *p_e )
526 return libvlc_get_track_description( p_mi, "video-es", p_e);
529 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
530 libvlc_exception_t *p_e )
532 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
533 vlc_value_t val_list;
539 if( !p_input_thread )
542 i_ret = var_Get( p_input_thread, "video-es", &val );
545 libvlc_exception_raise( p_e, "Getting Video track information failed" );
546 vlc_object_release( p_input_thread );
550 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
551 for( i = 0; i < val_list.p_list->i_count; i++ )
553 if( val_list.p_list->p_values[i].i_int == val.i_int )
559 var_FreeList( &val_list, NULL );
560 vlc_object_release( p_input_thread );
564 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
565 libvlc_exception_t *p_e )
567 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
568 vlc_value_t val_list;
572 if( !p_input_thread )
575 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
576 for( i = 0; i < val_list.p_list->i_count; i++ )
578 vlc_value_t val = val_list.p_list->p_values[i];
579 if( i_track == val.i_int )
581 i_ret = var_Set( p_input_thread, "video-es", val );
583 libvlc_exception_raise( p_e, "Setting video track failed" );
587 libvlc_exception_raise( p_e, "Video track out of range" );
590 var_FreeList( &val_list, NULL );
591 vlc_object_release( p_input_thread );
594 /******************************************************************************
595 * libvlc_video_set_deinterlace : enable deinterlace
596 *****************************************************************************/
597 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
598 const char *psz_mode,
599 libvlc_exception_t *p_e )
601 vout_thread_t *p_vout = GetVout( p_mi, p_e );
605 libvlc_exception_raise( p_e, "Unable to get video output" );
611 /* be sure that the filter name given is supported */
612 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
613 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
614 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x") )
616 /* set deinterlace filter chosen */
617 var_SetString( p_vout, "deinterlace", psz_mode );
621 libvlc_exception_raise( p_e, "Unsuported or bad deinterlace filter name" );
626 /* disable deinterlace filter */
627 var_SetString( p_vout, "deinterlace", "" );
630 vlc_object_release( p_vout );
633 /*****************************************************************************
634 * Marquee: FIXME: That implementation has no persistent state and requires
636 *****************************************************************************/
638 static const char *get_marquee_int_option_identifier(unsigned option)
640 static const char tab[][16] =
652 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
657 static const char *get_marquee_string_option_identifier(unsigned option)
659 static const char tab[][16] =
663 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
669 static vlc_object_t *get_marquee_object( libvlc_media_player_t * p_mi )
671 libvlc_exception_t e;
672 libvlc_exception_init(&e);
673 vout_thread_t * vout = GetVout( p_mi, &e );
674 libvlc_exception_clear(&e);
677 vlc_object_t * object = vlc_object_find_name( vout, "marq", FIND_CHILD );
678 vlc_object_release(vout);
682 /*****************************************************************************
683 * libvlc_video_get_marquee_option_as_int : get a marq option value
684 *****************************************************************************/
685 int libvlc_video_get_marquee_option_as_int( libvlc_media_player_t *p_mi,
687 libvlc_exception_t *p_e )
689 const char * identifier = get_marquee_int_option_identifier(option);
692 libvlc_exception_raise( p_e, "This option is not available" );
695 vlc_object_t * marquee = get_marquee_object(p_mi);
697 /* Handle the libvlc_marquee_Enabled separately */
698 if(option == libvlc_marquee_Enabled)
700 bool isEnabled = marquee != NULL;
701 vlc_object_release(marquee);
708 libvlc_exception_raise( p_e, "Marquee is not enabled" );
711 int ret = var_GetInteger(marquee, identifier);
712 vlc_object_release(marquee);
716 /*****************************************************************************
717 * libvlc_video_get_marquee_option_as_string : get a marq option value
718 *****************************************************************************/
719 char * libvlc_video_get_marquee_option_as_string( libvlc_media_player_t *p_mi,
721 libvlc_exception_t *p_e )
723 const char * identifier = get_marquee_string_option_identifier(option);
726 libvlc_exception_raise( p_e, "This option is not available" );
730 vlc_object_t * marquee = get_marquee_object(p_mi);
733 libvlc_exception_raise( p_e, "Marquee is not enabled" );
736 char *ret = var_GetString(marquee, identifier);
737 vlc_object_release(marquee);
741 /*****************************************************************************
742 * libvlc_video_set_marquee_option_as_int: enable, disable or set an int option
743 *****************************************************************************/
744 void libvlc_video_set_marquee_option_as_int( libvlc_media_player_t *p_mi,
746 int value, libvlc_exception_t *p_e )
748 const char * identifier = get_marquee_int_option_identifier(option);
751 libvlc_exception_raise( p_e, "This option is not available" );
755 /* Handle the libvlc_marquee_Enabled separately */
756 if(option == libvlc_marquee_Enabled)
758 libvlc_exception_t e;
759 libvlc_exception_init(&e);
760 vout_thread_t * vout = GetVout( p_mi, &e );
761 libvlc_exception_clear(&e);
764 vout_EnableFilter(vout, identifier, value, false);
765 vlc_object_release(vout);
769 libvlc_exception_raise( p_e, "No Vout" );
774 vlc_object_t * marquee = get_marquee_object(p_mi);
777 libvlc_exception_raise( p_e, "Marquee is not enabled" );
780 var_SetInteger(marquee, identifier, value);
781 vlc_object_release(marquee);
784 /*****************************************************************************
785 * libvlc_video_set_marquee_option_as_string: set a string option
786 *****************************************************************************/
787 void libvlc_video_set_marquee_option_as_string( libvlc_media_player_t *p_mi,
790 libvlc_exception_t *p_e )
792 const char * identifier = get_marquee_string_option_identifier(option);
795 libvlc_exception_raise( p_e, "This option is not available" );
798 vlc_object_t * marquee = get_marquee_object(p_mi);
801 libvlc_exception_raise( p_e, "Marquee is not enabled" );
804 var_SetString(marquee, identifier, value);
805 vlc_object_release(marquee);