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 );
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 );
65 libvlc_exception_raise( p_exception );
66 libvlc_printerr( "No active input" );
71 /**********************************************************************
73 **********************************************************************/
75 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
76 libvlc_exception_t *p_e )
78 /* We only work on the first vout */
79 vout_thread_t *p_vout = GetVout( p_mi, p_e );
81 /* GetVout will raise the exception for us */
84 var_SetBool( p_vout, "fullscreen", b_fullscreen );
86 vlc_object_release( p_vout );
89 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
90 libvlc_exception_t *p_e )
92 /* We only work on the first vout */
93 vout_thread_t *p_vout = GetVout( p_mi, p_e );
96 /* GetVout will raise the exception for us */
97 if( !p_vout ) return 0;
99 i_ret = var_GetBool( p_vout, "fullscreen" );
101 vlc_object_release( p_vout );
106 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
107 libvlc_exception_t *p_e )
109 /* We only work on the first vout */
110 vout_thread_t *p_vout = GetVout( p_mi, p_e );
112 /* GetVout will raise the exception for us */
113 if( !p_vout ) return;
115 var_ToggleBool( p_vout, "fullscreen" );
117 vlc_object_release( p_vout );
120 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
122 var_SetBool (p_mi, "keyboard-events", !!on);
125 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
127 var_SetBool (p_mi, "mouse-events", !!on);
131 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
132 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
134 vout_thread_t *p_vout;
136 assert( psz_filepath );
138 /* We must have an input */
139 if( !p_mi->p_input_thread )
141 libvlc_exception_raise( p_e );
142 libvlc_printerr( "Input does not exist" );
146 /* GetVout will raise the exception for us */
147 p_vout = GetVout( p_mi, p_e );
148 if( !p_vout ) return;
150 var_SetInteger( p_vout, "snapshot-width", i_width );
151 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" );
156 var_TriggerCallback( p_vout, "video-snapshot" );
157 vlc_object_release( p_vout );
160 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
161 libvlc_exception_t *p_e )
165 vout_thread_t *p_vout = GetVout( p_mi, p_e );
166 if( !p_vout ) return 0;
168 height = p_vout->i_window_height;
170 vlc_object_release( p_vout );
175 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
176 libvlc_exception_t *p_e )
180 vout_thread_t *p_vout = GetVout( p_mi, p_e );
181 if( !p_vout ) return 0;
183 width = p_vout->i_window_width;
185 vlc_object_release( p_vout );
190 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
191 libvlc_exception_t *p_e )
193 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi);
194 bool has_vout = false;
198 vout_thread_t *p_vout;
200 p_vout = input_GetVout( p_input_thread );
204 vlc_object_release( p_vout );
206 vlc_object_release( p_input_thread );
211 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
212 libvlc_exception_t *p_e )
214 vout_thread_t *p_vout = GetVout( p_mp, p_e );
218 float f_scale = var_GetFloat( p_vout, "scale" );
219 if( var_GetBool( p_vout, "autoscale" ) )
221 vlc_object_release( p_vout );
225 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
226 libvlc_exception_t *p_e )
228 vout_thread_t *p_vout = GetVout( p_mp, p_e );
233 var_SetFloat( p_vout, "scale", f_scale );
234 var_SetBool( p_vout, "autoscale", f_scale != 0. );
235 vlc_object_release( p_vout );
238 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
239 libvlc_exception_t *p_e )
241 char *psz_aspect = NULL;
242 vout_thread_t *p_vout = GetVout( p_mi, p_e );
244 if( !p_vout ) return NULL;
246 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
247 vlc_object_release( p_vout );
248 return psz_aspect ? psz_aspect : strdup("");
251 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
252 const char *psz_aspect, libvlc_exception_t *p_e )
254 vout_thread_t *p_vout = GetVout( p_mi, p_e );
257 if( !p_vout ) return;
259 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
260 vlc_object_release( p_vout );
263 libvlc_exception_raise( p_e );
264 libvlc_printerr( "Bad or unsupported aspect ratio" );
268 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
269 libvlc_exception_t *p_e )
271 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
272 vlc_value_t val_list;
278 if( !p_input_thread )
280 libvlc_exception_raise( p_e );
281 libvlc_printerr( "No active input" );
285 i_ret = var_Get( p_input_thread, "spu-es", &val );
288 vlc_object_release( p_input_thread );
289 libvlc_exception_raise( p_e );
290 libvlc_printerr( "Subtitle informations not found" );
294 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
295 for( i = 0; i < val_list.p_list->i_count; i++ )
297 if( val.i_int == val_list.p_list->p_values[i].i_int )
303 var_FreeList( &val_list, NULL );
304 vlc_object_release( p_input_thread );
308 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
309 libvlc_exception_t *p_e )
311 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
314 if( !p_input_thread )
316 libvlc_exception_raise( p_e );
317 libvlc_printerr( "No active input" );
321 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
323 vlc_object_release( p_input_thread );
327 libvlc_track_description_t *
328 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
329 libvlc_exception_t *p_e )
331 return libvlc_get_track_description( p_mi, "spu-es" );
334 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
335 libvlc_exception_t *p_e )
337 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
338 vlc_value_t val_list;
342 if( !p_input_thread )
344 libvlc_exception_raise( p_e );
345 libvlc_printerr( "No active input" );
349 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
351 if( ( val_list.p_list->i_count == 0 )
352 || (i_spu < 0) || (i_spu > val_list.p_list->i_count) )
354 libvlc_exception_raise( p_e );
355 libvlc_printerr( "Subtitle number out of range" );
359 newval = val_list.p_list->p_values[i_spu];
360 i_ret = var_Set( p_input_thread, "spu-es", newval );
363 libvlc_exception_raise( p_e );
364 libvlc_printerr( "Subtitle selection error" );
368 var_FreeList( &val_list, NULL );
369 vlc_object_release( p_input_thread );
372 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
373 const char *psz_subtitle,
374 libvlc_exception_t *p_e )
376 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
381 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
383 vlc_object_release( p_input_thread );
388 libvlc_track_description_t *
389 libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
390 libvlc_exception_t * p_e )
392 return libvlc_get_track_description( p_mi, "title" );
395 libvlc_track_description_t *
396 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
398 libvlc_exception_t *p_e )
401 sprintf( psz_title, "title %2i", i_title );
402 return libvlc_get_track_description( p_mi, psz_title );
405 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
406 libvlc_exception_t *p_e )
408 char *psz_geometry = 0;
409 vout_thread_t *p_vout = GetVout( p_mi, p_e );
411 if( !p_vout ) return 0;
413 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
414 vlc_object_release( p_vout );
415 return psz_geometry ? psz_geometry : strdup("");
418 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
419 const char *psz_geometry, libvlc_exception_t *p_e )
421 vout_thread_t *p_vout = GetVout( p_mi, p_e );
424 if( !p_vout ) return;
426 i_ret = var_SetString( p_vout, "crop", psz_geometry );
427 vlc_object_release( p_vout );
431 libvlc_exception_raise( p_e );
432 libvlc_printerr( "Bad or unsupported cropping geometry" );
436 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
437 libvlc_exception_t *p_e )
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,
469 libvlc_exception_t *p_e )
471 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
474 if( !p_input_thread )
477 i_track_count = var_CountChoices( p_input_thread, "video-es" );
479 vlc_object_release( p_input_thread );
480 return i_track_count;
483 libvlc_track_description_t *
484 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
485 libvlc_exception_t *p_e )
487 return libvlc_get_track_description( p_mi, "video-es" );
490 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
491 libvlc_exception_t *p_e )
493 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
494 vlc_value_t val_list;
500 if( !p_input_thread )
503 i_ret = var_Get( p_input_thread, "video-es", &val );
506 libvlc_exception_raise( p_e );
507 libvlc_printerr( "Video track information not found" );
508 vlc_object_release( p_input_thread );
512 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
513 for( i = 0; i < val_list.p_list->i_count; i++ )
515 if( val_list.p_list->p_values[i].i_int == val.i_int )
521 var_FreeList( &val_list, NULL );
522 vlc_object_release( p_input_thread );
526 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
527 libvlc_exception_t *p_e )
529 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
530 vlc_value_t val_list;
534 if( !p_input_thread )
537 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
538 for( i = 0; i < val_list.p_list->i_count; i++ )
540 if( i_track == val_list.p_list->p_values[i].i_int )
542 i_ret = var_SetInteger( p_input_thread, "video-es", i_track );
548 libvlc_exception_raise( p_e );
549 libvlc_printerr( "Video track number out of range" );
551 var_FreeList( &val_list, NULL );
552 vlc_object_release( p_input_thread );
555 /******************************************************************************
556 * libvlc_video_set_deinterlace : enable deinterlace
557 *****************************************************************************/
558 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
559 const char *psz_mode,
560 libvlc_exception_t *p_e )
562 vout_thread_t *p_vout = GetVout( p_mi, p_e );
569 /* be sure that the filter name given is supported */
570 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
571 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
572 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x")
573 || !strcmp(psz_mode, "yadif") || !strcmp(psz_mode, "yadif2x") )
575 /* set deinterlace filter chosen */
576 var_SetString( p_vout, "deinterlace-mode", psz_mode );
577 var_SetInteger( p_vout, "deinterlace", 1 );
581 libvlc_exception_raise( p_e );
582 libvlc_printerr( "Bad or unsupported deinterlacing mode" );
587 /* disable deinterlace filter */
588 var_SetInteger( p_vout, "deinterlace", 0 );
591 vlc_object_release( p_vout );
600 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
601 const char *name, libvlc_exception_t *p_e )
603 vlc_object_t *object = NULL;
604 vout_thread_t *vout = GetVout( p_mi, p_e );
605 libvlc_exception_clear( p_e );
608 object = vlc_object_find_name( vout, name, FIND_CHILD );
609 vlc_object_release(vout);
613 libvlc_exception_raise( p_e );
614 libvlc_printerr( "%s not enabled", name );
620 typedef const struct {
621 const char name[20]; /* probably will become a const char * sometime */
627 set_int( libvlc_media_player_t *p_mi, const char *name,
628 const opt_t *opt, int value, libvlc_exception_t *p_e )
632 if( !opt->type ) /* the enabler */
634 vout_thread_t *vout = GetVout( p_mi, p_e );
635 libvlc_exception_clear( p_e );
638 vout_EnableFilter( vout, opt->name, value, false );
639 vlc_object_release( vout );
644 vlc_object_t *object = get_object( p_mi, name, p_e );
645 if( !object ) return;
649 case VLC_VAR_INTEGER:
650 var_SetInteger(object, opt->name, value);
653 libvlc_exception_raise( p_e );
654 libvlc_printerr( "Invalid argument for %s in %s", name, "set int" );
657 vlc_object_release( object );
662 get_int( libvlc_media_player_t *p_mi, const char *name,
663 const opt_t *opt, libvlc_exception_t *p_e )
667 vlc_object_t *object = get_object( p_mi, name, p_e );
668 if( !object ) return 0;
673 case 0: /* the enabler */
674 ret = NULL != object;
676 case VLC_VAR_INTEGER:
677 ret = var_GetInteger(object, opt->name);
680 libvlc_exception_raise( p_e );
681 libvlc_printerr( "Invalid argument for %s in %s", name, "get int" );
685 vlc_object_release( object );
691 set_string( libvlc_media_player_t *p_mi, const char *name, const opt_t *opt,
692 const char *psz_value, libvlc_exception_t *p_e )
695 vlc_object_t *object = get_object( p_mi, name, p_e );
696 if( !object ) return;
701 var_SetString( object, opt->name, psz_value );
704 libvlc_exception_raise( p_e );
705 libvlc_printerr( "Invalid argument for %s in %s", name, "set string" );
708 vlc_object_release( object );
713 get_string( libvlc_media_player_t *p_mi, const char *name,
714 const opt_t *opt, libvlc_exception_t *p_e )
716 if( !opt ) return NULL;
717 vlc_object_t *object = get_object( p_mi, name, p_e );
718 if( !object ) return NULL;
724 ret = var_GetString( object, opt->name );
727 libvlc_exception_raise( p_e );
728 libvlc_printerr( "Invalid argument for %s in %s", name, "get string" );
732 vlc_object_release( object );
737 /*****************************************************************************
738 * Marquee: FIXME: That implementation has no persistent state and requires
740 *****************************************************************************/
743 marq_option_bynumber(unsigned option, libvlc_exception_t *p_e)
748 { "marq-marquee", VLC_VAR_STRING },
749 { "marq-color", VLC_VAR_INTEGER },
750 { "marq-opacity", VLC_VAR_INTEGER },
751 { "marq-position", VLC_VAR_INTEGER },
752 { "marq-refresh", VLC_VAR_INTEGER },
753 { "marq-size", VLC_VAR_INTEGER },
754 { "marq-timeout", VLC_VAR_INTEGER },
755 { "marq-x", VLC_VAR_INTEGER },
756 { "marq-y", VLC_VAR_INTEGER },
758 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
760 opt_t *r = option < num_opts ? optlist+option : NULL;
763 libvlc_exception_raise( p_e );
764 libvlc_printerr( "Unknown marquee option" );
769 static vlc_object_t *get_object( libvlc_media_player_t *,
770 const char *, libvlc_exception_t *);
772 /*****************************************************************************
773 * libvlc_video_get_marquee_int : get a marq option value
774 *****************************************************************************/
775 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
776 unsigned option, libvlc_exception_t *p_e )
778 return get_int( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
781 /*****************************************************************************
782 * libvlc_video_get_marquee_string : get a marq option value
783 *****************************************************************************/
784 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
785 unsigned option, libvlc_exception_t *p_e )
787 return get_string( p_mi, "marq", marq_option_bynumber(option,p_e), p_e );
790 /*****************************************************************************
791 * libvlc_video_set_marquee_int: enable, disable or set an int option
792 *****************************************************************************/
793 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
794 unsigned option, int value, libvlc_exception_t *p_e )
796 set_int( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
799 /*****************************************************************************
800 * libvlc_video_set_marquee_string: set a string option
801 *****************************************************************************/
802 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
803 unsigned option, const char * value, libvlc_exception_t *p_e )
805 set_string( p_mi, "marq", marq_option_bynumber(option,p_e), value, p_e );
809 /* logo module support */
813 logo_option_bynumber( unsigned option, libvlc_exception_t *p_e )
815 opt_t vlogo_optlist[] = /* depends on libvlc_video_logo_option_t */
818 { "logo-file", VLC_VAR_STRING },
819 { "logo-x", VLC_VAR_INTEGER },
820 { "logo-y", VLC_VAR_INTEGER },
821 { "logo-delay", VLC_VAR_INTEGER },
822 { "logo-repeat", VLC_VAR_INTEGER },
823 { "logo-opacity", VLC_VAR_INTEGER },
824 { "logo-position", VLC_VAR_INTEGER },
826 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
828 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
831 libvlc_exception_raise( p_e );
832 libvlc_printerr( "Unknown logo option" );
838 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
839 unsigned option, const char *psz_value,
840 libvlc_exception_t *p_e )
842 set_string( p_mi,"logo",logo_option_bynumber(option,p_e),psz_value,p_e );
846 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
847 unsigned option, int value,
848 libvlc_exception_t *p_e )
850 set_int( p_mi, "logo", logo_option_bynumber(option, p_e), value, p_e );
854 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
855 unsigned option, libvlc_exception_t *p_e )
857 return get_int( p_mi, "logo", logo_option_bynumber(option,p_e), p_e );