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;
163 /* GetVout will raise the exception for us */
169 p_input_thread = (input_thread_t*)vlc_object_get(
170 p_input->p_instance->p_libvlc_int,
171 p_input->i_input_id );
172 if( !p_input_thread )
174 libvlc_exception_raise( p_e, "Input does not exist" );
178 snprintf( path, 255, "%s", psz_filepath );
179 var_SetString( p_vout, "snapshot-path", path );
180 var_SetString( p_vout, "snapshot-format", "png" );
182 vout_Control( p_vout, VOUT_SNAPSHOT );
183 vlc_object_release( p_vout );
184 vlc_object_release( p_input_thread );
187 int libvlc_video_get_height( libvlc_input_t *p_input,
188 libvlc_exception_t *p_e )
190 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
194 vlc_object_release( p_vout1 );
196 return p_vout1->i_window_height;
199 int libvlc_video_get_width( libvlc_input_t *p_input,
200 libvlc_exception_t *p_e )
202 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
206 vlc_object_release( p_vout1 );
208 return p_vout1->i_window_width;
211 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
212 libvlc_exception_t *p_e )
214 input_thread_t *p_input_thread = GetInputThread(p_input, p_e);
215 vlc_bool_t has_vout = VLC_FALSE;
219 vout_thread_t *p_vout;
221 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
225 vlc_object_release( p_vout );
227 vlc_object_release( p_input_thread );
232 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
233 libvlc_exception_t *p_e )
235 vout_thread_t *p_vout = GetVout( p_input, p_e );
239 vout_Control( p_vout , VOUT_REPARENT, d);
240 vlc_object_release( p_vout );
245 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
247 vout_thread_t *p_vout = GetVout( p_input, p_e );
250 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
251 vlc_object_release( p_vout );
255 void libvlc_video_redraw_rectangle( libvlc_input_t *p_input,
256 const libvlc_rectangle_t *area,
257 libvlc_exception_t *p_e )
260 && ((area->bottom - area->top) > 0)
261 && ((area->right - area->left) > 0) )
263 vout_thread_t *p_vout = GetVout( p_input, p_e );
266 /* tell running vout to redraw area */
267 vout_Control( p_vout , VOUT_REDRAW_RECT,
268 area->top, area->left, area->bottom, area->right );
269 vlc_object_release( p_vout );
274 /* global video settings */
276 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
277 libvlc_exception_t *p_e )
279 /* set as default for future vout instances */
280 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
282 if( libvlc_playlist_isplaying(p_instance, p_e) )
284 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
287 vout_thread_t *p_vout = GetVout( p_input, p_e );
290 /* tell running vout to re-parent */
291 vout_Control( p_vout , VOUT_REPARENT, d);
292 vlc_object_release( p_vout );
294 libvlc_input_free(p_input);
299 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
301 libvlc_drawable_t result;
303 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
309 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
310 libvlc_exception_t *p_e )
312 /* set as default for future vout instances */
313 config_PutInt(p_instance->p_libvlc_int, "width", width);
314 config_PutInt(p_instance->p_libvlc_int, "height", height);
316 if( libvlc_playlist_isplaying(p_instance, p_e) )
318 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
321 vout_thread_t *p_vout = GetVout( p_input, p_e );
324 /* tell running vout to re-size */
325 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
326 vlc_object_release( p_vout );
328 libvlc_input_free(p_input);
333 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
334 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
335 libvlc_exception_t *p_e )
339 libvlc_exception_raise( p_e, "viewport is NULL" );
342 /* if clip is NULL, then use view rectangle as clip */
346 /* set as default for future vout instances */
347 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
348 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
349 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
350 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
351 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
352 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
353 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
354 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
356 if( libvlc_playlist_isplaying(p_instance, p_e) )
358 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
361 vout_thread_t *p_vout = GetVout( p_input, p_e );
364 /* change viewport for running vout */
365 vout_Control( p_vout , VOUT_SET_VIEWPORT,
366 view->top, view->left, view->bottom, view->right,
367 clip->top, clip->left, clip->bottom, clip->right );
368 vlc_object_release( p_vout );
370 libvlc_input_free(p_input);
375 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
376 libvlc_exception_t *p_e )
378 char *psz_aspect = 0;
379 vout_thread_t *p_vout = GetVout( p_input, p_e );
384 psz_aspect = var_GetString( p_vout, "aspect-ratio" );
385 vlc_object_release( p_vout );
389 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
390 char *psz_aspect, libvlc_exception_t *p_e )
392 vout_thread_t *p_vout = GetVout( p_input, p_e );
398 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
400 libvlc_exception_raise( p_e,
401 "Unexpected error while setting aspect-ratio value" );
403 vlc_object_release( p_vout );
406 int libvlc_video_get_spu( libvlc_input_t *p_input,
407 libvlc_exception_t *p_e )
409 input_thread_t *p_input_thread = GetInputThread( p_input, p_e );
410 vlc_value_t val_list;
416 if( !p_input_thread )
419 i_ret = var_Get( p_input_thread, "spu-es", &val );
422 libvlc_exception_raise( p_e, "Getting subtitle information failed" );
423 vlc_object_release( p_input_thread );
427 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
428 for( i = 0; i < val_list.p_list->i_count; i++ )
430 vlc_value_t spu_val = val_list.p_list->p_values[i];
431 if( val.i_int == spu_val.i_int )
437 vlc_object_release( p_input_thread );
441 void libvlc_video_set_spu( libvlc_input_t *p_input, int i_spu,
442 libvlc_exception_t *p_e )
444 input_thread_t *p_input_thread = GetInputThread( p_input, p_e );
445 vlc_value_t val_list;
449 if( !p_input_thread )
452 var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
453 for( i = 0; i < val_list.p_list->i_count; i++ )
455 vlc_value_t val = val_list.p_list->p_values[i];
460 new_val.i_int = val.i_int;
461 i_ret = var_Set( p_input_thread, "spu-es", new_val );
464 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
466 vlc_object_release( p_input_thread );
470 libvlc_exception_raise( p_e, "Subtitle value out of range" );
471 vlc_object_release( p_input_thread );
474 char *libvlc_video_get_crop_geometry( libvlc_input_t *p_input,
475 libvlc_exception_t *p_e )
477 char *psz_geometry = 0;
478 vout_thread_t *p_vout = GetVout( p_input, p_e );
483 psz_geometry = var_GetString( p_vout, "crop" );
484 vlc_object_release( p_vout );
488 void libvlc_video_set_crop_geometry( libvlc_input_t *p_input,
489 char *psz_geometry, libvlc_exception_t *p_e )
491 vout_thread_t *p_vout = GetVout( p_input, p_e );
497 i_ret = var_SetString( p_vout, "crop", psz_geometry );
499 libvlc_exception_raise( p_e,
500 "Unexpected error while setting crop geometry" );
502 vlc_object_release( p_vout );
505 int libvlc_video_destroy( libvlc_input_t *p_input,
506 libvlc_exception_t *p_e )
508 vout_thread_t *p_vout = GetVout( p_input, p_e );
509 vlc_object_detach( p_vout );
510 vlc_object_release( p_vout );
511 vout_Destroy( p_vout );