Have MediaSourceEngine fill in buffering info

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
This commit is contained in:
Aaron Vaage
2019-03-29 02:35:39 +00:00
parent 2d9c6d62a6
commit 22aee05d49
2 changed files with 28 additions and 27 deletions
+18 -19
View File
@@ -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 = [];
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});
}
}
return {
total: getBufferedInfo(this.video_.buffered),
audio: getBufferedInfo(this.getBuffered_(ContentType.AUDIO)),
video: getBufferedInfo(this.getBuffered_(ContentType.VIDEO)),
text: textRanges,
};
};
+10 -8
View File
@@ -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;
};