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 bool b_fullscreen = var_ToggleBool (p_mi, "fullscreen");
114 /* Apply to current video outputs (if any) */
116 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
117 for (size_t i = 0; i < n; i++)
119 vout_thread_t *p_vout = pp_vouts[i];
121 var_SetBool (p_vout, "fullscreen", b_fullscreen);
122 vlc_object_release (p_vout);
127 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
129 var_SetBool (p_mi, "keyboard-events", !!on);
132 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
134 var_SetBool (p_mi, "mouse-events", !!on);
138 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
139 const char *psz_filepath,
140 unsigned int i_width, unsigned int i_height )
142 assert( psz_filepath );
144 vout_thread_t *p_vout = GetVout (p_mi, num);
148 /* FIXME: This is not atomic. Someone else could change the values,
149 * at least in theory. */
150 var_SetInteger( p_vout, "snapshot-width", i_width);
151 var_SetInteger( p_vout, "snapshot-height", i_height );
152 var_SetString( p_vout, "snapshot-path", psz_filepath );
153 var_SetString( p_vout, "snapshot-format", "png" );
154 var_TriggerCallback (p_vout, "video-snapshot" );
158 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
159 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);
175 int libvlc_video_get_height( libvlc_media_player_t *p_mi )
177 unsigned height, width;
179 if (libvlc_video_get_size (p_mi, 0, &height, &width))
184 int libvlc_video_get_width( libvlc_media_player_t *p_mi )
186 unsigned height, width;
188 if (libvlc_video_get_size (p_mi, 0, &height, &width))
193 int libvlc_video_get_cursor( libvlc_media_player_t *mp, unsigned num,
194 int *restrict px, int *restrict py )
196 vout_thread_t *p_vout = GetVout (mp, num);
200 var_GetCoords (p_vout, "mouse-moved", px, py);
201 vlc_object_release (p_vout);
205 unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
208 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
209 for (size_t i = 0; i < n; i++)
210 vlc_object_release (pp_vouts[i]);
215 float libvlc_video_get_scale( libvlc_media_player_t *mp )
217 float f_scale = var_GetFloat (mp, "scale");
218 if (var_GetBool (mp, "autoscale"))
223 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
226 var_SetFloat (p_mp, "scale", f_scale);
227 var_SetBool (p_mp, "autoscale", f_scale != 0.);
229 /* Apply to current video outputs (if any) */
231 vout_thread_t **pp_vouts = GetVouts (p_mp, &n);
232 for (size_t i = 0; i < n; i++)
234 vout_thread_t *p_vout = pp_vouts[i];
237 var_SetFloat (p_vout, "scale", f_scale);
238 var_SetBool (p_mp, "autoscale", f_scale != 0.);
239 vlc_object_release (p_vout);
244 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi )
246 return var_GetNonEmptyString (p_mi, "aspect-ratio");
249 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
250 const char *psz_aspect )
252 if (psz_aspect == NULL)
254 var_SetString (p_mi, "aspect-ratio", psz_aspect);
257 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
258 for (size_t i = 0; i < n; i++)
260 vout_thread_t *p_vout = pp_vouts[i];
262 var_SetString (p_vout, "aspect-ratio", psz_aspect);
263 vlc_object_release (p_vout);
268 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
270 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
271 vlc_value_t val_list;
277 if( !p_input_thread )
279 libvlc_printerr( "No active input" );
283 i_ret = var_Get( p_input_thread, "spu-es", &val );
286 vlc_object_release( p_input_thread );
287 libvlc_printerr( "Subtitle informations not found" );
291 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
292 for( i = 0; i < val_list.p_list->i_count; i++ )
294 if( val.i_int == val_list.p_list->p_values[i].i_int )
300 var_FreeList( &val_list, NULL );
301 vlc_object_release( p_input_thread );
305 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi )
307 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
310 if( !p_input_thread )
313 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
314 vlc_object_release( p_input_thread );
318 libvlc_track_description_t *
319 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi )
321 return libvlc_get_track_description( p_mi, "spu-es" );
324 int libvlc_video_set_spu( libvlc_media_player_t *p_mi, unsigned i_spu )
326 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
330 if( !p_input_thread )
333 var_Change (p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list, NULL);
335 if (i_spu > (unsigned)list.p_list->i_count)
337 libvlc_printerr( "Subtitle number out of range (%u/%u)",
338 i_spu, list.p_list->i_count );
342 var_SetInteger (p_input_thread, "spu-es",
343 list.p_list->p_values[i_spu].i_int);
345 vlc_object_release (p_input_thread);
346 var_FreeList (&list, NULL);
350 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
351 const char *psz_subtitle )
353 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
358 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
360 vlc_object_release( p_input_thread );
365 libvlc_track_description_t *
366 libvlc_video_get_title_description( libvlc_media_player_t *p_mi )
368 return libvlc_get_track_description( p_mi, "title" );
371 libvlc_track_description_t *
372 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
376 sprintf( psz_title, "title %2i", i_title );
377 return libvlc_get_track_description( p_mi, psz_title );
380 char *libvlc_video_get_crop_geometry (libvlc_media_player_t *p_mi)
382 return var_GetNonEmptyString (p_mi, "crop");
385 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
386 const char *psz_geometry )
388 if (psz_geometry == NULL)
391 var_SetString (p_mi, "crop", psz_geometry);
394 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
396 for (size_t i = 0; i < n; i++)
398 vout_thread_t *p_vout = pp_vouts[i];
400 var_SetString (p_vout, "crop", psz_geometry);
401 vlc_object_release (p_vout);
406 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi )
408 return var_GetInteger (p_mi, "vbi-page");
411 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page )
413 input_thread_t *p_input_thread;
414 vlc_object_t *p_zvbi = NULL;
417 var_SetInteger (p_mi, "vbi-page", i_page);
419 p_input_thread = libvlc_get_input_thread( p_mi );
420 if( !p_input_thread ) return;
422 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
424 vlc_object_release( p_input_thread );
428 telx = var_GetInteger( p_input_thread, "teletext-es" );
429 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
432 var_SetInteger( p_zvbi, "vbi-page", i_page );
433 vlc_object_release( p_zvbi );
435 vlc_object_release( p_input_thread );
438 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
440 input_thread_t *p_input_thread;
442 p_input_thread = libvlc_get_input_thread(p_mi);
443 if( !p_input_thread ) return;
445 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
447 vlc_object_release( p_input_thread );
450 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
453 var_SetInteger( p_input_thread, "spu-es", -1 );
458 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
460 if( list.p_list->i_count > 0 )
461 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
463 var_FreeList( &list, NULL );
466 vlc_object_release( p_input_thread );
469 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
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 )
486 return libvlc_get_track_description( p_mi, "video-es" );
489 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
491 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
492 vlc_value_t val_list;
496 if( !p_input_thread )
499 if( var_Get( p_input_thread, "video-es", &val ) < 0 )
501 libvlc_printerr( "Video track information not found" );
502 vlc_object_release( p_input_thread );
506 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
507 for( int i = 0; i < val_list.p_list->i_count; i++ )
509 if( val_list.p_list->p_values[i].i_int == val.i_int )
515 var_FreeList( &val_list, NULL );
516 vlc_object_release( p_input_thread );
520 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
522 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
523 vlc_value_t val_list;
526 if( !p_input_thread )
529 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
530 for( int i = 0; i < val_list.p_list->i_count; i++ )
532 if( i_track == val_list.p_list->p_values[i].i_int )
534 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
540 libvlc_printerr( "Video track number out of range" );
542 var_FreeList( &val_list, NULL );
543 vlc_object_release( p_input_thread );
547 /******************************************************************************
548 * libvlc_video_set_deinterlace : enable deinterlace
549 *****************************************************************************/
550 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi,
551 const char *psz_mode )
553 if (psz_mode == NULL)
556 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
557 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
558 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
559 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x"))
564 var_SetString (p_mi, "deinterlace-mode", psz_mode);
565 var_SetInteger (p_mi, "deinterlace", 1);
568 var_SetInteger (p_mi, "deinterlace", 0);
571 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
572 for (size_t i = 0; i < n; i++)
574 vout_thread_t *p_vout = pp_vouts[i];
578 var_SetString (p_vout, "deinterlace-mode", psz_mode);
579 var_SetInteger (p_vout, "deinterlace", 1);
582 var_SetInteger (p_vout, "deinterlace", 0);
583 vlc_object_release (p_vout);
593 static vlc_object_t *get_object( libvlc_media_player_t * p_mi,
596 vlc_object_t *object;
597 vout_thread_t *vout = GetVout( p_mi, 0 );
601 object = vlc_object_find_name( vout, name, FIND_CHILD );
602 vlc_object_release(vout);
608 libvlc_printerr( "%s not enabled", name );
613 typedef const struct {
620 set_int( libvlc_media_player_t *p_mi, const char *restrict name,
621 const opt_t *restrict opt, int value )
625 if( !opt->type ) /* the enabler */
627 vout_thread_t *vout = GetVout( p_mi, 0 );
630 vout_EnableFilter( vout, opt->name, value, false );
631 vlc_object_release( vout );
636 if( opt->type != VLC_VAR_INTEGER )
638 libvlc_printerr( "Invalid argument to %s in %s", name, "set int" );
642 var_SetInteger(p_mi, opt->name, value);
643 vlc_object_t *object = get_object( p_mi, name );
646 var_SetInteger(object, opt->name, value);
647 vlc_object_release( object );
653 get_int( libvlc_media_player_t *p_mi, const char *restrict name,
654 const opt_t *restrict opt )
660 case 0: /* the enabler */
662 vlc_object_t *object = get_object( p_mi, name );
663 vlc_object_release( object );
664 return object != NULL;
666 case VLC_VAR_INTEGER:
667 return var_GetInteger(p_mi, opt->name);
669 libvlc_printerr( "Invalid argument to %s in %s", name, "get int" );
676 set_string( libvlc_media_player_t *p_mi, const char *restrict name,
677 const opt_t *restrict opt, const char *restrict psz_value )
681 if( opt->type != VLC_VAR_STRING )
683 libvlc_printerr( "Invalid argument to %s in %s", name, "set string" );
687 var_SetString( p_mi, opt->name, psz_value );
689 vlc_object_t *object = get_object( p_mi, name );
692 var_SetString(object, opt->name, psz_value );
693 vlc_object_release( object );
699 get_string( libvlc_media_player_t *p_mi, const char *restrict name,
700 const opt_t *restrict opt )
702 if( !opt ) return NULL;
704 if( opt->type != VLC_VAR_STRING )
706 libvlc_printerr( "Invalid argument to %s in %s", name, "get string" );
710 return var_GetString( p_mi, opt->name );
715 marq_option_bynumber(unsigned option)
717 static const opt_t optlist[] =
720 { "marq-marquee", VLC_VAR_STRING },
721 { "marq-color", VLC_VAR_INTEGER },
722 { "marq-opacity", VLC_VAR_INTEGER },
723 { "marq-position", VLC_VAR_INTEGER },
724 { "marq-refresh", VLC_VAR_INTEGER },
725 { "marq-size", VLC_VAR_INTEGER },
726 { "marq-timeout", VLC_VAR_INTEGER },
727 { "marq-x", VLC_VAR_INTEGER },
728 { "marq-y", VLC_VAR_INTEGER },
730 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
732 opt_t *r = option < num_opts ? optlist+option : NULL;
734 libvlc_printerr( "Unknown marquee option" );
738 static vlc_object_t *get_object( libvlc_media_player_t *, const char *);
740 /*****************************************************************************
741 * libvlc_video_get_marquee_int : get a marq option value
742 *****************************************************************************/
743 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
746 return get_int( p_mi, "marq", marq_option_bynumber(option) );
749 /*****************************************************************************
750 * libvlc_video_get_marquee_string : get a marq option value
751 *****************************************************************************/
752 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
755 return get_string( p_mi, "marq", marq_option_bynumber(option) );
758 /*****************************************************************************
759 * libvlc_video_set_marquee_int: enable, disable or set an int option
760 *****************************************************************************/
761 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
762 unsigned option, int value )
764 set_int( p_mi, "marq", marq_option_bynumber(option), value );
767 /*****************************************************************************
768 * libvlc_video_set_marquee_string: set a string option
769 *****************************************************************************/
770 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
771 unsigned option, const char * value )
773 set_string( p_mi, "marq", marq_option_bynumber(option), value );
777 /* logo module support */
781 logo_option_bynumber( unsigned option )
783 static const opt_t vlogo_optlist[] =
784 /* depends on libvlc_video_logo_option_t */
787 { "logo-file", VLC_VAR_STRING },
788 { "logo-x", VLC_VAR_INTEGER },
789 { "logo-y", VLC_VAR_INTEGER },
790 { "logo-delay", VLC_VAR_INTEGER },
791 { "logo-repeat", VLC_VAR_INTEGER },
792 { "logo-opacity", VLC_VAR_INTEGER },
793 { "logo-position", VLC_VAR_INTEGER },
795 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
797 opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
799 libvlc_printerr( "Unknown logo option" );
804 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
805 unsigned option, const char *psz_value )
807 set_string( p_mi,"logo",logo_option_bynumber(option),psz_value );
811 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
812 unsigned option, int value )
814 set_int( p_mi, "logo", logo_option_bynumber(option), value );
818 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
821 return get_int( p_mi, "logo", logo_option_bynumber(option) );