]> git.sesse.net Git - vlc/blob - src/control/video.c
Removes trailing spaces. Removes tabs.
[vlc] / src / control / video.c
1 /*****************************************************************************
2  * video.c: libvlc new API video functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
7  *
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>
12  *
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.
17  *
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.
22  *
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  *****************************************************************************/
27
28 #include <vlc/libvlc.h>
29 #include <vlc_input.h>
30 #include <vlc_vout.h>
31
32 #include "libvlc_internal.h"
33
34 /*
35  * Remember to release the returned vout_thread_t since it is locked at
36  * the end of this function.
37  */
38 static vout_thread_t *GetVout( libvlc_media_instance_t *p_mi,
39                                libvlc_exception_t *p_exception )
40 {
41     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_exception );
42     vout_thread_t *p_vout = NULL;
43
44     if( p_input_thread )
45     {
46         p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
47         if( !p_vout )
48         {
49             libvlc_exception_raise( p_exception, "No active video output" );
50         }
51         vlc_object_release( p_input_thread );
52     }
53     return p_vout;
54 }
55
56 /**********************************************************************
57  * Exported functions
58  **********************************************************************/
59
60 void libvlc_set_fullscreen( libvlc_media_instance_t *p_mi, int b_fullscreen,
61                             libvlc_exception_t *p_e )
62 {
63     /* We only work on the first vout */
64     vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
65     vlc_value_t val; int i_ret;
66
67     /* GetVout will raise the exception for us */
68     if( !p_vout1 )
69     {
70         return;
71     }
72
73     if( b_fullscreen ) val.b_bool = VLC_TRUE;
74     else               val.b_bool = VLC_FALSE;
75
76     i_ret = var_Set( p_vout1, "fullscreen", val );
77     if( i_ret )
78         libvlc_exception_raise( p_e,
79                         "Unexpected error while setting fullscreen value" );
80
81     vlc_object_release( p_vout1 );
82 }
83
84 int libvlc_get_fullscreen( libvlc_media_instance_t *p_mi,
85                             libvlc_exception_t *p_e )
86 {
87     /* We only work on the first vout */
88     vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
89     vlc_value_t val; int i_ret;
90
91     /* GetVout will raise the exception for us */
92     if( !p_vout1 )
93         return 0;
94
95     i_ret = var_Get( p_vout1, "fullscreen", &val );
96     if( i_ret )
97         libvlc_exception_raise( p_e,
98                         "Unexpected error while looking up fullscreen value" );
99
100     return val.b_bool == VLC_TRUE ? 1 : 0;
101 }
102
103 void libvlc_toggle_fullscreen( libvlc_media_instance_t *p_mi,
104                                libvlc_exception_t *p_e )
105 {
106     /* We only work on the first vout */
107     vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
108     vlc_value_t val; int i_ret;
109
110     /* GetVout will raise the exception for us */
111     if( !p_vout1 )
112         return;
113
114     i_ret = var_Get( p_vout1, "fullscreen", &val );
115     if( i_ret )
116         libvlc_exception_raise( p_e,
117                         "Unexpected error while looking up fullscreen value" );
118
119     val.b_bool = !val.b_bool;
120     i_ret = var_Set( p_vout1, "fullscreen", val );
121     if( i_ret )
122         libvlc_exception_raise( p_e,
123                         "Unexpected error while setting fullscreen value" );
124
125     vlc_object_release( p_vout1 );
126 }
127
128 void
129 libvlc_video_take_snapshot( libvlc_media_instance_t *p_mi, char *psz_filepath,
130                        libvlc_exception_t *p_e )
131 {
132     vout_thread_t *p_vout = GetVout( p_mi, p_e );
133     input_thread_t *p_input_thread;
134
135     /* GetVout will raise the exception for us */
136     if( !p_vout )
137     {
138         return;
139     }
140
141     if( !psz_filepath )
142     {
143         libvlc_exception_raise( p_e, "filepath is null" );
144         return;
145     }
146
147
148     p_input_thread = (input_thread_t*)vlc_object_get(
149                                  p_mi->p_libvlc_instance->p_libvlc_int,
150                                  p_mi->i_input_id );
151     if( !p_input_thread )
152     {
153         libvlc_exception_raise( p_e, "Input does not exist" );
154         return;
155     }
156
157     var_SetString( p_vout, "snapshot-path", psz_filepath );
158     var_SetString( p_vout, "snapshot-format", "png" );
159
160     vout_Control( p_vout, VOUT_SNAPSHOT );
161     vlc_object_release( p_vout );
162     vlc_object_release( p_input_thread );
163 }
164
165 int libvlc_video_get_height( libvlc_media_instance_t *p_mi,
166                              libvlc_exception_t *p_e )
167 {
168     vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
169     if( !p_vout1 )
170         return 0;
171
172     vlc_object_release( p_vout1 );
173
174     return p_vout1->i_window_height;
175 }
176
177 int libvlc_video_get_width( libvlc_media_instance_t *p_mi,
178                             libvlc_exception_t *p_e )
179 {
180     vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
181     if( !p_vout1 )
182         return 0;
183
184     vlc_object_release( p_vout1 );
185
186     return p_vout1->i_window_width;
187 }
188
189 vlc_bool_t libvlc_media_instance_has_vout( libvlc_media_instance_t *p_mi,
190                                   libvlc_exception_t *p_e )
191 {
192     input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
193     vlc_bool_t has_vout = VLC_FALSE;
194
195     if( p_input_thread )
196     {
197         vout_thread_t *p_vout;
198
199         p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
200         if( p_vout )
201         {
202             has_vout = VLC_TRUE;
203             vlc_object_release( p_vout );
204         }
205         vlc_object_release( p_input_thread );
206     }
207     return has_vout;
208 }
209
210 int libvlc_video_reparent( libvlc_media_instance_t *p_mi, libvlc_drawable_t d,
211                            libvlc_exception_t *p_e )
212 {
213     vout_thread_t *p_vout = GetVout( p_mi, p_e );
214
215     if( p_vout )
216     {
217         vout_Control( p_vout , VOUT_REPARENT, d);
218         vlc_object_release( p_vout );
219     }
220     return 0;
221 }
222
223 void libvlc_video_resize( libvlc_media_instance_t *p_mi, int width, int height, libvlc_exception_t *p_e )
224 {
225     vout_thread_t *p_vout = GetVout( p_mi, p_e );
226     if( p_vout )
227     {
228         vout_Control( p_vout, VOUT_SET_SIZE, width, height );
229         vlc_object_release( p_vout );
230     }
231 }
232
233 void libvlc_video_redraw_rectangle( libvlc_media_instance_t *p_mi,
234                            const libvlc_rectangle_t *area,
235                            libvlc_exception_t *p_e )
236 {
237     if( (NULL != area)
238      && ((area->bottom - area->top) > 0)
239      && ((area->right - area->left) > 0) )
240     {
241         vout_thread_t *p_vout = GetVout( p_mi, p_e );
242         if( p_vout )
243         {
244             /* tell running vout to redraw area */
245             vout_Control( p_vout , VOUT_REDRAW_RECT,
246                                area->top, area->left, area->bottom, area->right );
247             vlc_object_release( p_vout );
248         }
249     }
250 }
251
252 /* global video settings */
253
254 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
255                               libvlc_exception_t *p_e )
256 {
257     /* set as default for future vout instances */
258     var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
259
260     if( libvlc_playlist_isplaying(p_instance, p_e) )
261     {
262         libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
263         if( p_mi )
264         {
265             vout_thread_t *p_vout = GetVout( p_mi, p_e );
266             if( p_vout )
267             {
268                 /* tell running vout to re-parent */
269                 vout_Control( p_vout , VOUT_REPARENT, d);
270                 vlc_object_release( p_vout );
271             }
272             libvlc_media_instance_release(p_mi);
273         }
274     }
275 }
276
277 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
278 {
279     libvlc_drawable_t result;
280  
281     result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
282  
283     return result;
284 }
285
286
287 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
288                            libvlc_exception_t *p_e )
289 {
290     /* set as default for future vout instances */
291     config_PutInt(p_instance->p_libvlc_int, "width", width);
292     config_PutInt(p_instance->p_libvlc_int, "height", height);
293
294     if( libvlc_playlist_isplaying(p_instance, p_e) )
295     {
296         libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
297         if( p_mi )
298         {
299             vout_thread_t *p_vout = GetVout( p_mi, p_e );
300             if( p_vout )
301             {
302                 /* tell running vout to re-size */
303                 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
304                 vlc_object_release( p_vout );
305             }
306             libvlc_media_instance_release(p_mi);
307         }
308     }
309 }
310
311 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
312                             const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
313                            libvlc_exception_t *p_e )
314 {
315     if( NULL == view )
316     {
317         libvlc_exception_raise( p_e, "viewport is NULL" );
318     }
319
320     /* if clip is NULL, then use view rectangle as clip */
321     if( NULL == clip )
322         clip = view;
323
324     /* set as default for future vout instances */
325     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
326     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
327     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
328     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
329     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
330     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
331     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
332     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
333
334     if( libvlc_playlist_isplaying(p_instance, p_e) )
335     {
336         libvlc_media_instance_t *p_mi = libvlc_playlist_get_media_instance(p_instance, p_e);
337         if( p_mi )
338         {
339             vout_thread_t *p_vout = GetVout( p_mi, p_e );
340             if( p_vout )
341             {
342                 /* change viewport for running vout */
343                 vout_Control( p_vout , VOUT_SET_VIEWPORT,
344                                    view->top, view->left, view->bottom, view->right,
345                                    clip->top, clip->left, clip->bottom, clip->right );
346                 vlc_object_release( p_vout );
347             }
348             libvlc_media_instance_release(p_mi);
349         }
350     }
351 }
352
353 char *libvlc_video_get_aspect_ratio( libvlc_media_instance_t *p_mi,
354                                      libvlc_exception_t *p_e )
355 {
356     char *psz_aspect = 0;
357     vout_thread_t *p_vout = GetVout( p_mi, p_e );
358
359     if( !p_vout )
360         return 0;
361
362     psz_aspect = var_GetString( p_vout, "aspect-ratio" );
363     vlc_object_release( p_vout );
364     return psz_aspect;
365 }
366
367 void libvlc_video_set_aspect_ratio( libvlc_media_instance_t *p_mi,
368                                     char *psz_aspect, libvlc_exception_t *p_e )
369 {
370     vout_thread_t *p_vout = GetVout( p_mi, p_e );
371     int i_ret = -1;
372
373     if( !p_vout )
374         return;
375
376     i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
377     if( i_ret )
378         libvlc_exception_raise( p_e,
379                         "Unexpected error while setting aspect-ratio value" );
380
381     vlc_object_release( p_vout );
382 }
383
384 int libvlc_video_get_spu( libvlc_media_instance_t *p_mi,
385                           libvlc_exception_t *p_e )
386 {
387     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
388     vlc_value_t val_list;
389     vlc_value_t val;
390     int i_spu = -1;
391     int i_ret = -1;
392     int i;
393
394     if( !p_input_thread )
395         return -1;
396
397     i_ret = var_Get( p_input_thread, "spu-es", &val );
398     if( i_ret < 0 )
399     {
400         libvlc_exception_raise( p_e, "Getting subtitle information failed" );
401         vlc_object_release( p_input_thread );
402         return i_ret;
403     }
404
405     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
406     for( i = 0; i < val_list.p_list->i_count; i++ )
407     {
408         vlc_value_t spu_val = val_list.p_list->p_values[i];
409         if( val.i_int == spu_val.i_int )
410         {
411             i_spu = i;
412             break;
413         }
414     }
415     vlc_object_release( p_input_thread );
416     return i_spu;
417 }
418
419 void libvlc_video_set_spu( libvlc_media_instance_t *p_mi, int i_spu,
420                            libvlc_exception_t *p_e )
421 {
422     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
423     vlc_value_t val_list;
424     int i_ret = -1;
425     int i;
426
427     if( !p_input_thread )
428         return;
429
430     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
431     for( i = 0; i < val_list.p_list->i_count; i++ )
432     {
433         vlc_value_t val = val_list.p_list->p_values[i];
434         if( i_spu == i )
435         {
436             vlc_value_t new_val;
437
438             new_val.i_int = val.i_int;
439             i_ret = var_Set( p_input_thread, "spu-es", new_val );
440             if( i_ret < 0 )
441             {
442                 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
443             }
444             vlc_object_release( p_input_thread );
445             return;
446         }
447     }
448     libvlc_exception_raise( p_e, "Subtitle value out of range" );
449     vlc_object_release( p_input_thread );
450 }
451
452 char *libvlc_video_get_crop_geometry( libvlc_media_instance_t *p_mi,
453                                    libvlc_exception_t *p_e )
454 {
455     char *psz_geometry = 0;
456     vout_thread_t *p_vout = GetVout( p_mi, p_e );
457
458     if( !p_vout )
459         return 0;
460
461     psz_geometry = var_GetString( p_vout, "crop" );
462     vlc_object_release( p_vout );
463     return psz_geometry;
464 }
465
466 void libvlc_video_set_crop_geometry( libvlc_media_instance_t *p_mi,
467                                     char *psz_geometry, libvlc_exception_t *p_e )
468 {
469     vout_thread_t *p_vout = GetVout( p_mi, p_e );
470     int i_ret = -1;
471
472     if( !p_vout )
473         return;
474
475     i_ret = var_SetString( p_vout, "crop", psz_geometry );
476     if( i_ret )
477         libvlc_exception_raise( p_e,
478                         "Unexpected error while setting crop geometry" );
479
480     vlc_object_release( p_vout );
481 }
482
483 int libvlc_video_get_teletext( libvlc_media_instance_t *p_mi,
484                                libvlc_exception_t *p_e )
485 {
486     vout_thread_t *p_vout = GetVout( p_mi, p_e );
487     int i_ret = -1;
488
489     if( !p_vout )
490         return i_ret;
491
492     i_ret = var_GetInteger( p_vout, "vbi-page" );
493     vlc_object_release( p_vout );
494     return i_ret;
495 }
496
497 void libvlc_video_set_teletext( libvlc_media_instance_t *p_mi, int i_page,
498                                 libvlc_exception_t *p_e )
499 {
500     vout_thread_t *p_vout = GetVout( p_mi, p_e );
501     int i_ret = -1;
502
503     if( !p_vout )
504         return;
505
506     i_ret = var_SetInteger( p_vout, "vbi-page", i_page );
507     if( i_ret )
508         libvlc_exception_raise( p_e,
509                         "Unexpected error while setting teletext page" );
510     vlc_object_release( p_vout );
511 }
512
513 int libvlc_video_destroy( libvlc_media_instance_t *p_mi,
514                           libvlc_exception_t *p_e )
515 {
516     vout_thread_t *p_vout = GetVout( p_mi, p_e );
517     vlc_object_detach( p_vout );
518     vlc_object_release( p_vout );
519     vout_Destroy( p_vout );
520
521     return 0;
522 }