[vlc-commits] lib: correct and uniformize audio/video track IDs (fixes #7645)
Rémi Denis-Courmont
git at videolan.org
Thu Nov 8 21:40:04 CET 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Nov 8 22:39:35 2012 +0200| [2c5ee1707b1962ee3f47dbe4abb7c199aeccc022] | committer: Rémi Denis-Courmont
lib: correct and uniformize audio/video track IDs (fixes #7645)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2c5ee1707b1962ee3f47dbe4abb7c199aeccc022
---
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 aefef02..568188d 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1154,7 +1154,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 );
@@ -1162,7 +1162,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
@@ -1577,7 +1577,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 );
@@ -1585,7 +1585,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 0d3fcce..799bdc8 100644
--- a/lib/audio.c
+++ b/lib/audio.c
@@ -341,33 +341,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;
}
/*****************************************************************************
@@ -377,30 +356,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 75a5553..2736933 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -549,32 +549,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 )
@@ -597,7 +578,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