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 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
393 input_thread_t *p_input_thread;
395 p_input_thread = libvlc_get_input_thread(p_mi);
396 if( !p_input_thread ) return;
398 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
400 vlc_object_release( p_input_thread );
403 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
406 var_SetInteger( p_input_thread, "spu-es", -1 );
411 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
413 if( list.p_list->i_count > 0 )
414 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
416 var_FreeList( &list, NULL );
419 vlc_object_release( p_input_thread );
422 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
424 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
427 if( !p_input_thread )
430 i_track_count = var_CountChoices( p_input_thread, "video-es" );
432 vlc_object_release( p_input_thread );
433 return i_track_count;
436 libvlc_track_description_t *
437 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
439 return libvlc_get_track_description( p_mi, "video-es" );
442 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
444 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
445 vlc_value_t val_list;
449 if( !p_input_thread )
452 if( var_Get( p_input_thread, "video-es", &val ) < 0 )
454 libvlc_printerr( "Video track information not found" );
455 vlc_object_release( p_input_thread );
459 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
460 for( int i = 0; i < val_list.p_list->i_count; i++ )
462 if( val_list.p_list->p_values[i].i_int == val.i_int )
468 var_FreeList( &val_list, NULL );
469 vlc_object_release( p_input_thread );
473 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
475 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
476 vlc_value_t val_list;
479 if( !p_input_thread )
482 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
483 for( int i = 0; i < val_list.p_list->i_count; i++ )
485 if( i_track == val_list.p_list->p_values[i].i_int )
487 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
493 libvlc_printerr( "Video track number out of range" );
495 var_FreeList( &val_list, NULL );
496 vlc_object_release( p_input_thread );
500 /******************************************************************************
501 * libvlc_video_set_deinterlace : enable deinterlace
502 *****************************************************************************/
503 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi,
504 const char *psz_mode )
506 if (psz_mode == NULL)
509 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
510 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
511 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
512 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x"))
517 var_SetString (p_mi, "deinterlace-mode", psz_mode);
518 var_SetInteger (p_mi, "deinterlace", 1);
521 var_SetInteger (p_mi, "deinterlace", 0);
524 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
525 for (size_t i = 0; i < n; i++)
527 vout_thread_t *p_vout = pp_vouts[i];
531 var_SetString (p_vout, "deinterlace-mode", psz_mode);
532 var_SetInteger (p_vout, "deinterlace", 1);
535 var_SetInteger (p_vout, "deinterlace", 0);
536 vlc_object_release (p_vout);
546 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
547 const char *name, libvlc_exception_t *p_e )
549 vlc_object_t *object = NULL;
550 vout_thread_t *vout = GetVout( p_mi, 0 );
551 libvlc_exception_clear( p_e );
554 object = vlc_object_find_name( vout, name, FIND_CHILD );
555 vlc_object_release(vout);
559 libvlc_exception_raise( p_e );
560 libvlc_printerr( "%s not enabled", name );
566 typedef const struct {
567 const char name[20]; /* probably will become a const char * sometime */
573 set_int( libvlc_media_player_t *p_mi, const char *name,
574 const opt_t *opt, int value, libvlc_exception_t *p_e )
578 if( !opt->type ) /* the enabler */
580 vout_thread_t *vout = GetVout( p_mi, 0 );
583 vout_EnableFilter( vout, opt->name, value, false );
584 vlc_object_release( vout );
589 vlc_object_t *object = get_object( p_mi, name, p_e );
590 if( !object ) return;
594 case VLC_VAR_INTEGER:
595 var_SetInteger(object, opt->name, value);
598 libvlc_exception_raise( p_e );
599 libvlc_printerr( "Invalid argument for %s in %s", name, "set int" );
602 vlc_object_release( object );
607 get_int( libvlc_media_player_t *p_mi, const char *name,
608 const opt_t *opt, libvlc_exception_t *p_e )
612 vlc_object_t *object = get_object( p_mi, name, p_e );
613 if( !object ) return 0;
618 case 0: /* the enabler */
619 ret = NULL != object;
621 case VLC_VAR_INTEGER:
622 ret = var_GetInteger(object, opt->name);
625 libvlc_exception_raise( p_e );
626 libvlc_printerr( "Invalid argument for %s in %s", name, "get int" );
630 vlc_object_release( object );
636 set_string( libvlc_media_player_t *p_mi, const char *name, const opt_t *opt,
637 const char *psz_value, libvlc_exception_t *p_e )
640 vlc_object_t *object = get_object( p_mi, name, p_e );
641 if( !object ) return;
646 var_SetString( object, opt->name, psz_value );
649 libvlc_exception_raise( p_e );
650 libvlc_printerr( "Invalid argument for %s in %s", name, "set string" );
653 vlc_object_release( object );
658 get_string( libvlc_media_player_t *p_mi, const char *name,
659 const opt_t *opt, libvlc_exception_t *p_e )
661 if( !opt ) return NULL;
662 vlc_object_t *object = get_object( p_mi, name, p_e );
663 if( !object ) return NULL;
669 ret = var_GetString( object, opt->name );
672 libvlc_exception_raise( p_e );
673 libvlc_printerr( "Invalid argument for %s in %s", name, "get string" );
677 vlc_object_release( object );
682 /*****************************************************************************
683 * Marquee: FIXME: That implementation has no persistent state and requires
685 *****************************************************************************/
688 marq_option_bynumber(unsigned option, libvlc_exception_t *p_e)
693 { "marq-marquee", VLC_VAR_STRING },
694 { "marq-color", VLC_VAR_INTEGER },
695 { "marq-opacity", VLC_VAR_INTEGER },
696 { "marq-position", VLC_VAR_INTEGER },
697 { "marq-refresh", VLC_VAR_INTEGER },
698 { "marq-size", VLC_VAR_INTEGER },
699 { "marq-timeout", VLC_VAR_INTEGER },
700 { "marq-x", VLC_VAR_INTEGER },
701 { "marq-y", VLC_VAR_INTEGER },
703 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
705 opt_t *r = option < num_opts ? optlist+option : NULL;
708 libvlc_exception_raise( p_e );
709 libvlc_printerr( "Unknown marquee option" );
714 static vlc_object_t *get_object( libvlc_media_player_t *,
715 const char *, libvlc_exception_t *);
717 /*****************************************************************************
718 * libvlc_video_get_marquee_int : get a marq option value
719 *****************************************************************************/
720 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
721 unsigned option, libvlc_exception_t *p_e )
723 return get_int( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
726 /*****************************************************************************
727 * libvlc_video_get_marquee_string : get a marq option value
728 *****************************************************************************/
729 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
730 unsigned option, libvlc_exception_t *p_e )
732 return get_string( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
735 /*****************************************************************************
736 * libvlc_video_set_marquee_int: enable, disable or set an int option
737 *****************************************************************************/
738 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
739 unsigned option, int value, libvlc_exception_t *p_e )
741 set_int( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
744 /*****************************************************************************
745 * libvlc_video_set_marquee_string: set a string option
746 *****************************************************************************/
747 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
748 unsigned option, const char * value, libvlc_exception_t *p_e )
750 set_string( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
754 /* logo module support */
758 logo_option_bynumber( unsigned option, libvlc_exception_t *p_e )
760 opt_t vlogo_optlist[] = /* depends on libvlc_video_logo_option_t */
763 { "logo-file", VLC_VAR_STRING },
764 { "logo-x", VLC_VAR_INTEGER },
765 { "logo-y", VLC_VAR_INTEGER },
766 { "logo-delay", VLC_VAR_INTEGER },
767 { "logo-repeat", VLC_VAR_INTEGER },
768 { "logo-opacity", VLC_VAR_INTEGER },
769 { "logo-position", VLC_VAR_INTEGER },
771 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
773 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
776 libvlc_exception_raise( p_e );
777 libvlc_printerr( "Unknown logo option" );
783 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
784 unsigned option, const char *psz_value,
785 libvlc_exception_t *p_e )
787 set_string( p_mi,"logo",logo_option_bynumber(option,p_e),psz_value,p_e );
791 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
792 unsigned option, int value,
793 libvlc_exception_t *p_e )
795 set_int( p_mi, "logo", logo_option_bynumber(option, p_e), value, p_e );
799 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
800 unsigned option, libvlc_exception_t *p_e )
802 return get_int( p_mi, "logo", logo_option_bynumber(option,p_e), p_e );