video.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:23k
源码类别:

midi

开发平台:

Unix_Linux

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