Skip to content

Commit

Permalink
use xhr and bandwidth parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Sep 22, 2023
1 parent 5ee0b01 commit 72af63a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
16 changes: 9 additions & 7 deletions src/content-steering-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class SteeringManifest {
* https://datatracker.ietf.org/doc/draft-pantos-hls-rfc8216bis/ section 4.4.6.6.
* DASH: https://dashif.org/docs/DASH-IF-CTS-00XX-Content-Steering-Community-Review.pdf
*
* @param {Object} segmentLoader a reference to the mainSegmentLoader
* @param {function} xhr for making a network request from the browser.
* @param {function} bandwidth for fetching the current bandwidth from the main segment loader.
*/
export default class ContentSteeringController extends videojs.EventTarget {
// pass a segment loader reference for throughput rate and xhr
constructor(segmentLoader) {
constructor(xhr, bandwidth) {
super();

this.currentPathway = null;
Expand All @@ -84,8 +84,9 @@ export default class ContentSteeringController extends videojs.EventTarget {
this.ttlTimeout_ = null;
this.request_ = null;
this.excludedSteeringManifestURLs = new Set();
this.mainSegmentLoader_ = segmentLoader;
this.logger_ = logger('Content Steering');
this.xhr_ = xhr;
this.getBandwidth_ = bandwidth;
}

/**
Expand Down Expand Up @@ -159,7 +160,7 @@ export default class ContentSteeringController extends videojs.EventTarget {
return;
}

this.request_ = this.mainSegmentLoader_.vhs_.xhr({
this.request_ = this.xhr_({
uri
}, (error, errorInfo) => {
if (error) {
Expand Down Expand Up @@ -236,17 +237,18 @@ export default class ContentSteeringController extends videojs.EventTarget {
setSteeringParams_(url) {
const urlObject = new window.URL(url);
const path = this.getPathway();
const networkThroughput = this.getBandwidth_();

if (path) {
const pathwayKey = `_${this.manifestType_}_pathway`;

urlObject.searchParams.set(pathwayKey, path);
}

if (this.mainSegmentLoader_.throughput.rate) {
if (networkThroughput) {
const throughputKey = `_${this.manifestType_}_throughput`;

urlObject.searchParams.set(throughputKey, this.mainSegmentLoader_.bandwidth);
urlObject.searchParams.set(throughputKey, networkThroughput);
}
return urlObject.toString();
}
Expand Down
7 changes: 5 additions & 2 deletions src/playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ export class PlaylistController extends videojs.EventTarget {
})
}), options);

// pass main segment loader for current throughput.
this.contentSteeringController_ = new ContentSteeringController(this.mainSegmentLoader_);
const getBandwidth = () => {
return this.mainSegmentLoader_.bandwidth;
};

this.contentSteeringController_ = new ContentSteeringController(this.vhs_.xhr, getBandwidth);
this.setupSegmentLoaderListeners_();

if (this.bufferBasedABR) {
Expand Down
23 changes: 10 additions & 13 deletions test/content-steering-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ QUnit.module('ContentSteering', {
beforeEach(assert) {
this.env = useFakeEnvironment(assert);
this.requests = this.env.requests;
this.fakeVhs = {
xhr: xhrFactory()
};
this.mockSegmentLoader = {
vhs_: this.fakeVhs,
throughput: {
rate: 0
}
};
this.baseURL = 'https://foo.bar';
this.contentSteeringController = new ContentSteeringController(this.mockSegmentLoader);
this.contentSteeringController = new ContentSteeringController(xhrFactory(), () => undefined);
this.contentSteeringController.addAvailablePathway('test-1');
// handles a common testing flow of assigning tag properties and requesting the steering manifest immediately.
this.assignAndRequest = (steeringTag) => {
Expand Down Expand Up @@ -97,8 +88,10 @@ QUnit.test('Can add HLS pathway and throughput to steering manifest requests', f
};
const expectedThroughputUrl = steeringTag.serverUri + '/?_HLS_pathway=cdn-a&_HLS_throughput=99999';

this.contentSteeringController.getBandwidth_ = () => {
return 99999;
};
this.contentSteeringController.assignTagProperties(this.baseURL, steeringTag);
this.mockSegmentLoader.throughput.rate = 99999;
assert.equal(this.contentSteeringController.setSteeringParams_(steeringTag.serverUri), expectedThroughputUrl, 'pathway and throughput parameters set as expected');
});

Expand Down Expand Up @@ -169,8 +162,10 @@ QUnit.test('Can add DASH pathway and throughput to steering manifest requests',
};
const expectedThroughputUrl = steeringTag.serverURL + '&_DASH_pathway=cdn-c&_DASH_throughput=9999';

this.contentSteeringController.getBandwidth_ = () => {
return 9999;
};
this.contentSteeringController.assignTagProperties(this.baseURL, steeringTag);
this.mockSegmentLoader.throughput.rate = 9999;
assert.equal(this.contentSteeringController.setSteeringParams_(steeringTag.serverURL), expectedThroughputUrl, 'pathway and throughput parameters set as expected');
});

Expand All @@ -192,7 +187,9 @@ QUnit.test('Can handle DASH proxyServerURL', function(assert) {
};
const expectedProxyUrl = 'https://proxy.url/?url=https%3A%2F%2Fcontent.steering.dash%2F%3Fprevious%3Dparams&_DASH_pathway=dash-cdn&_DASH_throughput=99';

this.mockSegmentLoader.throughput.rate = 99;
this.contentSteeringController.getBandwidth_ = () => {
return 99;
};
this.assignAndRequest(steeringTag);
assert.equal(this.requests[0].uri, expectedProxyUrl, 'returns expected proxy server URL');
});
Expand Down

0 comments on commit 72af63a

Please sign in to comment.