Skip to content

Commit

Permalink
Have MediaSourceEngine fill in buffering info
Browse files Browse the repository at this point in the history
To make the getBufferedInfo method simpler for when we have three
different ways of responding (not loaded, loaded with media source, and
loaded with src=), this changes media source to fill-in a buffered info
object rather than return one.

Issue #816
Issue #997

Change-Id: If9e4558ca324808a1b94e3c235f4bfb42a5df8ce
  • Loading branch information
vaage committed Mar 29, 2019
1 parent 2d9c6d6 commit 22aee05
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
39 changes: 19 additions & 20 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,29 +449,28 @@ shaka.media.MediaSourceEngine.prototype.bufferedAheadOf =


/**
* Gets the current buffered ranges.
* @return {shaka.extern.BufferedInfo}
* Fill in the given buffered info object with the buffered info that media
* source knows about.
*
* @param {shaka.extern.BufferedInfo} info
*/
shaka.media.MediaSourceEngine.prototype.getBufferedInfo = function() {
shaka.media.MediaSourceEngine.prototype.getBufferedInfo = function(info) {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
let getBufferedInfo = shaka.media.TimeRangesUtils.getBufferedInfo;

let textRanges;
if (this.textEngine_ && this.textEngine_.bufferStart() != null) {
textRanges = [{
start: this.textEngine_.bufferStart(),
end: this.textEngine_.bufferEnd(),
}];
} else {
textRanges = [];
}

return {
total: getBufferedInfo(this.video_.buffered),
audio: getBufferedInfo(this.getBuffered_(ContentType.AUDIO)),
video: getBufferedInfo(this.getBuffered_(ContentType.VIDEO)),
text: textRanges,
};
const getBufferedInfo = shaka.media.TimeRangesUtils.getBufferedInfo;
info.total = getBufferedInfo(this.video_.buffered);
info.audio = getBufferedInfo(this.getBuffered_(ContentType.AUDIO));
info.video = getBufferedInfo(this.getBuffered_(ContentType.VIDEO));
info.text = [];

if (this.textEngine_) {
const start = this.textEngine_.bufferStart();
const end = this.textEngine_.bufferEnd();

if (start != null && end != null) {
info.text.push({start: start, end: end});
}
}
};


Expand Down
18 changes: 10 additions & 8 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2719,16 +2719,18 @@ shaka.Player.prototype.getPresentationStartTimeAsDate = function() {
* @export
*/
shaka.Player.prototype.getBufferedInfo = function() {
if (!this.mediaSourceEngine_) {
return {
total: [],
audio: [],
video: [],
text: [],
};
const info = {
total: [],
audio: [],
video: [],
text: [],
};

if (this.mediaSourceEngine_) {
this.mediaSourceEngine_.getBufferedInfo(info);
}

return this.mediaSourceEngine_.getBufferedInfo();
return info;
};


Expand Down

0 comments on commit 22aee05

Please sign in to comment.