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"
39 * Remember to release the returned vout_thread_t.
41 static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
42 libvlc_exception_t *p_exception )
44 input_thread_t *p_input = libvlc_get_input_thread( p_mi, p_exception );
45 vout_thread_t *p_vout = NULL;
49 p_vout = input_GetVout( p_input );
52 libvlc_exception_raise( p_exception, "No active video output" );
54 vlc_object_release( p_input );
59 /**********************************************************************
61 **********************************************************************/
63 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
64 libvlc_exception_t *p_e )
66 /* We only work on the first vout */
67 vout_thread_t *p_vout = GetVout( p_mi, p_e );
69 /* GetVout will raise the exception for us */
72 var_SetBool( p_vout, "fullscreen", b_fullscreen );
74 vlc_object_release( p_vout );
77 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
78 libvlc_exception_t *p_e )
80 /* We only work on the first vout */
81 vout_thread_t *p_vout = GetVout( p_mi, p_e );
84 /* GetVout will raise the exception for us */
85 if( !p_vout ) return 0;
87 i_ret = var_GetBool( p_vout, "fullscreen" );
89 vlc_object_release( p_vout );
94 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
95 libvlc_exception_t *p_e )
97 /* We only work on the first vout */
98 vout_thread_t *p_vout = GetVout( p_mi, p_e );
101 /* GetVout will raise the exception for us */
102 if( !p_vout ) return;
104 ret = var_GetBool( p_vout, "fullscreen" );
105 var_SetBool( p_vout, "fullscreen", !ret );
107 vlc_object_release( p_vout );
111 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
112 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
114 vout_thread_t *p_vout;
116 /* The filepath must be not NULL */
119 libvlc_exception_raise( p_e, "filepath is null" );
122 /* We must have an input */
123 if( !p_mi->p_input_thread )
125 libvlc_exception_raise( p_e, "Input does not exist" );
129 /* GetVout will raise the exception for us */
130 p_vout = GetVout( p_mi, p_e );
131 if( !p_vout ) return;
133 var_SetInteger( p_vout, "snapshot-width", i_width );
134 var_SetInteger( p_vout, "snapshot-height", i_height );
136 var_SetString( p_vout, "snapshot-path", psz_filepath );
137 var_SetString( p_vout, "snapshot-format", "png" );
139 var_TriggerCallback( p_vout, "video-snapshot" );
140 vlc_object_release( p_vout );
143 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
144 libvlc_exception_t *p_e )
148 vout_thread_t *p_vout = GetVout( p_mi, p_e );
149 if( !p_vout ) return 0;
151 height = p_vout->i_window_height;
153 vlc_object_release( p_vout );
158 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
159 libvlc_exception_t *p_e )
163 vout_thread_t *p_vout = GetVout( p_mi, p_e );
164 if( !p_vout ) return 0;
166 width = p_vout->i_window_width;
168 vlc_object_release( p_vout );
173 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
174 libvlc_exception_t *p_e )
176 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
177 bool has_vout = false;
181 vout_thread_t *p_vout;
183 p_vout = input_GetVout( p_input_thread );
187 vlc_object_release( p_vout );
189 vlc_object_release( p_input_thread );
194 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
195 libvlc_exception_t *p_e )
197 vout_thread_t *p_vout = GetVout( p_mp, p_e );
201 float f_scale = var_GetFloat( p_vout, "scale" );
202 if( var_GetBool( p_vout, "autoscale" ) )
204 vlc_object_release( p_vout );
208 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
209 libvlc_exception_t *p_e )
211 vout_thread_t *p_vout = GetVout( p_mp, p_e );
216 var_SetFloat( p_vout, "scale", f_scale );
217 var_SetBool( p_vout, "autoscale", f_scale != 0. );
218 vlc_object_release( p_vout );
221 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
222 libvlc_exception_t *p_e )
224 char *psz_aspect = 0;
225 vout_thread_t *p_vout = GetVout( p_mi, p_e );
227 if( !p_vout ) return 0;
229 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
230 vlc_object_release( p_vout );
231 return psz_aspect ? psz_aspect : strdup("");
234 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
235 char *psz_aspect, libvlc_exception_t *p_e )
237 vout_thread_t *p_vout = GetVout( p_mi, p_e );
240 if( !p_vout ) return;
242 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
244 libvlc_exception_raise( p_e,
245 "Unexpected error while setting aspect-ratio value" );
247 vlc_object_release( p_vout );
250 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
251 libvlc_exception_t *p_e )
253 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
254 vlc_value_t val_list;
260 if( !p_input_thread ) return -1;
262 i_ret = var_Get( p_input_thread, "spu-es", &val );
265 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
266 vlc_object_release( p_input_thread );
270 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
271 for( i = 0; i < val_list.p_list->i_count; i++ )
273 if( val.i_int == val_list.p_list->p_values[i].i_int )
279 var_FreeList( &val_list, NULL );
280 vlc_object_release( p_input_thread );
284 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
285 libvlc_exception_t *p_e )
287 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
290 if( !p_input_thread )
293 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
295 vlc_object_release( p_input_thread );
299 libvlc_track_description_t *
300 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
301 libvlc_exception_t *p_e )
303 return libvlc_get_track_description( p_mi, "spu-es", p_e);
306 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
307 libvlc_exception_t *p_e )
309 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
310 vlc_value_t val_list;
314 if( !p_input_thread ) return;
316 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
318 if( val_list.p_list->i_count == 0 )
320 libvlc_exception_raise( p_e, "Subtitle value out of range" );
324 if( (i_spu < 0) && (i_spu > val_list.p_list->i_count) )
326 libvlc_exception_raise( p_e, "Subtitle value out of range" );
330 newval = val_list.p_list->p_values[i_spu];
331 i_ret = var_Set( p_input_thread, "spu-es", newval );
334 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
338 var_FreeList( &val_list, NULL );
339 vlc_object_release( p_input_thread );
342 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
344 libvlc_exception_t *p_e )
346 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
351 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
353 vlc_object_release( p_input_thread );
358 libvlc_track_description_t *
359 libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
360 libvlc_exception_t * p_e )
362 return libvlc_get_track_description( p_mi, "title", p_e);
365 libvlc_track_description_t *
366 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
368 libvlc_exception_t *p_e )
371 sprintf( psz_title, "title %2i", i_title );
372 return libvlc_get_track_description( p_mi, psz_title, p_e);
375 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
376 libvlc_exception_t *p_e )
378 char *psz_geometry = 0;
379 vout_thread_t *p_vout = GetVout( p_mi, p_e );
381 if( !p_vout ) return 0;
383 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
384 vlc_object_release( p_vout );
385 return psz_geometry ? psz_geometry : strdup("");
388 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
389 char *psz_geometry, libvlc_exception_t *p_e )
391 vout_thread_t *p_vout = GetVout( p_mi, p_e );
394 if( !p_vout ) return;
396 i_ret = var_SetString( p_vout, "crop", psz_geometry );
398 libvlc_exception_raise( p_e,
399 "Unexpected error while setting crop geometry" );
401 vlc_object_release( p_vout );
404 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
405 libvlc_exception_t *p_e )
407 vout_thread_t *p_vout = GetVout( p_mi, p_e );
411 if( !p_vout ) return i_ret;
413 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
417 i_ret = var_GetInteger( p_vbi, "vbi-page" );
418 vlc_object_release( p_vbi );
421 vlc_object_release( p_vout );
425 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
426 libvlc_exception_t *p_e )
428 vout_thread_t *p_vout = GetVout( p_mi, p_e );
432 if( !p_vout ) return;
434 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
438 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
439 vlc_object_release( p_vbi );
441 libvlc_exception_raise( p_e,
442 "Unexpected error while setting teletext page" );
444 vlc_object_release( p_vout );
447 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
448 libvlc_exception_t *p_e )
450 input_thread_t *p_input_thread;
454 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
455 if( !p_input_thread ) return;
457 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
459 vlc_object_release( p_input_thread );
462 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
464 p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
470 /* FIXME Gni, why that ? */
471 i_ret = var_SetInteger( p_vbi, "vbi-page",
472 var_GetInteger( p_vbi, "vbi-page" ) );
474 libvlc_exception_raise( p_e,
475 "Unexpected error while setting teletext page" );
480 i_ret = var_SetBool( p_vbi, "vbi-opaque",
481 !var_GetBool( p_vbi, "vbi-opaque" ) );
483 libvlc_exception_raise( p_e,
484 "Unexpected error while setting teletext transparency" );
486 vlc_object_release( p_vbi );
488 else if( b_selected )
490 var_SetInteger( p_input_thread, "spu-es", -1 );
495 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
497 if( list.p_list->i_count > 0 )
498 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
500 var_FreeList( &list, NULL );
503 vlc_object_release( p_input_thread );
506 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
507 libvlc_exception_t *p_e )
509 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
512 if( !p_input_thread )
515 i_track_count = var_CountChoices( p_input_thread, "video-es" );
517 vlc_object_release( p_input_thread );
518 return i_track_count;
521 libvlc_track_description_t *
522 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
523 libvlc_exception_t *p_e )
525 return libvlc_get_track_description( p_mi, "video-es", p_e);
528 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
529 libvlc_exception_t *p_e )
531 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
532 vlc_value_t val_list;
538 if( !p_input_thread )
541 i_ret = var_Get( p_input_thread, "video-es", &val );
544 libvlc_exception_raise( p_e, "Getting Video track information failed" );
545 vlc_object_release( p_input_thread );
549 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
550 for( i = 0; i < val_list.p_list->i_count; i++ )
552 if( val_list.p_list->p_values[i].i_int == val.i_int )
558 var_FreeList( &val_list, NULL );
559 vlc_object_release( p_input_thread );
563 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
564 libvlc_exception_t *p_e )
566 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
567 vlc_value_t val_list;
571 if( !p_input_thread )
574 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
575 for( i = 0; i < val_list.p_list->i_count; i++ )
577 vlc_value_t val = val_list.p_list->p_values[i];
578 if( i_track == val.i_int )
580 i_ret = var_Set( p_input_thread, "audio-es", val );
582 libvlc_exception_raise( p_e, "Setting video track failed" );
586 libvlc_exception_raise( p_e, "Video track out of range" );
589 var_FreeList( &val_list, NULL );
590 vlc_object_release( p_input_thread );
593 /******************************************************************************
594 * libvlc_video_set_deinterlace : enable deinterlace
595 *****************************************************************************/
596 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int b_enable,
597 const char *psz_mode,
598 libvlc_exception_t *p_e )
600 vout_thread_t *p_vout = GetVout( p_mi, p_e );
604 libvlc_exception_raise( p_e, "Unable to get video output" );
610 /* be sure that the filter name given is supported */
611 if( !strcmp(psz_mode, "blend") || !strcmp(psz_mode, "bob")
612 || !strcmp(psz_mode, "discard") || !strcmp(psz_mode, "linear")
613 || !strcmp(psz_mode, "mean") || !strcmp(psz_mode, "x") )
615 /* set deinterlace filter chosen */
616 var_SetString( p_vout, "deinterlace", psz_mode );
620 libvlc_exception_raise( p_e, "Unsuported or bad deinterlace filter name" );
625 /* disable deinterlace filter */
626 var_SetString( p_vout, "deinterlace", "" );
629 vlc_object_release( p_vout );