Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix demuxer switching on level switch and discontinuities #2900

Merged
merged 1 commit into from Jul 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/demux/demuxer-inline.js
Expand Up @@ -65,11 +65,11 @@ class DemuxerInline {

pushDecrypted (data, decryptdata, initSegment, audioCodec, videoCodec, timeOffset, discontinuity, trackSwitch, contiguous, duration, accurateTimeOffset, defaultInitPTS) {
let demuxer = this.demuxer;
let remuxer = this.remuxer;
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;
Expand All @@ -82,23 +82,28 @@ 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 remuxer and demuxer are still valid
if (!remuxer || !(remuxer instanceof mux.remux)) {
remuxer = new mux.remux(observer, config, typeSupported, this.vendor);
}
if (!demuxer || !(demuxer instanceof mux.demux)) {
demuxer = new mux.demux(observer, remuxer, config, typeSupported);
this.probe = mux.demux.probe;
}
this.demuxer = demuxer;
this.remuxer = remuxer;
}
const remuxer = this.remuxer;

if (discontinuity || trackSwitch) {
demuxer.resetInitSegment(initSegment, audioCodec, videoCodec, duration);
Expand Down