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

feat(CMCD): Add support to rtp parameter #6184

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ shakaDemo.Config = class {
.addBoolInput_('Enabled', 'cmcd.enabled')
.addTextInput_('Session ID', 'cmcd.sessionId')
.addTextInput_('Content ID', 'cmcd.contentId')
.addNumberInput_('RTP safety Factor', 'cmcd.rtpSafetyFactor',
/* canBeDecimal= */ true)
.addBoolInput_('Use Headers', 'cmcd.useHeaders');
}

Expand Down
6 changes: 5 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,8 @@ shaka.extern.AdvancedAbrConfiguration;
* enabled: boolean,
* useHeaders: boolean,
* sessionId: string,
* contentId: string
* contentId: string,
* rtpSafetyFactor: number
* }}
*
* @description
Expand All @@ -1533,6 +1534,9 @@ shaka.extern.AdvancedAbrConfiguration;
* characters. This value is consistent across multiple different sessions and
* devices and is defined and updated at the discretion of the service
* provider.
* @property {number} rtpSafetyFactor
* RTP safety factor.
* Defaults to <code>5</code>.
* @exportDoc
*/
shaka.extern.CmcdConfiguration;
Expand Down
35 changes: 33 additions & 2 deletions lib/util/cmcd_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ goog.require('shaka.log');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.util.ArrayUtils');

goog.requireType('shaka.media.SegmentReference');

/**
* @summary
* A CmcdManager maintains CMCD state as well as a collection of utility
Expand Down Expand Up @@ -235,6 +237,10 @@ shaka.util.CmcdManager = class {
}
}
}
const rtp = this.calculateRtp_(stream, segment);
if (!isNaN(rtp)) {
data.rtp = rtp;
}
}
}

Expand Down Expand Up @@ -373,8 +379,6 @@ shaka.util.CmcdManager = class {
data.su = this.buffering_;
}

// TODO: Implement rtp

if (useHeaders) {
const headers = shaka.util.CmcdManager.toHeaders(data);
if (!Object.keys(headers).length) {
Expand Down Expand Up @@ -554,6 +558,33 @@ shaka.util.CmcdManager = class {
return toPath.join('/');
}

/**
* Calculate requested maximun throughput
*
* @param {shaka.extern.Stream} stream
* @param {shaka.media.SegmentReference} segment
* @return {number}
* @private
*/
calculateRtp_(stream, segment) {
const playbackRate = this.playerInterface_.getPlaybackRate() || 1;
const currentBufferLevel =
this.getRemainingBufferLength_(stream.type) || 500;
const bandwidth = stream.bandwidth;
if (!bandwidth) {
return NaN;
}
const segmentDuration = segment.endTime - segment.startTime;
// Calculate file size in kilobits
const segmentSize = bandwidth * segmentDuration / 1000;
// Calculate time available to load file in seconds
const timeToLoad = (currentBufferLevel / playbackRate) / 1000;
// Calculate the exact bandwidth required
const minBandwidth = segmentSize / timeToLoad;
// Include a safety buffer
return minBandwidth * this.config_.rtpSafetyFactor;
}

/**
* Get the stream format
*
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 @@ -322,6 +322,7 @@ shaka.util.PlayerConfiguration = class {
enabled: false,
sessionId: '',
contentId: '',
rtpSafetyFactor: 5,
useHeaders: false,
};

Expand Down
1 change: 1 addition & 0 deletions test/util/cmcd_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe('CmcdManager', () => {
enabled: false,
sessionId: '',
contentId: 'testing',
rtpSafetyFactor: 5,
useHeaders: false,
};

Expand Down
Loading