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 **GetVouts( libvlc_media_player_t *p_mi, size_t *n )
49 input_thread_t *p_input = libvlc_get_input_thread( p_mi );
53 vout_thread_t **pp_vouts;
54 if (input_Control( p_input, INPUT_GET_VOUTS, &pp_vouts, n))
59 vlc_object_release (p_input);
63 static vout_thread_t *GetVout (libvlc_media_player_t *mp, size_t num)
65 vout_thread_t *p_vout = NULL;
67 vout_thread_t **pp_vouts = GetVouts (mp, &n);
72 p_vout = pp_vouts[num];
74 for (size_t i = 0; i < n; i++)
76 vlc_object_release (pp_vouts[i]);
81 libvlc_printerr ("Video output not active");
85 /**********************************************************************
87 **********************************************************************/
89 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen )
91 /* This will work even if the video is not currently active */
92 var_SetBool (p_mi, "fullscreen", !!b_fullscreen);
94 /* Apply to current video outputs (if any) */
96 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
97 for (size_t i = 0; i < n; i++)
99 var_SetBool (pp_vouts[i], "fullscreen", b_fullscreen);
100 vlc_object_release (pp_vouts[i]);
105 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi )
107 return var_GetBool (p_mi, "fullscreen");
110 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi )
112 var_ToggleBool (p_mi, "fullscreen");
113 bool b_fullscreen = var_GetBool (p_mi, "fullscreen");
115 /* Apply to current video outputs (if any) */
117 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
118 for (size_t i = 0; i < n; i++)
120 vout_thread_t *p_vout = pp_vouts[i];
122 var_SetBool (p_vout, "fullscreen", b_fullscreen);
123 vlc_object_release (p_vout);
128 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
130 var_SetBool (p_mi, "keyboard-events", !!on);
133 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
135 var_SetBool (p_mi, "mouse-events", !!on);
139 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
140 const char *psz_filepath,
141 unsigned int i_width, unsigned int i_height )
143 assert( psz_filepath );
145 vout_thread_t *p_vout = GetVout (p_mi, num);
149 /* FIXME: This is not atomic. Someone else could change the values,
150 * at least in theory. */
151 var_SetInteger( p_vout, "snapshot-width", i_width);
152 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" );
155 var_TriggerCallback (p_vout, "video-snapshot" );
159 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
160 unsigned *restrict px, unsigned *restrict py )
162 vout_thread_t *p_vout = GetVout (p_mi, num);
166 *px = p_vout->i_window_height;
167 *py = p_vout->i_window_width;
168 vlc_object_release (p_vout);
172 int libvlc_video_get_height( libvlc_media_player_t *p_mi )
174 unsigned height, width;
176 if (libvlc_video_get_size (p_mi, 0, &height, &width))
181 int libvlc_video_get_width( libvlc_media_player_t *p_mi )
183 unsigned height, width;
185 if (libvlc_video_get_size (p_mi, 0, &height, &width))
190 unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
193 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
194 for (size_t i = 0; i < n; i++)
195 vlc_object_release (pp_vouts[i]);
200 float libvlc_video_get_scale( libvlc_media_player_t *mp )
202 float f_scale = var_GetFloat (mp, "scale");
203 if (var_GetBool (mp, "autoscale"))
208 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
211 var_SetFloat (p_mp, "scale", f_scale);
212 var_SetBool (p_mp, "autoscale", f_scale != 0.);
214 /* Apply to current video outputs (if any) */
216 vout_thread_t **pp_vouts = GetVouts (p_mp, &n);
217 for (size_t i = 0; i < n; i++)
219 vout_thread_t *p_vout = pp_vouts[i];
222 var_SetFloat (p_vout, "scale", f_scale);
223 var_SetBool (p_mp, "autoscale", f_scale != 0.);
224 vlc_object_release (p_vout);
229 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi )
231 return var_GetNonEmptyString (p_mi, "aspect-ratio");
234 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
235 const char *psz_aspect )
237 if (psz_aspect == NULL)
239 var_SetString (p_mi, "aspect-ratio", psz_aspect);
242 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
243 for (size_t i = 0; i < n; i++)
245 vout_thread_t *p_vout = pp_vouts[i];
247 var_SetString (p_vout, "aspect-ratio", psz_aspect);
248 vlc_object_release (p_vout);
253 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
255 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
256 vlc_value_t val_list;
262 if( !p_input_thread )
264 libvlc_printerr( "No active input" );
268 i_ret = var_Get( p_input_thread, "spu-es", &val );
271 vlc_object_release( p_input_thread );
272 libvlc_printerr( "Subtitle informations not found" );
276 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
277 for( i = 0; i < val_list.p_list->i_count; i++ )
279 if( val.i_int == val_list.p_list->p_values[i].i_int )
285 var_FreeList( &val_list, NULL );
286 vlc_object_release( p_input_thread );
290 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi )
292 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
295 if( !p_input_thread )
298 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 )
306 return libvlc_get_track_description( p_mi, "spu-es" );
309 int libvlc_video_set_spu( libvlc_media_player_t *p_mi, unsigned i_spu )
311 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
315 if( !p_input_thread )
318 var_Change (p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list, NULL);
320 if (i_spu > (unsigned)list.p_list->i_count)
322 libvlc_printerr( "Subtitle number out of range (%u/%u)",
323 i_spu, list.p_list->i_count );
327 var_SetInteger (p_input_thread, "spu-es",
328 list.p_list->p_values[i_spu].i_int);
330 vlc_object_release (p_input_thread);
331 var_FreeList (&list, NULL);
335 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
336 const char *psz_subtitle )
338 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
343 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
345 vlc_object_release( p_input_thread );
350 libvlc_track_description_t *
351 libvlc_video_get_title_description( libvlc_media_player_t *p_mi )
353 return libvlc_get_track_description( p_mi, "title" );
356 libvlc_track_description_t *
357 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
361 sprintf( psz_title, "title %2i", i_title );
362 return libvlc_get_track_description( p_mi, psz_title );
365 char *libvlc_video_get_crop_geometry (libvlc_media_player_t *p_mi)
367 return var_GetNonEmptyString (p_mi, "crop");
370 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
371 const char *psz_geometry )
373 if (psz_geometry == NULL)
376 var_SetString (p_mi, "crop", psz_geometry);
379 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
381 for (size_t i = 0; i < n; i++)
383 vout_thread_t *p_vout = pp_vouts[i];
385 var_SetString (p_vout, "crop", psz_geometry);
386 vlc_object_release (p_vout);
391 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi )
393 return var_GetInteger (p_mi, "vbi-page");
396 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page )
398 input_thread_t *p_input_thread;
399 vlc_object_t *p_zvbi = NULL;
402 var_SetInteger (p_mi, "vbi-page", i_page);
404 p_input_thread = libvlc_get_input_thread( p_mi );
405 if( !p_input_thread ) return;
407 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
409 vlc_object_release( p_input_thread );
413 telx = var_GetInteger( p_input_thread, "teletext-es" );
414 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
417 var_SetInteger( p_zvbi, "vbi-page", i_page );
418 vlc_object_release( p_zvbi );
420 vlc_object_release( p_input_thread );
423 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
425 input_thread_t *p_input_thread;
427 p_input_thread = libvlc_get_input_thread(p_mi);
428 if( !p_input_thread ) return;
430 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
432 vlc_object_release( p_input_thread );
435 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
438 var_SetInteger( p_input_thread, "spu-es", -1 );
443 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
445 if( list.p_list->i_count > 0 )
446 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
448 var_FreeList( &list, NULL );
451 vlc_object_release( p_input_thread );
454 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
456 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
459 if( !p_input_thread )
462 i_track_count = var_CountChoices( p_input_thread, "video-es" );
464 vlc_object_release( p_input_thread );
465 return i_track_count;
468 libvlc_track_description_t *
469 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
471 return libvlc_get_track_description( p_mi, "video-es" );
474 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
476 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
477 vlc_value_t val_list;
481 if( !p_input_thread )
484 if( var_Get( p_input_thread, "video-es", &val ) < 0 )
486 libvlc_printerr( "Video track information not found" );
487 vlc_object_release( p_input_thread );
491 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
492 for( int i = 0; i < val_list.p_list->i_count; i++ )
494 if( val_list.p_list->p_values[i].i_int == val.i_int )
500 var_FreeList( &val_list, NULL );
501 vlc_object_release( p_input_thread );
505 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
507 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
508 vlc_value_t val_list;
511 if( !p_input_thread )
514 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
515 for( int i = 0; i < val_list.p_list->i_count; i++ )
517 if( i_track == val_list.p_list->p_values[i].i_int )
519 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
525 libvlc_printerr( "Video track number out of range" );
527 var_FreeList( &val_list, NULL );
528 vlc_object_release( p_input_thread );
532 /******************************************************************************
533 * libvlc_video_set_deinterlace : enable deinterlace
534 *****************************************************************************/
535 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi,
536 const char *psz_mode )
538 if (psz_mode == NULL)
541 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
542 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
543 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
544 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x"))
549 var_SetString (p_mi, "deinterlace-mode", psz_mode);
550 var_SetInteger (p_mi, "deinterlace", 1);
553 var_SetInteger (p_mi, "deinterlace", 0);
556 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
557 for (size_t i = 0; i < n; i++)
559 vout_thread_t *p_vout = pp_vouts[i];
563 var_SetString (p_vout, "deinterlace-mode", psz_mode);
564 var_SetInteger (p_vout, "deinterlace", 1);
567 var_SetInteger (p_vout, "deinterlace", 0);
568 vlc_object_release (p_vout);
578 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
579 const char *name, libvlc_exception_t *p_e )
581 vlc_object_t *object = NULL;
582 vout_thread_t *vout = GetVout( p_mi, 0 );
583 libvlc_exception_clear( p_e );
586 object = vlc_object_find_name( vout, name, FIND_CHILD );
587 vlc_object_release(vout);
591 libvlc_exception_raise( p_e );
592 libvlc_printerr( "%s not enabled", name );
598 typedef const struct {
605 set_int( libvlc_media_player_t *p_mi, const char *name,
606 const opt_t *opt, int value, libvlc_exception_t *p_e )
610 if( !opt->type ) /* the enabler */
612 vout_thread_t *vout = GetVout( p_mi, 0 );
615 vout_EnableFilter( vout, opt->name, value, false );
616 vlc_object_release( vout );
621 vlc_object_t *object = get_object( p_mi, name, p_e );
622 if( !object ) return;
626 case VLC_VAR_INTEGER:
627 var_SetInteger(object, opt->name, value);
630 libvlc_exception_raise( p_e );
631 libvlc_printerr( "Invalid argument for %s in %s", name, "set int" );
634 vlc_object_release( object );
639 get_int( libvlc_media_player_t *p_mi, const char *name,
640 const opt_t *opt, libvlc_exception_t *p_e )
644 vlc_object_t *object = get_object( p_mi, name, p_e );
645 if( !object ) return 0;
650 case 0: /* the enabler */
651 ret = NULL != object;
653 case VLC_VAR_INTEGER:
654 ret = var_GetInteger(object, opt->name);
657 libvlc_exception_raise( p_e );
658 libvlc_printerr( "Invalid argument for %s in %s", name, "get int" );
662 vlc_object_release( object );
668 set_string( libvlc_media_player_t *p_mi, const char *name, const opt_t *opt,
669 const char *psz_value, libvlc_exception_t *p_e )
672 vlc_object_t *object = get_object( p_mi, name, p_e );
673 if( !object ) return;
678 var_SetString( object, opt->name, psz_value );
681 libvlc_exception_raise( p_e );
682 libvlc_printerr( "Invalid argument for %s in %s", name, "set string" );
685 vlc_object_release( object );
690 get_string( libvlc_media_player_t *p_mi, const char *name,
691 const opt_t *opt, libvlc_exception_t *p_e )
693 if( !opt ) return NULL;
694 vlc_object_t *object = get_object( p_mi, name, p_e );
695 if( !object ) return NULL;
701 ret = var_GetString( object, opt->name );
704 libvlc_exception_raise( p_e );
705 libvlc_printerr( "Invalid argument for %s in %s", name, "get string" );
709 vlc_object_release( object );
714 /*****************************************************************************
715 * Marquee: FIXME: That implementation has no persistent state and requires
717 *****************************************************************************/
720 marq_option_bynumber(unsigned option, libvlc_exception_t *p_e)
725 { "marq-marquee", VLC_VAR_STRING },
726 { "marq-color", VLC_VAR_INTEGER },
727 { "marq-opacity", VLC_VAR_INTEGER },
728 { "marq-position", VLC_VAR_INTEGER },
729 { "marq-refresh", VLC_VAR_INTEGER },
730 { "marq-size", VLC_VAR_INTEGER },
731 { "marq-timeout", VLC_VAR_INTEGER },
732 { "marq-x", VLC_VAR_INTEGER },
733 { "marq-y", VLC_VAR_INTEGER },
735 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
737 opt_t *r = option < num_opts ? optlist+option : NULL;
740 libvlc_exception_raise( p_e );
741 libvlc_printerr( "Unknown marquee option" );
746 static vlc_object_t *get_object( libvlc_media_player_t *,
747 const char *, libvlc_exception_t *);
749 /*****************************************************************************
750 * libvlc_video_get_marquee_int : get a marq option value
751 *****************************************************************************/
752 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
753 unsigned option, libvlc_exception_t *p_e )
755 return get_int( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
758 /*****************************************************************************
759 * libvlc_video_get_marquee_string : get a marq option value
760 *****************************************************************************/
761 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
762 unsigned option, libvlc_exception_t *p_e )
764 return get_string( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
767 /*****************************************************************************
768 * libvlc_video_set_marquee_int: enable, disable or set an int option
769 *****************************************************************************/
770 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
771 unsigned option, int value, libvlc_exception_t *p_e )
773 set_int( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
776 /*****************************************************************************
777 * libvlc_video_set_marquee_string: set a string option
778 *****************************************************************************/
779 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
780 unsigned option, const char * value, libvlc_exception_t *p_e )
782 set_string( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
786 /* logo module support */
790 logo_option_bynumber( unsigned option, libvlc_exception_t *p_e )
792 opt_t vlogo_optlist[] = /* depends on libvlc_video_logo_option_t */
795 { "logo-file", VLC_VAR_STRING },
796 { "logo-x", VLC_VAR_INTEGER },
797 { "logo-y", VLC_VAR_INTEGER },
798 { "logo-delay", VLC_VAR_INTEGER },
799 { "logo-repeat", VLC_VAR_INTEGER },
800 { "logo-opacity", VLC_VAR_INTEGER },
801 { "logo-position", VLC_VAR_INTEGER },
803 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
805 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
808 libvlc_exception_raise( p_e );
809 libvlc_printerr( "Unknown logo option" );
815 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
816 unsigned option, const char *psz_value,
817 libvlc_exception_t *p_e )
819 set_string( p_mi,"logo",logo_option_bynumber(option,p_e),psz_value,p_e );
823 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
824 unsigned option, int value,
825 libvlc_exception_t *p_e )
827 set_int( p_mi, "logo", logo_option_bynumber(option, p_e), value, p_e );
831 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
832 unsigned option, libvlc_exception_t *p_e )
834 return get_int( p_mi, "logo", logo_option_bynumber(option,p_e), p_e );