Skip to content

Commit

Permalink
feat(HLS): Allow disable streams when the media playlist fails (#6807)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Jun 13, 2024
1 parent 1f579bb commit c866d7b
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 4 deletions.
6 changes: 5 additions & 1 deletion externs/shaka/manifest_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ shaka.extern.ManifestParser = class {
* onManifestUpdated: function(),
* getBandwidthEstimate: function():number,
* onMetadata: function(string, number, ?number,
* !Array.<shaka.extern.MetadataFrame>)
* !Array.<shaka.extern.MetadataFrame>),
* disableStream: function(!shaka.extern.Stream)
* }}
*
* @description
Expand Down Expand Up @@ -172,6 +173,9 @@ shaka.extern.ManifestParser = class {
* @property {function(string, number, ?number,
* !Array.<shaka.extern.MetadataFrame>)} onMetadata
* Called when an metadata is found in the manifest.
* @property {function(!shaka.extern.Stream)} disableStream
* Called to temporarily disable a stream i.e. disabling all variant
* containing said stream.
* @exportDoc
*/
shaka.extern.ManifestParser.PlayerInterface;
Expand Down
12 changes: 10 additions & 2 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,16 @@ shaka.hls.HlsParser = class {
}
manifestUris.push(uriObj.toString());
}
const response =
await this.requestManifest_(manifestUris, /* isPlaylist= */ true);
let response;
try {
response =
await this.requestManifest_(manifestUris, /* isPlaylist= */ true);
} catch (e) {
if (this.playerInterface_) {
this.playerInterface_.disableStream(streamInfo.stream);
}
throw e;
}
if (!streamInfo.stream.segmentIndex) {
// The stream was closed since the update was first requested.
return;
Expand Down
7 changes: 6 additions & 1 deletion lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,12 @@ shaka.media.StreamingEngine = class {
if (!mediaState.stream.segmentIndex) {
const thisStream = mediaState.stream;

await mediaState.stream.createSegmentIndex();
try {
await mediaState.stream.createSegmentIndex();
} catch (error) {
await this.handleStreamingError_(mediaState, error);
return;
}

if (thisStream != mediaState.stream) {
// We switched streams while in the middle of this async call to
Expand Down
1 change: 1 addition & 0 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ shaka.offline.Storage = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => config.abr.defaultBandwidthEstimate,
onMetadata: () => {},
disableStream: (stream) => {},
};

parser.configure(config.manifest);
Expand Down
3 changes: 3 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
});
}
},
disableStream: (stream) => {
this.disableStream(stream, this.config_.streaming.maxDisabledTime);
},
};
const regionTimeline =
new shaka.media.RegionTimeline(() => this.seekRange());
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: () => {},
disableStream: (stream) => {},
};

const actual = await dashParser.start(
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: () => {},
disableStream: (stream) => {},
};
});

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 @@ -57,6 +57,7 @@ describe('DashParser Manifest', () => {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
};
});

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: () => {},
disableStream: (stream) => {},
};
Date.now = () => publishTime.getTime() + 10;

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: () => {},
disableStream: (stream) => {},
};
});

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: () => {},
disableStream: (stream) => {},
};
try {
const manifest = await dashParser.start('dummy://foo', playerInterface);
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: () => {},
disableStream: (stream) => {},
};
});

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: () => {},
disableStream: (stream) => {},
};

parser = new shaka.hls.HlsParser();
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),
disableStream: (stream) => {},
};

parser = new shaka.hls.HlsParser();
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: () => {},
disableStream: (stream) => {},
};
});

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: () => {},
disableStream: (stream) => {},
};
try {
const manifest = await dashParser.start('dummy://foo', playerInterface);
Expand Down Expand Up @@ -91,6 +92,7 @@ shaka.test.Dash = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
};

try {
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: () => {},
disableStream: (stream) => {},
};
const manifest = await mssParser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].audio;
Expand Down Expand Up @@ -87,6 +88,7 @@ shaka.test.Mss = class {
onManifestUpdated: () => {},
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
};
const p = mssParser.start('dummy://foo', playerInterface);
await expectAsync(p).toBeRejectedWith(
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: () => {},
disableStream: (stream) => {},
};
const config = shaka.util.PlayerConfiguration.createDefault().manifest;
manager = new shaka.util.ContentSteeringManager(playerInterface);
Expand Down

0 comments on commit c866d7b

Please sign in to comment.