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"
44 * Remember to release the returned vout_thread_t.
46 static vout_thread_t **GetVouts( libvlc_media_player_t *p_mi, size_t *n )
48 input_thread_t *p_input = libvlc_get_input_thread( p_mi );
52 vout_thread_t **pp_vouts;
53 if (input_Control( p_input, INPUT_GET_VOUTS, &pp_vouts, n))
58 vlc_object_release (p_input);
62 static vout_thread_t *GetVout (libvlc_media_player_t *mp, size_t num)
64 vout_thread_t *p_vout = NULL;
66 vout_thread_t **pp_vouts = GetVouts (mp, &n);
71 p_vout = pp_vouts[num];
73 for (size_t i = 0; i < n; i++)
75 vlc_object_release (pp_vouts[i]);
80 libvlc_printerr ("Video output not active");
84 /**********************************************************************
86 **********************************************************************/
88 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen )
90 /* This will work even if the video is not currently active */
91 var_SetBool (p_mi, "fullscreen", !!b_fullscreen);
93 /* Apply to current video outputs (if any) */
95 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
96 for (size_t i = 0; i < n; i++)
98 var_SetBool (pp_vouts[i], "fullscreen", b_fullscreen);
99 vlc_object_release (pp_vouts[i]);
104 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi )
106 return var_GetBool (p_mi, "fullscreen");
109 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi )
111 bool b_fullscreen = var_ToggleBool (p_mi, "fullscreen");
113 /* Apply to current video outputs (if any) */
115 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
116 for (size_t i = 0; i < n; i++)
118 vout_thread_t *p_vout = pp_vouts[i];
120 var_SetBool (p_vout, "fullscreen", b_fullscreen);
121 vlc_object_release (p_vout);
126 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
128 var_SetBool (p_mi, "keyboard-events", !!on);
131 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
133 var_SetBool (p_mi, "mouse-events", !!on);
137 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
138 const char *psz_filepath,
139 unsigned int i_width, unsigned int i_height )
141 assert( psz_filepath );
143 vout_thread_t *p_vout = GetVout (p_mi, num);
147 /* FIXME: This is not atomic. Someone else could change the values,
148 * at least in theory. */
149 var_SetInteger( p_vout, "snapshot-width", i_width);
150 var_SetInteger( p_vout, "snapshot-height", i_height );
151 var_SetString( p_vout, "snapshot-path", psz_filepath );
152 var_SetString( p_vout, "snapshot-format", "png" );
153 var_TriggerCallback (p_vout, "video-snapshot" );
157 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
158 unsigned *restrict px, unsigned *restrict py )
161 vout_thread_t *p_vout = GetVout (p_mi, num);
165 *px = p_vout->i_window_height;
166 *py = p_vout->i_window_width;
167 vlc_object_release (p_vout);
174 int libvlc_video_get_height( libvlc_media_player_t *p_mi )
176 unsigned height, width;
178 if (libvlc_video_get_size (p_mi, 0, &height, &width))
183 int libvlc_video_get_width( libvlc_media_player_t *p_mi )
185 unsigned height, width;
187 if (libvlc_video_get_size (p_mi, 0, &height, &width))
192 int libvlc_video_get_cursor( libvlc_media_player_t *mp, unsigned num,
193 int *restrict px, int *restrict py )
195 vout_thread_t *p_vout = GetVout (mp, num);
199 var_GetCoords (p_vout, "mouse-moved", px, py);
200 vlc_object_release (p_vout);
204 unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
207 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
208 for (size_t i = 0; i < n; i++)
209 vlc_object_release (pp_vouts[i]);
214 float libvlc_video_get_scale( libvlc_media_player_t *mp )
216 float f_scale = var_GetFloat (mp, "scale");
217 if (var_GetBool (mp, "autoscale"))
222 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
225 var_SetFloat (p_mp, "scale", f_scale);
226 var_SetBool (p_mp, "autoscale", f_scale != 0.);
228 /* Apply to current video outputs (if any) */
230 vout_thread_t **pp_vouts = GetVouts (p_mp, &n);
231 for (size_t i = 0; i < n; i++)
233 vout_thread_t *p_vout = pp_vouts[i];
236 var_SetFloat (p_vout, "scale", f_scale);
237 var_SetBool (p_mp, "autoscale", f_scale != 0.);
238 vlc_object_release (p_vout);
243 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi )
245 return var_GetNonEmptyString (p_mi, "aspect-ratio");
248 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
249 const char *psz_aspect )
251 if (psz_aspect == NULL)
253 var_SetString (p_mi, "aspect-ratio", psz_aspect);
256 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
257 for (size_t i = 0; i < n; i++)
259 vout_thread_t *p_vout = pp_vouts[i];
261 var_SetString (p_vout, "aspect-ratio", psz_aspect);
262 vlc_object_release (p_vout);
267 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
269 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
270 vlc_value_t val_list;
276 if( !p_input_thread )
278 libvlc_printerr( "No active input" );
282 i_ret = var_Get( p_input_thread, "spu-es", &val );
285 vlc_object_release( p_input_thread );
286 libvlc_printerr( "Subtitle informations not found" );
290 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
291 for( i = 0; i < val_list.p_list->i_count; i++ )
293 if( val.i_int == val_list.p_list->p_values[i].i_int )
299 var_FreeList( &val_list, NULL );
300 vlc_object_release( p_input_thread );
304 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi )
306 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
309 if( !p_input_thread )
312 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
313 vlc_object_release( p_input_thread );
317 libvlc_track_description_t *
318 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi )
320 return libvlc_get_track_description( p_mi, "spu-es" );
323 int libvlc_video_set_spu( libvlc_media_player_t *p_mi, unsigned i_spu )
325 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
329 if( !p_input_thread )
332 var_Change (p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list, NULL);
334 if (i_spu > (unsigned)list.p_list->i_count)
336 libvlc_printerr( "Subtitle number out of range (%u/%u)",
337 i_spu, list.p_list->i_count );
341 var_SetInteger (p_input_thread, "spu-es",
342 list.p_list->p_values[i_spu].i_int);
344 vlc_object_release (p_input_thread);
345 var_FreeList (&list, NULL);
349 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
350 const char *psz_subtitle )
352 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
357 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
359 vlc_object_release( p_input_thread );
364 libvlc_track_description_t *
365 libvlc_video_get_title_description( libvlc_media_player_t *p_mi )
367 return libvlc_get_track_description( p_mi, "title" );
370 libvlc_track_description_t *
371 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
375 sprintf( psz_title, "title %2i", i_title );
376 return libvlc_get_track_description( p_mi, psz_title );
379 char *libvlc_video_get_crop_geometry (libvlc_media_player_t *p_mi)
381 return var_GetNonEmptyString (p_mi, "crop");
384 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
385 const char *psz_geometry )
387 if (psz_geometry == NULL)
390 var_SetString (p_mi, "crop", psz_geometry);
393 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
395 for (size_t i = 0; i < n; i++)
397 vout_thread_t *p_vout = pp_vouts[i];
399 var_SetString (p_vout, "crop", psz_geometry);
400 vlc_object_release (p_vout);
405 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi )
407 return var_GetInteger (p_mi, "vbi-page");
410 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page )
412 input_thread_t *p_input_thread;
413 vlc_object_t *p_zvbi = NULL;
416 var_SetInteger (p_mi, "vbi-page", i_page);
418 p_input_thread = libvlc_get_input_thread( p_mi );
419 if( !p_input_thread ) return;
421 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
423 vlc_object_release( p_input_thread );
427 telx = var_GetInteger( p_input_thread, "teletext-es" );
428 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
431 var_SetInteger( p_zvbi, "vbi-page", i_page );
432 vlc_object_release( p_zvbi );
434 vlc_object_release( p_input_thread );
437 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
439 input_thread_t *p_input_thread;
441 p_input_thread = libvlc_get_input_thread(p_mi);
442 if( !p_input_thread ) return;
444 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
446 vlc_object_release( p_input_thread );
449 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
452 var_SetInteger( p_input_thread, "spu-es", -1 );
457 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
459 if( list.p_list->i_count > 0 )
460 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
462 var_FreeList( &list, NULL );
465 vlc_object_release( p_input_thread );
468 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
470 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
473 if( !p_input_thread )
476 i_track_count = var_CountChoices( p_input_thread, "video-es" );
478 vlc_object_release( p_input_thread );
479 return i_track_count;
482 libvlc_track_description_t *
483 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
485 return libvlc_get_track_description( p_mi, "video-es" );
488 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
490 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
491 vlc_value_t val_list;
495 if( !p_input_thread )
498 if( var_Get( p_input_thread, "video-es", &val ) < 0 )
500 libvlc_printerr( "Video track information not found" );
501 vlc_object_release( p_input_thread );
505 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
506 for( int i = 0; i < val_list.p_list->i_count; i++ )
508 if( val_list.p_list->p_values[i].i_int == val.i_int )
514 var_FreeList( &val_list, NULL );
515 vlc_object_release( p_input_thread );
519 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
521 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
522 vlc_value_t val_list;
525 if( !p_input_thread )
528 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
529 for( int i = 0; i < val_list.p_list->i_count; i++ )
531 if( i_track == val_list.p_list->p_values[i].i_int )
533 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
539 libvlc_printerr( "Video track number out of range" );
541 var_FreeList( &val_list, NULL );
542 vlc_object_release( p_input_thread );
546 /******************************************************************************
547 * libvlc_video_set_deinterlace : enable deinterlace
548 *****************************************************************************/
549 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi,
550 const char *psz_mode )
552 if (psz_mode == NULL)
555 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
556 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
557 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
558 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x"))
563 var_SetString (p_mi, "deinterlace-mode", psz_mode);
564 var_SetInteger (p_mi, "deinterlace", 1);
567 var_SetInteger (p_mi, "deinterlace", 0);
570 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
571 for (size_t i = 0; i < n; i++)
573 vout_thread_t *p_vout = pp_vouts[i];
577 var_SetString (p_vout, "deinterlace-mode", psz_mode);
578 var_SetInteger (p_vout, "deinterlace", 1);
581 var_SetInteger (p_vout, "deinterlace", 0);
582 vlc_object_release (p_vout);
592 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
595 vlc_object_t *object;
596 vout_thread_t *vout = GetVout( p_mi, 0 );
600 object = vlc_object_find_name( vout, name, FIND_CHILD );
601 vlc_object_release(vout);
607 libvlc_printerr( "%s not enabled", name );
612 typedef const struct {
619 set_int( libvlc_media_player_t *p_mi, const char *restrict name,
620 const opt_t *restrict opt, int value )
624 if( !opt->type ) /* the enabler */
626 vout_thread_t *vout = GetVout( p_mi, 0 );
629 vout_EnableFilter( vout, opt->name, value, false );
630 vlc_object_release( vout );
635 if( opt->type != VLC_VAR_INTEGER )
637 libvlc_printerr( "Invalid argument to %s in %s", name, "set int" );
641 var_SetInteger(p_mi, opt->name, value);
642 vlc_object_t *object = get_object( p_mi, name );
645 var_SetInteger(object, opt->name, value);
646 vlc_object_release( object );
652 get_int( libvlc_media_player_t *p_mi, const char *restrict name,
653 const opt_t *restrict opt )
659 case 0: /* the enabler */
661 vlc_object_t *object = get_object( p_mi, name );
662 vlc_object_release( object );
663 return object != NULL;
665 case VLC_VAR_INTEGER:
666 return var_GetInteger(p_mi, opt->name);
668 libvlc_printerr( "Invalid argument to %s in %s", name, "get int" );
675 set_float( libvlc_media_player_t *p_mi, const char *restrict name,
676 const opt_t *restrict opt, float value )
680 if( opt->type != VLC_VAR_FLOAT )
682 libvlc_printerr( "Invalid argument to %s in %s", name, "set float" );
686 var_SetFloat( p_mi, opt->name, value );
688 vlc_object_t *object = get_object( p_mi, name );
691 var_SetFloat(object, opt->name, value );
692 vlc_object_release( object );
698 get_float( libvlc_media_player_t *p_mi, const char *restrict name,
699 const opt_t *restrict opt )
701 if( !opt ) return 0.0;
704 if( opt->type != VLC_VAR_FLOAT )
706 libvlc_printerr( "Invalid argument to %s in %s", name, "get float" );
710 return var_GetFloat( p_mi, opt->name );
715 set_string( libvlc_media_player_t *p_mi, const char *restrict name,
716 const opt_t *restrict opt, const char *restrict psz_value )
720 if( opt->type != VLC_VAR_STRING )
722 libvlc_printerr( "Invalid argument to %s in %s", name, "set string" );
726 var_SetString( p_mi, opt->name, psz_value );
728 vlc_object_t *object = get_object( p_mi, name );
731 var_SetString(object, opt->name, psz_value );
732 vlc_object_release( object );
738 get_string( libvlc_media_player_t *p_mi, const char *restrict name,
739 const opt_t *restrict opt )
741 if( !opt ) return NULL;
743 if( opt->type != VLC_VAR_STRING )
745 libvlc_printerr( "Invalid argument to %s in %s", name, "get string" );
749 return var_GetString( p_mi, opt->name );
754 marq_option_bynumber(unsigned option)
756 static const opt_t optlist[] =
759 { "marq-marquee", VLC_VAR_STRING },
760 { "marq-color", VLC_VAR_INTEGER },
761 { "marq-opacity", VLC_VAR_INTEGER },
762 { "marq-position", VLC_VAR_INTEGER },
763 { "marq-refresh", VLC_VAR_INTEGER },
764 { "marq-size", VLC_VAR_INTEGER },
765 { "marq-timeout", VLC_VAR_INTEGER },
766 { "marq-x", VLC_VAR_INTEGER },
767 { "marq-y", VLC_VAR_INTEGER },
769 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
771 opt_t *r = option < num_opts ? optlist+option : NULL;
773 libvlc_printerr( "Unknown marquee option" );
777 static vlc_object_t *get_object( libvlc_media_player_t *, const char *);
779 /*****************************************************************************
780 * libvlc_video_get_marquee_int : get a marq option value
781 *****************************************************************************/
782 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
785 return get_int( p_mi, "marq", marq_option_bynumber(option) );
788 /*****************************************************************************
789 * libvlc_video_get_marquee_string : get a marq option value
790 *****************************************************************************/
791 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
794 return get_string( p_mi, "marq", marq_option_bynumber(option) );
797 /*****************************************************************************
798 * libvlc_video_set_marquee_int: enable, disable or set an int option
799 *****************************************************************************/
800 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
801 unsigned option, int value )
803 set_int( p_mi, "marq", marq_option_bynumber(option), value );
806 /*****************************************************************************
807 * libvlc_video_set_marquee_string: set a string option
808 *****************************************************************************/
809 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
810 unsigned option, const char * value )
812 set_string( p_mi, "marq", marq_option_bynumber(option), value );
816 /* logo module support */
820 logo_option_bynumber( unsigned option )
822 static const opt_t vlogo_optlist[] =
823 /* depends on libvlc_video_logo_option_t */
826 { "logo-file", VLC_VAR_STRING },
827 { "logo-x", VLC_VAR_INTEGER },
828 { "logo-y", VLC_VAR_INTEGER },
829 { "logo-delay", VLC_VAR_INTEGER },
830 { "logo-repeat", VLC_VAR_INTEGER },
831 { "logo-opacity", VLC_VAR_INTEGER },
832 { "logo-position", VLC_VAR_INTEGER },
834 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
836 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
838 libvlc_printerr( "Unknown logo option" );
843 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
844 unsigned option, const char *psz_value )
846 set_string( p_mi,"logo",logo_option_bynumber(option),psz_value );
850 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
851 unsigned option, int value )
853 set_int( p_mi, "logo", logo_option_bynumber(option), value );
857 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
860 return get_int( p_mi, "logo", logo_option_bynumber(option) );
864 /* adjust module support */
868 adjust_option_bynumber( unsigned option )
870 static const opt_t optlist[] =
873 { "contrast", VLC_VAR_FLOAT },
874 { "brightness", VLC_VAR_FLOAT },
875 { "hue", VLC_VAR_INTEGER },
876 { "saturation", VLC_VAR_FLOAT },
877 { "gamma", VLC_VAR_FLOAT },
879 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
881 opt_t *r = option < num_opts ? optlist+option : NULL;
883 libvlc_printerr( "Unknown adjust option" );
888 void libvlc_video_set_adjust_int( libvlc_media_player_t *p_mi,
889 unsigned option, int value )
891 set_int( p_mi, "adjust", adjust_option_bynumber(option), value );
895 int libvlc_video_get_adjust_int( libvlc_media_player_t *p_mi,
898 return get_int( p_mi, "adjust", adjust_option_bynumber(option) );
902 void libvlc_video_set_adjust_float( libvlc_media_player_t *p_mi,
903 unsigned option, float value )
905 set_float( p_mi, "adjust", adjust_option_bynumber(option), value );
909 float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
912 return get_float( p_mi, "adjust", adjust_option_bynumber(option) );