Skip to content

Commit

Permalink
perf: don't enable captionParser for audio or subtitle loaders (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev committed May 1, 2019
1 parent a49ad3a commit 358877f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/media-segment-request.js
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
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

0 comments on commit 358877f

Please sign in to comment.