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 input_thread_t *p_input_thread;
394 vlc_object_t *p_zvbi = NULL;
395 int i_ret = -1, telx;
397 p_input_thread = libvlc_get_input_thread( p_mi );
398 if( !p_input_thread ) return i_ret;
400 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
402 vlc_object_release( p_input_thread );
406 telx = var_GetInteger( p_input_thread, "teletext-es" );
407 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
410 i_ret = var_GetInteger( p_zvbi, "vbi-page" );
411 vlc_object_release( p_zvbi );
413 vlc_object_release( p_input_thread );
417 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
418 libvlc_exception_t *p_e )
420 input_thread_t *p_input_thread;
421 vlc_object_t *p_zvbi = NULL;
424 p_input_thread = libvlc_get_input_thread( p_mi );
425 if( !p_input_thread ) return;
427 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
429 vlc_object_release( p_input_thread );
433 telx = var_GetInteger( p_input_thread, "teletext-es" );
434 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
437 int i_ret = var_SetInteger( p_zvbi, "vbi-page", i_page );
438 vlc_object_release( p_zvbi );
441 libvlc_exception_raise( p_e );
442 libvlc_printerr( "Unexpected error while setting teletext page" );
445 vlc_object_release( p_input_thread );
448 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
450 input_thread_t *p_input_thread;
452 p_input_thread = libvlc_get_input_thread(p_mi);
453 if( !p_input_thread ) return;
455 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
457 vlc_object_release( p_input_thread );
460 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
463 var_SetInteger( p_input_thread, "spu-es", -1 );
468 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
470 if( list.p_list->i_count > 0 )
471 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
473 var_FreeList( &list, NULL );
476 vlc_object_release( p_input_thread );
479 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
481 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
484 if( !p_input_thread )
487 i_track_count = var_CountChoices( p_input_thread, "video-es" );
489 vlc_object_release( p_input_thread );
490 return i_track_count;
493 libvlc_track_description_t *
494 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
496 return libvlc_get_track_description( p_mi, "video-es" );
499 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
501 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
502 vlc_value_t val_list;
506 if( !p_input_thread )
509 if( var_Get( p_input_thread, "video-es", &val ) < 0 )
511 libvlc_printerr( "Video track information not found" );
512 vlc_object_release( p_input_thread );
516 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
517 for( int i = 0; i < val_list.p_list->i_count; i++ )
519 if( val_list.p_list->p_values[i].i_int == val.i_int )
525 var_FreeList( &val_list, NULL );
526 vlc_object_release( p_input_thread );
530 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
532 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
533 vlc_value_t val_list;
536 if( !p_input_thread )
539 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
540 for( int i = 0; i < val_list.p_list->i_count; i++ )
542 if( i_track == val_list.p_list->p_values[i].i_int )
544 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
550 libvlc_printerr( "Video track number out of range" );
552 var_FreeList( &val_list, NULL );
553 vlc_object_release( p_input_thread );
557 /******************************************************************************
558 * libvlc_video_set_deinterlace : enable deinterlace
559 *****************************************************************************/
560 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi,
561 const char *psz_mode )
563 if (psz_mode == NULL)
566 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
567 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
568 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
569 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x"))
574 var_SetString (p_mi, "deinterlace-mode", psz_mode);
575 var_SetInteger (p_mi, "deinterlace", 1);
578 var_SetInteger (p_mi, "deinterlace", 0);
581 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
582 for (size_t i = 0; i < n; i++)
584 vout_thread_t *p_vout = pp_vouts[i];
588 var_SetString (p_vout, "deinterlace-mode", psz_mode);
589 var_SetInteger (p_vout, "deinterlace", 1);
592 var_SetInteger (p_vout, "deinterlace", 0);
593 vlc_object_release (p_vout);
603 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
604 const char *name, libvlc_exception_t *p_e )
606 vlc_object_t *object = NULL;
607 vout_thread_t *vout = GetVout( p_mi, 0 );
608 libvlc_exception_clear( p_e );
611 object = vlc_object_find_name( vout, name, FIND_CHILD );
612 vlc_object_release(vout);
616 libvlc_exception_raise( p_e );
617 libvlc_printerr( "%s not enabled", name );
623 typedef const struct {
624 const char name[20]; /* probably will become a const char * sometime */
630 set_int( libvlc_media_player_t *p_mi, const char *name,
631 const opt_t *opt, int value, libvlc_exception_t *p_e )
635 if( !opt->type ) /* the enabler */
637 vout_thread_t *vout = GetVout( p_mi, 0 );
640 vout_EnableFilter( vout, opt->name, value, false );
641 vlc_object_release( vout );
646 vlc_object_t *object = get_object( p_mi, name, p_e );
647 if( !object ) return;
651 case VLC_VAR_INTEGER:
652 var_SetInteger(object, opt->name, value);
655 libvlc_exception_raise( p_e );
656 libvlc_printerr( "Invalid argument for %s in %s", name, "set int" );
659 vlc_object_release( object );
664 get_int( libvlc_media_player_t *p_mi, const char *name,
665 const opt_t *opt, libvlc_exception_t *p_e )
669 vlc_object_t *object = get_object( p_mi, name, p_e );
670 if( !object ) return 0;
675 case 0: /* the enabler */
676 ret = NULL != object;
678 case VLC_VAR_INTEGER:
679 ret = var_GetInteger(object, opt->name);
682 libvlc_exception_raise( p_e );
683 libvlc_printerr( "Invalid argument for %s in %s", name, "get int" );
687 vlc_object_release( object );
693 set_string( libvlc_media_player_t *p_mi, const char *name, const opt_t *opt,
694 const char *psz_value, libvlc_exception_t *p_e )
697 vlc_object_t *object = get_object( p_mi, name, p_e );
698 if( !object ) return;
703 var_SetString( object, opt->name, psz_value );
706 libvlc_exception_raise( p_e );
707 libvlc_printerr( "Invalid argument for %s in %s", name, "set string" );
710 vlc_object_release( object );
715 get_string( libvlc_media_player_t *p_mi, const char *name,
716 const opt_t *opt, libvlc_exception_t *p_e )
718 if( !opt ) return NULL;
719 vlc_object_t *object = get_object( p_mi, name, p_e );
720 if( !object ) return NULL;
726 ret = var_GetString( object, opt->name );
729 libvlc_exception_raise( p_e );
730 libvlc_printerr( "Invalid argument for %s in %s", name, "get string" );
734 vlc_object_release( object );
739 /*****************************************************************************
740 * Marquee: FIXME: That implementation has no persistent state and requires
742 *****************************************************************************/
745 marq_option_bynumber(unsigned option, libvlc_exception_t *p_e)
750 { "marq-marquee", VLC_VAR_STRING },
751 { "marq-color", VLC_VAR_INTEGER },
752 { "marq-opacity", VLC_VAR_INTEGER },
753 { "marq-position", VLC_VAR_INTEGER },
754 { "marq-refresh", VLC_VAR_INTEGER },
755 { "marq-size", VLC_VAR_INTEGER },
756 { "marq-timeout", VLC_VAR_INTEGER },
757 { "marq-x", VLC_VAR_INTEGER },
758 { "marq-y", VLC_VAR_INTEGER },
760 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
762 opt_t *r = option < num_opts ? optlist+option : NULL;
765 libvlc_exception_raise( p_e );
766 libvlc_printerr( "Unknown marquee option" );
771 static vlc_object_t *get_object( libvlc_media_player_t *,
772 const char *, libvlc_exception_t *);
774 /*****************************************************************************
775 * libvlc_video_get_marquee_int : get a marq option value
776 *****************************************************************************/
777 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
778 unsigned option, libvlc_exception_t *p_e )
780 return get_int( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
783 /*****************************************************************************
784 * libvlc_video_get_marquee_string : get a marq option value
785 *****************************************************************************/
786 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
787 unsigned option, libvlc_exception_t *p_e )
789 return get_string( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
792 /*****************************************************************************
793 * libvlc_video_set_marquee_int: enable, disable or set an int option
794 *****************************************************************************/
795 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
796 unsigned option, int value, libvlc_exception_t *p_e )
798 set_int( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
801 /*****************************************************************************
802 * libvlc_video_set_marquee_string: set a string option
803 *****************************************************************************/
804 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
805 unsigned option, const char * value, libvlc_exception_t *p_e )
807 set_string( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
811 /* logo module support */
815 logo_option_bynumber( unsigned option, libvlc_exception_t *p_e )
817 opt_t vlogo_optlist[] = /* depends on libvlc_video_logo_option_t */
820 { "logo-file", VLC_VAR_STRING },
821 { "logo-x", VLC_VAR_INTEGER },
822 { "logo-y", VLC_VAR_INTEGER },
823 { "logo-delay", VLC_VAR_INTEGER },
824 { "logo-repeat", VLC_VAR_INTEGER },
825 { "logo-opacity", VLC_VAR_INTEGER },
826 { "logo-position", VLC_VAR_INTEGER },
828 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
830 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
833 libvlc_exception_raise( p_e );
834 libvlc_printerr( "Unknown logo option" );
840 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
841 unsigned option, const char *psz_value,
842 libvlc_exception_t *p_e )
844 set_string( p_mi,"logo",logo_option_bynumber(option,p_e),psz_value,p_e );
848 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
849 unsigned option, int value,
850 libvlc_exception_t *p_e )
852 set_int( p_mi, "logo", logo_option_bynumber(option, p_e), value, p_e );
856 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
857 unsigned option, libvlc_exception_t *p_e )
859 return get_int( p_mi, "logo", logo_option_bynumber(option,p_e), p_e );