1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
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_CHILD );
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 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" );
148 p_input_thread = (input_thread_t*)vlc_object_get(
149 p_mi->p_libvlc_instance->p_libvlc_int,
151 if( !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 );
162 vlc_object_release( p_input_thread );
165 int libvlc_video_get_height( libvlc_media_instance_t *p_mi,
166 libvlc_exception_t *p_e )
168 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
172 vlc_object_release( p_vout1 );
174 return p_vout1->i_window_height;
177 int libvlc_video_get_width( libvlc_media_instance_t *p_mi,
178 libvlc_exception_t *p_e )
180 vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
184 vlc_object_release( p_vout1 );
186 return p_vout1->i_window_width;
189 vlc_bool_t libvlc_media_instance_has_vout( libvlc_media_instance_t *p_mi,
190 libvlc_exception_t *p_e )
192 input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
193 vlc_bool_t has_vout = VLC_FALSE;
197 vout_thread_t *p_vout;
199 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
203 vlc_object_release( p_vout );
205 vlc_object_release( p_input_thread );
210 int libvlc_video_reparent( libvlc_media_instance_t *p_mi, libvlc_drawable_t d,
211 libvlc_exception_t *p_e )
213 vout_thread_t *p_vout = GetVout( p_mi, p_e );
217 vout_Control( p_vout , VOUT_REPARENT, d);
218 vlc_object_release( p_vout );
223 void libvlc_video_resize( libvlc_media_instance_t *p_mi, int width, int height, libvlc_exception_t *p_e )
225 vout_thread_t *p_vout = GetVout( p_mi, p_e );
228 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
229 vlc_object_release( p_vout );
233 void libvlc_video_redraw_rectangle( libvlc_media_instance_t *p_mi,
234 const libvlc_rectangle_t *area,
235 libvlc_exception_t *p_e )
238 && ((area->bottom - area->top) > 0)
239 && ((area->right - area->left) > 0) )
241 vout_thread_t *p_vout = GetVout( p_mi, p_e );
244 /* tell running vout to redraw area */
245 vout_Control( p_vout , VOUT_REDRAW_RECT,
246 area->top, area->left, area->bottom, area->right );
247 vlc_object_release( p_vout );
252 /* global video settings */
254 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
255 libvlc_exception_t *p_e )
257 /* set as default for future vout instances */
258 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
260 if( libvlc_playlist_isplaying(p_instance, p_e) )
262 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
265 vout_thread_t *p_vout = GetVout( p_mi, p_e );
268 /* tell running vout to re-parent */
269 vout_Control( p_vout , VOUT_REPARENT, d);
270 vlc_object_release( p_vout );
272 libvlc_media_instance_release(p_mi);
277 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
279 libvlc_drawable_t result;
281 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
287 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
288 libvlc_exception_t *p_e )
290 /* set as default for future vout instances */
291 config_PutInt(p_instance->p_libvlc_int, "width", width);
292 config_PutInt(p_instance->p_libvlc_int, "height", height);
294 if( libvlc_playlist_isplaying(p_instance, p_e) )
296 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
299 vout_thread_t *p_vout = GetVout( p_mi, p_e );
302 /* tell running vout to re-size */
303 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
304 vlc_object_release( p_vout );
306 libvlc_media_instance_release(p_mi);
311 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
312 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
313 libvlc_exception_t *p_e )
317 libvlc_exception_raise( p_e, "viewport is NULL" );
320 /* if clip is NULL, then use view rectangle as clip */
324 /* set as default for future vout instances */
325 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
326 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
327 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
328 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
329 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
330 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
331 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
332 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
334 if( libvlc_playlist_isplaying(p_instance, p_e) )
336 libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
339 vout_thread_t *p_vout = GetVout( p_mi, p_e );
342 /* change viewport for running vout */
343 vout_Control( p_vout , VOUT_SET_VIEWPORT,
344 view->top, view->left, view->bottom, view->right,
345 clip->top, clip->left, clip->bottom, clip->right );
346 vlc_object_release( p_vout );
348 libvlc_media_instance_release(p_mi);
353 char *libvlc_video_get_aspect_ratio( libvlc_media_instance_t *p_mi,
354 libvlc_exception_t *p_e )
356 char *psz_aspect = 0;
357 vout_thread_t *p_vout = GetVout( p_mi, p_e );
362 psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
363 vlc_object_release( p_vout );
364 return psz_aspect ? psz_aspect : strdup("");
367 void libvlc_video_set_aspect_ratio( libvlc_media_instance_t *p_mi,
368 char *psz_aspect, libvlc_exception_t *p_e )
370 vout_thread_t *p_vout = GetVout( p_mi, p_e );
376 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
378 libvlc_exception_raise( p_e,
379 "Unexpected error while setting aspect-ratio value" );
381 vlc_object_release( p_vout );
384 int libvlc_video_get_spu( libvlc_media_instance_t *p_mi,
385 libvlc_exception_t *p_e )
387 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
388 vlc_value_t val_list;
394 if( !p_input_thread )
397 i_ret = var_Get( p_input_thread, "spu-es", &val );
400 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
401 vlc_object_release( p_input_thread );
405 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
406 for( i = 0; i < val_list.p_list->i_count; i++ )
408 vlc_value_t spu_val = val_list.p_list->p_values[i];
409 if( val.i_int == spu_val.i_int )
415 vlc_object_release( p_input_thread );
419 void libvlc_video_set_spu( libvlc_media_instance_t *p_mi, int i_spu,
420 libvlc_exception_t *p_e )
422 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
423 vlc_value_t val_list;
427 if( !p_input_thread )
430 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
431 for( i = 0; i < val_list.p_list->i_count; i++ )
433 vlc_value_t val = val_list.p_list->p_values[i];
438 new_val.i_int = val.i_int;
439 i_ret = var_Set( p_input_thread, "spu-es", new_val );
442 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
444 vlc_object_release( p_input_thread );
448 libvlc_exception_raise( p_e, "Subtitle value out of range" );
449 vlc_object_release( p_input_thread );
452 char *libvlc_video_get_crop_geometry( libvlc_media_instance_t *p_mi,
453 libvlc_exception_t *p_e )
455 char *psz_geometry = 0;
456 vout_thread_t *p_vout = GetVout( p_mi, p_e );
461 psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
462 vlc_object_release( p_vout );
463 return psz_geometry ? psz_geometry : strdup("");
466 void libvlc_video_set_crop_geometry( libvlc_media_instance_t *p_mi,
467 char *psz_geometry, libvlc_exception_t *p_e )
469 vout_thread_t *p_vout = GetVout( p_mi, p_e );
475 i_ret = var_SetString( p_vout, "crop", psz_geometry );
477 libvlc_exception_raise( p_e,
478 "Unexpected error while setting crop geometry" );
480 vlc_object_release( p_vout );
483 int libvlc_video_get_teletext( libvlc_media_instance_t *p_mi,
484 libvlc_exception_t *p_e )
486 vout_thread_t *p_vout = GetVout( p_mi, p_e );
492 i_ret = var_GetInteger( p_vout, "vbi-page" );
493 vlc_object_release( p_vout );
497 void libvlc_video_set_teletext( libvlc_media_instance_t *p_mi, int i_page,
498 libvlc_exception_t *p_e )
500 vout_thread_t *p_vout = GetVout( p_mi, p_e );
506 i_ret = var_SetInteger( p_vout, "vbi-page", i_page );
508 libvlc_exception_raise( p_e,
509 "Unexpected error while setting teletext page" );
510 vlc_object_release( p_vout );
513 int libvlc_video_destroy( libvlc_media_instance_t *p_mi,
514 libvlc_exception_t *p_e )
516 vout_thread_t *p_vout = GetVout( p_mi, p_e );
517 vlc_object_detach( p_vout );
518 vlc_object_release( p_vout );
519 vout_Destroy( p_vout );