1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005-2010 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 );
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 );
65 libvlc_exception_raise( p_exception );
66 libvlc_printerr( "No active input" );
71 /**********************************************************************
73 **********************************************************************/
75 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
76 libvlc_exception_t *p_e )
78 /* We only work on the first vout */
79 vout_thread_t *p_vout = GetVout( p_mi, p_e );
81 /* GetVout will raise the exception for us */
84 var_SetBool( p_vout, "fullscreen", b_fullscreen );
86 vlc_object_release( p_vout );
89 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
90 libvlc_exception_t *p_e )
92 /* We only work on the first vout */
93 vout_thread_t *p_vout = GetVout( p_mi, p_e );
96 /* GetVout will raise the exception for us */
97 if( !p_vout ) return 0;
99 i_ret = var_GetBool( p_vout, "fullscreen" );
101 vlc_object_release( p_vout );
106 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
107 libvlc_exception_t *p_e )
109 /* We only work on the first vout */
110 vout_thread_t *p_vout = GetVout( p_mi, p_e );
112 /* GetVout will raise the exception for us */
113 if( !p_vout ) return;
115 var_ToggleBool( p_vout, "fullscreen" );
117 vlc_object_release( p_vout );
120 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
122 var_SetBool (p_mi, "keyboard-events", !!on);
125 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
127 var_SetBool (p_mi, "mouse-events", !!on);
131 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
132 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
134 vout_thread_t *p_vout;
136 assert( psz_filepath );
138 /* We must have an input */
139 if( !p_mi->p_input_thread )
141 libvlc_exception_raise( p_e );
142 libvlc_printerr( "Input does not exist" );
146 /* GetVout will raise the exception for us */
147 p_vout = GetVout( p_mi, p_e );
148 if( !p_vout ) return;
150 var_SetInteger( p_vout, "snapshot-width", i_width );
151 var_SetInteger( p_vout, "snapshot-height", i_height );
153 var_SetString( p_vout, "snapshot-path", psz_filepath );
154 var_SetString( p_vout, "snapshot-format", "png" );
156 var_TriggerCallback( p_vout, "video-snapshot" );
157 vlc_object_release( p_vout );
160 int libvlc_video_get_height( 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 height = p_vout->i_window_height;
170 vlc_object_release( p_vout );
175 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
176 libvlc_exception_t *p_e )
180 vout_thread_t *p_vout = GetVout( p_mi, p_e );
181 if( !p_vout ) return 0;
183 width = p_vout->i_window_width;
185 vlc_object_release( p_vout );
190 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
192 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi);
193 bool has_vout = false;
197 vout_thread_t *p_vout;
199 p_vout = input_GetVout( p_input_thread );
203 vlc_object_release( p_vout );
205 vlc_object_release( p_input_thread );
210 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
211 libvlc_exception_t *p_e )
213 vout_thread_t *p_vout = GetVout( p_mp, p_e );
217 float f_scale = var_GetFloat( p_vout, "scale" );
218 if( var_GetBool( p_vout, "autoscale" ) )
220 vlc_object_release( p_vout );
224 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
225 libvlc_exception_t *p_e )
227 vout_thread_t *p_vout = GetVout( p_mp, p_e );
232 var_SetFloat( p_vout, "scale", f_scale );
233 var_SetBool( p_vout, "autoscale", f_scale != 0. );
234 vlc_object_release( p_vout );
237 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
238 libvlc_exception_t *p_e )
240 char *psz_aspect = NULL;
241 vout_thread_t *p_vout = GetVout( p_mi, p_e );
243 if( !p_vout ) return NULL;
245 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
246 vlc_object_release( p_vout );
247 return psz_aspect ? psz_aspect : strdup("");
250 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
251 const char *psz_aspect, libvlc_exception_t *p_e )
253 vout_thread_t *p_vout = GetVout( p_mi, p_e );
256 if( !p_vout ) return;
258 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
259 vlc_object_release( p_vout );
262 libvlc_exception_raise( p_e );
263 libvlc_printerr( "Bad or unsupported aspect ratio" );
267 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
268 libvlc_exception_t *p_e )
270 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
271 vlc_value_t val_list;
277 if( !p_input_thread )
279 libvlc_exception_raise( p_e );
280 libvlc_printerr( "No active input" );
284 i_ret = var_Get( p_input_thread, "spu-es", &val );
287 vlc_object_release( p_input_thread );
288 libvlc_exception_raise( p_e );
289 libvlc_printerr( "Subtitle informations not found" );
293 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
294 for( i = 0; i < val_list.p_list->i_count; i++ )
296 if( val.i_int == val_list.p_list->p_values[i].i_int )
302 var_FreeList( &val_list, NULL );
303 vlc_object_release( p_input_thread );
307 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
308 libvlc_exception_t *p_e )
310 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
313 if( !p_input_thread )
315 libvlc_exception_raise( p_e );
316 libvlc_printerr( "No active input" );
320 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
322 vlc_object_release( p_input_thread );
326 libvlc_track_description_t *
327 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi )
329 return libvlc_get_track_description( p_mi, "spu-es" );
332 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
333 libvlc_exception_t *p_e )
335 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
336 vlc_value_t val_list;
340 if( !p_input_thread )
342 libvlc_exception_raise( p_e );
343 libvlc_printerr( "No active input" );
347 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
349 if( ( val_list.p_list->i_count == 0 )
350 || (i_spu < 0) || (i_spu > val_list.p_list->i_count) )
352 libvlc_exception_raise( p_e );
353 libvlc_printerr( "Subtitle number out of range" );
357 newval = val_list.p_list->p_values[i_spu];
358 i_ret = var_Set( p_input_thread, "spu-es", newval );
361 libvlc_exception_raise( p_e );
362 libvlc_printerr( "Subtitle selection error" );
366 var_FreeList( &val_list, NULL );
367 vlc_object_release( p_input_thread );
370 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
371 const char *psz_subtitle )
373 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
378 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
380 vlc_object_release( p_input_thread );
385 libvlc_track_description_t *
386 libvlc_video_get_title_description( libvlc_media_player_t *p_mi )
388 return libvlc_get_track_description( p_mi, "title" );
391 libvlc_track_description_t *
392 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
396 sprintf( psz_title, "title %2i", i_title );
397 return libvlc_get_track_description( p_mi, psz_title );
400 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
401 libvlc_exception_t *p_e )
403 char *psz_geometry = 0;
404 vout_thread_t *p_vout = GetVout( p_mi, p_e );
406 if( !p_vout ) return 0;
408 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
409 vlc_object_release( p_vout );
410 return psz_geometry ? psz_geometry : strdup("");
413 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
414 const char *psz_geometry, libvlc_exception_t *p_e )
416 vout_thread_t *p_vout = GetVout( p_mi, p_e );
419 if( !p_vout ) return;
421 i_ret = var_SetString( p_vout, "crop", psz_geometry );
422 vlc_object_release( p_vout );
426 libvlc_exception_raise( p_e );
427 libvlc_printerr( "Bad or unsupported cropping geometry" );
431 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
433 input_thread_t *p_input_thread;
435 p_input_thread = libvlc_get_input_thread(p_mi);
436 if( !p_input_thread ) return;
438 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
440 vlc_object_release( p_input_thread );
443 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
446 var_SetInteger( p_input_thread, "spu-es", -1 );
451 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
453 if( list.p_list->i_count > 0 )
454 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
456 var_FreeList( &list, NULL );
459 vlc_object_release( p_input_thread );
462 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
464 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
467 if( !p_input_thread )
470 i_track_count = var_CountChoices( p_input_thread, "video-es" );
472 vlc_object_release( p_input_thread );
473 return i_track_count;
476 libvlc_track_description_t *
477 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
479 return libvlc_get_track_description( p_mi, "video-es" );
482 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
483 libvlc_exception_t *p_e )
485 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
486 vlc_value_t val_list;
492 if( !p_input_thread )
495 i_ret = var_Get( p_input_thread, "video-es", &val );
498 libvlc_exception_raise( p_e );
499 libvlc_printerr( "Video track information not found" );
500 vlc_object_release( p_input_thread );
504 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
505 for( i = 0; i < val_list.p_list->i_count; i++ )
507 if( val_list.p_list->p_values[i].i_int == val.i_int )
513 var_FreeList( &val_list, NULL );
514 vlc_object_release( p_input_thread );
518 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
519 libvlc_exception_t *p_e )
521 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
522 vlc_value_t val_list;
526 if( !p_input_thread )
529 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
530 for( i = 0; i < val_list.p_list->i_count; i++ )
532 if( i_track == val_list.p_list->p_values[i].i_int )
534 i_ret = var_SetInteger( p_input_thread, "video-es", i_track );
540 libvlc_exception_raise( p_e );
541 libvlc_printerr( "Video track number out of range" );
543 var_FreeList( &val_list, NULL );
544 vlc_object_release( p_input_thread );
547 /******************************************************************************
548 * libvlc_video_set_deinterlace : enable deinterlace
549 *****************************************************************************/
550 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
551 const char *psz_mode,
552 libvlc_exception_t *p_e )
554 vout_thread_t *p_vout = GetVout( p_mi, p_e );
561 /* be sure that the filter name given is supported */
562 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
563 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
564 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x")
565 || !strcmp(psz_mode, "yadif") || !strcmp(psz_mode, "yadif2x") )
567 /* set deinterlace filter chosen */
568 var_SetString( p_vout, "deinterlace-mode", psz_mode );
569 var_SetInteger( p_vout, "deinterlace", 1 );
573 libvlc_exception_raise( p_e );
574 libvlc_printerr( "Bad or unsupported deinterlacing mode" );
579 /* disable deinterlace filter */
580 var_SetInteger( p_vout, "deinterlace", 0 );
583 vlc_object_release( p_vout );
592 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
593 const char *name, libvlc_exception_t *p_e )
595 vlc_object_t *object = NULL;
596 vout_thread_t *vout = GetVout( p_mi, p_e );
597 libvlc_exception_clear( p_e );
600 object = vlc_object_find_name( vout, name, FIND_CHILD );
601 vlc_object_release(vout);
605 libvlc_exception_raise( p_e );
606 libvlc_printerr( "%s not enabled", name );
612 typedef const struct {
613 const char name[20]; /* probably will become a const char * sometime */
619 set_int( libvlc_media_player_t *p_mi, const char *name,
620 const opt_t *opt, int value, libvlc_exception_t *p_e )
624 if( !opt->type ) /* the enabler */
626 vout_thread_t *vout = GetVout( p_mi, p_e );
627 libvlc_exception_clear( p_e );
630 vout_EnableFilter( vout, opt->name, value, false );
631 vlc_object_release( vout );
636 vlc_object_t *object = get_object( p_mi, name, p_e );
637 if( !object ) return;
641 case VLC_VAR_INTEGER:
642 var_SetInteger(object, opt->name, value);
645 libvlc_exception_raise( p_e );
646 libvlc_printerr( "Invalid argument for %s in %s", name, "set int" );
649 vlc_object_release( object );
654 get_int( libvlc_media_player_t *p_mi, const char *name,
655 const opt_t *opt, libvlc_exception_t *p_e )
659 vlc_object_t *object = get_object( p_mi, name, p_e );
660 if( !object ) return 0;
665 case 0: /* the enabler */
666 ret = NULL != object;
668 case VLC_VAR_INTEGER:
669 ret = var_GetInteger(object, opt->name);
672 libvlc_exception_raise( p_e );
673 libvlc_printerr( "Invalid argument for %s in %s", name, "get int" );
677 vlc_object_release( object );
683 set_string( libvlc_media_player_t *p_mi, const char *name, const opt_t *opt,
684 const char *psz_value, libvlc_exception_t *p_e )
687 vlc_object_t *object = get_object( p_mi, name, p_e );
688 if( !object ) return;
693 var_SetString( object, opt->name, psz_value );
696 libvlc_exception_raise( p_e );
697 libvlc_printerr( "Invalid argument for %s in %s", name, "set string" );
700 vlc_object_release( object );
705 get_string( libvlc_media_player_t *p_mi, const char *name,
706 const opt_t *opt, libvlc_exception_t *p_e )
708 if( !opt ) return NULL;
709 vlc_object_t *object = get_object( p_mi, name, p_e );
710 if( !object ) return NULL;
716 ret = var_GetString( object, opt->name );
719 libvlc_exception_raise( p_e );
720 libvlc_printerr( "Invalid argument for %s in %s", name, "get string" );
724 vlc_object_release( object );
729 /*****************************************************************************
730 * Marquee: FIXME: That implementation has no persistent state and requires
732 *****************************************************************************/
735 marq_option_bynumber(unsigned option, libvlc_exception_t *p_e)
740 { "marq-marquee", VLC_VAR_STRING },
741 { "marq-color", VLC_VAR_INTEGER },
742 { "marq-opacity", VLC_VAR_INTEGER },
743 { "marq-position", VLC_VAR_INTEGER },
744 { "marq-refresh", VLC_VAR_INTEGER },
745 { "marq-size", VLC_VAR_INTEGER },
746 { "marq-timeout", VLC_VAR_INTEGER },
747 { "marq-x", VLC_VAR_INTEGER },
748 { "marq-y", VLC_VAR_INTEGER },
750 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
752 opt_t *r = option < num_opts ? optlist+option : NULL;
755 libvlc_exception_raise( p_e );
756 libvlc_printerr( "Unknown marquee option" );
761 static vlc_object_t *get_object( libvlc_media_player_t *,
762 const char *, libvlc_exception_t *);
764 /*****************************************************************************
765 * libvlc_video_get_marquee_int : get a marq option value
766 *****************************************************************************/
767 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
768 unsigned option, libvlc_exception_t *p_e )
770 return get_int( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
773 /*****************************************************************************
774 * libvlc_video_get_marquee_string : get a marq option value
775 *****************************************************************************/
776 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
777 unsigned option, libvlc_exception_t *p_e )
779 return get_string( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
782 /*****************************************************************************
783 * libvlc_video_set_marquee_int: enable, disable or set an int option
784 *****************************************************************************/
785 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
786 unsigned option, int value, libvlc_exception_t *p_e )
788 set_int( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
791 /*****************************************************************************
792 * libvlc_video_set_marquee_string: set a string option
793 *****************************************************************************/
794 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
795 unsigned option, const char * value, libvlc_exception_t *p_e )
797 set_string( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
801 /* logo module support */
805 logo_option_bynumber( unsigned option, libvlc_exception_t *p_e )
807 opt_t vlogo_optlist[] = /* depends on libvlc_video_logo_option_t */
810 { "logo-file", VLC_VAR_STRING },
811 { "logo-x", VLC_VAR_INTEGER },
812 { "logo-y", VLC_VAR_INTEGER },
813 { "logo-delay", VLC_VAR_INTEGER },
814 { "logo-repeat", VLC_VAR_INTEGER },
815 { "logo-opacity", VLC_VAR_INTEGER },
816 { "logo-position", VLC_VAR_INTEGER },
818 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
820 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
823 libvlc_exception_raise( p_e );
824 libvlc_printerr( "Unknown logo option" );
830 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
831 unsigned option, const char *psz_value,
832 libvlc_exception_t *p_e )
834 set_string( p_mi,"logo",logo_option_bynumber(option,p_e),psz_value,p_e );
838 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
839 unsigned option, int value,
840 libvlc_exception_t *p_e )
842 set_int( p_mi, "logo", logo_option_bynumber(option, p_e), value, p_e );
846 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
847 unsigned option, libvlc_exception_t *p_e )
849 return get_int( p_mi, "logo", logo_option_bynumber(option,p_e), p_e );