1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005 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 *****************************************************************************/
28 #include <vlc/libvlc.h>
29 #include <vlc/libvlc_media.h>
30 #include <vlc/libvlc_media_player.h>
32 #include <vlc_common.h>
33 #include <vlc_input.h>
36 #include "media_player_internal.h"
40 * Remember to release the returned vout_thread_t.
42 static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
43 libvlc_exception_t *p_exception )
45 input_thread_t *p_input = libvlc_get_input_thread( p_mi, p_exception );
46 vout_thread_t *p_vout = NULL;
50 p_vout = input_GetVout( p_input );
53 libvlc_exception_raise( p_exception, "No active video output" );
55 vlc_object_release( p_input );
60 /**********************************************************************
62 **********************************************************************/
64 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
65 libvlc_exception_t *p_e )
67 /* We only work on the first vout */
68 vout_thread_t *p_vout = GetVout( p_mi, p_e );
70 /* GetVout will raise the exception for us */
73 var_SetBool( p_vout, "fullscreen", b_fullscreen );
75 vlc_object_release( p_vout );
78 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
79 libvlc_exception_t *p_e )
81 /* We only work on the first vout */
82 vout_thread_t *p_vout = GetVout( p_mi, p_e );
85 /* GetVout will raise the exception for us */
86 if( !p_vout ) return 0;
88 i_ret = var_GetBool( p_vout, "fullscreen" );
90 vlc_object_release( p_vout );
95 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
96 libvlc_exception_t *p_e )
98 /* We only work on the first vout */
99 vout_thread_t *p_vout = GetVout( p_mi, p_e );
101 /* GetVout will raise the exception for us */
102 if( !p_vout ) return;
104 var_ToggleBool( p_vout, "fullscreen" );
106 vlc_object_release( p_vout );
110 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
111 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
113 vout_thread_t *p_vout;
115 /* The filepath must be not NULL */
118 libvlc_exception_raise( p_e, "filepath is null" );
121 /* We must have an input */
122 if( !p_mi->p_input_thread )
124 libvlc_exception_raise( p_e, "Input does not exist" );
128 /* GetVout will raise the exception for us */
129 p_vout = GetVout( p_mi, p_e );
130 if( !p_vout ) return;
132 var_SetInteger( p_vout, "snapshot-width", i_width );
133 var_SetInteger( p_vout, "snapshot-height", i_height );
135 var_SetString( p_vout, "snapshot-path", psz_filepath );
136 var_SetString( p_vout, "snapshot-format", "png" );
138 var_TriggerCallback( p_vout, "video-snapshot" );
139 vlc_object_release( p_vout );
142 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
143 libvlc_exception_t *p_e )
147 vout_thread_t *p_vout = GetVout( p_mi, p_e );
148 if( !p_vout ) return 0;
150 height = p_vout->i_window_height;
152 vlc_object_release( p_vout );
157 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
158 libvlc_exception_t *p_e )
162 vout_thread_t *p_vout = GetVout( p_mi, p_e );
163 if( !p_vout ) return 0;
165 width = p_vout->i_window_width;
167 vlc_object_release( p_vout );
172 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
173 libvlc_exception_t *p_e )
175 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
176 bool has_vout = false;
180 vout_thread_t *p_vout;
182 p_vout = input_GetVout( p_input_thread );
186 vlc_object_release( p_vout );
188 vlc_object_release( p_input_thread );
193 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
194 libvlc_exception_t *p_e )
196 vout_thread_t *p_vout = GetVout( p_mp, p_e );
200 float f_scale = var_GetFloat( p_vout, "scale" );
201 if( var_GetBool( p_vout, "autoscale" ) )
203 vlc_object_release( p_vout );
207 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
208 libvlc_exception_t *p_e )
210 vout_thread_t *p_vout = GetVout( p_mp, p_e );
215 var_SetFloat( p_vout, "scale", f_scale );
216 var_SetBool( p_vout, "autoscale", f_scale != 0. );
217 vlc_object_release( p_vout );
220 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
221 libvlc_exception_t *p_e )
223 char *psz_aspect = NULL;
224 vout_thread_t *p_vout = GetVout( p_mi, p_e );
226 if( !p_vout ) return NULL;
228 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
229 vlc_object_release( p_vout );
230 return psz_aspect ? psz_aspect : strdup("");
233 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
234 const char *psz_aspect, libvlc_exception_t *p_e )
236 vout_thread_t *p_vout = GetVout( p_mi, p_e );
239 if( !p_vout ) return;
241 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
243 libvlc_exception_raise( p_e,
244 "Unexpected error while setting aspect-ratio value" );
246 vlc_object_release( p_vout );
249 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
250 libvlc_exception_t *p_e )
252 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
253 vlc_value_t val_list;
259 if( !p_input_thread ) return -1;
261 i_ret = var_Get( p_input_thread, "spu-es", &val );
264 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
265 vlc_object_release( p_input_thread );
269 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
270 for( i = 0; i < val_list.p_list->i_count; i++ )
272 if( val.i_int == val_list.p_list->p_values[i].i_int )
278 var_FreeList( &val_list, NULL );
279 vlc_object_release( p_input_thread );
283 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
284 libvlc_exception_t *p_e )
286 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
289 if( !p_input_thread )
292 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
294 vlc_object_release( p_input_thread );
298 libvlc_track_description_t *
299 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
300 libvlc_exception_t *p_e )
302 return libvlc_get_track_description( p_mi, "spu-es", p_e);
305 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
306 libvlc_exception_t *p_e )
308 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
309 vlc_value_t val_list;
313 if( !p_input_thread ) return;
315 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
317 if( val_list.p_list->i_count == 0 )
319 libvlc_exception_raise( p_e, "Subtitle value out of range" );
323 if( (i_spu < 0) || (i_spu > val_list.p_list->i_count) )
325 libvlc_exception_raise( p_e, "Subtitle value out of range" );
329 newval = val_list.p_list->p_values[i_spu];
330 i_ret = var_Set( p_input_thread, "spu-es", newval );
333 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
337 var_FreeList( &val_list, NULL );
338 vlc_object_release( p_input_thread );
341 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
342 const char *psz_subtitle,
343 libvlc_exception_t *p_e )
345 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
350 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
352 vlc_object_release( p_input_thread );
357 libvlc_track_description_t *
358 libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
359 libvlc_exception_t * p_e )
361 return libvlc_get_track_description( p_mi, "title", p_e);
364 libvlc_track_description_t *
365 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
367 libvlc_exception_t *p_e )
370 sprintf( psz_title, "title %2i", i_title );
371 return libvlc_get_track_description( p_mi, psz_title, p_e);
374 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
375 libvlc_exception_t *p_e )
377 char *psz_geometry = 0;
378 vout_thread_t *p_vout = GetVout( p_mi, p_e );
380 if( !p_vout ) return 0;
382 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
383 vlc_object_release( p_vout );
384 return psz_geometry ? psz_geometry : strdup("");
387 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
388 const char *psz_geometry, libvlc_exception_t *p_e )
390 vout_thread_t *p_vout = GetVout( p_mi, p_e );
393 if( !p_vout ) return;
395 i_ret = var_SetString( p_vout, "crop", psz_geometry );
397 libvlc_exception_raise( p_e,
398 "Unexpected error while setting crop geometry" );
400 vlc_object_release( p_vout );
403 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
404 libvlc_exception_t *p_e )
406 vout_thread_t *p_vout = GetVout( p_mi, p_e );
410 if( !p_vout ) return i_ret;
412 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
416 i_ret = var_GetInteger( p_vbi, "vbi-page" );
417 vlc_object_release( p_vbi );
420 vlc_object_release( p_vout );
424 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
425 libvlc_exception_t *p_e )
427 vout_thread_t *p_vout = GetVout( p_mi, p_e );
431 if( !p_vout ) return;
433 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
437 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
438 vlc_object_release( p_vbi );
440 libvlc_exception_raise( p_e,
441 "Unexpected error while setting teletext page" );
443 vlc_object_release( p_vout );
446 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
447 libvlc_exception_t *p_e )
449 input_thread_t *p_input_thread;
453 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
454 if( !p_input_thread ) return;
456 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
458 vlc_object_release( p_input_thread );
461 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
463 p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
469 /* FIXME Gni, why that ? */
470 i_ret = var_SetInteger( p_vbi, "vbi-page",
471 var_GetInteger( p_vbi, "vbi-page" ) );
473 libvlc_exception_raise( p_e,
474 "Unexpected error while setting teletext page" );
479 i_ret = var_SetBool( p_vbi, "vbi-opaque",
480 !var_GetBool( p_vbi, "vbi-opaque" ) );
482 libvlc_exception_raise( p_e,
483 "Unexpected error while setting teletext transparency" );
485 vlc_object_release( p_vbi );
487 else if( b_selected )
489 var_SetInteger( p_input_thread, "spu-es", -1 );
494 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
496 if( list.p_list->i_count > 0 )
497 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
499 var_FreeList( &list, NULL );
502 vlc_object_release( p_input_thread );
505 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
506 libvlc_exception_t *p_e )
508 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
511 if( !p_input_thread )
514 i_track_count = var_CountChoices( p_input_thread, "video-es" );
516 vlc_object_release( p_input_thread );
517 return i_track_count;
520 libvlc_track_description_t *
521 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
522 libvlc_exception_t *p_e )
524 return libvlc_get_track_description( p_mi, "video-es", p_e);
527 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
528 libvlc_exception_t *p_e )
530 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
531 vlc_value_t val_list;
537 if( !p_input_thread )
540 i_ret = var_Get( p_input_thread, "video-es", &val );
543 libvlc_exception_raise( p_e, "Getting Video track information failed" );
544 vlc_object_release( p_input_thread );
548 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
549 for( i = 0; i < val_list.p_list->i_count; i++ )
551 if( val_list.p_list->p_values[i].i_int == val.i_int )
557 var_FreeList( &val_list, NULL );
558 vlc_object_release( p_input_thread );
562 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
563 libvlc_exception_t *p_e )
565 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
566 vlc_value_t val_list;
570 if( !p_input_thread )
573 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
574 for( i = 0; i < val_list.p_list->i_count; i++ )
576 vlc_value_t val = val_list.p_list->p_values[i];
577 if( i_track == val.i_int )
579 i_ret = var_Set( p_input_thread, "video-es", val );
581 libvlc_exception_raise( p_e, "Setting video track failed" );
585 libvlc_exception_raise( p_e, "Video track out of range" );
588 var_FreeList( &val_list, NULL );
589 vlc_object_release( p_input_thread );
592 /******************************************************************************
593 * libvlc_video_set_deinterlace : enable deinterlace
594 *****************************************************************************/
595 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
596 const char *psz_mode,
597 libvlc_exception_t *p_e )
599 vout_thread_t *p_vout = GetVout( p_mi, p_e );
603 libvlc_exception_raise( p_e, "Unable to get video output" );
609 /* be sure that the filter name given is supported */
610 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
611 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
612 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x") )
614 /* set deinterlace filter chosen */
615 var_SetString( p_vout, "deinterlace", psz_mode );
619 libvlc_exception_raise( p_e, "Unsuported or bad deinterlace filter name" );
624 /* disable deinterlace filter */
625 var_SetString( p_vout, "deinterlace", "" );
628 vlc_object_release( p_vout );
631 /*****************************************************************************
632 * Marquee: FIXME: That implementation has no persistent state and requires
634 *****************************************************************************/
636 static const char *get_marquee_int_option_identifier(unsigned option)
638 static const char tab[][16] =
650 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
655 static const char *get_marquee_string_option_identifier(unsigned option)
657 static const char tab[][16] =
661 if( option >= sizeof( tab ) / sizeof( tab[0] ) )
667 static vlc_object_t *get_marquee_object( libvlc_media_player_t * p_mi )
669 libvlc_exception_t e;
670 libvlc_exception_init(&e);
671 vout_thread_t * vout = GetVout( p_mi, &e );
672 libvlc_exception_clear(&e);
675 vlc_object_t * object = vlc_object_find_name( vout, "marq", FIND_CHILD );
676 vlc_object_release(vout);
680 /*****************************************************************************
681 * libvlc_video_get_marquee_option_as_int : get a marq option value
682 *****************************************************************************/
683 int libvlc_video_get_marquee_option_as_int( libvlc_media_player_t *p_mi,
684 libvlc_video_marquee_int_option_t option,
685 libvlc_exception_t *p_e )
687 const char * identifier = get_marquee_int_option_identifier(option);
690 libvlc_exception_raise( p_e, "This option is not available" );
693 vlc_object_t * marquee = get_marquee_object(p_mi);
695 /* Handle the libvlc_marquee_Enabled separately */
696 if(option == libvlc_marquee_Enabled)
698 bool isEnabled = marquee != NULL;
699 vlc_object_release(marquee);
706 libvlc_exception_raise( p_e, "Marquee is not enabled" );
709 int ret = var_GetInteger(marquee, identifier);
710 vlc_object_release(marquee);
714 /*****************************************************************************
715 * libvlc_video_get_marquee_option_as_string : get a marq option value
716 *****************************************************************************/
717 char * libvlc_video_get_marquee_option_as_string( libvlc_media_player_t *p_mi,
718 libvlc_video_marquee_string_option_t option,
719 libvlc_exception_t *p_e )
721 const char * identifier = get_marquee_string_option_identifier(option);
724 libvlc_exception_raise( p_e, "This option is not available" );
728 vlc_object_t * marquee = get_marquee_object(p_mi);
731 libvlc_exception_raise( p_e, "Marquee is not enabled" );
734 char *ret = var_GetString(marquee, identifier);
735 vlc_object_release(marquee);
739 /*****************************************************************************
740 * libvlc_video_set_marquee_option_as_int: enable, disable or set an int option
741 *****************************************************************************/
742 void libvlc_video_set_marquee_option_as_int( libvlc_media_player_t *p_mi,
743 libvlc_video_marquee_int_option_t option,
744 int value, libvlc_exception_t *p_e )
746 const char * identifier = get_marquee_int_option_identifier(option);
749 libvlc_exception_raise( p_e, "This option is not available" );
753 /* Handle the libvlc_marquee_Enabled separately */
754 if(option == libvlc_marquee_Enabled)
756 libvlc_exception_t e;
757 libvlc_exception_init(&e);
758 vout_thread_t * vout = GetVout( p_mi, &e );
759 libvlc_exception_clear(&e);
762 vout_EnableFilter(vout, identifier, value, false);
763 vlc_object_release(vout);
767 libvlc_exception_raise( p_e, "No Vout" );
772 vlc_object_t * marquee = get_marquee_object(p_mi);
775 libvlc_exception_raise( p_e, "Marquee is not enabled" );
778 var_SetInteger(marquee, identifier, value);
779 vlc_object_release(marquee);
782 /*****************************************************************************
783 * libvlc_video_set_marquee_option_as_string: set a string option
784 *****************************************************************************/
785 void libvlc_video_set_marquee_option_as_string( libvlc_media_player_t *p_mi,
786 libvlc_video_marquee_string_option_t option,
788 libvlc_exception_t *p_e )
790 const char * identifier = get_marquee_string_option_identifier(option);
793 libvlc_exception_raise( p_e, "This option is not available" );
796 vlc_object_t * marquee = get_marquee_object(p_mi);
799 libvlc_exception_raise( p_e, "Marquee is not enabled" );
802 var_SetString(marquee, identifier, value);
803 vlc_object_release(marquee);