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

perf: don't enable captionParser for audio or subtitle loaders #487

Merged
merged 2 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const handleInitSegmentResponse = (segment, captionParser, finishProcessingFn) =
segment.map.bytes = new Uint8Array(request.response);

// Initialize CaptionParser if it hasn't been yet
if (!captionParser.isInitialized()) {
if (captionParser && !captionParser.isInitialized()) {
captionParser.init();
}

Expand Down Expand Up @@ -210,7 +210,7 @@ const handleSegmentResponse = (segment, captionParser, finishProcessingFn) => (e

// This is likely an FMP4 and has the init segment.
// Run through the CaptionParser in case there are captions.
if (segment.map && segment.map.bytes) {
if (captionParser && segment.map && segment.map.bytes) {
// Initialize CaptionParser if it hasn't been yet
if (!captionParser.isInitialized()) {
captionParser.init();
Expand Down
22 changes: 17 additions & 5 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ export default class SegmentLoader extends videojs.EventTarget {
this.keyCache_ = {};

// Fmp4 CaptionParser
this.captionParser_ = new CaptionParser();
if (this.loaderType_ === 'main') {
this.captionParser_ = new CaptionParser();
} else {
this.captionParser_ = null;
}

this.decrypter_ = settings.decrypter;

Expand Down Expand Up @@ -250,7 +254,9 @@ export default class SegmentLoader extends videojs.EventTarget {
this.sourceUpdater_.dispose();
}
this.resetStats_();
this.captionParser_.reset();
if (this.captionParser_) {
this.captionParser_.reset();
}
}

/**
Expand Down Expand Up @@ -606,7 +612,9 @@ export default class SegmentLoader extends videojs.EventTarget {
this.resetLoader();
this.remove(0, this.duration_(), done);
// clears fmp4 captions
this.captionParser_.clearAllCaptions();
if (this.captionParser_) {
this.captionParser_.clearAllCaptions();
}
this.trigger('reseteverything');
}

Expand Down Expand Up @@ -739,7 +747,9 @@ export default class SegmentLoader extends videojs.EventTarget {
segmentInfo.startOfSegment < this.sourceUpdater_.timestampOffset())) {
this.syncController_.reset();
segmentInfo.timestampOffset = segmentInfo.startOfSegment;
this.captionParser_.clearAllCaptions();
if (this.captionParser_) {
this.captionParser_.clearAllCaptions();
}
}

this.loadSegment_(segmentInfo);
Expand Down Expand Up @@ -1215,7 +1225,9 @@ export default class SegmentLoader extends videojs.EventTarget {
});
// Reset stored captions since we added parsed
// captions to a text track at this point
this.captionParser_.clearParsedCaptions();
if (this.captionParser_) {
this.captionParser_.clearParsedCaptions();
}
}

this.handleSegment_();
Expand Down