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 "libvlc_internal.h"
30 #include <vlc/libvlc.h>
31 #include <vlc_input.h>
35 * Remember to release the returned vout_thread_t.
37 static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
38 libvlc_exception_t *p_exception )
40 input_thread_t *p_input = libvlc_get_input_thread( p_mi, p_exception );
41 vout_thread_t *p_vout = NULL;
45 p_vout = input_GetVout( p_input );
48 libvlc_exception_raise( p_exception, "No active video output" );
50 vlc_object_release( p_input );
55 /**********************************************************************
57 **********************************************************************/
59 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
60 libvlc_exception_t *p_e )
62 /* We only work on the first vout */
63 vout_thread_t *p_vout = GetVout( p_mi, p_e );
65 /* GetVout will raise the exception for us */
68 var_SetBool( p_vout, "fullscreen", b_fullscreen );
70 vlc_object_release( p_vout );
73 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
74 libvlc_exception_t *p_e )
76 /* We only work on the first vout */
77 vout_thread_t *p_vout = GetVout( p_mi, p_e );
80 /* GetVout will raise the exception for us */
81 if( !p_vout ) return 0;
83 i_ret = var_GetBool( p_vout, "fullscreen" );
85 vlc_object_release( p_vout );
90 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
91 libvlc_exception_t *p_e )
93 /* We only work on the first vout */
94 vout_thread_t *p_vout = GetVout( p_mi, p_e );
97 /* GetVout will raise the exception for us */
100 ret = var_GetBool( p_vout, "fullscreen" );
101 var_SetBool( p_vout, "fullscreen", !ret );
103 vlc_object_release( p_vout );
107 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
108 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
110 vout_thread_t *p_vout;
112 /* The filepath must be not NULL */
115 libvlc_exception_raise( p_e, "filepath is null" );
118 /* We must have an input */
119 if( !p_mi->p_input_thread )
121 libvlc_exception_raise( p_e, "Input does not exist" );
125 /* GetVout will raise the exception for us */
126 p_vout = GetVout( p_mi, p_e );
127 if( !p_vout ) return;
129 var_SetInteger( p_vout, "snapshot-width", i_width );
130 var_SetInteger( p_vout, "snapshot-height", i_height );
132 var_SetString( p_vout, "snapshot-path", psz_filepath );
133 var_SetString( p_vout, "snapshot-format", "png" );
135 var_TriggerCallback( p_vout, "video-snapshot" );
136 vlc_object_release( p_vout );
139 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
140 libvlc_exception_t *p_e )
144 vout_thread_t *p_vout = GetVout( p_mi, p_e );
145 if( !p_vout ) return 0;
147 height = p_vout->i_window_height;
149 vlc_object_release( p_vout );
154 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
155 libvlc_exception_t *p_e )
159 vout_thread_t *p_vout = GetVout( p_mi, p_e );
160 if( !p_vout ) return 0;
162 width = p_vout->i_window_width;
164 vlc_object_release( p_vout );
169 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
170 libvlc_exception_t *p_e )
172 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
173 bool has_vout = false;
177 vout_thread_t *p_vout;
179 p_vout = input_GetVout( p_input_thread );
183 vlc_object_release( p_vout );
185 vlc_object_release( p_input_thread );
190 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
191 libvlc_exception_t *p_e )
193 vout_thread_t *p_vout = GetVout( p_mp, p_e );
197 float f_scale = var_GetFloat( p_vout, "scale" );
198 if( var_GetBool( p_vout, "autoscale" ) )
200 vlc_object_release( p_vout );
204 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
205 libvlc_exception_t *p_e )
207 vout_thread_t *p_vout = GetVout( p_mp, p_e );
212 var_SetFloat( p_vout, "scale", f_scale );
213 var_SetBool( p_vout, "autoscale", f_scale != 0. );
214 vlc_object_release( p_vout );
217 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
218 libvlc_exception_t *p_e )
220 char *psz_aspect = 0;
221 vout_thread_t *p_vout = GetVout( p_mi, p_e );
223 if( !p_vout ) return 0;
225 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
226 vlc_object_release( p_vout );
227 return psz_aspect ? psz_aspect : strdup("");
230 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
231 char *psz_aspect, libvlc_exception_t *p_e )
233 vout_thread_t *p_vout = GetVout( p_mi, p_e );
236 if( !p_vout ) return;
238 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
240 libvlc_exception_raise( p_e,
241 "Unexpected error while setting aspect-ratio value" );
243 vlc_object_release( p_vout );
246 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
247 libvlc_exception_t *p_e )
249 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
250 vlc_value_t val_list;
256 if( !p_input_thread ) return -1;
258 i_ret = var_Get( p_input_thread, "spu-es", &val );
261 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
262 vlc_object_release( p_input_thread );
266 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
267 for( i = 0; i < val_list.p_list->i_count; i++ )
269 if( val.i_int == val_list.p_list->p_values[i].i_int )
275 var_FreeList( &val_list, NULL );
276 vlc_object_release( p_input_thread );
280 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
281 libvlc_exception_t *p_e )
283 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
286 if( !p_input_thread )
289 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
291 vlc_object_release( p_input_thread );
295 libvlc_track_description_t *
296 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
297 libvlc_exception_t *p_e )
299 return libvlc_get_track_description( p_mi, "spu-es", p_e);
302 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
303 libvlc_exception_t *p_e )
305 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
306 vlc_value_t val_list;
310 if( !p_input_thread ) return;
312 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
314 if( val_list.p_list->i_count == 0 )
316 libvlc_exception_raise( p_e, "Subtitle value out of range" );
320 if( (i_spu < 0) && (i_spu > val_list.p_list->i_count) )
322 libvlc_exception_raise( p_e, "Subtitle value out of range" );
326 newval = val_list.p_list->p_values[i_spu];
327 i_ret = var_Set( p_input_thread, "spu-es", newval );
330 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
334 var_FreeList( &val_list, NULL );
335 vlc_object_release( p_input_thread );
338 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
340 libvlc_exception_t *p_e )
342 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
347 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
349 vlc_object_release( p_input_thread );
354 libvlc_track_description_t *
355 libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
356 libvlc_exception_t * p_e )
358 return libvlc_get_track_description( p_mi, "title", p_e);
361 libvlc_track_description_t *
362 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
364 libvlc_exception_t *p_e )
367 sprintf( psz_title, "title %2i", i_title );
368 return libvlc_get_track_description( p_mi, psz_title, p_e);
371 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
372 libvlc_exception_t *p_e )
374 char *psz_geometry = 0;
375 vout_thread_t *p_vout = GetVout( p_mi, p_e );
377 if( !p_vout ) return 0;
379 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
380 vlc_object_release( p_vout );
381 return psz_geometry ? psz_geometry : strdup("");
384 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
385 char *psz_geometry, libvlc_exception_t *p_e )
387 vout_thread_t *p_vout = GetVout( p_mi, p_e );
390 if( !p_vout ) return;
392 i_ret = var_SetString( p_vout, "crop", psz_geometry );
394 libvlc_exception_raise( p_e,
395 "Unexpected error while setting crop geometry" );
397 vlc_object_release( p_vout );
400 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
401 libvlc_exception_t *p_e )
403 vout_thread_t *p_vout = GetVout( p_mi, p_e );
407 if( !p_vout ) return i_ret;
409 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
413 i_ret = var_GetInteger( p_vbi, "vbi-page" );
414 vlc_object_release( p_vbi );
417 vlc_object_release( p_vout );
421 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
422 libvlc_exception_t *p_e )
424 vout_thread_t *p_vout = GetVout( p_mi, p_e );
428 if( !p_vout ) return;
430 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
434 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
435 vlc_object_release( p_vbi );
437 libvlc_exception_raise( p_e,
438 "Unexpected error while setting teletext page" );
440 vlc_object_release( p_vout );
443 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
444 libvlc_exception_t *p_e )
446 input_thread_t *p_input_thread;
450 p_input_thread = libvlc_get_input_thread(p_mi, p_e);
451 if( !p_input_thread ) return;
453 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
455 vlc_object_release( p_input_thread );
458 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
460 p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
466 /* FIXME Gni, why that ? */
467 i_ret = var_SetInteger( p_vbi, "vbi-page",
468 var_GetInteger( p_vbi, "vbi-page" ) );
470 libvlc_exception_raise( p_e,
471 "Unexpected error while setting teletext page" );
476 i_ret = var_SetBool( p_vbi, "vbi-opaque",
477 !var_GetBool( p_vbi, "vbi-opaque" ) );
479 libvlc_exception_raise( p_e,
480 "Unexpected error while setting teletext transparency" );
482 vlc_object_release( p_vbi );
484 else if( b_selected )
486 var_SetInteger( p_input_thread, "spu-es", -1 );
491 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
493 if( list.p_list->i_count > 0 )
494 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
496 var_FreeList( &list, NULL );
499 vlc_object_release( p_input_thread );
502 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
503 libvlc_exception_t *p_e )
505 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
508 if( !p_input_thread )
511 i_track_count = var_CountChoices( p_input_thread, "video-es" );
513 vlc_object_release( p_input_thread );
514 return i_track_count;
517 libvlc_track_description_t *
518 libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
519 libvlc_exception_t *p_e )
521 return libvlc_get_track_description( p_mi, "video-es", p_e);
524 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
525 libvlc_exception_t *p_e )
527 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
528 vlc_value_t val_list;
534 if( !p_input_thread )
537 i_ret = var_Get( p_input_thread, "video-es", &val );
540 libvlc_exception_raise( p_e, "Getting Video track information failed" );
541 vlc_object_release( p_input_thread );
545 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
546 for( i = 0; i < val_list.p_list->i_count; i++ )
548 if( val_list.p_list->p_values[i].i_int == val.i_int )
554 var_FreeList( &val_list, NULL );
555 vlc_object_release( p_input_thread );
559 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
560 libvlc_exception_t *p_e )
562 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
563 vlc_value_t val_list;
567 if( !p_input_thread )
570 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
571 for( i = 0; i < val_list.p_list->i_count; i++ )
573 vlc_value_t val = val_list.p_list->p_values[i];
574 if( i_track == val.i_int )
576 i_ret = var_Set( p_input_thread, "audio-es", val );
578 libvlc_exception_raise( p_e, "Setting video track failed" );
582 libvlc_exception_raise( p_e, "Video track out of range" );
585 var_FreeList( &val_list, NULL );
586 vlc_object_release( p_input_thread );