From 6f217bbe2f9cc4406f6c4abe2dc719e92bb1cc8d Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Thu, 16 Jul 2020 19:17:22 -0400 Subject: [PATCH] Fix demuxer switching on level switch and discontinuities #2887 --- src/demux/demuxer-inline.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/demux/demuxer-inline.js b/src/demux/demuxer-inline.js index d7e214a2614..61f6b3e2370 100644 --- a/src/demux/demuxer-inline.js +++ b/src/demux/demuxer-inline.js @@ -68,8 +68,7 @@ class DemuxerInline { if (!demuxer || // in case of continuity change, or track switch // we might switch from content type (AAC container to TS container, or TS to fmp4 for example) - // so let's check that current demuxer is still valid - ((discontinuity || trackSwitch) && !this.probe(data))) { + (discontinuity || trackSwitch)) { const observer = this.observer; const typeSupported = this.typeSupported; const config = this.config; @@ -82,20 +81,23 @@ class DemuxerInline { ]; // probe for content type + let mux; for (let i = 0, len = muxConfig.length; i < len; i++) { - const mux = muxConfig[i]; - const probe = mux.demux.probe; - if (probe(data)) { - const remuxer = this.remuxer = new mux.remux(observer, config, typeSupported, this.vendor); - demuxer = new mux.demux(observer, remuxer, config, typeSupported); - this.probe = probe; + mux = muxConfig[i]; + if (mux.demux.probe(data)) { break; } } - if (!demuxer) { + if (!mux) { observer.trigger(Event.ERROR, { type: ErrorTypes.MEDIA_ERROR, details: ErrorDetails.FRAG_PARSING_ERROR, fatal: true, reason: 'no demux matching with content found' }); return; } + // so let's check that current demuxer is still valid + if (!demuxer || !(demuxer instanceof mux.demux)) { + const remuxer = this.remuxer = this.remuxer || new mux.remux(observer, config, typeSupported, this.vendor); + demuxer = new mux.demux(observer, remuxer, config, typeSupported); + this.probe = mux.demux.probe; + } this.demuxer = demuxer; } const remuxer = this.remuxer;