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_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
73 libvlc_exception_t *p_e )
75 /* We only work on the first vout */
76 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
77 vlc_value_t val; int i_ret;
79 /* GetVout will raise the exception for us */
85 if( b_fullscreen ) val.b_bool = VLC_TRUE;
86 else val.b_bool = VLC_FALSE;
88 i_ret = var_Set( p_vout1, "fullscreen", val );
90 libvlc_exception_raise( p_e,
91 "Unexpected error while setting fullscreen value" );
93 vlc_object_release( p_vout1 );
96 int libvlc_get_fullscreen( libvlc_input_t *p_input,
97 libvlc_exception_t *p_e )
99 /* We only work on the first vout */
100 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
101 vlc_value_t val; int i_ret;
103 /* GetVout will raise the exception for us */
107 i_ret = var_Get( p_vout1, "fullscreen", &val );
109 libvlc_exception_raise( p_e,
110 "Unexpected error while looking up fullscreen value" );
112 return val.b_bool == VLC_TRUE ? 1 : 0;
115 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
116 libvlc_exception_t *p_e )
118 /* We only work on the first vout */
119 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
120 vlc_value_t val; int i_ret;
122 /* GetVout will raise the exception for us */
126 i_ret = var_Get( p_vout1, "fullscreen", &val );
128 libvlc_exception_raise( p_e,
129 "Unexpected error while looking up fullscreen value" );
131 val.b_bool = !val.b_bool;
132 i_ret = var_Set( p_vout1, "fullscreen", val );
134 libvlc_exception_raise( p_e,
135 "Unexpected error while setting fullscreen value" );
137 vlc_object_release( p_vout1 );
141 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
142 libvlc_exception_t *p_e )
144 vout_thread_t *p_vout = GetVout( p_input, p_e );
145 input_thread_t *p_input_thread;
149 /* GetVout will raise the exception for us */
155 p_input_thread = (input_thread_t*)vlc_object_get(
156 p_input->p_instance->p_libvlc_int,
157 p_input->i_input_id );
158 if( !p_input_thread )
160 libvlc_exception_raise( p_e, "Input does not exist" );
164 snprintf( path, 255, "%s", psz_filepath );
165 var_SetString( p_vout, "snapshot-path", path );
166 var_SetString( p_vout, "snapshot-format", "png" );
168 vout_Control( p_vout, VOUT_SNAPSHOT );
169 vlc_object_release( p_vout );
170 vlc_object_release( p_input_thread );
173 int libvlc_video_get_height( libvlc_input_t *p_input,
174 libvlc_exception_t *p_e )
176 vout_thread_t *p_vout1 = GetVout( p_input, p_e );
180 vlc_object_release( p_vout1 );
182 return p_vout1->i_window_height;
185 int libvlc_video_get_width( 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_width;
197 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
198 libvlc_exception_t *p_e )
200 vout_thread_t *p_vout = GetVout( p_input, p_e );
202 /* GetVout will raise the exception for us */
208 vlc_object_release( p_vout );
213 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
214 libvlc_exception_t *p_e )
216 vout_thread_t *p_vout = GetVout( p_input, p_e );
217 vout_Control( p_vout , VOUT_REPARENT, d);
218 vlc_object_release( p_vout );
223 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
225 vout_thread_t *p_vout = GetVout( p_input, p_e );
226 vout_Control( p_vout, VOUT_SET_SIZE, width, height );
227 vlc_object_release( p_vout );
230 /* global video settings */
232 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
233 libvlc_exception_t *p_e )
235 /* set as default for future vout instances */
236 var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
238 if( libvlc_playlist_isplaying(p_instance, p_e) )
240 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
243 vout_thread_t *p_vout = GetVout( p_input, p_e );
246 /* tell running vout to re-parent */
247 vout_Control( p_vout , VOUT_REPARENT, d);
248 vlc_object_release( p_vout );
250 libvlc_input_free(p_input);
255 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
256 libvlc_exception_t *p_e )
258 /* set as default for future vout instances */
259 config_PutInt(p_instance->p_libvlc_int, "width", width);
260 config_PutInt(p_instance->p_libvlc_int, "height", height);
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-size */
271 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
272 vlc_object_release( p_vout );
274 libvlc_input_free(p_input);
279 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
280 const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
281 libvlc_exception_t *p_e )
285 libvlc_exception_raise( p_e, "viewport is NULL" );
288 /* if clip is NULL, then use view rectangle as clip */
292 /* set as default for future vout instances */
293 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
294 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
295 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
296 var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
297 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
298 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
299 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
300 var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
302 if( libvlc_playlist_isplaying(p_instance, p_e) )
304 libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
307 vout_thread_t *p_vout = GetVout( p_input, p_e );
310 /* change viewport for running vout */
311 vout_Control( p_vout , VOUT_SET_VIEWPORT,
312 view->top, view->left, view->bottom, view->right,
313 clip->top, clip->left, clip->bottom, clip->right );
314 vlc_object_release( p_vout );
316 libvlc_input_free(p_input);
321 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
322 libvlc_exception_t *p_e )
324 char *psz_aspect = 0;
325 vout_thread_t *p_vout = GetVout( p_input, p_e );
330 psz_aspect = var_GetString( p_vout1, "aspect-ratio" );
331 vlc_object_release( p_vout );
335 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
336 char *psz_aspect, libvlc_exception_t *p_e )
338 vout_thread_t *p_vout = GetVout( p_input, p_e );
344 i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
346 libvlc_exception_raise( p_e,
347 "Unexpected error while setting aspect-ratio value" );
349 vlc_object_release( p_vout );
352 int libvlc_video_destroy( libvlc_input_t *p_input,
353 libvlc_exception_t *p_e )
355 vout_thread_t *p_vout = GetVout( p_input, p_e );
356 vlc_object_detach( p_vout );
357 vlc_object_release( p_vout );
358 vout_Destroy( p_vout );