]> git.sesse.net Git - vlc/blob - src/control/video.c
update module LIST file.
[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$
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 "libvlc_internal.h"
29
30 #include <vlc/libvlc.h>
31 #include <vlc_input.h>
32 #include <vlc_vout.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_player_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_ANYWHERE );
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_player_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_player_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_player_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_player_t *p_mi, char *psz_filepath,
130         unsigned int i_width, unsigned int i_height, 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     var_SetInteger( p_vout, "snapshot-width", i_width );
148     var_SetInteger( p_vout, "snapshot-height", i_height );
149
150     p_input_thread = p_mi->p_input_thread;
151     if( !p_mi->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 }
163
164 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
165                              libvlc_exception_t *p_e )
166 {
167     vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
168     if( !p_vout1 )
169         return 0;
170
171     vlc_object_release( p_vout1 );
172
173     return p_vout1->i_window_height;
174 }
175
176 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
177                             libvlc_exception_t *p_e )
178 {
179     vout_thread_t *p_vout1 = GetVout( p_mi, p_e );
180     if( !p_vout1 )
181         return 0;
182
183     vlc_object_release( p_vout1 );
184
185     return p_vout1->i_window_width;
186 }
187
188 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
189                                      libvlc_exception_t *p_e )
190 {
191     input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
192     vlc_bool_t has_vout = VLC_FALSE;
193
194     if( p_input_thread )
195     {
196         vout_thread_t *p_vout;
197
198         p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
199         if( p_vout )
200         {
201             has_vout = VLC_TRUE;
202             vlc_object_release( p_vout );
203         }
204         vlc_object_release( p_input_thread );
205     }
206     return has_vout;
207 }
208
209 int libvlc_video_reparent( libvlc_media_player_t *p_mi, libvlc_drawable_t d,
210                            libvlc_exception_t *p_e )
211 {
212     vout_thread_t *p_vout = GetVout( p_mi, p_e );
213
214     if( p_vout )
215     {
216         vout_Control( p_vout , VOUT_REPARENT, d);
217         vlc_object_release( p_vout );
218     }
219     return 0;
220 }
221
222 void libvlc_video_resize( libvlc_media_player_t *p_mi, int width, int height, libvlc_exception_t *p_e )
223 {
224     vout_thread_t *p_vout = GetVout( p_mi, p_e );
225     if( p_vout )
226     {
227         vout_Control( p_vout, VOUT_SET_SIZE, width, height );
228         vlc_object_release( p_vout );
229     }
230 }
231
232 void libvlc_video_redraw_rectangle( libvlc_media_player_t *p_mi,
233                            const libvlc_rectangle_t *area,
234                            libvlc_exception_t *p_e )
235 {
236     if( (NULL != area)
237      && ((area->bottom - area->top) > 0)
238      && ((area->right - area->left) > 0) )
239     {
240         vout_thread_t *p_vout = GetVout( p_mi, p_e );
241         if( p_vout )
242         {
243             /* tell running vout to redraw area */
244             vout_Control( p_vout , VOUT_REDRAW_RECT,
245                                area->top, area->left, area->bottom, area->right );
246             vlc_object_release( p_vout );
247         }
248     }
249 }
250
251 /* global video settings */
252
253 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
254                               libvlc_exception_t *p_e )
255 {
256     /* set as default for future vout instances */
257     var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
258
259     if( libvlc_playlist_isplaying(p_instance, p_e) )
260     {
261         libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
262         if( p_mi )
263         {
264             vout_thread_t *p_vout = GetVout( p_mi, p_e );
265             if( p_vout )
266             {
267                 /* tell running vout to re-parent */
268                 vout_Control( p_vout , VOUT_REPARENT, d);
269                 vlc_object_release( p_vout );
270             }
271             libvlc_media_player_release(p_mi);
272         }
273     }
274 }
275
276 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
277 {
278     VLC_UNUSED(p_e);
279
280     libvlc_drawable_t result;
281  
282     result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
283  
284     return result;
285 }
286
287
288 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
289                            libvlc_exception_t *p_e )
290 {
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);
294
295     if( libvlc_playlist_isplaying(p_instance, p_e) )
296     {
297         libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
298         if( p_mi )
299         {
300             vout_thread_t *p_vout = GetVout( p_mi, p_e );
301             if( p_vout )
302             {
303                 /* tell running vout to re-size */
304                 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
305                 vlc_object_release( p_vout );
306             }
307             libvlc_media_player_release(p_mi);
308         }
309     }
310 }
311
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 )
315 {
316     if( NULL == view )
317     {
318         libvlc_exception_raise( p_e, "viewport is NULL" );
319     }
320
321     /* if clip is NULL, then use view rectangle as clip */
322     if( NULL == clip )
323         clip = view;
324
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 );
334
335     if( libvlc_playlist_isplaying(p_instance, p_e) )
336     {
337         libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
338         if( p_mi )
339         {
340             vout_thread_t *p_vout = GetVout( p_mi, p_e );
341             if( p_vout )
342             {
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 );
348             }
349             libvlc_media_player_release(p_mi);
350         }
351     }
352 }
353
354 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
355                                      libvlc_exception_t *p_e )
356 {
357     char *psz_aspect = 0;
358     vout_thread_t *p_vout = GetVout( p_mi, p_e );
359
360     if( !p_vout )
361         return 0;
362
363     psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
364     vlc_object_release( p_vout );
365     return psz_aspect ? psz_aspect : strdup("");
366 }
367
368 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
369                                     char *psz_aspect, libvlc_exception_t *p_e )
370 {
371     vout_thread_t *p_vout = GetVout( p_mi, p_e );
372     int i_ret = -1;
373
374     if( !p_vout )
375         return;
376
377     i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
378     if( i_ret )
379         libvlc_exception_raise( p_e,
380                         "Unexpected error while setting aspect-ratio value" );
381
382     vlc_object_release( p_vout );
383 }
384
385 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
386                           libvlc_exception_t *p_e )
387 {
388     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
389     vlc_value_t val_list;
390     vlc_value_t val;
391     int i_spu = -1;
392     int i_ret = -1;
393     int i;
394
395     if( !p_input_thread )
396         return -1;
397
398     i_ret = var_Get( p_input_thread, "spu-es", &val );
399     if( i_ret < 0 )
400     {
401         libvlc_exception_raise( p_e, "Getting subtitle information failed" );
402         vlc_object_release( p_input_thread );
403         return i_ret;
404     }
405
406     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
407     for( i = 0; i < val_list.p_list->i_count; i++ )
408     {
409         vlc_value_t spu_val = val_list.p_list->p_values[i];
410         if( val.i_int == spu_val.i_int )
411         {
412             i_spu = i;
413             break;
414         }
415     }
416     vlc_object_release( p_input_thread );
417     return i_spu;
418 }
419
420 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
421                            libvlc_exception_t *p_e )
422 {
423     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
424     vlc_value_t val_list;
425     int i_ret = -1;
426     int i;
427
428     if( !p_input_thread )
429         return;
430
431     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
432     for( i = 0; i < val_list.p_list->i_count; i++ )
433     {
434         vlc_value_t val = val_list.p_list->p_values[i];
435         if( i_spu == i )
436         {
437             vlc_value_t new_val;
438
439             new_val.i_int = val.i_int;
440             i_ret = var_Set( p_input_thread, "spu-es", new_val );
441             if( i_ret < 0 )
442             {
443                 libvlc_exception_raise( p_e, "Setting subtitle value failed" );
444             }
445             vlc_object_release( p_input_thread );
446             return;
447         }
448     }
449     libvlc_exception_raise( p_e, "Subtitle value out of range" );
450     vlc_object_release( p_input_thread );
451 }
452
453 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
454                                    libvlc_exception_t *p_e )
455 {
456     char *psz_geometry = 0;
457     vout_thread_t *p_vout = GetVout( p_mi, p_e );
458
459     if( !p_vout )
460         return 0;
461
462     psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
463     vlc_object_release( p_vout );
464     return psz_geometry ? psz_geometry : strdup("");
465 }
466
467 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
468                                     char *psz_geometry, libvlc_exception_t *p_e )
469 {
470     vout_thread_t *p_vout = GetVout( p_mi, p_e );
471     int i_ret = -1;
472
473     if( !p_vout )
474         return;
475
476     i_ret = var_SetString( p_vout, "crop", psz_geometry );
477     if( i_ret )
478         libvlc_exception_raise( p_e,
479                         "Unexpected error while setting crop geometry" );
480
481     vlc_object_release( p_vout );
482 }
483
484 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
485                                libvlc_exception_t *p_e )
486 {
487     vout_thread_t *p_vout = GetVout( p_mi, p_e );
488     vlc_object_t *p_vbi;
489     int i_ret = -1;
490
491     if( !p_vout )
492         return i_ret;
493
494     p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
495                                                    FIND_ANYWHERE );
496     if( p_vbi )
497     {
498         i_ret = var_GetInteger( p_vbi, "vbi-page" );
499         vlc_object_release( p_vbi );
500     }
501
502     vlc_object_release( p_vout );
503     return i_ret;
504 }
505
506 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
507                                 libvlc_exception_t *p_e )
508 {
509     vout_thread_t *p_vout = GetVout( p_mi, p_e );
510     vlc_object_t *p_vbi;
511     int i_ret = -1;
512
513     if( !p_vout )
514         return;
515
516     p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
517                                                    FIND_ANYWHERE );
518     if( p_vbi )
519     {
520         i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
521         vlc_object_release( p_vbi );
522     }
523     if( i_ret )
524         libvlc_exception_raise( p_e,
525                         "Unexpected error while setting teletext page" );
526     vlc_object_release( p_vout );
527 }
528
529 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
530                              libvlc_exception_t *p_e )
531 {
532     /* We only work on the first vout */
533     vout_thread_t *p_vout = GetVout( p_mi, p_e );
534     vlc_value_t val; int i_ret;
535
536     /* GetVout will raise the exception for us */
537     if( !p_vout )
538         return;
539
540     i_ret = var_Get( p_vout, "vbi-opaque", &val );
541     if( i_ret )
542         libvlc_exception_raise( p_e,
543                         "Unexpected error while looking up teletext value" );
544
545     val.b_bool = !val.b_bool;
546     i_ret = var_Set( p_vout, "vbi-opaque", val );
547     if( i_ret )
548         libvlc_exception_raise( p_e,
549                         "Unexpected error while setting teletext value" );
550
551     vlc_object_release( p_vout );
552 }
553
554 int libvlc_video_destroy( libvlc_media_player_t *p_mi,
555                           libvlc_exception_t *p_e )
556 {
557     vout_thread_t *p_vout = GetVout( p_mi, p_e );
558     vlc_object_detach( p_vout );
559     vlc_object_release( p_vout );
560     vout_Destroy( p_vout );
561
562     return 0;
563 }