Commit 2c5ee170 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

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

parent 0b1cc788
......@@ -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 );
......
......@@ -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 );
......
......@@ -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 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment