Skip to content

Commit

Permalink
chore: Unify getBuffered_ behaviour in MediaSourceEngine to avoid iss…
Browse files Browse the repository at this point in the history
…ues (#7496)
  • Loading branch information
avelad committed Oct 24, 2024
1 parent 7ba1ee7 commit 819861a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,7 @@ shaka.media.MediaSourceEngine = class {
* @return {?number} The timestamp in seconds, or null if nothing is buffered.
*/
bufferStart(contentType) {
if (this.reloadingMediaSource_ ||
!Object.keys(this.sourceBuffers_).length) {
if (!Object.keys(this.sourceBuffers_).length) {
return null;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
Expand All @@ -672,7 +671,7 @@ shaka.media.MediaSourceEngine = class {
* @return {?number} The timestamp in seconds, or null if nothing is buffered.
*/
bufferEnd(contentType) {
if (this.reloadingMediaSource_) {
if (!Object.keys(this.sourceBuffers_).length) {
return null;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
Expand All @@ -692,9 +691,6 @@ shaka.media.MediaSourceEngine = class {
* @return {boolean}
*/
isBuffered(contentType, time) {
if (this.reloadingMediaSource_) {
return false;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
if (contentType == ContentType.TEXT) {
return this.textEngine_.isBuffered(time);
Expand All @@ -713,9 +709,6 @@ shaka.media.MediaSourceEngine = class {
* @return {number} The amount of time buffered ahead in seconds.
*/
bufferedAheadOf(contentType, time) {
if (this.reloadingMediaSource_) {
return 0;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
if (contentType == ContentType.TEXT) {
return this.textEngine_.bufferedAheadOf(time);
Expand All @@ -736,9 +729,9 @@ shaka.media.MediaSourceEngine = class {
const info = {
total: this.reloadingMediaSource_ ? [] :
TimeRangesUtils.getBufferedInfo(this.video_.buffered),
audio: this.reloadingMediaSource_ ? [] :
audio:
TimeRangesUtils.getBufferedInfo(this.getBuffered_(ContentType.AUDIO)),
video: this.reloadingMediaSource_ ? [] :
video:
TimeRangesUtils.getBufferedInfo(this.getBuffered_(ContentType.VIDEO)),
text: [],
};
Expand All @@ -761,6 +754,9 @@ shaka.media.MediaSourceEngine = class {
* @private
*/
getBuffered_(contentType) {
if (this.reloadingMediaSource_) {
return null;
}
try {
return this.sourceBuffers_[contentType].buffered;
} catch (exception) {
Expand Down

0 comments on commit 819861a

Please sign in to comment.