From 01fa34d53790ab9efd214bcc12f46b01c9d8057e Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 20 Aug 2011 02:43:51 +0300 Subject: demux_mkv: check for valid track in video/audio switching When switching audio or video tracks, demux_mkv only checked that the new index fell in the range corresponding to tracks existing in the file being played. However, if the demuxer can not recognize the format of a track or detects an error, some of those tracks in the file may not be exported from the demuxer and are not visible to the rest of the player. Selecting such a track would cause a crash. Add checks skip such tracks when cycling to next track and switch to nosound instead if given an explicit track number corresponding to such a track. --- libmpdemux/demux_mkv.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'libmpdemux/demux_mkv.c') diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index 4da94ac99d..9bb98f9f6f 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -2494,9 +2494,16 @@ static int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg) int current_aid = demuxer->audio->id; if (current_aid < 0) current_aid = -1; - if (new_aid == -1) // cycle to next - new_aid = (current_aid + 2) % (mkv_d->num_audio_tracks + 1) - 1; - if (new_aid < 0 || new_aid >= mkv_d->num_audio_tracks) + if (new_aid == -1) { // cycle to next + new_aid = current_aid; + while (1) { + new_aid = (new_aid + 2) % (mkv_d->num_audio_tracks + 1) - 1; + if (new_aid == -1 || demuxer->a_streams[new_aid]) + break; + } + } + if (new_aid < 0 || new_aid >= mkv_d->num_audio_tracks || + !demuxer->a_streams[new_aid]) new_aid = -2; *(int *) arg = new_aid; if (current_aid != new_aid) @@ -2509,9 +2516,16 @@ static int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg) int current_vid = demuxer->video->id; if (current_vid < 0) current_vid = -1; - if (new_vid == -1) // cycle to next - new_vid = (current_vid + 2) % (mkv_d->num_video_tracks + 1) - 1; - if (new_vid < 0 || new_vid >= mkv_d->num_video_tracks) + if (new_vid == -1) { // cycle to next + new_vid = current_vid; + while (1) { + new_vid = (new_vid + 2) % (mkv_d->num_video_tracks + 1) - 1; + if (new_vid == -1 || demuxer->v_streams[new_vid]) + break; + } + } + if (new_vid < 0 || new_vid >= mkv_d->num_video_tracks || + !demuxer->v_streams[new_vid]) new_vid = -2; *(int *) arg = new_vid; if (current_vid != new_vid) -- cgit v1.2.3