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 "libvlc_internal.h"
29 #include <vlc/libvlc.h>
30 #include <vlc_input.h>
34 * Remember to release the returned input_thread_t since it is locked at
35 * the end of this function.
37 static input_thread_t *GetInputThread( libvlc_input_t *p_input,
38 libvlc_exception_t *p_exception )
40 input_thread_t *p_input_thread;
44 libvlc_exception_raise( p_exception, "Input is NULL" );
48 p_input_thread = (input_thread_t*)vlc_object_get(
49 p_input->p_instance->p_libvlc_int,
50 p_input->i_input_id );
53 libvlc_exception_raise( p_exception, "Input does not exist" );
57 return p_input_thread;;
61 * Remember to release the returned vout_thread_t since it is locked at
62 * the end of this function.
64 static vout_thread_t *GetVout( libvlc_input_t *p_input,
65 libvlc_exception_t *p_exception )
67 input_thread_t *p_input_thread = GetInputThread(p_input, p_exception);
68 vout_thread_t *p_vout = NULL;
72 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
75 libvlc_exception_raise( p_exception, "No active video output" );
77 vlc_object_release( p_input_thread );
82 /**********************************************************************
84 **********************************************************************/
86 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
87 libvlc_exception_t *p_e )
89 /* We only work on the first vout */
90 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
91 vlc_value_t val; int i_ret;
93 /* GetVout will raise the exception for us */
99 if( b_fullscreen ) val.b_bool = VLC_TRUE;
100 else val.b_bool = VLC_FALSE;
102 i_ret = var_Set( p_vout1, "fullscreen", val );
104 libvlc_exception_raise( p_e,
105 "Unexpected error while setting fullscreen value" );
107 vlc_object_release( p_vout1 );
110 int libvlc_get_fullscreen( libvlc_input_t *p_input,
111 libvlc_exception_t *p_e )
113 /* We only work on the first vout */
114 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
115 vlc_value_t val; int i_ret;
117 /* GetVout will raise the exception for us */
121 i_ret = var_Get( p_vout1, "fullscreen", &val );
123 libvlc_exception_raise( p_e,
124 "Unexpected error while looking up fullscreen value" );
126 return val.b_bool == VLC_TRUE ? 1 : 0;
129 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
130 libvlc_exception_t *p_e )
132 /* We only work on the first vout */
133 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
134 vlc_value_t val; int i_ret;
136 /* GetVout will raise the exception for us */
140 i_ret = var_Get( p_vout1, "fullscreen", &val );
142 libvlc_exception_raise( p_e,
143 "Unexpected error while looking up fullscreen value" );
145 val.b_bool = !val.b_bool;
146 i_ret = var_Set( p_vout1, "fullscreen", val );
148 libvlc_exception_raise( p_e,
149 "Unexpected error while setting fullscreen value" );
151 vlc_object_release( p_vout1 );
155 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
156 libvlc_exception_t *p_e )
158 vout_thread_t *p_vout = GetVout( p_input, p_e );
159 input_thread_t *p_input_thread;
161 /* GetVout will raise the exception for us */
169 libvlc_exception_raise( p_e, "filepath is null" );
174 p_input_thread = (input_thread_t*)vlc_object_get(
175 p_input->p_instance->p_libvlc_int,
176 p_input->i_input_id );
177 if( !p_input_thread )
179 libvlc_exception_raise( p_e, "Input does not exist" );
183 var_SetString( p_vout, "snapshot-path", psz_filepath );
184 var_SetString( p_vout, "snapshot-format", "png" );
186 vout_Control( p_vout, VOUT_SNAPSHOT );
187 vlc_object_release( p_vout );
188 vlc_object_release( p_input_thread );
191 int libvlc_video_get_height( libvlc_input_t *p_input,
192 libvlc_exception_t *p_e )
194 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
198 vlc_object_release( p_vout1 );
200 return p_vout1->i_window_height;
203 int libvlc_video_get_width( libvlc_input_t *p_input,
204 libvlc_exception_t *p_e )
206 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
210 vlc_object_release( p_vout1 );
212 return p_vout1->i_window_width;
215 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
216 libvlc_exception_t *p_e )
218 input_thread_t *p_input_thread = GetInputThread(p_input, p_e);
219 vlc_bool_t has_vout = VLC_FALSE;
223 vout_thread_t *p_vout;
225 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
229 vlc_object_release( p_vout );
231 vlc_object_release( p_input_thread );
236 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
237 libvlc_exception_t *p_e )
239 vout_thread_t *p_vout = GetVout( p_input, p_e );
243 vout_Control( p_vout , VOUT_REPARENT, d);
244 vlc_object_release( p_vout );
249 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
251 vout_thread_t *p_vout = GetVout( p_input, p_e );
254 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
255 vlc_object_release( p_vout );
259 void libvlc_video_redraw_rectangle( libvlc_input_t *p_input,
260 const libvlc_rectangle_t *area,
261 libvlc_exception_t *p_e )
264 && ((area->bottom - area->top) > 0)
265 && ((area->right - area->left) > 0) )
267 vout_thread_t *p_vout = GetVout( p_input, p_e );
270 /* tell running vout to redraw area */
271 vout_Control( p_vout , VOUT_REDRAW_RECT,
272 area->top, area->left, area->bottom, area->right );
273 vlc_object_release( p_vout );
278 /* global video settings */
280 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
281 libvlc_exception_t *p_e )
283 /* set as default for future vout instances */
284 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
286 if( libvlc_playlist_isplaying(p_instance, p_e) )
288 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
291 vout_thread_t *p_vout = GetVout( p_input, p_e );
294 /* tell running vout to re-parent */
295 vout_Control( p_vout , VOUT_REPARENT, d);
296 vlc_object_release( p_vout );
298 libvlc_input_free(p_input);
303 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
305 libvlc_drawable_t result;
307 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
313 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
314 libvlc_exception_t *p_e )
316 /* set as default for future vout instances */
317 config_PutInt(p_instance->p_libvlc_int, "width", width);
318 config_PutInt(p_instance->p_libvlc_int, "height", height);
320 if( libvlc_playlist_isplaying(p_instance, p_e) )
322 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
325 vout_thread_t *p_vout = GetVout( p_input, p_e );
328 /* tell running vout to re-size */
329 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
330 vlc_object_release( p_vout );
332 libvlc_input_free(p_input);
337 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
338 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
339 libvlc_exception_t *p_e )
343 libvlc_exception_raise( p_e, "viewport is NULL" );
346 /* if clip is NULL, then use view rectangle as clip */
350 /* set as default for future vout instances */
351 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
352 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
353 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
354 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
355 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
356 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
357 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
358 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
360 if( libvlc_playlist_isplaying(p_instance, p_e) )
362 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
365 vout_thread_t *p_vout = GetVout( p_input, p_e );
368 /* change viewport for running vout */
369 vout_Control( p_vout , VOUT_SET_VIEWPORT,
370 view->top, view->left, view->bottom, view->right,
371 clip->top, clip->left, clip->bottom, clip->right );
372 vlc_object_release( p_vout );
374 libvlc_input_free(p_input);
379 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
380 libvlc_exception_t *p_e )
382 char *psz_aspect = 0;
383 vout_thread_t *p_vout = GetVout( p_input, p_e );
388 psz_aspect = var_GetString( p_vout, "aspect-ratio" );
389 vlc_object_release( p_vout );
393 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
394 char *psz_aspect, libvlc_exception_t *p_e )
396 vout_thread_t *p_vout = GetVout( p_input, p_e );
402 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
404 libvlc_exception_raise( p_e,
405 "Unexpected error while setting aspect-ratio value" );
407 vlc_object_release( p_vout );
410 int libvlc_video_get_spu( libvlc_input_t *p_input,
411 libvlc_exception_t *p_e )
413 input_thread_t *p_input_thread = GetInputThread( p_input, p_e );
414 vlc_value_t val_list;
420 if( !p_input_thread )
423 i_ret = var_Get( p_input_thread, "spu-es", &val );
426 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
427 vlc_object_release( 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 spu_val = val_list.p_list->p_values[i];
435 if( val.i_int == spu_val.i_int )
441 vlc_object_release( p_input_thread );
445 void libvlc_video_set_spu( libvlc_input_t *p_input, int i_spu,
446 libvlc_exception_t *p_e )
448 input_thread_t *p_input_thread = GetInputThread( p_input, p_e );
449 vlc_value_t val_list;
453 if( !p_input_thread )
456 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
457 for( i = 0; i < val_list.p_list->i_count; i++ )
459 vlc_value_t val = val_list.p_list->p_values[i];
464 new_val.i_int = val.i_int;
465 i_ret = var_Set( p_input_thread, "spu-es", new_val );
468 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
470 vlc_object_release( p_input_thread );
474 libvlc_exception_raise( p_e, "Subtitle value out of range" );
475 vlc_object_release( p_input_thread );
478 char *libvlc_video_get_crop_geometry( libvlc_input_t *p_input,
479 libvlc_exception_t *p_e )
481 char *psz_geometry = 0;
482 vout_thread_t *p_vout = GetVout( p_input, p_e );
487 psz_geometry = var_GetString( p_vout, "crop" );
488 vlc_object_release( p_vout );
492 void libvlc_video_set_crop_geometry( libvlc_input_t *p_input,
493 char *psz_geometry, libvlc_exception_t *p_e )
495 vout_thread_t *p_vout = GetVout( p_input, p_e );
501 i_ret = var_SetString( p_vout, "crop", psz_geometry );
503 libvlc_exception_raise( p_e,
504 "Unexpected error while setting crop geometry" );
506 vlc_object_release( p_vout );
509 int libvlc_video_destroy( libvlc_input_t *p_input,
510 libvlc_exception_t *p_e )
512 vout_thread_t *p_vout = GetVout( p_input, p_e );
513 vlc_object_detach( p_vout );
514 vlc_object_release( p_vout );
515 vout_Destroy( p_vout );