1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
8 * Authors: Cl�ent 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 since it is locked at
36 * the end of this function.
38 static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
39 libvlc_exception_t *p_exception )
41 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_exception );
42 vout_thread_t *p_vout = NULL;
46 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_ANYWHERE );
49 libvlc_exception_raise( p_exception, "No active video output" );
51 vlc_object_release( p_input_thread );
56 /**********************************************************************
58 **********************************************************************/
60 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
61 libvlc_exception_t *p_e )
63 /* We only work on the first vout */
64 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
65 vlc_value_t val; int i_ret;
67 /* GetVout will raise the exception for us */
73 if( b_fullscreen ) val.b_bool = VLC_TRUE;
74 else val.b_bool = VLC_FALSE;
76 i_ret = var_Set( p_vout1, "fullscreen", val );
78 libvlc_exception_raise( p_e,
79 "Unexpected error while setting fullscreen value" );
81 vlc_object_release( p_vout1 );
84 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
85 libvlc_exception_t *p_e )
87 /* We only work on the first vout */
88 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
89 vlc_value_t val; int i_ret;
91 /* GetVout will raise the exception for us */
95 i_ret = var_Get( p_vout1, "fullscreen", &val );
97 libvlc_exception_raise( p_e,
98 "Unexpected error while looking up fullscreen value" );
100 return val.b_bool == VLC_TRUE ? 1 : 0;
103 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
104 libvlc_exception_t *p_e )
106 /* We only work on the first vout */
107 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
108 vlc_value_t val; int i_ret;
110 /* GetVout will raise the exception for us */
114 i_ret = var_Get( p_vout1, "fullscreen", &val );
116 libvlc_exception_raise( p_e,
117 "Unexpected error while looking up fullscreen value" );
119 val.b_bool = !val.b_bool;
120 i_ret = var_Set( p_vout1, "fullscreen", val );
122 libvlc_exception_raise( p_e,
123 "Unexpected error while setting fullscreen value" );
125 vlc_object_release( p_vout1 );
129 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, char *psz_filepath,
130 unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
132 vout_thread_t *p_vout = GetVout( p_mi, p_e );
133 input_thread_t *p_input_thread;
135 /* GetVout will raise the exception for us */
143 libvlc_exception_raise( p_e, "filepath is null" );
147 var_SetInteger( p_vout, "snapshot-width", i_width );
148 var_SetInteger( p_vout, "snapshot-height", i_height );
150 p_input_thread = p_mi->p_input_thread;
151 if( !p_mi->p_input_thread )
153 libvlc_exception_raise( p_e, "Input does not exist" );
157 var_SetString( p_vout, "snapshot-path", psz_filepath );
158 var_SetString( p_vout, "snapshot-format", "png" );
160 vout_Control( p_vout, VOUT_SNAPSHOT );
161 vlc_object_release( p_vout );
164 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
165 libvlc_exception_t *p_e )
167 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
171 vlc_object_release( p_vout1 );
173 return p_vout1->i_window_height;
176 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
177 libvlc_exception_t *p_e )
179 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
183 vlc_object_release( p_vout1 );
185 return p_vout1->i_window_width;
188 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
189 libvlc_exception_t *p_e )
191 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
192 vlc_bool_t has_vout = VLC_FALSE;
196 vout_thread_t *p_vout;
198 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
202 vlc_object_release( p_vout );
204 vlc_object_release( p_input_thread );
209 int libvlc_video_reparent( libvlc_media_player_t *p_mi, libvlc_drawable_t d,
210 libvlc_exception_t *p_e )
212 vout_thread_t *p_vout = GetVout( p_mi, p_e );
216 vout_Control( p_vout , VOUT_REPARENT, d);
217 vlc_object_release( p_vout );
222 void libvlc_video_resize( libvlc_media_player_t *p_mi, int width, int height, libvlc_exception_t *p_e )
224 vout_thread_t *p_vout = GetVout( p_mi, p_e );
227 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
228 vlc_object_release( p_vout );
232 void libvlc_video_redraw_rectangle( libvlc_media_player_t *p_mi,
233 const libvlc_rectangle_t *area,
234 libvlc_exception_t *p_e )
237 && ((area->bottom - area->top) > 0)
238 && ((area->right - area->left) > 0) )
240 vout_thread_t *p_vout = GetVout( p_mi, p_e );
243 /* tell running vout to redraw area */
244 vout_Control( p_vout , VOUT_REDRAW_RECT,
245 area->top, area->left, area->bottom, area->right );
246 vlc_object_release( p_vout );
251 /* global video settings */
253 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
254 libvlc_exception_t *p_e )
256 /* set as default for future vout instances */
257 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
259 if( libvlc_playlist_isplaying(p_instance, p_e) )
261 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
264 vout_thread_t *p_vout = GetVout( p_mi, p_e );
267 /* tell running vout to re-parent */
268 vout_Control( p_vout , VOUT_REPARENT, d);
269 vlc_object_release( p_vout );
271 libvlc_media_player_release(p_mi);
276 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
280 libvlc_drawable_t result;
282 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
288 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
289 libvlc_exception_t *p_e )
291 /* set as default for future vout instances */
292 config_PutInt(p_instance->p_libvlc_int, "width", width);
293 config_PutInt(p_instance->p_libvlc_int, "height", height);
295 if( libvlc_playlist_isplaying(p_instance, p_e) )
297 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
300 vout_thread_t *p_vout = GetVout( p_mi, p_e );
303 /* tell running vout to re-size */
304 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
305 vlc_object_release( p_vout );
307 libvlc_media_player_release(p_mi);
312 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
313 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
314 libvlc_exception_t *p_e )
318 libvlc_exception_raise( p_e, "viewport is NULL" );
321 /* if clip is NULL, then use view rectangle as clip */
325 /* set as default for future vout instances */
326 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
327 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
328 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
329 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
330 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
331 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
332 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
333 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
335 if( libvlc_playlist_isplaying(p_instance, p_e) )
337 libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
340 vout_thread_t *p_vout = GetVout( p_mi, p_e );
343 /* change viewport for running vout */
344 vout_Control( p_vout , VOUT_SET_VIEWPORT,
345 view->top, view->left, view->bottom, view->right,
346 clip->top, clip->left, clip->bottom, clip->right );
347 vlc_object_release( p_vout );
349 libvlc_media_player_release(p_mi);
354 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
355 libvlc_exception_t *p_e )
357 char *psz_aspect = 0;
358 vout_thread_t *p_vout = GetVout( p_mi, p_e );
363 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
364 vlc_object_release( p_vout );
365 return psz_aspect ? psz_aspect : strdup("");
368 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
369 char *psz_aspect, libvlc_exception_t *p_e )
371 vout_thread_t *p_vout = GetVout( p_mi, p_e );
377 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
379 libvlc_exception_raise( p_e,
380 "Unexpected error while setting aspect-ratio value" );
382 vlc_object_release( p_vout );
385 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
386 libvlc_exception_t *p_e )
388 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
389 vlc_value_t val_list;
395 if( !p_input_thread )
398 i_ret = var_Get( p_input_thread, "spu-es", &val );
401 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
402 vlc_object_release( p_input_thread );
406 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
407 for( i = 0; i < val_list.p_list->i_count; i++ )
409 vlc_value_t spu_val = val_list.p_list->p_values[i];
410 if( val.i_int == spu_val.i_int )
416 vlc_object_release( p_input_thread );
420 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
421 libvlc_exception_t *p_e )
423 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
424 vlc_value_t val_list;
428 if( !p_input_thread )
431 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
432 for( i = 0; i < val_list.p_list->i_count; i++ )
434 vlc_value_t val = val_list.p_list->p_values[i];
439 new_val.i_int = val.i_int;
440 i_ret = var_Set( p_input_thread, "spu-es", new_val );
443 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
445 vlc_object_release( p_input_thread );
449 libvlc_exception_raise( p_e, "Subtitle value out of range" );
450 vlc_object_release( p_input_thread );
453 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
454 libvlc_exception_t *p_e )
456 char *psz_geometry = 0;
457 vout_thread_t *p_vout = GetVout( p_mi, p_e );
462 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
463 vlc_object_release( p_vout );
464 return psz_geometry ? psz_geometry : strdup("");
467 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
468 char *psz_geometry, libvlc_exception_t *p_e )
470 vout_thread_t *p_vout = GetVout( p_mi, p_e );
476 i_ret = var_SetString( p_vout, "crop", psz_geometry );
478 libvlc_exception_raise( p_e,
479 "Unexpected error while setting crop geometry" );
481 vlc_object_release( p_vout );
484 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
485 libvlc_exception_t *p_e )
487 vout_thread_t *p_vout = GetVout( p_mi, p_e );
494 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
498 i_ret = var_GetInteger( p_vbi, "vbi-page" );
499 vlc_object_release( p_vbi );
502 vlc_object_release( p_vout );
506 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
507 libvlc_exception_t *p_e )
509 vout_thread_t *p_vout = GetVout( p_mi, p_e );
516 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
520 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
521 vlc_object_release( p_vbi );
524 libvlc_exception_raise( p_e,
525 "Unexpected error while setting teletext page" );
526 vlc_object_release( p_vout );
529 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
530 libvlc_exception_t *p_e )
532 /* We only work on the first vout */
533 vout_thread_t *p_vout = GetVout( p_mi, p_e );
534 vlc_value_t val; int i_ret;
536 /* GetVout will raise the exception for us */
540 i_ret = var_Get( p_vout, "vbi-opaque", &val );
542 libvlc_exception_raise( p_e,
543 "Unexpected error while looking up teletext value" );
545 val.b_bool = !val.b_bool;
546 i_ret = var_Set( p_vout, "vbi-opaque", val );
548 libvlc_exception_raise( p_e,
549 "Unexpected error while setting teletext value" );
551 vlc_object_release( p_vout );
554 int libvlc_video_destroy( libvlc_media_player_t *p_mi,
555 libvlc_exception_t *p_e )
557 vout_thread_t *p_vout = GetVout( p_mi, p_e );
558 vlc_object_detach( p_vout );
559 vlc_object_release( p_vout );
560 vout_Destroy( p_vout );