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>
33 * Remember to release the returned vout_thread_t since it is locked at
34 * the end of this function.
36 static vout_thread_t *GetVout( libvlc_input_t *p_input,
37 libvlc_exception_t *p_exception )
39 input_thread_t *p_input_thread;
40 vout_thread_t *p_vout;
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 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
60 vlc_object_release( p_input_thread );
61 libvlc_exception_raise( p_exception, "No active video output" );
64 vlc_object_release( p_input_thread );
68 /**********************************************************************
70 **********************************************************************/
72 void libvlc_set_video_drawable( libvlc_instance_t *p_instance,
73 libvlc_drawable_t drawable,
74 libvlc_exception_t *p_e )
77 value.i_int = drawable;
79 var_Set( p_instance->p_libvlc_int, "drawable", value);
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 vout_thread_t *p_vout = GetVout( p_input, p_e );
214 /* GetVout will raise the exception for us */
220 vlc_object_release( p_vout );
225 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
226 libvlc_exception_t *p_e )
228 vout_thread_t *p_vout = GetVout( p_input, p_e );
229 vout_Control( p_vout , VOUT_REPARENT, d);
230 vlc_object_release( p_vout );
235 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
237 vout_thread_t *p_vout = GetVout( p_input, p_e );
238 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
239 vlc_object_release( p_vout );
242 /* global video settings */
244 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
245 libvlc_exception_t *p_e )
247 /* set as default for future vout instances */
248 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
250 if( libvlc_playlist_isplaying(p_instance, p_e) )
252 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
255 vout_thread_t *p_vout = GetVout( p_input, p_e );
258 /* tell running vout to re-parent */
259 vout_Control( p_vout , VOUT_REPARENT, d);
260 vlc_object_release( p_vout );
262 libvlc_input_free(p_input);
267 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
268 libvlc_exception_t *p_e )
270 /* set as default for future vout instances */
271 config_PutInt(p_instance->p_libvlc_int, "width", width);
272 config_PutInt(p_instance->p_libvlc_int, "height", height);
274 if( libvlc_playlist_isplaying(p_instance, p_e) )
276 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
279 vout_thread_t *p_vout = GetVout( p_input, p_e );
282 /* tell running vout to re-size */
283 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
284 vlc_object_release( p_vout );
286 libvlc_input_free(p_input);
291 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
292 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
293 libvlc_exception_t *p_e )
297 libvlc_exception_raise( p_e, "viewport is NULL" );
300 /* if clip is NULL, then use view rectangle as clip */
304 /* set as default for future vout instances */
305 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
306 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
307 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
308 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
309 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
310 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
311 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
312 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
314 if( libvlc_playlist_isplaying(p_instance, p_e) )
316 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
319 vout_thread_t *p_vout = GetVout( p_input, p_e );
322 /* change viewport for running vout */
323 vout_Control( p_vout , VOUT_SET_VIEWPORT,
324 view->top, view->left, view->bottom, view->right,
325 clip->top, clip->left, clip->bottom, clip->right );
326 vlc_object_release( p_vout );
328 libvlc_input_free(p_input);
333 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
334 libvlc_exception_t *p_e )
336 char *psz_aspect = 0;
337 vout_thread_t *p_vout = GetVout( p_input, p_e );
342 psz_aspect = var_GetString( p_vout, "aspect-ratio" );
343 vlc_object_release( p_vout );
347 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
348 char *psz_aspect, libvlc_exception_t *p_e )
350 vout_thread_t *p_vout = GetVout( p_input, p_e );
356 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
358 libvlc_exception_raise( p_e,
359 "Unexpected error while setting aspect-ratio value" );
361 vlc_object_release( p_vout );
364 int libvlc_video_destroy( libvlc_input_t *p_input,
365 libvlc_exception_t *p_e )
367 vout_thread_t *p_vout = GetVout( p_input, p_e );
368 vlc_object_detach( p_vout );
369 vlc_object_release( p_vout );
370 vout_Destroy( p_vout );