1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
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"
30 #include <vlc/libvlc.h>
31 #include <vlc_input.h>
35 * Remember to release the returned vout_thread_t.
37 static vout_thread_t
*GetVout( libvlc_media_player_t
*p_mi
,
38 libvlc_exception_t
*p_exception
)
40 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
, p_exception
);
41 vout_thread_t
*p_vout
= NULL
;
45 p_vout
= vlc_object_find( p_input_thread
, VLC_OBJECT_VOUT
, FIND_CHILD
);
48 libvlc_exception_raise( p_exception
, "No active video output" );
50 vlc_object_release( p_input_thread
);
55 /**********************************************************************
57 **********************************************************************/
59 void libvlc_set_fullscreen( libvlc_media_player_t
*p_mi
, int b_fullscreen
,
60 libvlc_exception_t
*p_e
)
62 /* We only work on the first vout */
63 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
65 /* GetVout will raise the exception for us */
68 var_SetBool( p_vout
, "fullscreen", b_fullscreen
);
70 vlc_object_release( p_vout
);
73 int libvlc_get_fullscreen( libvlc_media_player_t
*p_mi
,
74 libvlc_exception_t
*p_e
)
76 /* We only work on the first vout */
77 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
80 /* GetVout will raise the exception for us */
81 if( !p_vout
) return 0;
83 i_ret
= var_GetBool( p_vout
, "fullscreen" );
85 vlc_object_release( p_vout
);
90 void libvlc_toggle_fullscreen( libvlc_media_player_t
*p_mi
,
91 libvlc_exception_t
*p_e
)
93 /* We only work on the first vout */
94 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
97 /* GetVout will raise the exception for us */
100 ret
= var_GetBool( p_vout
, "fullscreen" );
101 var_SetBool( p_vout
, "fullscreen", !ret
);
103 vlc_object_release( p_vout
);
107 libvlc_video_take_snapshot( libvlc_media_player_t
*p_mi
, char *psz_filepath
,
108 unsigned int i_width
, unsigned int i_height
, libvlc_exception_t
*p_e
)
110 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
111 input_thread_t
*p_input_thread
;
113 /* GetVout will raise the exception for us */
114 if( !p_vout
) return;
118 libvlc_exception_raise( p_e
, "filepath is null" );
122 var_SetInteger( p_vout
, "snapshot-width", i_width
);
123 var_SetInteger( p_vout
, "snapshot-height", i_height
);
125 p_input_thread
= p_mi
->p_input_thread
;
126 if( !p_mi
->p_input_thread
)
128 libvlc_exception_raise( p_e
, "Input does not exist" );
132 var_SetString( p_vout
, "snapshot-path", psz_filepath
);
133 var_SetString( p_vout
, "snapshot-format", "png" );
135 vout_Control( p_vout
, VOUT_SNAPSHOT
);
136 vlc_object_release( p_vout
);
139 int libvlc_video_get_height( libvlc_media_player_t
*p_mi
,
140 libvlc_exception_t
*p_e
)
144 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
145 if( !p_vout
) return 0;
147 height
= p_vout
->i_window_height
;
149 vlc_object_release( p_vout
);
154 int libvlc_video_get_width( libvlc_media_player_t
*p_mi
,
155 libvlc_exception_t
*p_e
)
159 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
160 if( !p_vout
) return 0;
162 width
= p_vout
->i_window_width
;
164 vlc_object_release( p_vout
);
169 int libvlc_media_player_has_vout( libvlc_media_player_t
*p_mi
,
170 libvlc_exception_t
*p_e
)
172 input_thread_t
*p_input_thread
= libvlc_get_input_thread(p_mi
, p_e
);
173 bool has_vout
= false;
177 vout_thread_t
*p_vout
;
179 p_vout
= vlc_object_find( p_input_thread
, VLC_OBJECT_VOUT
, FIND_CHILD
);
183 vlc_object_release( p_vout
);
185 vlc_object_release( p_input_thread
);
190 int libvlc_video_reparent( libvlc_media_player_t
*p_mi
, libvlc_drawable_t d
,
191 libvlc_exception_t
*p_e
)
193 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
197 vout_Control( p_vout
, VOUT_REPARENT
, d
);
198 vlc_object_release( p_vout
);
203 void libvlc_video_resize( libvlc_media_player_t
*p_mi
, int width
, int height
, libvlc_exception_t
*p_e
)
205 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
208 vout_Control( p_vout
, VOUT_SET_SIZE
, width
, height
);
209 vlc_object_release( p_vout
);
213 void libvlc_video_redraw_rectangle( libvlc_media_player_t
*p_mi
,
214 const libvlc_rectangle_t
*area
,
215 libvlc_exception_t
*p_e
)
218 && ((area
->bottom
- area
->top
) > 0)
219 && ((area
->right
- area
->left
) > 0) )
221 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
224 /* tell running vout to redraw area */
225 vout_Control( p_vout
, VOUT_REDRAW_RECT
,
226 area
->top
, area
->left
, area
->bottom
, area
->right
);
227 vlc_object_release( p_vout
);
232 /* global video settings */
234 /* Deprecated use libvlc_media_player_set_drawable() */
235 void libvlc_video_set_parent( libvlc_instance_t
*p_instance
, libvlc_drawable_t d
,
236 libvlc_exception_t
*p_e
)
238 /* set as default for future vout instances */
239 var_SetInteger(p_instance
->p_libvlc_int
, "drawable", (int)d
);
241 libvlc_media_player_t
*p_mi
= libvlc_playlist_get_media_player(p_instance
, p_e
);
244 libvlc_media_player_set_drawable( p_mi
, d
, p_e
);
245 libvlc_media_player_release(p_mi
);
249 /* Deprecated use libvlc_media_player_get_drawable() */
250 libvlc_drawable_t
libvlc_video_get_parent( libvlc_instance_t
*p_instance
, libvlc_exception_t
*p_e
)
254 libvlc_drawable_t result
;
256 result
= var_GetInteger( p_instance
->p_libvlc_int
, "drawable" );
262 void libvlc_video_set_size( libvlc_instance_t
*p_instance
, int width
, int height
,
263 libvlc_exception_t
*p_e
)
265 /* set as default for future vout instances */
266 config_PutInt(p_instance
->p_libvlc_int
, "width", width
);
267 config_PutInt(p_instance
->p_libvlc_int
, "height", height
);
269 libvlc_media_player_t
*p_mi
= libvlc_playlist_get_media_player(p_instance
, p_e
);
272 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
275 /* tell running vout to re-size */
276 vout_Control( p_vout
, VOUT_SET_SIZE
, width
, height
);
277 vlc_object_release( p_vout
);
279 libvlc_media_player_release(p_mi
);
283 void libvlc_video_set_viewport( libvlc_instance_t
*p_instance
,
284 const libvlc_rectangle_t
*view
, const libvlc_rectangle_t
*clip
,
285 libvlc_exception_t
*p_e
)
289 libvlc_exception_raise( p_e
, "viewport is NULL" );
293 /* if clip is NULL, then use view rectangle as clip */
297 /* set as default for future vout instances */
298 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-view-top", view
->top
);
299 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-view-left", view
->left
);
300 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-view-bottom", view
->bottom
);
301 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-view-right", view
->right
);
302 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-clip-top", clip
->top
);
303 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-clip-left", clip
->left
);
304 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-clip-bottom", clip
->bottom
);
305 var_SetInteger( p_instance
->p_libvlc_int
, "drawable-clip-right", clip
->right
);
307 libvlc_media_player_t
*p_mi
= libvlc_playlist_get_media_player(p_instance
, p_e
);
310 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
313 /* change viewport for running vout */
314 vout_Control( p_vout
, VOUT_SET_VIEWPORT
,
315 view
->top
, view
->left
, view
->bottom
, view
->right
,
316 clip
->top
, clip
->left
, clip
->bottom
, clip
->right
);
317 vlc_object_release( p_vout
);
319 libvlc_media_player_release(p_mi
);
323 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t
*p_mi
,
324 libvlc_exception_t
*p_e
)
326 char *psz_aspect
= 0;
327 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
329 if( !p_vout
) return 0;
331 psz_aspect
= var_GetNonEmptyString( p_vout
, "aspect-ratio" );
332 vlc_object_release( p_vout
);
333 return psz_aspect
? psz_aspect
: strdup("");
336 void libvlc_video_set_aspect_ratio( libvlc_media_player_t
*p_mi
,
337 char *psz_aspect
, libvlc_exception_t
*p_e
)
339 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
342 if( !p_vout
) return;
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_get_spu( libvlc_media_player_t
*p_mi
,
353 libvlc_exception_t
*p_e
)
355 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
, p_e
);
356 vlc_value_t val_list
;
362 if( !p_input_thread
) return -1;
364 i_ret
= var_Get( p_input_thread
, "spu-es", &val
);
367 libvlc_exception_raise( p_e
, "Getting subtitle information failed" );
368 vlc_object_release( p_input_thread
);
372 var_Change( p_input_thread
, "spu-es", VLC_VAR_GETCHOICES
, &val_list
, NULL
);
373 for( i
= 0; i
< val_list
.p_list
->i_count
; i
++ )
375 vlc_value_t spu_val
= val_list
.p_list
->p_values
[i
];
376 if( val
.i_int
== spu_val
.i_int
)
382 vlc_object_release( p_input_thread
);
386 void libvlc_video_set_spu( libvlc_media_player_t
*p_mi
, int i_spu
,
387 libvlc_exception_t
*p_e
)
389 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
, p_e
);
390 vlc_value_t val_list
;
394 if( !p_input_thread
) return;
396 var_Change( p_input_thread
, "spu-es", VLC_VAR_GETCHOICES
, &val_list
, NULL
);
397 for( i
= 0; i
< val_list
.p_list
->i_count
; i
++ )
399 vlc_value_t val
= val_list
.p_list
->p_values
[i
];
400 if( i_spu
== val
.i_int
)
404 new_val
.i_int
= val
.i_int
;
405 i_ret
= var_Set( p_input_thread
, "spu-es", new_val
);
408 libvlc_exception_raise( p_e
, "Setting subtitle value failed" );
410 vlc_object_release( p_input_thread
);
414 libvlc_exception_raise( p_e
, "Subtitle value out of range" );
415 vlc_object_release( p_input_thread
);
418 int libvlc_video_set_subtitle_file( libvlc_media_player_t
*p_mi
,
420 libvlc_exception_t
*p_e
)
422 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
, p_e
);
427 if( input_AddSubtitles( p_input_thread
, psz_subtitle
, true ) )
429 vlc_object_release( p_input_thread
);
434 char *libvlc_video_get_crop_geometry( libvlc_media_player_t
*p_mi
,
435 libvlc_exception_t
*p_e
)
437 char *psz_geometry
= 0;
438 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
440 if( !p_vout
) return 0;
442 psz_geometry
= var_GetNonEmptyString( p_vout
, "crop" );
443 vlc_object_release( p_vout
);
444 return psz_geometry
? psz_geometry
: strdup("");
447 void libvlc_video_set_crop_geometry( libvlc_media_player_t
*p_mi
,
448 char *psz_geometry
, libvlc_exception_t
*p_e
)
450 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
453 if( !p_vout
) return;
455 i_ret
= var_SetString( p_vout
, "crop", psz_geometry
);
457 libvlc_exception_raise( p_e
,
458 "Unexpected error while setting crop geometry" );
460 vlc_object_release( p_vout
);
463 int libvlc_video_get_teletext( libvlc_media_player_t
*p_mi
,
464 libvlc_exception_t
*p_e
)
466 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
470 if( !p_vout
) return i_ret
;
472 p_vbi
= (vlc_object_t
*) vlc_object_find_name( p_vout
, "zvbi",
476 i_ret
= var_GetInteger( p_vbi
, "vbi-page" );
477 vlc_object_release( p_vbi
);
480 vlc_object_release( p_vout
);
484 void libvlc_video_set_teletext( libvlc_media_player_t
*p_mi
, int i_page
,
485 libvlc_exception_t
*p_e
)
487 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
491 if( !p_vout
) return;
493 p_vbi
= (vlc_object_t
*) vlc_object_find_name( p_vout
, "zvbi",
497 i_ret
= var_SetInteger( p_vbi
, "vbi-page", i_page
);
498 vlc_object_release( p_vbi
);
501 libvlc_exception_raise( p_e
,
502 "Unexpected error while setting teletext page" );
503 vlc_object_release( p_vout
);
506 void libvlc_toggle_teletext( libvlc_media_player_t
*p_mi
,
507 libvlc_exception_t
*p_e
)
509 /* We only work on the first vout */
510 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
511 bool opaque
; int i_ret
;
513 /* GetVout will raise the exception for us */
514 if( !p_vout
) return;
516 opaque
= var_GetBool( p_vout
, "vbi-opaque" );
517 i_ret
= var_SetBool( p_vout
, "vbi-opaque", !opaque
);
519 libvlc_exception_raise( p_e
,
520 "Unexpected error while setting teletext value" );
522 vlc_object_release( p_vout
);
525 int libvlc_video_destroy( libvlc_media_player_t
*p_mi
,
526 libvlc_exception_t
*p_e
)
528 vout_thread_t
*p_vout
= GetVout( p_mi
, p_e
);
529 vlc_object_detach( p_vout
);
530 vlc_object_release( p_vout
);
531 vlc_object_release( p_vout
);