Skip to content

Commit

Permalink
fix: Change quality only when adding the last partial segment and it …
Browse files Browse the repository at this point in the history
…is fast switching (#6114)
  • Loading branch information
avelad committed Jan 18, 2024
1 parent e692d68 commit 48626f2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
9 changes: 9 additions & 0 deletions externs/shaka/abr_manager.js
Expand Up @@ -96,6 +96,15 @@ shaka.extern.AbrManager = class {
*/
segmentDownloaded(deltaTimeMs, numBytes, allowSwitch) {}

/**
* Notifies the ABR that it is a time to suggest new streams. This is used by
* the Player when it finishes adding the last partial segment of a fast
* switching stream.
*
* @exportDoc
*/
trySuggestStreams() {}

/**
* Gets an estimate of the current bandwidth in bit/sec. This is used by the
* Player to generate stats.
Expand Down
11 changes: 11 additions & 0 deletions lib/abr/simple_abr_manager.js
Expand Up @@ -320,6 +320,17 @@ shaka.abr.SimpleAbrManager = class {
}


/**
* @override
* @export
*/
trySuggestStreams() {
if ((this.lastTimeChosenMs_ != null) && this.enabled_) {
this.suggestStreams_();
}
}


/**
* @override
* @export
Expand Down
4 changes: 4 additions & 0 deletions lib/media/segment_prefetch.js
Expand Up @@ -97,6 +97,10 @@ shaka.media.SegmentPrefetch = class {
this.segmentPrefetchMap_.set(reference, segmentPrefetchOperation);
}
this.prefetchPosTime_ = reference.startTime;
if (this.stream_.fastSwitching && reference.isPartial() &&
reference.isLastPartial()) {
break;
}
reference = iterator.next().value;
}
}
Expand Down
12 changes: 5 additions & 7 deletions lib/media/streaming_engine.js
Expand Up @@ -1488,8 +1488,7 @@ shaka.media.StreamingEngine = class {
JSON.stringify(buffered));

if (!mediaState.waitingToClearBuffer) {
this.playerInterface_.onSegmentAppended(
reference.startTime, reference.endTime, mediaState.type);
this.playerInterface_.onSegmentAppended(reference, mediaState.stream);
}

// Update right away.
Expand Down Expand Up @@ -2540,8 +2539,8 @@ shaka.media.StreamingEngine = class {
* onError: function(!shaka.util.Error),
* onEvent: function(!Event),
* onManifestUpdate: function(),
* onSegmentAppended: function(number, number,
* !shaka.util.ManifestParserUtils.ContentType),
* onSegmentAppended: function(!shaka.media.SegmentReference,
* !shaka.extern.Stream),
* onInitSegmentAppended: function(!number,!shaka.media.InitSegmentReference),
* beforeAppendSegment: function(
* shaka.util.ManifestParserUtils.ContentType,!BufferSource):Promise,
Expand All @@ -2566,10 +2565,9 @@ shaka.media.StreamingEngine = class {
* Called when an event occurs that should be sent to the app.
* @property {function()} onManifestUpdate
* Called when an embedded 'emsg' box should trigger a manifest update.
* @property {function(number, number,
* !shaka.util.ManifestParserUtils.ContentType)} onSegmentAppended
* @property {function(!shaka.media.SegmentReference,
* !shaka.extern.Stream)} onSegmentAppended
* Called after a segment is successfully appended to a MediaSource.
* The parameters are the start and end time.
* @property
* {function(!number, !shaka.media.InitSegmentReference)} onInitSegmentAppended
* Called when an init segment is appended to a MediaSource.
Expand Down
2 changes: 1 addition & 1 deletion lib/net/networking_engine.js
Expand Up @@ -700,7 +700,7 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {
const segment = context.segment;
const stream = context.stream;
if (segment && stream && stream.fastSwitching) {
if (segment.isPartial() && !segment.isLastPartial()) {
if (segment.isPartial()) {
return false;
}
}
Expand Down
15 changes: 13 additions & 2 deletions lib/player.js
Expand Up @@ -1858,6 +1858,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
'Please use an AbrManager with setCmsdManager function.');
this.abrManager_.setCmsdManager = () => {};
}
if (typeof this.abrManager_.trySuggestStreams != 'function') {
shaka.Deprecate.deprecateFeature(5,
'AbrManager',
'Please use an AbrManager with trySuggestStreams function.');
this.abrManager_.trySuggestStreams = () => {};
}
this.abrManager_.configure(this.config_.abr);
}

Expand Down Expand Up @@ -2915,8 +2921,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
onError: (error) => this.onError_(error),
onEvent: (event) => this.dispatchEvent(event),
onManifestUpdate: () => this.onManifestUpdate_(),
onSegmentAppended: (start, end, contentType) => {
this.onSegmentAppended_(start, end, contentType);
onSegmentAppended: (reference, stream) => {
this.onSegmentAppended_(
reference.startTime, reference.endTime, stream.type);
if (this.abrManager_ && stream.fastSwitching &&
reference.isPartial() && reference.isLastPartial()) {
this.abrManager_.trySuggestStreams();
}
},
onInitSegmentAppended: (position, initSegment) => {
const mediaQuality = initSegment.getMediaQuality();
Expand Down

0 comments on commit 48626f2

Please sign in to comment.