Skip to content

Commit

Permalink
feat(HLS): Add allowRangeRequestsToGuessMimeType config (#7979)
Browse files Browse the repository at this point in the history
Close #7973
  • Loading branch information
avelad authored Jan 29, 2025
1 parent 45c37d3 commit 195fd2b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ shakaDemo.Config = class {
.addBoolInput_('Allow LL-HLS byterange optimization',
'manifest.hls.allowLowLatencyByteRangeOptimization')
.addNumberInput_('override the Update time of the manifest',
'manifest.hls.updatePeriod');
'manifest.hls.updatePeriod')
.addBoolInput_('Allow range request to guess mime type',
'manifest.hls.allowRangeRequestsToGuessMimeType');
}

/** @private */
Expand Down
8 changes: 7 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,8 @@ shaka.extern.DashManifestConfiguration;
* disableCodecGuessing: boolean,
* disableClosedCaptionsDetection: boolean,
* allowLowLatencyByteRangeOptimization: boolean,
* updatePeriod: number
* updatePeriod: number,
* allowRangeRequestsToGuessMimeType: boolean
* }}
*
* @property {boolean} ignoreTextStreamFailures
Expand Down Expand Up @@ -1314,6 +1315,11 @@ shaka.extern.DashManifestConfiguration;
* trigger a new download of the manifest.
* <br>
* Defaults to <code>-1</code>.
* @property {boolean} allowRangeRequestsToGuessMimeType
* If set to true, the HLS parser will use range request (only first byte) to
* guess the mime type.
* <br>
* Defaults to <code>false</code>.
* @exportDoc
*/
shaka.extern.HlsManifestConfiguration;
Expand Down
4 changes: 4 additions & 0 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4522,6 +4522,10 @@ shaka.hls.HlsParser = class {
(error.code == shaka.util.Error.Code.HTTP_ERROR ||
error.code == shaka.util.Error.Code.BAD_HTTP_STATUS)) {
headRequest.method = 'GET';
if (this.config_.hls.allowRangeRequestsToGuessMimeType) {
// Only requesting first byte
headRequest.headers['Range'] = 'bytes=0-0';
}
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type}).promise;

Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ shaka.util.PlayerConfiguration = class {
disableClosedCaptionsDetection: false,
updatePeriod: -1,
allowLowLatencyByteRangeOptimization: true,
allowRangeRequestsToGuessMimeType: false,
},
mss: {
manifestPreprocessor:
Expand Down

0 comments on commit 195fd2b

Please sign in to comment.