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>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #include "libvlc_internal.h"
28 #include <vlc/libvlc.h>
29 #include <vlc_input.h>
33 * Remember to release the returned input_thread_t since it is locked at
34 * the end of this function.
36 static input_thread_t *GetInputThread( libvlc_input_t *p_input,
37 libvlc_exception_t *p_exception )
39 input_thread_t *p_input_thread;
43 libvlc_exception_raise( p_exception, "Input is NULL" );
47 p_input_thread = (input_thread_t*)vlc_object_get(
48 p_input->p_instance->p_libvlc_int,
49 p_input->i_input_id );
52 libvlc_exception_raise( p_exception, "Input does not exist" );
56 return p_input_thread;;
60 * Remember to release the returned vout_thread_t since it is locked at
61 * the end of this function.
63 static vout_thread_t *GetVout( libvlc_input_t *p_input,
64 libvlc_exception_t *p_exception )
66 input_thread_t *p_input_thread = GetInputThread(p_input, p_exception);
67 vout_thread_t *p_vout = NULL;
71 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
74 libvlc_exception_raise( p_exception, "No active video output" );
76 vlc_object_release( p_input_thread );
81 /**********************************************************************
83 **********************************************************************/
85 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
86 libvlc_exception_t *p_e )
88 /* We only work on the first vout */
89 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
90 vlc_value_t val; int i_ret;
92 /* GetVout will raise the exception for us */
98 if( b_fullscreen ) val.b_bool = VLC_TRUE;
99 else val.b_bool = VLC_FALSE;
101 i_ret = var_Set( p_vout1, "fullscreen", val );
103 libvlc_exception_raise( p_e,
104 "Unexpected error while setting fullscreen value" );
106 vlc_object_release( p_vout1 );
109 int libvlc_get_fullscreen( libvlc_input_t *p_input,
110 libvlc_exception_t *p_e )
112 /* We only work on the first vout */
113 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
114 vlc_value_t val; int i_ret;
116 /* GetVout will raise the exception for us */
120 i_ret = var_Get( p_vout1, "fullscreen", &val );
122 libvlc_exception_raise( p_e,
123 "Unexpected error while looking up fullscreen value" );
125 return val.b_bool == VLC_TRUE ? 1 : 0;
128 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
129 libvlc_exception_t *p_e )
131 /* We only work on the first vout */
132 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
133 vlc_value_t val; int i_ret;
135 /* GetVout will raise the exception for us */
139 i_ret = var_Get( p_vout1, "fullscreen", &val );
141 libvlc_exception_raise( p_e,
142 "Unexpected error while looking up fullscreen value" );
144 val.b_bool = !val.b_bool;
145 i_ret = var_Set( p_vout1, "fullscreen", val );
147 libvlc_exception_raise( p_e,
148 "Unexpected error while setting fullscreen value" );
150 vlc_object_release( p_vout1 );
154 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
155 libvlc_exception_t *p_e )
157 vout_thread_t *p_vout = GetVout( p_input, p_e );
158 input_thread_t *p_input_thread;
162 /* GetVout will raise the exception for us */
168 p_input_thread = (input_thread_t*)vlc_object_get(
169 p_input->p_instance->p_libvlc_int,
170 p_input->i_input_id );
171 if( !p_input_thread )
173 libvlc_exception_raise( p_e, "Input does not exist" );
177 snprintf( path, 255, "%s", psz_filepath );
178 var_SetString( p_vout, "snapshot-path", path );
179 var_SetString( p_vout, "snapshot-format", "png" );
181 vout_Control( p_vout, VOUT_SNAPSHOT );
182 vlc_object_release( p_vout );
183 vlc_object_release( p_input_thread );
186 int libvlc_video_get_height( libvlc_input_t *p_input,
187 libvlc_exception_t *p_e )
189 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
193 vlc_object_release( p_vout1 );
195 return p_vout1->i_window_height;
198 int libvlc_video_get_width( libvlc_input_t *p_input,
199 libvlc_exception_t *p_e )
201 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
205 vlc_object_release( p_vout1 );
207 return p_vout1->i_window_width;
210 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
211 libvlc_exception_t *p_e )
213 input_thread_t *p_input_thread = GetInputThread(p_input, p_e);
214 vlc_bool_t has_vout = VLC_FALSE;
218 vout_thread_t *p_vout;
220 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
224 vlc_object_release( p_vout );
226 vlc_object_release( p_input_thread );
231 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
232 libvlc_exception_t *p_e )
234 vout_thread_t *p_vout = GetVout( p_input, p_e );
238 vout_Control( p_vout , VOUT_REPARENT, d);
239 vlc_object_release( p_vout );
244 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
246 vout_thread_t *p_vout = GetVout( p_input, p_e );
249 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
250 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_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
267 vout_thread_t *p_vout = GetVout( p_input, 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_input_free(p_input);
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_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
301 vout_thread_t *p_vout = GetVout( p_input, 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_input_free(p_input);
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_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
341 vout_thread_t *p_vout = GetVout( p_input, 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_input_free(p_input);
355 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
356 libvlc_exception_t *p_e )
358 char *psz_aspect = 0;
359 vout_thread_t *p_vout = GetVout( p_input, p_e );
364 psz_aspect = var_GetString( p_vout, "aspect-ratio" );
365 vlc_object_release( p_vout );
369 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
370 char *psz_aspect, libvlc_exception_t *p_e )
372 vout_thread_t *p_vout = GetVout( p_input, 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_input_t *p_input,
387 libvlc_exception_t *p_e )
389 input_thread_t *p_input_thread = GetInputThread( p_input, 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_input_t *p_input, int i_spu,
422 libvlc_exception_t *p_e )
424 input_thread_t *p_input_thread = GetInputThread( p_input, 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_input_t *p_input,
455 libvlc_exception_t *p_e )
457 char *psz_geometry = 0;
458 vout_thread_t *p_vout = GetVout( p_input, p_e );
463 psz_geometry = var_GetString( p_vout, "crop" );
464 vlc_object_release( p_vout );
468 void libvlc_video_set_crop_geometry( libvlc_input_t *p_input,
469 char *psz_geometry, libvlc_exception_t *p_e )
471 vout_thread_t *p_vout = GetVout( p_input, 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_destroy( libvlc_input_t *p_input,
486 libvlc_exception_t *p_e )
488 vout_thread_t *p_vout = GetVout( p_input, p_e );
489 vlc_object_detach( p_vout );
490 vlc_object_release( p_vout );
491 vout_Destroy( p_vout );