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, p_exception );
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 );
66 /**********************************************************************
68 **********************************************************************/
70 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
71 libvlc_exception_t *p_e )
73 /* We only work on the first vout */
74 vout_thread_t *p_vout = GetVout( p_mi, p_e );
76 /* GetVout will raise the exception for us */
79 var_SetBool( p_vout, "fullscreen", b_fullscreen );
81 vlc_object_release( p_vout );
84 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
85 libvlc_exception_t *p_e )
87 /* We only work on the first vout */
88 vout_thread_t *p_vout = GetVout( p_mi, p_e );
91 /* GetVout will raise the exception for us */
92 if( !p_vout ) return 0;
94 i_ret = var_GetBool( p_vout, "fullscreen" );
96 vlc_object_release( p_vout );
101 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
102 libvlc_exception_t *p_e )
104 /* We only work on the first vout */
105 vout_thread_t *p_vout = GetVout( p_mi, p_e );
107 /* GetVout will raise the exception for us */
108 if( !p_vout ) return;
110 var_ToggleBool( p_vout, "fullscreen" );
112 vlc_object_release( p_vout );
115 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
117 var_SetBool (p_mi, "keyboard-events", !!on);
120 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
122 var_SetBool (p_mi, "mouse-events", !!on);
126 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
127 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
129 vout_thread_t *p_vout;
131 assert( psz_filepath );
133 /* We must have an input */
134 if( !p_mi->p_input_thread )
136 libvlc_exception_raise( p_e );
137 libvlc_printerr( "Input does not exist" );
141 /* GetVout will raise the exception for us */
142 p_vout = GetVout( p_mi, p_e );
143 if( !p_vout ) return;
145 var_SetInteger( p_vout, "snapshot-width", i_width );
146 var_SetInteger( p_vout, "snapshot-height", i_height );
148 var_SetString( p_vout, "snapshot-path", psz_filepath );
149 var_SetString( p_vout, "snapshot-format", "png" );
151 var_TriggerCallback( p_vout, "video-snapshot" );
152 vlc_object_release( p_vout );
155 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
156 libvlc_exception_t *p_e )
160 vout_thread_t *p_vout = GetVout( p_mi, p_e );
161 if( !p_vout ) return 0;
163 height = p_vout->i_window_height;
165 vlc_object_release( p_vout );
170 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
171 libvlc_exception_t *p_e )
175 vout_thread_t *p_vout = GetVout( p_mi, p_e );
176 if( !p_vout ) return 0;
178 width = p_vout->i_window_width;
180 vlc_object_release( p_vout );
185 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
186 libvlc_exception_t *p_e )
188 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
189 bool has_vout = false;
193 vout_thread_t *p_vout;
195 p_vout = input_GetVout( p_input_thread );
199 vlc_object_release( p_vout );
201 vlc_object_release( p_input_thread );
206 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
207 libvlc_exception_t *p_e )
209 vout_thread_t *p_vout = GetVout( p_mp, p_e );
213 float f_scale = var_GetFloat( p_vout, "scale" );
214 if( var_GetBool( p_vout, "autoscale" ) )
216 vlc_object_release( p_vout );
220 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
221 libvlc_exception_t *p_e )
223 vout_thread_t *p_vout = GetVout( p_mp, p_e );
228 var_SetFloat( p_vout, "scale", f_scale );
229 var_SetBool( p_vout, "autoscale", f_scale != 0. );
230 vlc_object_release( p_vout );
233 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
234 libvlc_exception_t *p_e )
236 char *psz_aspect = NULL;
237 vout_thread_t *p_vout = GetVout( p_mi, p_e );
239 if( !p_vout ) return NULL;
241 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
242 vlc_object_release( p_vout );
243 return psz_aspect ? psz_aspect : strdup("");
246 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
247 const char *psz_aspect, libvlc_exception_t *p_e )
249 vout_thread_t *p_vout = GetVout( p_mi, p_e );
252 if( !p_vout ) return;
254 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
255 vlc_object_release( p_vout );
258 libvlc_exception_raise( p_e );
259 libvlc_printerr( "Bad or unsupported aspect ratio" );
263 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
264 libvlc_exception_t *p_e )
266 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
267 vlc_value_t val_list;
273 if( !p_input_thread ) return -1;
275 i_ret = var_Get( p_input_thread, "spu-es", &val );
278 vlc_object_release( p_input_thread );
279 libvlc_exception_raise( p_e );
280 libvlc_printerr( "Subtitle informations not found" );
284 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
285 for( i = 0; i < val_list.p_list->i_count; i++ )
287 if( val.i_int == val_list.p_list->p_values[i].i_int )
293 var_FreeList( &val_list, NULL );
294 vlc_object_release( p_input_thread );
298 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
299 libvlc_exception_t *p_e )
301 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
304 if( !p_input_thread )
307 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
309 vlc_object_release( p_input_thread );
313 libvlc_track_description_t *
314 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
315 libvlc_exception_t *p_e )
317 return libvlc_get_track_description( p_mi, "spu-es", p_e);
320 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
321 libvlc_exception_t *p_e )
323 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
324 vlc_value_t val_list;
328 if( !p_input_thread ) return;
330 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
332 if( ( val_list.p_list->i_count == 0 )
333 || (i_spu < 0) || (i_spu > val_list.p_list->i_count) )
335 libvlc_exception_raise( p_e );
336 libvlc_printerr( "Subtitle number out of range" );
340 newval = val_list.p_list->p_values[i_spu];
341 i_ret = var_Set( p_input_thread, "spu-es", newval );
344 libvlc_exception_raise( p_e );
345 libvlc_printerr( "Subtitle selection error" );
349 var_FreeList( &val_list, NULL );
350 vlc_object_release( p_input_thread );
353 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
354 const char *psz_subtitle,
355 libvlc_exception_t *p_e )
357 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
362 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
364 vlc_object_release( p_input_thread );
369 libvlc_track_description_t *
370 libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
371 libvlc_exception_t * p_e )
373 return libvlc_get_track_description( p_mi, "title", p_e);
376 libvlc_track_description_t *
377 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
379 libvlc_exception_t *p_e )
382 sprintf( psz_title, "title %2i", i_title );
383 return libvlc_get_track_description( p_mi, psz_title, p_e);
386 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
387 libvlc_exception_t *p_e )
389 char *psz_geometry = 0;
390 vout_thread_t *p_vout = GetVout( p_mi, p_e );
392 if( !p_vout ) return 0;
394 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
395 vlc_object_release( p_vout );
396 return psz_geometry ? psz_geometry : strdup("");
399 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
400 const char *psz_geometry, libvlc_exception_t *p_e )
402 vout_thread_t *p_vout = GetVout( p_mi, p_e );
405 if( !p_vout ) return;
407 i_ret = var_SetString( p_vout, "crop", psz_geometry );
408 vlc_object_release( p_vout );
412 libvlc_exception_raise( p_e );
413 libvlc_printerr( "Bad or unsupported cropping geometry" );
417 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
418 libvlc_exception_t *p_e )
420 input_thread_t *p_input_thread;
422 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
423 if( !p_input_thread ) return;
425 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
427 vlc_object_release( p_input_thread );
430 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
433 var_SetInteger( p_input_thread, "spu-es", -1 );
438 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
440 if( list.p_list->i_count > 0 )
441 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
443 var_FreeList( &list, NULL );
446 vlc_object_release( p_input_thread );
449 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
450 libvlc_exception_t *p_e )
452 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
455 if( !p_input_thread )
458 i_track_count = var_CountChoices( p_input_thread, "video-es" );
460 vlc_object_release( p_input_thread );
461 return i_track_count;
464 libvlc_track_description_t *
465 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
466 libvlc_exception_t *p_e )
468 return libvlc_get_track_description( p_mi, "video-es", p_e);
471 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
472 libvlc_exception_t *p_e )
474 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
475 vlc_value_t val_list;
481 if( !p_input_thread )
484 i_ret = var_Get( p_input_thread, "video-es", &val );
487 libvlc_exception_raise( p_e );
488 libvlc_printerr( "Video track information not found" );
489 vlc_object_release( p_input_thread );
493 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
494 for( i = 0; i < val_list.p_list->i_count; i++ )
496 if( val_list.p_list->p_values[i].i_int == val.i_int )
502 var_FreeList( &val_list, NULL );
503 vlc_object_release( p_input_thread );
507 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
508 libvlc_exception_t *p_e )
510 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
511 vlc_value_t val_list;
515 if( !p_input_thread )
518 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
519 for( i = 0; i < val_list.p_list->i_count; i++ )
521 if( i_track == val_list.p_list->p_values[i].i_int )
523 i_ret = var_SetInteger( p_input_thread, "video-es", i_track );
529 libvlc_exception_raise( p_e );
530 libvlc_printerr( "Video track number out of range" );
532 var_FreeList( &val_list, NULL );
533 vlc_object_release( p_input_thread );
536 /******************************************************************************
537 * libvlc_video_set_deinterlace : enable deinterlace
538 *****************************************************************************/
539 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
540 const char *psz_mode,
541 libvlc_exception_t *p_e )
543 vout_thread_t *p_vout = GetVout( p_mi, p_e );
550 /* be sure that the filter name given is supported */
551 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
552 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
553 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x")
554 || !strcmp(psz_mode, "yadif") || !strcmp(psz_mode, "yadif2x") )
556 /* set deinterlace filter chosen */
557 var_SetString( p_vout, "deinterlace-mode", psz_mode );
558 var_SetInteger( p_vout, "deinterlace", 1 );
562 libvlc_exception_raise( p_e );
563 libvlc_printerr( "Bad or unsupported deinterlacing mode" );
568 /* disable deinterlace filter */
569 var_SetInteger( p_vout, "deinterlace", 0 );
572 vlc_object_release( p_vout );
581 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
582 const char *name, libvlc_exception_t *p_e )
584 vlc_object_t *object = NULL;
585 vout_thread_t *vout = GetVout( p_mi, p_e );
586 libvlc_exception_clear( p_e );
589 object = vlc_object_find_name( vout, name, FIND_CHILD );
590 vlc_object_release(vout);
594 libvlc_exception_raise( p_e );
595 libvlc_printerr( "%s not enabled", name );
601 typedef const struct {
602 const char name[20]; /* probably will become a const char * sometime */
608 set_int( libvlc_media_player_t *p_mi, const char *name,
609 const opt_t *opt, int value, libvlc_exception_t *p_e )
613 if( !opt->type ) /* the enabler */
615 vout_thread_t *vout = GetVout( p_mi, p_e );
616 libvlc_exception_clear( p_e );
619 vout_EnableFilter( vout, opt->name, value, false );
620 vlc_object_release( vout );
625 vlc_object_t *object = get_object( p_mi, name, p_e );
626 if( !object ) return;
630 case VLC_VAR_INTEGER:
631 var_SetInteger(object, opt->name, value);
634 libvlc_exception_raise( p_e );
635 libvlc_printerr( "Invalid argument for %s in %s", name, "set int" );
638 vlc_object_release( object );
643 get_int( libvlc_media_player_t *p_mi, const char *name,
644 const opt_t *opt, libvlc_exception_t *p_e )
648 vlc_object_t *object = get_object( p_mi, name, p_e );
649 if( !object ) return 0;
654 case 0: /* the enabler */
655 ret = NULL != object;
657 case VLC_VAR_INTEGER:
658 ret = var_GetInteger(object, opt->name);
661 libvlc_exception_raise( p_e );
662 libvlc_printerr( "Invalid argument for %s in %s", name, "get int" );
666 vlc_object_release( object );
672 set_string( libvlc_media_player_t *p_mi, const char *name, const opt_t *opt,
673 const char *psz_value, libvlc_exception_t *p_e )
676 vlc_object_t *object = get_object( p_mi, name, p_e );
677 if( !object ) return;
682 var_SetString( object, opt->name, psz_value );
685 libvlc_exception_raise( p_e );
686 libvlc_printerr( "Invalid argument for %s in %s", name, "set string" );
689 vlc_object_release( object );
694 get_string( libvlc_media_player_t *p_mi, const char *name,
695 const opt_t *opt, libvlc_exception_t *p_e )
697 if( !opt ) return NULL;
698 vlc_object_t *object = get_object( p_mi, name, p_e );
699 if( !object ) return NULL;
705 ret = var_GetString( object, opt->name );
708 libvlc_exception_raise( p_e );
709 libvlc_printerr( "Invalid argument for %s in %s", name, "get string" );
713 vlc_object_release( object );
718 /*****************************************************************************
719 * Marquee: FIXME: That implementation has no persistent state and requires
721 *****************************************************************************/
724 marq_option_bynumber(unsigned option, libvlc_exception_t *p_e)
729 { "marq-marquee", VLC_VAR_STRING },
730 { "marq-color", VLC_VAR_INTEGER },
731 { "marq-opacity", VLC_VAR_INTEGER },
732 { "marq-position", VLC_VAR_INTEGER },
733 { "marq-refresh", VLC_VAR_INTEGER },
734 { "marq-size", VLC_VAR_INTEGER },
735 { "marq-timeout", VLC_VAR_INTEGER },
736 { "marq-x", VLC_VAR_INTEGER },
737 { "marq-y", VLC_VAR_INTEGER },
739 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
741 opt_t *r = option < num_opts ? optlist+option : NULL;
744 libvlc_exception_raise( p_e );
745 libvlc_printerr( "Unknown marquee option" );
750 static vlc_object_t *get_object( libvlc_media_player_t *,
751 const char *, libvlc_exception_t *);
753 /*****************************************************************************
754 * libvlc_video_get_marquee_int : get a marq option value
755 *****************************************************************************/
756 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
757 unsigned option, libvlc_exception_t *p_e )
759 return get_int( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
762 /*****************************************************************************
763 * libvlc_video_get_marquee_string : get a marq option value
764 *****************************************************************************/
765 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
766 unsigned option, libvlc_exception_t *p_e )
768 return get_string( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
771 /*****************************************************************************
772 * libvlc_video_set_marquee_int: enable, disable or set an int option
773 *****************************************************************************/
774 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
775 unsigned option, int value, libvlc_exception_t *p_e )
777 set_int( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
780 /*****************************************************************************
781 * libvlc_video_set_marquee_string: set a string option
782 *****************************************************************************/
783 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
784 unsigned option, const char * value, libvlc_exception_t *p_e )
786 set_string( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
790 /* logo module support */
794 logo_option_bynumber( unsigned option, libvlc_exception_t *p_e )
796 opt_t vlogo_optlist[] = /* depends on libvlc_video_logo_option_t */
799 { "logo-file", VLC_VAR_STRING },
800 { "logo-x", VLC_VAR_INTEGER },
801 { "logo-y", VLC_VAR_INTEGER },
802 { "logo-delay", VLC_VAR_INTEGER },
803 { "logo-repeat", VLC_VAR_INTEGER },
804 { "logo-opacity", VLC_VAR_INTEGER },
805 { "logo-position", VLC_VAR_INTEGER },
807 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
809 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
812 libvlc_exception_raise( p_e );
813 libvlc_printerr( "Unknown logo option" );
819 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
820 unsigned option, const char *psz_value,
821 libvlc_exception_t *p_e )
823 set_string( p_mi,"logo",logo_option_bynumber(option,p_e),psz_value,p_e );
827 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
828 unsigned option, int value,
829 libvlc_exception_t *p_e )
831 set_int( p_mi, "logo", logo_option_bynumber(option, p_e), value, p_e );
835 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
836 unsigned option, libvlc_exception_t *p_e )
838 return get_int( p_mi, "logo", logo_option_bynumber(option,p_e), p_e );