Skip to content

Commit

Permalink
fix(DASH): Fix playback after DASH period eviction (shaka-project#7519)
Browse files Browse the repository at this point in the history
With this change, closeSegmentIndex() of all streams of a removed period
are defered in StreamingEngine.onUpdate_()

Fixes shaka-project#7516
  • Loading branch information
ncocaign authored Nov 13, 2024
1 parent 10659c5 commit 5eff038
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 1 deletion.
3 changes: 3 additions & 0 deletions externs/shaka/manifest_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ shaka.extern.ManifestParser = class {
* getBandwidthEstimate: function():number,
* onMetadata: function(string, number, ?number,
* !Array.<shaka.extern.MetadataFrame>),
* closeSegmentIndex: function(shaka.extern.Stream, function()),
* disableStream: function(!shaka.extern.Stream),
* addFont: function(string, string)
* }}
Expand Down Expand Up @@ -186,6 +187,8 @@ shaka.extern.ManifestParser = class {
* @property {function(!shaka.extern.Stream)} disableStream
* Called to temporarily disable a stream i.e. disabling all variant
* containing said stream.
* @property {function(!shaka.extern.Stream, function())} closeSegmentIndex
* Called to close a segment index.
* @property {function(string, string)} addFont
* Called when a new font needs to be added.
* @exportDoc
Expand Down
3 changes: 3 additions & 0 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ shaka.dash.DashParser = class {
this.lowLatencyMode_ = playerInterface.isLowLatencyMode();
this.manifestUris_ = [uri];
this.playerInterface_ = playerInterface;
if (this.periodCombiner_) {
this.periodCombiner_.setPlayerInterface(this.playerInterface_);
}

const updateDelay = await this.requestManifest_();

Expand Down
26 changes: 26 additions & 0 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,32 @@ shaka.media.StreamingEngine = class {
}
}

/**
* closeSegmentIndex if the stream is not active
* @param {shaka.extern.Stream} stream
* @param {function()} closeSegmentIndex
*/
closeSegmentIndex(stream, closeSegmentIndex) {
const type = /** @type {!shaka.util.ManifestParserUtils.ContentType} */
(stream.type);
const mediaState = this.mediaStates_.get(type);
if (mediaState) {
/**
* Closes the segmentIndex only if the stream is not active.
* If the stream is active the eviction will be peformed
* by the next onUpdate_().
*/
const matchedStreams = mediaState.stream.matchedStreams;
const found = matchedStreams.find((match) => match.id === stream.id);
if (!found) {
closeSegmentIndex();
}
} else {
// type of stream not active
closeSegmentIndex();
}
}


/**
* Handles deferred releases of old SegmentIndexes for the mediaState's
Expand Down
1 change: 1 addition & 0 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,7 @@ shaka.offline.Storage = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => config.abr.defaultBandwidthEstimate,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
7 changes: 7 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
});
}
},
closeSegmentIndex: (stream, closeSegmentIndex) => {
if (this.streamingEngine_) {
this.streamingEngine_.closeSegmentIndex(stream, closeSegmentIndex);
} else {
closeSegmentIndex();
}
},
disableStream: (stream) => this.disableStream(
stream, this.config_.streaming.maxDisabledTime),
addFont: (name, url) => this.addFont(name, url),
Expand Down
25 changes: 24 additions & 1 deletion lib/util/periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ shaka.util.PeriodCombiner = class {
/** @private {boolean} */
this.useStreamOnce_ = false;

/** @private {?shaka.extern.ManifestParser.PlayerInterface} */
this.playerInterface_ = null;

/**
* The IDs of the periods we have already used to generate streams.
* This helps us identify the periods which have been added when a live
Expand Down Expand Up @@ -80,6 +83,15 @@ shaka.util.PeriodCombiner = class {
this.usedPeriodIds_.clear();
}

/**
* @param {?shaka.extern.ManifestParser.PlayerInterface} playerInterface
*
* @export
*/
setPlayerInterface(playerInterface) {
this.playerInterface_ = playerInterface;
}

/**
* @return {!Array.<shaka.extern.Variant>}
*
Expand Down Expand Up @@ -155,8 +167,19 @@ shaka.util.PeriodCombiner = class {
}
}
if (stream.segmentIndex) {
stream.closeSegmentIndex();
if (this.playerInterface_) {
const closeSegmentIndex = () => {
stream.closeSegmentIndex();
};

this.playerInterface_.closeSegmentIndex(
stream,
closeSegmentIndex);
} else {
stream.closeSegmentIndex();
}
}

this.usedPeriodIds_.delete(periodId);
}

Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('DashParser ContentProtection', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('DashParser Live', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('DashParser Manifest', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: shaka.test.Util.spyFunc(addFontSpy),
};
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_patch_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('DashParser Patch', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_base_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('DashParser SegmentBase', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_list_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ describe('DashParser SegmentList', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('DashParser SegmentTemplate', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('HlsParser live', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('HlsParser', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: shaka.test.Util.spyFunc(onMetadataSpy),
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
2 changes: 2 additions & 0 deletions test/media/streaming_engine_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ describe('StreamingEngine', () => {
onSegmentAppended: () => playhead.notifyOfBufferingChange(),
onInitSegmentAppended: () => {},
beforeAppendSegment: () => Promise.resolve(),
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream, time) => false,
};
streamingEngine = new shaka.media.StreamingEngine(
Expand Down
1 change: 1 addition & 0 deletions test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ describe('StreamingEngine', () => {
onSegmentAppended: Util.spyFunc(onSegmentAppended),
onInitSegmentAppended: () => {},
beforeAppendSegment: Util.spyFunc(beforeAppendSegment),
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: Util.spyFunc(disableStream),
};
streamingEngine = new shaka.media.StreamingEngine(
Expand Down
1 change: 1 addition & 0 deletions test/mss/mss_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('MssParser Manifest', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
2 changes: 2 additions & 0 deletions test/test/util/dash_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ shaka.test.Dash = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down Expand Up @@ -98,6 +99,7 @@ shaka.test.Dash = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
2 changes: 2 additions & 0 deletions test/test/util/mss_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ shaka.test.Mss = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down Expand Up @@ -89,6 +90,7 @@ shaka.test.Mss = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down
1 change: 1 addition & 0 deletions test/util/content_steering_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('ContentSteeringManager', () => {
onManifestUpdated: fail,
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
closeSegmentIndex: (stream, closeSegmentIndex) => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Expand Down

0 comments on commit 5eff038

Please sign in to comment.