summaryrefslogtreecommitdiffstats
path: root/libmpdemux/demux_mkv.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-08-20 02:43:51 +0300
committerUoti Urpala <uau@mplayer2.org>2011-08-20 02:43:51 +0300
commit01fa34d53790ab9efd214bcc12f46b01c9d8057e (patch)
treece83e19a3451c142d3d3c51b8846b25dd5e1884d /libmpdemux/demux_mkv.c
parentf253de24af2acb6a60a0b22d3a891e3a9d6cd2c0 (diff)
downloadmpv-01fa34d53790ab9efd214bcc12f46b01c9d8057e.tar.bz2
mpv-01fa34d53790ab9efd214bcc12f46b01c9d8057e.tar.xz
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.
Diffstat (limited to 'libmpdemux/demux_mkv.c')
-rw-r--r--libmpdemux/demux_mkv.c26
1 files changed, 20 insertions, 6 deletions
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)