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 <vlc/libvlc.h>
29 #include <vlc_input.h>
32 #include "libvlc_internal.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_instance_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_instance_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_instance_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_instance_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_instance_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 = (input_thread_t*)vlc_object_get(
151 p_mi->p_libvlc_instance->p_libvlc_int,
153 if( !p_input_thread )
155 libvlc_exception_raise( p_e, "Input does not exist" );
159 var_SetString( p_vout, "snapshot-path", psz_filepath );
160 var_SetString( p_vout, "snapshot-format", "png" );
162 vout_Control( p_vout, VOUT_SNAPSHOT );
163 vlc_object_release( p_vout );
164 vlc_object_release( p_input_thread );
167 int libvlc_video_get_height( libvlc_media_instance_t *p_mi,
168 libvlc_exception_t *p_e )
170 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
174 vlc_object_release( p_vout1 );
176 return p_vout1->i_window_height;
179 int libvlc_video_get_width( libvlc_media_instance_t *p_mi,
180 libvlc_exception_t *p_e )
182 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
186 vlc_object_release( p_vout1 );
188 return p_vout1->i_window_width;
191 vlc_bool_t libvlc_media_instance_has_vout( libvlc_media_instance_t *p_mi,
192 libvlc_exception_t *p_e )
194 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
195 vlc_bool_t has_vout = VLC_FALSE;
199 vout_thread_t *p_vout;
201 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
205 vlc_object_release( p_vout );
207 vlc_object_release( p_input_thread );
212 int libvlc_video_reparent( libvlc_media_instance_t *p_mi, libvlc_drawable_t d,
213 libvlc_exception_t *p_e )
215 vout_thread_t *p_vout = GetVout( p_mi, p_e );
219 vout_Control( p_vout , VOUT_REPARENT, d);
220 vlc_object_release( p_vout );
225 void libvlc_video_resize( libvlc_media_instance_t *p_mi, int width, int height, libvlc_exception_t *p_e )
227 vout_thread_t *p_vout = GetVout( p_mi, p_e );
230 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
231 vlc_object_release( p_vout );
235 void libvlc_video_redraw_rectangle( libvlc_media_instance_t *p_mi,
236 const libvlc_rectangle_t *area,
237 libvlc_exception_t *p_e )
240 && ((area->bottom - area->top) > 0)
241 && ((area->right - area->left) > 0) )
243 vout_thread_t *p_vout = GetVout( p_mi, p_e );
246 /* tell running vout to redraw area */
247 vout_Control( p_vout , VOUT_REDRAW_RECT,
248 area->top, area->left, area->bottom, area->right );
249 vlc_object_release( p_vout );
254 /* global video settings */
256 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
257 libvlc_exception_t *p_e )
259 /* set as default for future vout instances */
260 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
262 if( libvlc_playlist_isplaying(p_instance, p_e) )
264 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
267 vout_thread_t *p_vout = GetVout( p_mi, p_e );
270 /* tell running vout to re-parent */
271 vout_Control( p_vout , VOUT_REPARENT, d);
272 vlc_object_release( p_vout );
274 libvlc_media_instance_release(p_mi);
279 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
281 libvlc_drawable_t result;
283 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
289 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
290 libvlc_exception_t *p_e )
292 /* set as default for future vout instances */
293 config_PutInt(p_instance->p_libvlc_int, "width", width);
294 config_PutInt(p_instance->p_libvlc_int, "height", height);
296 if( libvlc_playlist_isplaying(p_instance, p_e) )
298 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
301 vout_thread_t *p_vout = GetVout( p_mi, p_e );
304 /* tell running vout to re-size */
305 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
306 vlc_object_release( p_vout );
308 libvlc_media_instance_release(p_mi);
313 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
314 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
315 libvlc_exception_t *p_e )
319 libvlc_exception_raise( p_e, "viewport is NULL" );
322 /* if clip is NULL, then use view rectangle as clip */
326 /* set as default for future vout instances */
327 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
328 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
329 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
330 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
331 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
332 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
333 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
334 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
336 if( libvlc_playlist_isplaying(p_instance, p_e) )
338 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
341 vout_thread_t *p_vout = GetVout( p_mi, p_e );
344 /* change viewport for running vout */
345 vout_Control( p_vout , VOUT_SET_VIEWPORT,
346 view->top, view->left, view->bottom, view->right,
347 clip->top, clip->left, clip->bottom, clip->right );
348 vlc_object_release( p_vout );
350 libvlc_media_instance_release(p_mi);
355 char *libvlc_video_get_aspect_ratio( libvlc_media_instance_t *p_mi,
356 libvlc_exception_t *p_e )
358 char *psz_aspect = 0;
359 vout_thread_t *p_vout = GetVout( p_mi, p_e );
364 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
365 vlc_object_release( p_vout );
366 return psz_aspect ? psz_aspect : strdup("");
369 void libvlc_video_set_aspect_ratio( libvlc_media_instance_t *p_mi,
370 char *psz_aspect, libvlc_exception_t *p_e )
372 vout_thread_t *p_vout = GetVout( p_mi, p_e );
378 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
380 libvlc_exception_raise( p_e,
381 "Unexpected error while setting aspect-ratio value" );
383 vlc_object_release( p_vout );
386 int libvlc_video_get_spu( libvlc_media_instance_t *p_mi,
387 libvlc_exception_t *p_e )
389 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
390 vlc_value_t val_list;
396 if( !p_input_thread )
399 i_ret = var_Get( p_input_thread, "spu-es", &val );
402 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
403 vlc_object_release( p_input_thread );
407 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
408 for( i = 0; i < val_list.p_list->i_count; i++ )
410 vlc_value_t spu_val = val_list.p_list->p_values[i];
411 if( val.i_int == spu_val.i_int )
417 vlc_object_release( p_input_thread );
421 void libvlc_video_set_spu( libvlc_media_instance_t *p_mi, int i_spu,
422 libvlc_exception_t *p_e )
424 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
425 vlc_value_t val_list;
429 if( !p_input_thread )
432 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
433 for( i = 0; i < val_list.p_list->i_count; i++ )
435 vlc_value_t val = val_list.p_list->p_values[i];
440 new_val.i_int = val.i_int;
441 i_ret = var_Set( p_input_thread, "spu-es", new_val );
444 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
446 vlc_object_release( p_input_thread );
450 libvlc_exception_raise( p_e, "Subtitle value out of range" );
451 vlc_object_release( p_input_thread );
454 char *libvlc_video_get_crop_geometry( libvlc_media_instance_t *p_mi,
455 libvlc_exception_t *p_e )
457 char *psz_geometry = 0;
458 vout_thread_t *p_vout = GetVout( p_mi, p_e );
463 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
464 vlc_object_release( p_vout );
465 return psz_geometry ? psz_geometry : strdup("");
468 void libvlc_video_set_crop_geometry( libvlc_media_instance_t *p_mi,
469 char *psz_geometry, libvlc_exception_t *p_e )
471 vout_thread_t *p_vout = GetVout( p_mi, p_e );
477 i_ret = var_SetString( p_vout, "crop", psz_geometry );
479 libvlc_exception_raise( p_e,
480 "Unexpected error while setting crop geometry" );
482 vlc_object_release( p_vout );
485 int libvlc_video_get_teletext( libvlc_media_instance_t *p_mi,
486 libvlc_exception_t *p_e )
488 vout_thread_t *p_vout = GetVout( p_mi, p_e );
495 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
499 i_ret = var_GetInteger( p_vbi, "vbi-page" );
500 vlc_object_release( p_vbi );
503 vlc_object_release( p_vout );
507 void libvlc_video_set_teletext( libvlc_media_instance_t *p_mi, int i_page,
508 libvlc_exception_t *p_e )
510 vout_thread_t *p_vout = GetVout( p_mi, p_e );
517 p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
521 i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
522 vlc_object_release( p_vbi );
525 libvlc_exception_raise( p_e,
526 "Unexpected error while setting teletext page" );
527 vlc_object_release( p_vout );
530 void libvlc_toggle_teletext( libvlc_media_instance_t *p_mi,
531 libvlc_exception_t *p_e )
533 /* We only work on the first vout */
534 vout_thread_t *p_vout = GetVout( p_mi, p_e );
535 vlc_value_t val; int i_ret;
537 /* GetVout will raise the exception for us */
541 i_ret = var_Get( p_vout, "vbi-opaque", &val );
543 libvlc_exception_raise( p_e,
544 "Unexpected error while looking up teletext value" );
546 val.b_bool = !val.b_bool;
547 i_ret = var_Set( p_vout, "vbi-opaque", val );
549 libvlc_exception_raise( p_e,
550 "Unexpected error while setting teletext value" );
552 vlc_object_release( p_vout );
555 int libvlc_video_destroy( libvlc_media_instance_t *p_mi,
556 libvlc_exception_t *p_e )
558 vout_thread_t *p_vout = GetVout( p_mi, p_e );
559 vlc_object_detach( p_vout );
560 vlc_object_release( p_vout );
561 vout_Destroy( p_vout );