]> git.sesse.net Git - vlc/blob - src/control/video.c
Remove deprecated functions
[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Ă©ment 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.
36  */
37 static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
38                                libvlc_exception_t *p_exception )
39 {
40     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_exception );
41     vout_thread_t *p_vout = NULL;
42
43     if( p_input_thread )
44     {
45         p_vout = input_GetVout( p_input_thread );
46         if( !p_vout )
47         {
48             libvlc_exception_raise( p_exception, "No active video output" );
49         }
50         vlc_object_release( p_input_thread );
51     }
52     return p_vout;
53 }
54
55 /**********************************************************************
56  * Exported functions
57  **********************************************************************/
58
59 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen,
60                             libvlc_exception_t *p_e )
61 {
62     /* We only work on the first vout */
63     vout_thread_t *p_vout = GetVout( p_mi, p_e );
64
65     /* GetVout will raise the exception for us */
66     if( !p_vout ) return;
67
68     var_SetBool( p_vout, "fullscreen", b_fullscreen );
69
70     vlc_object_release( p_vout );
71 }
72
73 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi,
74                             libvlc_exception_t *p_e )
75 {
76     /* We only work on the first vout */
77     vout_thread_t *p_vout = GetVout( p_mi, p_e );
78     int i_ret;
79
80     /* GetVout will raise the exception for us */
81     if( !p_vout ) return 0;
82
83     i_ret = var_GetBool( p_vout, "fullscreen" );
84
85     vlc_object_release( p_vout );
86
87     return i_ret;
88 }
89
90 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi,
91                                libvlc_exception_t *p_e )
92 {
93     /* We only work on the first vout */
94     vout_thread_t *p_vout = GetVout( p_mi, p_e );
95     bool ret;
96
97     /* GetVout will raise the exception for us */
98     if( !p_vout ) return;
99
100     ret = var_GetBool( p_vout, "fullscreen" );
101     var_SetBool( p_vout, "fullscreen", !ret );
102
103     vlc_object_release( p_vout );
104 }
105
106 void
107 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath,
108         unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e )
109 {
110     vout_thread_t *p_vout = GetVout( p_mi, p_e );
111     input_thread_t *p_input_thread;
112
113     /* GetVout will raise the exception for us */
114     if( !p_vout ) return;
115
116     if( !psz_filepath )
117     {
118         libvlc_exception_raise( p_e, "filepath is null" );
119         return;
120     }
121
122     var_SetInteger( p_vout, "snapshot-width", i_width );
123     var_SetInteger( p_vout, "snapshot-height", i_height );
124
125     p_input_thread = p_mi->p_input_thread;
126     if( !p_mi->p_input_thread )
127     {
128         libvlc_exception_raise( p_e, "Input does not exist" );
129         return;
130     }
131
132     var_SetString( p_vout, "snapshot-path", psz_filepath );
133     var_SetString( p_vout, "snapshot-format", "png" );
134
135     var_TriggerCallback( p_vout, "video-snapshot" );
136     vlc_object_release( p_vout );
137 }
138
139 int libvlc_video_get_height( libvlc_media_player_t *p_mi,
140                              libvlc_exception_t *p_e )
141 {
142     int height;
143
144     vout_thread_t *p_vout = GetVout( p_mi, p_e );
145     if( !p_vout ) return 0;
146
147     height = p_vout->i_window_height;
148
149     vlc_object_release( p_vout );
150
151     return height;
152 }
153
154 int libvlc_video_get_width( libvlc_media_player_t *p_mi,
155                             libvlc_exception_t *p_e )
156 {
157     int width;
158
159     vout_thread_t *p_vout = GetVout( p_mi, p_e );
160     if( !p_vout ) return 0;
161
162     width = p_vout->i_window_width;
163
164     vlc_object_release( p_vout );
165
166     return width;
167 }
168
169 int libvlc_media_player_has_vout( libvlc_media_player_t *p_mi,
170                                      libvlc_exception_t *p_e )
171 {
172     input_thread_t *p_input_thread = libvlc_get_input_thread(p_mi, p_e);
173     bool has_vout = false;
174
175     if( p_input_thread )
176     {
177         vout_thread_t *p_vout;
178
179         p_vout = input_GetVout( p_input_thread );
180         if( p_vout )
181         {
182             has_vout = true;
183             vlc_object_release( p_vout );
184         }
185         vlc_object_release( p_input_thread );
186     }
187     return has_vout;
188 }
189
190 void libvlc_video_resize( libvlc_media_player_t *p_mi, int width, int height, libvlc_exception_t *p_e )
191 {
192     vout_thread_t *p_vout = GetVout( p_mi, p_e );
193     if( p_vout )
194     {
195         vout_Control( p_vout, VOUT_SET_SIZE, width, height );
196         vlc_object_release( p_vout );
197     }
198 }
199
200 void libvlc_video_redraw_rectangle( libvlc_media_player_t *p_mi,
201                            const libvlc_rectangle_t *area,
202                            libvlc_exception_t *p_e )
203 {
204 #ifdef __APPLE__
205     if( (NULL != area)
206      && ((area->bottom - area->top) > 0)
207      && ((area->right - area->left) > 0) )
208     {
209         vout_thread_t *p_vout = GetVout( p_mi, p_e );
210         if( p_vout )
211         {
212             /* tell running vout to redraw area */
213             vout_Control( p_vout , VOUT_REDRAW_RECT,
214                                area->top, area->left, area->bottom, area->right );
215             vlc_object_release( p_vout );
216         }
217     }
218 #else
219     (void) p_mi; (void) area; (void) p_e;
220 #endif
221 }
222
223 /* global video settings */
224
225 void libvlc_video_set_viewport( libvlc_instance_t *p_instance, libvlc_media_player_t *p_mi,
226                             const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
227                            libvlc_exception_t *p_e )
228 {
229 #ifdef __APPLE__
230     if( !view )
231     {
232         libvlc_exception_raise( p_e, "viewport is NULL" );
233         return;
234     }
235
236     /* if clip is NULL, then use view rectangle as clip */
237     if( !clip )
238         clip = view;
239
240     /* set as default for future vout instances */
241     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
242     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
243     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
244     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
245     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
246     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
247     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
248     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
249
250     if( p_mi )
251     {
252         vout_thread_t *p_vout = GetVout( p_mi, p_e );
253         if( p_vout )
254         {
255             /* change viewport for running vout */
256             vout_Control( p_vout, VOUT_SET_VIEWPORT,
257                                view->top, view->left, view->bottom, view->right,
258                                clip->top, clip->left, clip->bottom, clip->right );
259             vlc_object_release( p_vout );
260         }
261     }
262 #else
263     (void) p_instance; (void) view; (void) clip; (void) p_e; (void) p_mi;
264 #endif
265 }
266
267 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
268                                      libvlc_exception_t *p_e )
269 {
270     char *psz_aspect = 0;
271     vout_thread_t *p_vout = GetVout( p_mi, p_e );
272
273     if( !p_vout ) return 0;
274
275     psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
276     vlc_object_release( p_vout );
277     return psz_aspect ? psz_aspect : strdup("");
278 }
279
280 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
281                                     char *psz_aspect, libvlc_exception_t *p_e )
282 {
283     vout_thread_t *p_vout = GetVout( p_mi, p_e );
284     int i_ret = -1;
285
286     if( !p_vout ) return;
287
288     i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
289     if( i_ret )
290         libvlc_exception_raise( p_e,
291                         "Unexpected error while setting aspect-ratio value" );
292
293     vlc_object_release( p_vout );
294 }
295
296 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
297                           libvlc_exception_t *p_e )
298 {
299     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
300     vlc_value_t val_list;
301     vlc_value_t val;
302     int i_spu = -1;
303     int i_ret = -1;
304     int i;
305
306     if( !p_input_thread ) return -1;
307
308     i_ret = var_Get( p_input_thread, "spu-es", &val );
309     if( i_ret < 0 )
310     {
311         libvlc_exception_raise( p_e, "Getting subtitle information failed" );
312         vlc_object_release( p_input_thread );
313         return i_ret;
314     }
315
316     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
317     for( i = 0; i < val_list.p_list->i_count; i++ )
318     {
319         vlc_value_t spu_val = val_list.p_list->p_values[i];
320         if( val.i_int == spu_val.i_int )
321         {
322             i_spu = i;
323             break;
324         }
325     }
326     vlc_object_release( p_input_thread );
327     return i_spu;
328 }
329
330 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
331                                 libvlc_exception_t *p_e )
332 {
333     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
334     vlc_value_t val_list;
335
336     if( !p_input_thread )
337         return -1;
338
339     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
340     vlc_object_release( p_input_thread );
341     return val_list.p_list->i_count;
342 }
343
344 libvlc_track_description_t *
345         libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
346                                           libvlc_exception_t *p_e )
347 {
348     return libvlc_get_track_description( p_mi, "spu-es", p_e);
349 }
350
351 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
352                            libvlc_exception_t *p_e )
353 {
354     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
355     vlc_value_t val_list;
356     vlc_value_t newval;
357     int i_ret = -1;
358
359     if( !p_input_thread ) return;
360
361     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
362
363     if( val_list.p_list->i_count == 0 )
364     {
365         libvlc_exception_raise( p_e, "Subtitle value out of range" );
366         vlc_object_release( p_input_thread );
367         return;
368     }
369
370     if( (i_spu < 0) && (i_spu > val_list.p_list->i_count) )
371     {
372         libvlc_exception_raise( p_e, "Subtitle value out of range" );
373         vlc_object_release( p_input_thread );
374         return;
375     }
376
377     newval = val_list.p_list->p_values[i_spu];
378     i_ret = var_Set( p_input_thread, "spu-es", newval );
379     if( i_ret < 0 )
380     {
381         libvlc_exception_raise( p_e, "Setting subtitle value failed" );
382     }
383     vlc_object_release( p_input_thread );
384 }
385
386 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
387                                     char *psz_subtitle,
388                                     libvlc_exception_t *p_e )
389 {
390     input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
391     bool b_ret = false;
392
393     if( p_input_thread )
394     {
395         if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
396             b_ret = true;
397         vlc_object_release( p_input_thread );
398     }
399     return b_ret;
400 }
401
402 libvlc_track_description_t *
403         libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
404                                             libvlc_exception_t * p_e )
405 {
406     return libvlc_get_track_description( p_mi, "title", p_e);
407 }
408
409 libvlc_track_description_t *
410         libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
411                                               int i_title,
412                                               libvlc_exception_t *p_e )
413 {
414     char psz_title[12];
415     sprintf( psz_title,  "title %2i", i_title );
416     return libvlc_get_track_description( p_mi, psz_title, p_e);
417 }
418
419 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
420                                    libvlc_exception_t *p_e )
421 {
422     char *psz_geometry = 0;
423     vout_thread_t *p_vout = GetVout( p_mi, p_e );
424
425     if( !p_vout ) return 0;
426
427     psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
428     vlc_object_release( p_vout );
429     return psz_geometry ? psz_geometry : strdup("");
430 }
431
432 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
433                                     char *psz_geometry, libvlc_exception_t *p_e )
434 {
435     vout_thread_t *p_vout = GetVout( p_mi, p_e );
436     int i_ret = -1;
437
438     if( !p_vout ) return;
439
440     i_ret = var_SetString( p_vout, "crop", psz_geometry );
441     if( i_ret )
442         libvlc_exception_raise( p_e,
443                         "Unexpected error while setting crop geometry" );
444
445     vlc_object_release( p_vout );
446 }
447
448 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi,
449                                libvlc_exception_t *p_e )
450 {
451     vout_thread_t *p_vout = GetVout( p_mi, p_e );
452     vlc_object_t *p_vbi;
453     int i_ret = -1;
454
455     if( !p_vout ) return i_ret;
456
457     p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
458                                                    FIND_CHILD );
459     if( p_vbi )
460     {
461         i_ret = var_GetInteger( p_vbi, "vbi-page" );
462         vlc_object_release( p_vbi );
463     }
464
465     vlc_object_release( p_vout );
466     return i_ret;
467 }
468
469 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
470                                 libvlc_exception_t *p_e )
471 {
472     vout_thread_t *p_vout = GetVout( p_mi, p_e );
473     vlc_object_t *p_vbi;
474     int i_ret = -1;
475
476     if( !p_vout ) return;
477
478     p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
479                                                    FIND_CHILD );
480     if( p_vbi )
481     {
482         i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
483         vlc_object_release( p_vbi );
484         if( i_ret )
485             libvlc_exception_raise( p_e,
486                             "Unexpected error while setting teletext page" );
487     }
488     vlc_object_release( p_vout );
489 }
490
491 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
492                              libvlc_exception_t *p_e )
493 {
494     input_thread_t *p_input_thread;
495     vlc_object_t *p_vbi;
496     int i_ret;
497
498     p_input_thread = libvlc_get_input_thread(p_mi, p_e);
499     if( !p_input_thread ) return;
500
501     if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
502     {
503         vlc_object_release( p_input_thread );
504         return;
505     }
506     const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
507
508     p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
509                                                   FIND_CHILD );
510     if( p_vbi )
511     {
512         if( b_selected )
513         {
514             /* FIXME Gni, why that ? */
515             i_ret = var_SetInteger( p_vbi, "vbi-page",
516                                     var_GetInteger( p_vbi, "vbi-page" ) );
517             if( i_ret )
518                 libvlc_exception_raise( p_e,
519                                 "Unexpected error while setting teletext page" );
520         }
521         else
522         {
523             /* FIXME Gni^2 */
524             i_ret = var_SetBool( p_vbi, "vbi-opaque",
525                                  !var_GetBool( p_vbi, "vbi-opaque" ) );
526             if( i_ret )
527                 libvlc_exception_raise( p_e,
528                                 "Unexpected error while setting teletext transparency" );
529         }
530         vlc_object_release( p_vbi );
531     }
532     else if( b_selected )
533     {
534         var_SetInteger( p_input_thread, "spu-es", -1 );
535     }
536     else
537     {
538         vlc_value_t list;
539         if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
540         {
541             if( list.p_list->i_count > 0 )
542                 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
543
544             var_Change( p_input_thread, "teletext-es", VLC_VAR_FREELIST, &list, NULL );
545         }
546     }
547     vlc_object_release( p_input_thread );
548 }
549
550 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
551                                   libvlc_exception_t *p_e )
552 {
553     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
554     vlc_value_t val_list;
555
556     if( !p_input_thread )
557         return -1;
558
559     var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
560     vlc_object_release( p_input_thread );
561     return val_list.p_list->i_count;
562 }
563
564 libvlc_track_description_t *
565         libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
566                                             libvlc_exception_t *p_e )
567 {
568     return libvlc_get_track_description( p_mi, "video-es", p_e);
569 }
570
571 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
572                             libvlc_exception_t *p_e )
573 {
574     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
575     vlc_value_t val_list;
576     vlc_value_t val;
577     int i_track = -1;
578     int i_ret = -1;
579     int i;
580
581     if( !p_input_thread )
582         return -1;
583
584     i_ret = var_Get( p_input_thread, "video-es", &val );
585     if( i_ret < 0 )
586     {
587         libvlc_exception_raise( p_e, "Getting Video track information failed" );
588         vlc_object_release( p_input_thread );
589         return i_ret;
590     }
591
592     var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
593     for( i = 0; i < val_list.p_list->i_count; i++ )
594     {
595         vlc_value_t track_val = val_list.p_list->p_values[i];
596         if( track_val.i_int == val.i_int )
597         {
598             i_track = i;
599             break;
600        }
601     }
602     vlc_object_release( p_input_thread );
603     return i_track;
604 }
605
606 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
607                              libvlc_exception_t *p_e )
608 {
609     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
610     vlc_value_t val_list;
611     int i_ret = -1;
612     int i;
613
614     if( !p_input_thread )
615         return;
616
617     var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
618     for( i = 0; i < val_list.p_list->i_count; i++ )
619     {
620         vlc_value_t val = val_list.p_list->p_values[i];
621         if( i_track == val.i_int )
622         {
623             i_ret = var_Set( p_input_thread, "audio-es", val );
624             if( i_ret < 0 )
625                 libvlc_exception_raise( p_e, "Setting video track failed" );
626             vlc_object_release( p_input_thread );
627             return;
628         }
629     }
630     libvlc_exception_raise( p_e, "Video track out of range" );
631     vlc_object_release( p_input_thread );
632 }