Skip to content

Commit

Permalink
fix: Adds missing CMCD params to some http requests (shaka-project#5072)
Browse files Browse the repository at this point in the history
Fixes shaka-project#5067
Fixes shaka-project#5094

Co-authored-by: Dan Sparacio <daniel.sparacio@cbsinteractive.com>
  • Loading branch information
littlespex and dsparacio committed Mar 15, 2023
1 parent 6a0124d commit fe38e45
Show file tree
Hide file tree
Showing 25 changed files with 512 additions and 292 deletions.
2 changes: 1 addition & 1 deletion demo/common/asset.js
Expand Up @@ -373,7 +373,7 @@ const ShakaDemoAssetInfo = class {

if (this.licenseRequestHeaders.size) {
/** @type {!shaka.extern.RequestFilter} */
const filter = (requestType, request, advType) => {
const filter = (requestType, request, context) => {
return this.addLicenseRequestHeaders_(this.licenseRequestHeaders,
requestType,
request);
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/ad_monetization.md
Expand Up @@ -203,7 +203,7 @@ default, so you should only need to set this if you've enabled it in other parts
your code.

```js
player.getNetworkingEngine().registerRequestFilter(function(type, request, advType) {
player.getNetworkingEngine().registerRequestFilter(function(type, request, context) {
if (type == shaka.net.NetworkingEngine.RequestType.MANIFEST ||
type == shaka.net.NetworkingEngine.RequestType.SEGMENT) {
request.withCredentials = false;
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/application-level-redirects.md
Expand Up @@ -36,7 +36,7 @@ const HTTP_IN_HEX = 0x68747470;

const RequestType = shaka.net.NetworkingEngine.RequestType;

player.getNetworkingEngine().registerResponseFilter(async (type, response, advType) => {
player.getNetworkingEngine().registerResponseFilter(async (type, response, context) => {
// NOTE: If the system requires an ALR for both manifests and segments,
// remove this RequestType check.
if (type != RequestType.MANIFEST) {
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/fairplay.md
Expand Up @@ -90,7 +90,7 @@ or give the response in a different format. For more info, see the general
{@tutorial license-wrapping} tutorial:

```js
player.getNetworkingEngine().registerRequestFilter((type, request, advType) => {
player.getNetworkingEngine().registerRequestFilter((type, request, context) => {
if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) {
return;
}
Expand All @@ -103,7 +103,7 @@ player.getNetworkingEngine().registerRequestFilter((type, request, advType) => {
request.body = shaka.util.StringUtils.toUTF8(encodeURIComponent(params));
});

player.getNetworkingEngine().registerResponseFilter((type, response, advType) => {
player.getNetworkingEngine().registerResponseFilter((type, response, context) => {
if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) {
return;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ Note: If the url of the license server has to undergo any transformation
(eg: add the contentId), you would have to create your filter manually.

```js
player.getNetworkingEngine().registerRequestFilter((type, request, advType) => {
player.getNetworkingEngine().registerRequestFilter((type, request, context) => {
if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) {
return;
}
Expand Down Expand Up @@ -175,7 +175,7 @@ Note: If the url of the license server has to undergo any transformation
(eg: add the contentId), you would have to create your filter manually.

```js
player.getNetworkingEngine().registerRequestFilter((type, request, advType) => {
player.getNetworkingEngine().registerRequestFilter((type, request, context) => {
if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/license-server-auth.md
Expand Up @@ -62,7 +62,7 @@ arbitrary headers to Shaka's requests through a request filter callback.
Register the filter before calling `player.load()`:

```js
player.getNetworkingEngine().registerRequestFilter(function(type, request, advType) {
player.getNetworkingEngine().registerRequestFilter(function(type, request, context) {
// Only add headers to license requests:
if (type == shaka.net.NetworkingEngine.RequestType.LICENSE) {
// This is the specific header name and value the server wants:
Expand Down Expand Up @@ -92,7 +92,7 @@ try to use it without setting the parameter, you will see `Error code 6007`
We can use a request filter to modify the URL and add the required parameter:

```js
player.getNetworkingEngine().registerRequestFilter(function(type, request, advType) {
player.getNetworkingEngine().registerRequestFilter(function(type, request, context) {
// Only add headers to license requests:
if (type == shaka.net.NetworkingEngine.RequestType.LICENSE) {
// This is the specific parameter name and value the server wants:
Expand Down Expand Up @@ -140,7 +140,7 @@ Our `cookie_auth` endpoint sends back headers that allow credentialed requests,
so we set a flag in our request filter to send credentials cross-site:

```js
player.getNetworkingEngine().registerRequestFilter(function(type, request, advType) {
player.getNetworkingEngine().registerRequestFilter(function(type, request, context) {
if (type == shaka.net.NetworkingEngine.RequestType.LICENSE) {
request.allowCrossSiteCredentials = true;
}
Expand Down Expand Up @@ -205,7 +205,7 @@ const authToken = null;
Now change the request filter:

```js
player.getNetworkingEngine().registerRequestFilter(function(type, request, advType) {
player.getNetworkingEngine().registerRequestFilter(function(type, request, context) {
// Only add headers to license requests:
if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) return;

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/license-wrapping.md
Expand Up @@ -65,7 +65,7 @@ will see `Error code 6007`, which means `LICENSE_REQUEST_FAILED`. To wrap the
license request, we must register a request filter:

```js
player.getNetworkingEngine().registerRequestFilter(function(type, request, advType) {
player.getNetworkingEngine().registerRequestFilter(function(type, request, context) {
// Alias some utilities provided by the library.
const StringUtils = shaka.util.StringUtils;
const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
Expand Down Expand Up @@ -136,7 +136,7 @@ Widevine CDM does not understand this wrapped format, so we must unwrap it first
using a request filter:

```js
player.getNetworkingEngine().registerResponseFilter(function(type, response, advType) {
player.getNetworkingEngine().registerResponseFilter(function(type, response, context) {
// Alias some utilities provided by the library.
const StringUtils = shaka.util.StringUtils;
const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
Expand Down
10 changes: 0 additions & 10 deletions externs/shaka/manifest_parser.js
Expand Up @@ -100,10 +100,6 @@ shaka.extern.ManifestParser = class {
/**
* @typedef {{
* networkingEngine: !shaka.net.NetworkingEngine,
* modifyManifestRequest: function(!shaka.extern.Request,
* shaka.util.CmcdManager.ManifestInfo),
* modifySegmentRequest: function(!shaka.extern.Request,
* shaka.util.CmcdManager.SegmentInfo),
* filter: function(shaka.extern.Manifest):!Promise,
* makeTextStreamsForClosedCaptions: function(shaka.extern.Manifest),
* onTimelineRegionAdded: function(shaka.extern.TimelineRegionInfo),
Expand All @@ -124,12 +120,6 @@ shaka.extern.ManifestParser = class {
*
* @property {!shaka.net.NetworkingEngine} networkingEngine
* The networking engine to use for network requests.
* @property {function(!shaka.extern.Request,
* shaka.util.CmcdManager.ManifestInfo)} modifyManifestRequest
* Modify a manifest request
* @property {function(!shaka.extern.Request,
* shaka.util.CmcdManager.SegmentInfo)} modifySegmentRequest
* Modify a segment request
* @property {function(shaka.extern.Manifest):!Promise} filter
* Should be called when new variants or text streams are added to the
* Manifest. Note that this operation is asynchronous.
Expand Down
18 changes: 9 additions & 9 deletions externs/shaka/net.js
Expand Up @@ -203,14 +203,14 @@ shaka.extern.HeadersReceived;
* Defines a filter for requests. This filter takes the request and modifies
* it before it is sent to the scheme plugin.
* The RequestType describes the basic type of the request (manifest, segment,
* etc). The optional AdvancedRequestType will be provided in the case of a
* sub-type of the basic type (playlist manifest, init segment, etc).
* A request filter can run asynchronously by returning a promise; in this case,
* the request will not be sent until the promise is resolved.
* etc). The optional RequestContext will be provided where applicable to
* provide additional infomation about the request. A request filter can run
* asynchronously by returning a promise; in this case, the request will not be
* sent until the promise is resolved.
*
* @typedef {!function(shaka.net.NetworkingEngine.RequestType,
* shaka.extern.Request,
* shaka.net.NetworkingEngine.AdvancedRequestType=):
* shaka.net.NetworkingEngine.RequestContext=):
* (Promise|undefined)}
* @exportDoc
*/
Expand All @@ -221,13 +221,13 @@ shaka.extern.RequestFilter;
* Defines a filter for responses. This filter takes the response and modifies
* it before it is returned.
* The RequestType describes the basic type of the request (manifest, segment,
* etc). The optional AdvancedRequestType will be provided in the case of a
* sub-type of the basic type (playlist manifest, init segment, etc).
* A response filter can run asynchronously by returning a promise.
* etc). The optional RequestContext will be provided where applicable to
* provide additional infomation about the request. A response filter can run
* asynchronously by returning a promise.
*
* @typedef {!function(shaka.net.NetworkingEngine.RequestType,
* shaka.extern.Response,
* shaka.net.NetworkingEngine.AdvancedRequestType=):
* shaka.net.NetworkingEngine.RequestContext=):
* (Promise|undefined)}
* @exportDoc
*/
Expand Down
13 changes: 4 additions & 9 deletions lib/dash/dash_parser.js
Expand Up @@ -19,7 +19,6 @@ goog.require('shaka.media.PresentationTimeline');
goog.require('shaka.media.SegmentIndex');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.text.TextEngine');
goog.require('shaka.util.CmcdManager');
goog.require('shaka.util.Error');
goog.require('shaka.util.Functional');
goog.require('shaka.util.LanguageUtils');
Expand Down Expand Up @@ -222,16 +221,12 @@ shaka.dash.DashParser = class {
*/
async requestManifest_() {
const requestType = shaka.net.NetworkingEngine.RequestType.MANIFEST;
const advType = shaka.net.NetworkingEngine.AdvancedRequestType.MPD;
const type = shaka.net.NetworkingEngine.AdvancedRequestType.MPD;
const request = shaka.net.NetworkingEngine.makeRequest(
this.manifestUris_, this.config_.retryParameters);
const networkingEngine = this.playerInterface_.networkingEngine;

const format = shaka.util.CmcdManager.StreamingFormat.DASH;
this.playerInterface_.modifyManifestRequest(request, {format: format});

const startTime = Date.now();
const operation = networkingEngine.request(requestType, request, advType);
const operation = networkingEngine.request(requestType, request, {type});
this.operationManager_.manage(operation);

const response = await operation.promise;
Expand Down Expand Up @@ -1837,7 +1832,7 @@ shaka.dash.DashParser = class {
*/
async requestSegment_(uris, startByte, endByte, isInit) {
const requestType = shaka.net.NetworkingEngine.RequestType.SEGMENT;
const advType = isInit ?
const type = isInit ?
shaka.net.NetworkingEngine.AdvancedRequestType.INIT_SEGMENT :
shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;

Expand All @@ -1848,7 +1843,7 @@ shaka.dash.DashParser = class {
this.config_.retryParameters);

const networkingEngine = this.playerInterface_.networkingEngine;
const operation = networkingEngine.request(requestType, request, advType);
const operation = networkingEngine.request(requestType, request, {type});
this.operationManager_.manage(operation);
const response = await operation.promise;
return response.data;
Expand Down
14 changes: 5 additions & 9 deletions lib/hls/hls_parser.js
Expand Up @@ -26,7 +26,6 @@ goog.require('shaka.net.DataUriPlugin');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.util.ArrayUtils');
goog.require('shaka.util.BufferUtils');
goog.require('shaka.util.CmcdManager');
goog.require('shaka.util.Error');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.Functional');
Expand Down Expand Up @@ -3273,13 +3272,10 @@ shaka.hls.HlsParser = class {
const request = shaka.net.NetworkingEngine.makeRequest(
[absoluteUri], this.config_.retryParameters);

const format = shaka.util.CmcdManager.StreamingFormat.HLS;
this.playerInterface_.modifyManifestRequest(request, {format: format});

const advType = isPlaylist ?
const type = isPlaylist ?
shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_PLAYLIST :
shaka.net.NetworkingEngine.AdvancedRequestType.MASTER_PLAYLIST;
return this.makeNetworkRequest_(request, requestType, advType);
return this.makeNetworkRequest_(request, requestType, {type});
}

/**
Expand Down Expand Up @@ -3379,11 +3375,11 @@ shaka.hls.HlsParser = class {
*
* @param {shaka.extern.Request} request
* @param {shaka.net.NetworkingEngine.RequestType} type
* @param {shaka.net.NetworkingEngine.AdvancedRequestType=} advType
* @param {shaka.net.NetworkingEngine.RequestContext=} context
* @return {!Promise.<shaka.extern.Response>}
* @private
*/
makeNetworkRequest_(request, type, advType) {
makeNetworkRequest_(request, type, context) {
if (!this.operationManager_) {
throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
Expand All @@ -3392,7 +3388,7 @@ shaka.hls.HlsParser = class {
}

const op = this.playerInterface_.networkingEngine.request(
type, request, advType);
type, request, context);
this.operationManager_.manage(op);

return op.promise;
Expand Down
33 changes: 9 additions & 24 deletions lib/media/streaming_engine.js
Expand Up @@ -2109,10 +2109,11 @@ shaka.media.StreamingEngine = class {
*/
dispatchFetch_(reference, stream, streamDataCallback, isInit) {
const requestType = shaka.net.NetworkingEngine.RequestType.SEGMENT;
const advType = isInit ?
const type = isInit ?
shaka.net.NetworkingEngine.AdvancedRequestType.INIT_SEGMENT :
shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;

const segment = reference instanceof shaka.media.SegmentReference ?
reference : undefined;
const request = shaka.util.Networking.createSegmentRequest(
reference.getUris(),
reference.startByte,
Expand All @@ -2121,24 +2122,13 @@ shaka.media.StreamingEngine = class {
streamDataCallback);

shaka.log.v2('fetching: reference=', reference);
let duration = 0;
if (reference instanceof shaka.media.SegmentReference) {
// start and endTime are not defined in InitSegmentReference
duration = reference.endTime - reference.startTime;
}
this.playerInterface_.modifySegmentRequest(
request,
{
type: stream.type,
init: reference instanceof shaka.media.InitSegmentReference,
duration: duration,
mimeType: stream.mimeType,
codecs: stream.codecs,
bandwidth: stream.bandwidth,
},
);

return this.playerInterface_.netEngine.request(
requestType, request, advType);
requestType, request, {
type: type,
stream: stream,
segment: segment,
});
}

/**
Expand Down Expand Up @@ -2304,8 +2294,6 @@ shaka.media.StreamingEngine = class {
* @typedef {{
* getPresentationTime: function():number,
* getBandwidthEstimate: function():number,
* modifySegmentRequest: function(shaka.extern.Request,
* shaka.util.CmcdManager.SegmentInfo),
* mediaSourceEngine: !shaka.media.MediaSourceEngine,
* netEngine: shaka.net.NetworkingEngine,
* onError: function(!shaka.util.Error),
Expand All @@ -2324,9 +2312,6 @@ shaka.media.StreamingEngine = class {
* viewer is seeing on screen right now.
* @property {function():number} getBandwidthEstimate
* Get the estimated bandwidth in bits per second.
* @property {function(shaka.extern.Request,
* shaka.extern.Cmcd.SegmentInfo)} modifySegmentRequest
* The request modifier
* @property {!shaka.media.MediaSourceEngine} mediaSourceEngine
* The MediaSourceEngine. The caller retains ownership.
* @property {shaka.net.NetworkingEngine} netEngine
Expand Down

0 comments on commit fe38e45

Please sign in to comment.