Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing CMCD params in some http requests #5072

Merged
merged 53 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
90b4527
Merge remote-tracking branch 'upstream/master'
dsparacio Oct 29, 2020
49d611f
Merge branch 'master' of https://github.com/google/shaka-player
dsparacio Jan 25, 2021
93fdcd3
Merge remote-tracking branch 'upstream/master'
littlespex May 4, 2021
0b7ac5b
Merge branch 'google:master' into master
littlespex Sep 8, 2021
6db0e3c
Merge branch 'google:master' into master
littlespex Sep 15, 2021
efaebee
Merge branch 'google:master' into master
littlespex Sep 20, 2021
7fed0d0
Merge branch 'google:master' into master
littlespex Sep 22, 2021
7a30028
Merge branch 'google:master' into master
littlespex Sep 30, 2021
0168a7f
Merge branch 'google:master' into master
littlespex Oct 18, 2021
6b64092
Merge branch 'google:master' into master
littlespex Nov 2, 2021
a0cdf79
Merge branch 'google:master' into master
littlespex Dec 16, 2021
28564dd
Merge branch 'google:master' into master
littlespex Jan 7, 2022
5fb344e
Merge branch 'google:master' into master
littlespex Jan 10, 2022
1766930
Merge branch 'google:master' into master
littlespex Jan 12, 2022
b0cad7c
Merge branch 'google:master' into master
littlespex Jan 18, 2022
868b75b
Merge branch 'google:master' into master
littlespex Feb 4, 2022
95589c9
Merge branch 'shaka-project:main' into master
littlespex Mar 15, 2022
f331382
Merge branch 'shaka-project:main' into master
littlespex Jun 13, 2022
d14c111
Merge branch 'shaka-project:main' into master
littlespex Jun 29, 2022
b700d3b
Merge branch 'shaka-project:main' into master
littlespex Sep 21, 2022
0d9ea95
Merge branch 'shaka-project:main' into master
littlespex Oct 21, 2022
ef5177b
Merge branch 'shaka-project:main' into master
littlespex Oct 25, 2022
937638e
Merge branch 'shaka-project:main' into master
littlespex Oct 26, 2022
6f0d4fe
Merge branch 'shaka-project:main' into master
littlespex Oct 27, 2022
5a83556
Merge branch 'shaka-project:main' into master
littlespex Nov 9, 2022
6536603
Merge branch 'shaka-project:main' into master
littlespex Nov 10, 2022
62f7011
Merge branch 'shaka-project:main' into master
littlespex Nov 16, 2022
0e4d4a2
Merge branch 'shaka-project:main' into master
littlespex Nov 17, 2022
bfa45d3
Merge branch 'shaka-project:main' into master
littlespex Dec 9, 2022
f911668
Merge branch 'shaka-project:main' into master
littlespex Jan 21, 2023
5291a2a
Merge branch 'shaka-project:main' into master
littlespex Jan 25, 2023
dc64ede
Merge branch 'shaka-project:main' into master
littlespex Jan 26, 2023
7bee999
fix: exclude "future" segments from presentation timeline calculations
littlespex Jan 26, 2023
172fb81
Revert "fix: exclude "future" segments from presentation timeline cal…
littlespex Jan 26, 2023
127b183
fix: exclude "future" segments from presentation timeline calculations
littlespex Jan 26, 2023
7004b44
Revert "fix: exclude "future" segments from presentation timeline cal…
littlespex Jan 26, 2023
2632ea9
Merge branch 'shaka-project:main' into master
littlespex Feb 17, 2023
407a446
Merge branch 'shaka-project:main' into master
littlespex Mar 7, 2023
685107a
fix: missing CMCD params in HEAD requests
littlespex Mar 8, 2023
4c21d66
Refactor to use IReleaseable instead of IDestroyable
littlespex Mar 10, 2023
19cfe30
remove su override
littlespex Mar 10, 2023
5a78a52
Add comment to request filter
littlespex Mar 10, 2023
ab88756
Update player.js
littlespex Mar 10, 2023
ce5c955
Refactor CMCD and NetorkingEngine.request
littlespex Mar 13, 2023
daf16ae
lint fix
littlespex Mar 14, 2023
578c9e2
build fixes and doc updates
littlespex Mar 14, 2023
b7ea19d
fix unit test util
littlespex Mar 14, 2023
270b93a
test improvements
littlespex Mar 14, 2023
1fc1665
PR suggestions
littlespex Mar 14, 2023
2eff917
add "key" and "other" object types
littlespex Mar 14, 2023
6bb5316
type fix
littlespex Mar 14, 2023
525e6e4
add more tests
littlespex Mar 15, 2023
9f653e2
dont apply filter when cmcd is disabled
littlespex Mar 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/common/asset.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading