]> git.sesse.net Git - vlc/blob - src/control/video.c
Fix memleak (same problem with var_Change())
[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 = libvlc_get_input_thread( p_mi, p_exception );
41     vout_thread_t *p_vout = NULL;
42
43     if( p_input )
44     {
45         p_vout = input_GetVout( p_input );
46         if( !p_vout )
47         {
48             libvlc_exception_raise( p_exception, "No active video output" );
49         }
50         vlc_object_release( p_input );
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;
111
112     /* The filepath must be not NULL */
113     if( !psz_filepath )
114     {
115         libvlc_exception_raise( p_e, "filepath is null" );
116         return;
117     }
118     /* We must have an input */
119     if( !p_mi->p_input_thread )
120     {
121         libvlc_exception_raise( p_e, "Input does not exist" );
122         return;
123     }
124
125     /* GetVout will raise the exception for us */
126     p_vout = GetVout( p_mi, p_e );
127     if( !p_vout ) return;
128
129     var_SetInteger( p_vout, "snapshot-width", i_width );
130     var_SetInteger( p_vout, "snapshot-height", i_height );
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 int libvlc_video_reparent( libvlc_media_player_t *p_mi, libvlc_drawable_t d,
191                            libvlc_exception_t *p_e )
192 {
193     (void) p_mi; (void) d;
194     libvlc_exception_raise(p_e, "Reparenting not supported");
195     return -1;
196 }
197
198 void libvlc_video_resize( libvlc_media_player_t *p_mi, int width, int height, libvlc_exception_t *p_e )
199 {
200     vout_thread_t *p_vout = GetVout( p_mi, p_e );
201     if( p_vout )
202     {
203         vout_Control( p_vout, VOUT_SET_SIZE, width, height );
204         vlc_object_release( p_vout );
205     }
206 }
207
208 void libvlc_video_redraw_rectangle( libvlc_media_player_t *p_mi,
209                            const libvlc_rectangle_t *area,
210                            libvlc_exception_t *p_e )
211 {
212 #ifdef __APPLE__
213     if( (NULL != area)
214      && ((area->bottom - area->top) > 0)
215      && ((area->right - area->left) > 0) )
216     {
217         vout_thread_t *p_vout = GetVout( p_mi, p_e );
218         if( p_vout )
219         {
220             /* tell running vout to redraw area */
221             vout_Control( p_vout , VOUT_REDRAW_RECT,
222                                area->top, area->left, area->bottom, area->right );
223             vlc_object_release( p_vout );
224         }
225     }
226 #else
227     (void) p_mi; (void) area; (void) p_e;
228 #endif
229 }
230
231 /* global video settings */
232
233 /* Deprecated use libvlc_media_player_set_drawable() */
234 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
235                               libvlc_exception_t *p_e )
236 {
237     /* set as default for future vout instances */
238 #ifdef WIN32
239     vlc_value_t val;
240
241     if( sizeof(HWND) > sizeof(libvlc_drawable_t) )
242         return; /* BOOM! we told you not to use this function! */
243     val.p_address = (void *)(uintptr_t)d;
244     var_Set( p_instance->p_libvlc_int, "drawable-hwnd", val );
245 #elif defined(__APPLE__)
246     var_SetInteger( p_instance->p_libvlc_int, "drawable-agl", d );
247 #else
248     var_SetInteger( p_instance->p_libvlc_int, "drawable-xid", d );
249 #endif
250
251     libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
252     if( p_mi )
253     {
254         libvlc_media_player_set_drawable( p_mi, d, p_e );
255         libvlc_media_player_release(p_mi);
256     }
257 }
258
259 /* Deprecated use libvlc_media_player_get_drawable() */
260 libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
261 {
262     VLC_UNUSED(p_e);
263
264 #ifdef WIN32
265     vlc_value_t val;
266
267     if( sizeof(HWND) > sizeof(libvlc_drawable_t) )
268         return 0;
269     var_Get( p_instance->p_libvlc_int, "drawable-hwnd", &val );
270     return (uintptr_t)val.p_address;
271 #elif defined(__APPLE__)
272     return var_GetInteger( p_instance->p_libvlc_int, "drawable-agl" );
273 #else
274     return var_GetInteger( p_instance->p_libvlc_int, "drawable-xid" );
275 #endif
276 }
277
278 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
279                            libvlc_exception_t *p_e )
280 {
281     /* set as default for future vout instances */
282     config_PutInt(p_instance->p_libvlc_int, "width", width);
283     config_PutInt(p_instance->p_libvlc_int, "height", height);
284
285     libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
286     if( p_mi )
287     {
288         vout_thread_t *p_vout = GetVout( p_mi, p_e );
289         if( p_vout )
290         {
291             /* tell running vout to re-size */
292             vout_Control( p_vout , VOUT_SET_SIZE, width, height);
293             vlc_object_release( p_vout );
294         }
295         libvlc_media_player_release(p_mi);
296     }
297 }
298
299 void libvlc_video_set_viewport( libvlc_instance_t *p_instance, libvlc_media_player_t *p_mi,
300                             const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
301                            libvlc_exception_t *p_e )
302 {
303 #ifdef __APPLE__
304     if( !view )
305     {
306         libvlc_exception_raise( p_e, "viewport is NULL" );
307         return;
308     }
309
310     /* if clip is NULL, then use view rectangle as clip */
311     if( !clip )
312         clip = view;
313
314     /* set as default for future vout instances */
315     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
316     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
317     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
318     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
319     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
320     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
321     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
322     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
323
324     if( p_mi )
325     {
326         vout_thread_t *p_vout = GetVout( p_mi, p_e );
327         if( p_vout )
328         {
329             /* change viewport for running vout */
330             vout_Control( p_vout, VOUT_SET_VIEWPORT,
331                                view->top, view->left, view->bottom, view->right,
332                                clip->top, clip->left, clip->bottom, clip->right );
333             vlc_object_release( p_vout );
334         }
335     }
336 #else
337     (void) p_instance; (void) p_mi; (void) view; (void) clip; (void) p_e;
338 #endif
339 }
340
341 float libvlc_video_get_scale( libvlc_media_player_t *p_mp,
342                               libvlc_exception_t *p_e )
343 {
344     vout_thread_t *p_vout = GetVout( p_mp, p_e );
345     if( !p_vout )
346         return 0.;
347
348     float f_scale = var_GetFloat( p_vout, "scale" );
349     if( var_GetBool( p_vout, "autoscale" ) )
350         f_scale = 0.;
351     vlc_object_release( p_vout );
352     return f_scale;
353 }
354
355 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale,
356                              libvlc_exception_t *p_e )
357 {
358     vout_thread_t *p_vout = GetVout( p_mp, p_e );
359     if( !p_vout )
360         return;
361
362     if( f_scale != 0. )
363         var_SetFloat( p_vout, "scale", f_scale );
364     var_SetBool( p_vout, "autoscale", f_scale != 0. );
365     vlc_object_release( p_vout );
366 }
367
368 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi,
369                                      libvlc_exception_t *p_e )
370 {
371     char *psz_aspect = 0;
372     vout_thread_t *p_vout = GetVout( p_mi, p_e );
373
374     if( !p_vout ) return 0;
375
376     psz_aspect = var_GetNonEmptyString( p_vout, "aspect-ratio" );
377     vlc_object_release( p_vout );
378     return psz_aspect ? psz_aspect : strdup("");
379 }
380
381 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
382                                     char *psz_aspect, libvlc_exception_t *p_e )
383 {
384     vout_thread_t *p_vout = GetVout( p_mi, p_e );
385     int i_ret = -1;
386
387     if( !p_vout ) return;
388
389     i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
390     if( i_ret )
391         libvlc_exception_raise( p_e,
392                         "Unexpected error while setting aspect-ratio value" );
393
394     vlc_object_release( p_vout );
395 }
396
397 int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
398                           libvlc_exception_t *p_e )
399 {
400     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
401     vlc_value_t val_list;
402     vlc_value_t val;
403     int i_spu = -1;
404     int i_ret = -1;
405     int i;
406
407     if( !p_input_thread ) return -1;
408
409     i_ret = var_Get( p_input_thread, "spu-es", &val );
410     if( i_ret < 0 )
411     {
412         libvlc_exception_raise( p_e, "Getting subtitle information failed" );
413         vlc_object_release( p_input_thread );
414         return i_ret;
415     }
416
417     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
418     for( i = 0; i < val_list.p_list->i_count; i++ )
419     {
420         if( val.i_int == val_list.p_list->p_values[i].i_int )
421         {
422             i_spu = i;
423             break;
424         }
425     }
426     var_Change( p_input_thread, "spu-es", VLC_VAR_FREELIST, &val_list, NULL );
427     vlc_object_release( p_input_thread );
428     return i_spu;
429 }
430
431 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
432                                 libvlc_exception_t *p_e )
433 {
434     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
435     vlc_value_t val_list;
436     int i_spu_count;
437
438     if( !p_input_thread )
439         return -1;
440
441     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
442     i_spu_count = val_list.p_list->i_count;
443     var_Change( p_input_thread, "spu-es", VLC_VAR_FREELIST, &val_list, NULL );
444
445     vlc_object_release( p_input_thread );
446     return i_spu_count;
447 }
448
449 libvlc_track_description_t *
450         libvlc_video_get_spu_description( libvlc_media_player_t *p_mi,
451                                           libvlc_exception_t *p_e )
452 {
453     return libvlc_get_track_description( p_mi, "spu-es", p_e);
454 }
455
456 void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
457                            libvlc_exception_t *p_e )
458 {
459     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
460     vlc_value_t val_list;
461     vlc_value_t newval;
462     int i_ret = -1;
463
464     if( !p_input_thread ) return;
465
466     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
467
468     if( val_list.p_list->i_count == 0 )
469     {
470         libvlc_exception_raise( p_e, "Subtitle value out of range" );
471         goto end;
472     }
473
474     if( (i_spu < 0) && (i_spu > val_list.p_list->i_count) )
475     {
476         libvlc_exception_raise( p_e, "Subtitle value out of range" );
477         goto end;
478     }
479
480     newval = val_list.p_list->p_values[i_spu];
481     i_ret = var_Set( p_input_thread, "spu-es", newval );
482     if( i_ret < 0 )
483     {
484         libvlc_exception_raise( p_e, "Setting subtitle value failed" );
485     }
486
487 end:
488     var_Change( p_input_thread, "spu-es", VLC_VAR_FREELIST, &val_list, NULL );
489     vlc_object_release( p_input_thread );
490 }
491
492 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
493                                     char *psz_subtitle,
494                                     libvlc_exception_t *p_e )
495 {
496     input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
497     bool b_ret = false;
498
499     if( p_input_thread )
500     {
501         if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
502             b_ret = true;
503         vlc_object_release( p_input_thread );
504     }
505     return b_ret;
506 }
507
508 libvlc_track_description_t *
509         libvlc_video_get_title_description( libvlc_media_player_t *p_mi,
510                                             libvlc_exception_t * p_e )
511 {
512     return libvlc_get_track_description( p_mi, "title", p_e);
513 }
514
515 libvlc_track_description_t *
516         libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
517                                               int i_title,
518                                               libvlc_exception_t *p_e )
519 {
520     char psz_title[12];
521     sprintf( psz_title,  "title %2i", i_title );
522     return libvlc_get_track_description( p_mi, psz_title, p_e);
523 }
524
525 char *libvlc_video_get_crop_geometry( libvlc_media_player_t *p_mi,
526                                    libvlc_exception_t *p_e )
527 {
528     char *psz_geometry = 0;
529     vout_thread_t *p_vout = GetVout( p_mi, p_e );
530
531     if( !p_vout ) return 0;
532
533     psz_geometry = var_GetNonEmptyString( p_vout, "crop" );
534     vlc_object_release( p_vout );
535     return psz_geometry ? psz_geometry : strdup("");
536 }
537
538 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
539                                     char *psz_geometry, libvlc_exception_t *p_e )
540 {
541     vout_thread_t *p_vout = GetVout( p_mi, p_e );
542     int i_ret = -1;
543
544     if( !p_vout ) return;
545
546     i_ret = var_SetString( p_vout, "crop", psz_geometry );
547     if( i_ret )
548         libvlc_exception_raise( p_e,
549                         "Unexpected error while setting crop geometry" );
550
551     vlc_object_release( p_vout );
552 }
553
554 int libvlc_video_get_teletext( 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_t *p_vbi;
559     int i_ret = -1;
560
561     if( !p_vout ) return i_ret;
562
563     p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
564                                                    FIND_CHILD );
565     if( p_vbi )
566     {
567         i_ret = var_GetInteger( p_vbi, "vbi-page" );
568         vlc_object_release( p_vbi );
569     }
570
571     vlc_object_release( p_vout );
572     return i_ret;
573 }
574
575 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page,
576                                 libvlc_exception_t *p_e )
577 {
578     vout_thread_t *p_vout = GetVout( p_mi, p_e );
579     vlc_object_t *p_vbi;
580     int i_ret = -1;
581
582     if( !p_vout ) return;
583
584     p_vbi = (vlc_object_t *) vlc_object_find_name( p_vout, "zvbi",
585                                                    FIND_CHILD );
586     if( p_vbi )
587     {
588         i_ret = var_SetInteger( p_vbi, "vbi-page", i_page );
589         vlc_object_release( p_vbi );
590         if( i_ret )
591             libvlc_exception_raise( p_e,
592                             "Unexpected error while setting teletext page" );
593     }
594     vlc_object_release( p_vout );
595 }
596
597 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
598                              libvlc_exception_t *p_e )
599 {
600     input_thread_t *p_input_thread;
601     vlc_object_t *p_vbi;
602     int i_ret;
603
604     p_input_thread = libvlc_get_input_thread(p_mi, p_e);
605     if( !p_input_thread ) return;
606
607     if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
608     {
609         vlc_object_release( p_input_thread );
610         return;
611     }
612     const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
613
614     p_vbi = (vlc_object_t *)vlc_object_find_name( p_input_thread, "zvbi",
615                                                   FIND_CHILD );
616     if( p_vbi )
617     {
618         if( b_selected )
619         {
620             /* FIXME Gni, why that ? */
621             i_ret = var_SetInteger( p_vbi, "vbi-page",
622                                     var_GetInteger( p_vbi, "vbi-page" ) );
623             if( i_ret )
624                 libvlc_exception_raise( p_e,
625                                 "Unexpected error while setting teletext page" );
626         }
627         else
628         {
629             /* FIXME Gni^2 */
630             i_ret = var_SetBool( p_vbi, "vbi-opaque",
631                                  !var_GetBool( p_vbi, "vbi-opaque" ) );
632             if( i_ret )
633                 libvlc_exception_raise( p_e,
634                                 "Unexpected error while setting teletext transparency" );
635         }
636         vlc_object_release( p_vbi );
637     }
638     else if( b_selected )
639     {
640         var_SetInteger( p_input_thread, "spu-es", -1 );
641     }
642     else
643     {
644         vlc_value_t list;
645         if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETLIST, &list, NULL ) )
646         {
647             if( list.p_list->i_count > 0 )
648                 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
649
650             var_Change( p_input_thread, "teletext-es", VLC_VAR_FREELIST, &list, NULL );
651         }
652     }
653     vlc_object_release( p_input_thread );
654 }
655
656 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
657                                   libvlc_exception_t *p_e )
658 {
659     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
660     vlc_value_t val_list;
661     int i_track_count;
662
663     if( !p_input_thread )
664         return -1;
665
666     var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
667     i_track_count = val_list.p_list->i_count;
668     var_Change( p_input_thread, "video-es", VLC_VAR_FREELIST, &val_list, NULL );
669
670     vlc_object_release( p_input_thread );
671     return i_track_count;
672 }
673
674 libvlc_track_description_t *
675         libvlc_video_get_track_description( libvlc_media_player_t *p_mi,
676                                             libvlc_exception_t *p_e )
677 {
678     return libvlc_get_track_description( p_mi, "video-es", p_e);
679 }
680
681 int libvlc_video_get_track( libvlc_media_player_t *p_mi,
682                             libvlc_exception_t *p_e )
683 {
684     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
685     vlc_value_t val_list;
686     vlc_value_t val;
687     int i_track = -1;
688     int i_ret = -1;
689     int i;
690
691     if( !p_input_thread )
692         return -1;
693
694     i_ret = var_Get( p_input_thread, "video-es", &val );
695     if( i_ret < 0 )
696     {
697         libvlc_exception_raise( p_e, "Getting Video track information failed" );
698         vlc_object_release( p_input_thread );
699         return i_ret;
700     }
701
702     var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
703     for( i = 0; i < val_list.p_list->i_count; i++ )
704     {
705         if( val_list.p_list->p_values[i].i_int == val.i_int )
706         {
707             i_track = i;
708             break;
709         }
710     }
711     var_Change( p_input_thread, "video-es", VLC_VAR_FREELIST, &val_list, NULL );
712     vlc_object_release( p_input_thread );
713     return i_track;
714 }
715
716 void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
717                              libvlc_exception_t *p_e )
718 {
719     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
720     vlc_value_t val_list;
721     int i_ret = -1;
722     int i;
723
724     if( !p_input_thread )
725         return;
726
727     var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
728     for( i = 0; i < val_list.p_list->i_count; i++ )
729     {
730         vlc_value_t val = val_list.p_list->p_values[i];
731         if( i_track == val.i_int )
732         {
733             i_ret = var_Set( p_input_thread, "audio-es", val );
734             if( i_ret < 0 )
735                 libvlc_exception_raise( p_e, "Setting video track failed" );
736             goto end;
737         }
738     }
739     libvlc_exception_raise( p_e, "Video track out of range" );
740
741 end:
742     var_Change( p_input_thread, "video-es", VLC_VAR_FREELIST, &val_list, NULL );
743     vlc_object_release( p_input_thread );
744 }
745
746 int libvlc_video_destroy( libvlc_media_player_t *p_mi,
747                           libvlc_exception_t *p_e )
748 {
749     vout_thread_t *p_vout = GetVout( p_mi, p_e );
750     vlc_object_detach( p_vout );
751     vlc_object_release( p_vout );
752     vlc_object_release( p_vout );
753
754     return 0;
755 }