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>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #include "libvlc_internal.h"
27 #include <vlc/libvlc.h>
28 #include <vlc_input.h>
32 * Remember to release the returned input_thread_t since it is locked at
33 * the end of this function.
35 static input_thread_t *GetInputThread( libvlc_input_t *p_input,
36 libvlc_exception_t *p_exception )
38 input_thread_t *p_input_thread;
42 libvlc_exception_raise( p_exception, "Input is NULL" );
46 p_input_thread = (input_thread_t*)vlc_object_get(
47 p_input->p_instance->p_libvlc_int,
48 p_input->i_input_id );
51 libvlc_exception_raise( p_exception, "Input does not exist" );
55 return p_input_thread;;
59 * Remember to release the returned vout_thread_t since it is locked at
60 * the end of this function.
62 static vout_thread_t *GetVout( libvlc_input_t *p_input,
63 libvlc_exception_t *p_exception )
65 input_thread_t *p_input_thread = GetInputThread(p_input, p_exception);
66 vout_thread_t *p_vout = NULL;
70 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
73 libvlc_exception_raise( p_exception, "No active video output" );
75 vlc_object_release( p_input_thread );
80 /**********************************************************************
82 **********************************************************************/
84 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
85 libvlc_exception_t *p_e )
87 /* We only work on the first vout */
88 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
89 vlc_value_t val; int i_ret;
91 /* GetVout will raise the exception for us */
97 if( b_fullscreen ) val.b_bool = VLC_TRUE;
98 else val.b_bool = VLC_FALSE;
100 i_ret = var_Set( p_vout1, "fullscreen", val );
102 libvlc_exception_raise( p_e,
103 "Unexpected error while setting fullscreen value" );
105 vlc_object_release( p_vout1 );
108 int libvlc_get_fullscreen( libvlc_input_t *p_input,
109 libvlc_exception_t *p_e )
111 /* We only work on the first vout */
112 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
113 vlc_value_t val; int i_ret;
115 /* GetVout will raise the exception for us */
119 i_ret = var_Get( p_vout1, "fullscreen", &val );
121 libvlc_exception_raise( p_e,
122 "Unexpected error while looking up fullscreen value" );
124 return val.b_bool == VLC_TRUE ? 1 : 0;
127 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
128 libvlc_exception_t *p_e )
130 /* We only work on the first vout */
131 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
132 vlc_value_t val; int i_ret;
134 /* GetVout will raise the exception for us */
138 i_ret = var_Get( p_vout1, "fullscreen", &val );
140 libvlc_exception_raise( p_e,
141 "Unexpected error while looking up fullscreen value" );
143 val.b_bool = !val.b_bool;
144 i_ret = var_Set( p_vout1, "fullscreen", val );
146 libvlc_exception_raise( p_e,
147 "Unexpected error while setting fullscreen value" );
149 vlc_object_release( p_vout1 );
153 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
154 libvlc_exception_t *p_e )
156 vout_thread_t *p_vout = GetVout( p_input, p_e );
157 input_thread_t *p_input_thread;
161 /* GetVout will raise the exception for us */
167 p_input_thread = (input_thread_t*)vlc_object_get(
168 p_input->p_instance->p_libvlc_int,
169 p_input->i_input_id );
170 if( !p_input_thread )
172 libvlc_exception_raise( p_e, "Input does not exist" );
176 snprintf( path, 255, "%s", psz_filepath );
177 var_SetString( p_vout, "snapshot-path", path );
178 var_SetString( p_vout, "snapshot-format", "png" );
180 vout_Control( p_vout, VOUT_SNAPSHOT );
181 vlc_object_release( p_vout );
182 vlc_object_release( p_input_thread );
185 int libvlc_video_get_height( libvlc_input_t *p_input,
186 libvlc_exception_t *p_e )
188 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
192 vlc_object_release( p_vout1 );
194 return p_vout1->i_window_height;
197 int libvlc_video_get_width( libvlc_input_t *p_input,
198 libvlc_exception_t *p_e )
200 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
204 vlc_object_release( p_vout1 );
206 return p_vout1->i_window_width;
209 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
210 libvlc_exception_t *p_e )
212 input_thread_t *p_input_thread = GetInputThread(p_input, p_e);
213 vlc_bool_t has_vout = VLC_FALSE;
217 vout_thread_t *p_vout;
219 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
223 vlc_object_release( p_vout );
225 vlc_object_release( p_input_thread );
230 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
231 libvlc_exception_t *p_e )
233 vout_thread_t *p_vout = GetVout( p_input, p_e );
237 vout_Control( p_vout , VOUT_REPARENT, d);
238 vlc_object_release( p_vout );
243 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
245 vout_thread_t *p_vout = GetVout( p_input, p_e );
248 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
249 vlc_object_release( p_vout );
253 /* global video settings */
255 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
256 libvlc_exception_t *p_e )
258 /* set as default for future vout instances */
259 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
261 if( libvlc_playlist_isplaying(p_instance, p_e) )
263 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
266 vout_thread_t *p_vout = GetVout( p_input, p_e );
269 /* tell running vout to re-parent */
270 vout_Control( p_vout , VOUT_REPARENT, d);
271 vlc_object_release( p_vout );
273 libvlc_input_free(p_input);
278 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
280 libvlc_drawable_t result;
282 result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
288 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
289 libvlc_exception_t *p_e )
291 /* set as default for future vout instances */
292 config_PutInt(p_instance->p_libvlc_int, "width", width);
293 config_PutInt(p_instance->p_libvlc_int, "height", height);
295 if( libvlc_playlist_isplaying(p_instance, p_e) )
297 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
300 vout_thread_t *p_vout = GetVout( p_input, p_e );
303 /* tell running vout to re-size */
304 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
305 vlc_object_release( p_vout );
307 libvlc_input_free(p_input);
312 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
313 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
314 libvlc_exception_t *p_e )
318 libvlc_exception_raise( p_e, "viewport is NULL" );
321 /* if clip is NULL, then use view rectangle as clip */
325 /* set as default for future vout instances */
326 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
327 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
328 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
329 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
330 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
331 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
332 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
333 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
335 if( libvlc_playlist_isplaying(p_instance, p_e) )
337 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
340 vout_thread_t *p_vout = GetVout( p_input, p_e );
343 /* change viewport for running vout */
344 vout_Control( p_vout , VOUT_SET_VIEWPORT,
345 view->top, view->left, view->bottom, view->right,
346 clip->top, clip->left, clip->bottom, clip->right );
347 vlc_object_release( p_vout );
349 libvlc_input_free(p_input);
354 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
355 libvlc_exception_t *p_e )
357 char *psz_aspect = 0;
358 vout_thread_t *p_vout = GetVout( p_input, p_e );
363 psz_aspect = var_GetString( p_vout, "aspect-ratio" );
364 vlc_object_release( p_vout );
368 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
369 char *psz_aspect, libvlc_exception_t *p_e )
371 vout_thread_t *p_vout = GetVout( p_input, p_e );
377 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
379 libvlc_exception_raise( p_e,
380 "Unexpected error while setting aspect-ratio value" );
382 vlc_object_release( p_vout );
385 char *libvlc_video_get_crop_geometry( libvlc_input_t *p_input,
386 libvlc_exception_t *p_e )
388 char *psz_geometry = 0;
389 vout_thread_t *p_vout = GetVout( p_input, p_e );
394 psz_geometry = var_GetString( p_vout, "crop" );
395 vlc_object_release( p_vout );
399 void libvlc_video_set_crop_geometry( libvlc_input_t *p_input,
400 char *psz_geometry, libvlc_exception_t *p_e )
402 vout_thread_t *p_vout = GetVout( p_input, p_e );
408 i_ret = var_SetString( p_vout, "crop", psz_geometry );
410 libvlc_exception_raise( p_e,
411 "Unexpected error while setting crop geometry" );
413 vlc_object_release( p_vout );
416 int libvlc_video_destroy( libvlc_input_t *p_input,
417 libvlc_exception_t *p_e )
419 vout_thread_t *p_vout = GetVout( p_input, p_e );
420 vlc_object_detach( p_vout );
421 vlc_object_release( p_vout );
422 vout_Destroy( p_vout );