Files
shaka-player/lib/net/http_plugin_utils.js
T
michellezhuo e7965fe219 feat(LL-HLS):Set segment availability duration
When starting playback for HLS live, we have the availability window
same as the delay duration from live edge. Thus, the playback start time
is the same as availability window start, and falls behind the window as
the window keeps move forward.
This may cause the seeked partial segments to be unavailable.

To make our system more robust, we can skip checking if the segment fits
in the availability window. Instead, we can send the request anyway. If
the segment is not available, we can handle the 404 error and try to fetch
the segment again.
This would not require us to calculate the segment availability window
in advance.

Issue #1525

Change-Id: Ib9c0eca8e9db2d93404745d87a5171fcb5fdce20
2020-08-20 19:03:34 +00:00

64 lines
1.7 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.net.HttpPluginUtils');
goog.require('shaka.log');
goog.require('shaka.util.Error');
goog.require('shaka.util.StringUtils');
goog.requireType('shaka.net.NetworkingEngine');
/**
* @summary A set of http networking utility functions.
* @exportDoc
*/
shaka.net.HttpPluginUtils = class {
/**
* @param {!Object.<string,string>} headers
* @param {BufferSource} data
* @param {number} status
* @param {string} uri
* @param {string} responseURL
* @param {shaka.net.NetworkingEngine.RequestType} requestType
* @return {!shaka.extern.Response}
*/
static makeResponse(headers, data, status, uri, responseURL, requestType) {
if (status >= 200 && status <= 299 && status != 202) {
// Most 2xx HTTP codes are success cases.
/** @type {shaka.extern.Response} */
const response = {
uri: responseURL || uri,
originalUri: uri,
data: data,
headers: headers,
fromCache: !!headers['x-shaka-from-cache'],
};
return response;
} else {
let responseText = null;
try {
responseText = shaka.util.StringUtils.fromBytesAutoDetect(data);
} catch (exception) {}
shaka.log.debug('HTTP error text:', responseText);
const severity = status == 401 || status == 403 ?
shaka.util.Error.Severity.CRITICAL :
shaka.util.Error.Severity.RECOVERABLE;
throw new shaka.util.Error(
severity,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.BAD_HTTP_STATUS,
uri,
status,
responseText,
headers,
requestType);
}
}
};