[vlc-commits] lib: correct and uniformize audio/video track IDs (fixes #7645)

Rémi Denis-Courmont git at videolan.org
Thu Nov 8 21:43:07 CET 2012


vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Nov  8 22:39:35 2012 +0200| [1657da9db32ce092196c15990b8531364f444af8] | committer: Rémi Denis-Courmont

lib: correct and uniformize audio/video track IDs (fixes #7645)

(cherry picked from commit 2c5ee1707b1962ee3f47dbe4abb7c199aeccc022)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=1657da9db32ce092196c15990b8531364f444af8
---

 include/vlc/libvlc_media_player.h |    8 +++---
 lib/audio.c                       |   50 ++++++++-----------------------------
 lib/video.c                       |   25 +++----------------
 3 files changed, 18 insertions(+), 65 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index cc57521..ef7035f 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1143,7 +1143,7 @@ LIBVLC_API libvlc_track_description_t *
  * Get current video track.
  *
  * \param p_mi media player
- * \return the video track (int) or -1 if none
+ * \return the video track ID (int) or -1 if no active input
  */
 LIBVLC_API int libvlc_video_get_track( libvlc_media_player_t *p_mi );
 
@@ -1151,7 +1151,7 @@ LIBVLC_API int libvlc_video_get_track( libvlc_media_player_t *p_mi );
  * Set video track.
  *
  * \param p_mi media player
- * \param i_track the track (int)
+ * \param i_track the track ID (i_id field from track description)
  * \return 0 on success, -1 if out of range
  */
 LIBVLC_API
@@ -1521,7 +1521,7 @@ LIBVLC_API libvlc_track_description_t *
  * Get current audio track.
  *
  * \param p_mi media player
- * \return the audio track (int), or -1 if none.
+ * \return the audio track ID or -1 if no active input.
  */
 LIBVLC_API int libvlc_audio_get_track( libvlc_media_player_t *p_mi );
 
@@ -1529,7 +1529,7 @@ LIBVLC_API int libvlc_audio_get_track( libvlc_media_player_t *p_mi );
  * Set current audio track.
  *
  * \param p_mi media player
- * \param i_track the track (int)
+ * \param i_track the track ID (i_id field from track description)
  * \return 0 on success, -1 on error
  */
 LIBVLC_API int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track );
diff --git a/lib/audio.c b/lib/audio.c
index c0c8cf7..597de21 100644
--- a/lib/audio.c
+++ b/lib/audio.c
@@ -384,33 +384,12 @@ libvlc_track_description_t *
 int libvlc_audio_get_track( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
-    vlc_value_t val_list;
-    vlc_value_t val;
-    int i_track = -1;
-    int i;
-
     if( !p_input_thread )
         return -1;
 
-    if( var_Get( p_input_thread, "audio-es", &val ) < 0 )
-    {
-        vlc_object_release( p_input_thread );
-        libvlc_printerr( "Audio track information not found" );
-        return -1;
-    }
-
-    var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
-    for( i = 0; i < val_list.p_list->i_count; i++ )
-    {
-        if( val_list.p_list->p_values[i].i_int == val.i_int )
-        {
-            i_track = i;
-            break;
-        }
-    }
-    var_FreeList( &val_list, NULL );
+    int id = var_GetInteger( p_input_thread, "audio-es" );
     vlc_object_release( p_input_thread );
-    return i_track;
+    return id;
 }
 
 /*****************************************************************************
@@ -420,30 +399,23 @@ int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
     vlc_value_t val_list;
-    vlc_value_t newval;
     int i_ret;
 
     if( !p_input_thread )
         return -1;
 
     var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
-    if( (i_track < 0) || (i_track > val_list.p_list->i_count) )
+    for( int i = 0; i < val_list.p_list->i_count; i++ )
     {
-        libvlc_printerr( "Audio track out of range" );
-        i_ret = -1;
-        goto end;
-    }
-
-    newval = val_list.p_list->p_values[i_track];
-    i_ret = var_Set( p_input_thread, "audio-es", newval );
-    if( i_ret < 0 )
-    {
-        libvlc_printerr( "Audio track out of range" ); /* Race... */
-        i_ret = -1;
-        goto end;
+        if( i_track == val_list.p_list->p_values[i].i_int )
+        {
+            if( var_SetInteger( p_input_thread, "audio-es", i_track ) < 0 )
+                break;
+            i_ret = 0;
+            goto end;
+        }
     }
-    i_ret = 0;
-
+    libvlc_printerr( "Track identifier not found" );
 end:
     var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );
diff --git a/lib/video.c b/lib/video.c
index 0c7bb2d..c5035b4 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -543,32 +543,13 @@ libvlc_track_description_t *
 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
-    vlc_value_t val_list;
-    vlc_value_t val;
-    int i_track = -1;
 
     if( !p_input_thread )
         return -1;
 
-    if( var_Get( p_input_thread, "video-es", &val ) < 0 )
-    {
-        libvlc_printerr( "Video track information not found" );
-        vlc_object_release( p_input_thread );
-        return -1;
-    }
-
-    var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
-    for( int i = 0; i < val_list.p_list->i_count; i++ )
-    {
-        if( val_list.p_list->p_values[i].i_int == val.i_int )
-        {
-            i_track = i;
-            break;
-        }
-    }
-    var_FreeList( &val_list, NULL );
+    int id = var_GetInteger( p_input_thread, "video-es" );
     vlc_object_release( p_input_thread );
-    return i_track;
+    return id;
 }
 
 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
@@ -591,7 +572,7 @@ int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
             goto end;
         }
     }
-    libvlc_printerr( "Video track number out of range" );
+    libvlc_printerr( "Track identifier not found" );
 end:
     var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );



More information about the vlc-commits mailing list