Skip to content

Commit

Permalink
Adds settings parameters to configure the AbandonRequestsRule.js (#4298)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed Oct 11, 2023
1 parent 425fa72 commit 3f66a52
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
7 changes: 7 additions & 0 deletions index.d.ts
Expand Up @@ -1092,6 +1092,13 @@ declare namespace dashjs {
droppedFramesRule?: boolean,
abandonRequestsRule?: boolean
},
abrRulesParameters?: {
abandonRequestsRule: {
graceTimeThreshold: number,
abandonMultiplier: number,
minLengthToAverage: number
}
},
bandwidthSafetyFactor?: number;
useDefaultABRRules?: boolean;
useDeadTimeLatency?: boolean;
Expand Down
33 changes: 32 additions & 1 deletion src/core/Settings.js
Expand Up @@ -199,6 +199,13 @@ import Events from './events/Events';
* droppedFramesRule: true,
* abandonRequestsRule: true
* },
* abrRulesParameters: {
* abandonRequestsRule: {
* graceTimeThreshold: 500,
* abandonMultiplier: 1.8,
* minLengthToAverage: 5
* }
* },
* bandwidthSafetyFactor: 0.9,
* useDefaultABRRules: true,
* useDeadTimeLatency: true,
Expand Down Expand Up @@ -332,7 +339,7 @@ import Events from './events/Events';
* If this flag is set to true then dash.js will use the MSE v.2 API call "changeType()" before switching to a different track.
* Note that some platforms might not implement the changeType functio. dash.js is checking for the availability before trying to call it.
* @property {boolean} [mediaSourceDurationInfinity=true]
* If this flag is set to true then dash.js will allow `Infinity` to be set as the MediaSource duration otherwise the duration will be set to `Math.pow(2,32)` instead of `Infinity` to allow appending segments indefinitely.
* If this flag is set to true then dash.js will allow `Infinity` to be set as the MediaSource duration otherwise the duration will be set to `Math.pow(2,32)` instead of `Infinity` to allow appending segments indefinitely.
* Some platforms such as WebOS 4.x have issues with seeking when duration is set to `Infinity`, setting this flag to false resolve this.
* @property {boolean} [resetSourceBuffersForTrackSwitch=false]
* When switching to a track that is not compatible with the currently active MSE SourceBuffers, MSE will be reset. This happens when we switch codecs on a system
Expand Down Expand Up @@ -568,6 +575,22 @@ import Events from './events/Events';
* Enable to use the MediaCapabilities API to check whether codecs are supported. If disabled MSE.isTypeSupported will be used instead.
*/

/**
* @typedef {Object} AbrRulesParameters
* @property {module:Settings~AbandonRequestRuleParameters} abandonRequestRule
* Configuration parameters for the AbandonRequestRule
*/

/**
* @typedef {Object} AbandonRequestRuleParameters
* @property {number} [graceTimeThreshold=500]
* Minimum elapsed time in milliseconds that the segment download has to run before the rule considers abandoning the download.
* @property {number} [abandonMultiplier]
* This value is multiplied with the segment duration and compared to the estimated time of the download to decide the request should be abandoned.
* @property {number} [minLengthToAverage]
* Minimum number of throughput samples required to consider abandoning the download of the segment.
*/

/**
* @typedef {Object} AbrSettings
* @property {string} [movingAverageMethod="slidingWindow"]
Expand Down Expand Up @@ -595,6 +618,7 @@ import Events from './events/Events';
* @property {object} [trackSwitchMode={video: "neverReplace", audio: "alwaysReplace"}]
* @property {object} [additionalAbrRules={insufficientBufferRule: true,switchHistoryRule: true,droppedFramesRule: true,abandonRequestsRule: true}]
* Enable/Disable additional ABR rules in case ABRStrategy is set to "abrDynamic", "abrBola" or "abrThroughput".
* @property {module:Settings~AbrRulesParameters} abrRulesParameters Configuration options for the different ABR rules
* @property {number} [bandwidthSafetyFactor=0.9]
* Standard ABR throughput rules multiply the throughput by this value.
*
Expand Down Expand Up @@ -987,6 +1011,13 @@ function Settings() {
droppedFramesRule: true,
abandonRequestsRule: true
},
abrRulesParameters: {
abandonRequestsRule: {
graceTimeThreshold: 500,
abandonMultiplier: 1.8,
minLengthToAverage: 5
}
},
bandwidthSafetyFactor: 0.9,
useDefaultABRRules: true,
useDeadTimeLatency: true,
Expand Down
9 changes: 3 additions & 6 deletions src/streaming/rules/abr/AbandonRequestsRule.js
Expand Up @@ -35,9 +35,6 @@ import Debug from '../../../core/Debug';
function AbandonRequestsRule(config) {

config = config || {};
const ABANDON_MULTIPLIER = 1.8;
const GRACE_TIME_THRESHOLD = 500;
const MIN_LENGTH_TO_AVERAGE = 5;

const context = this.context;
const mediaPlayerModel = config.mediaPlayerModel;
Expand Down Expand Up @@ -108,15 +105,15 @@ function AbandonRequestsRule(config) {
storeLastRequestThroughputByType(mediaType, Math.round(fragmentInfo.bytesLoaded * 8 / fragmentInfo.elapsedTime));
}

if (throughputArray[mediaType].length >= MIN_LENGTH_TO_AVERAGE &&
fragmentInfo.elapsedTime > GRACE_TIME_THRESHOLD &&
if (throughputArray[mediaType].length >= settings.get().streaming.abr.abrRulesParameters.abandonRequestsRule.minLengthToAverage &&
fragmentInfo.elapsedTime > settings.get().streaming.abr.abrRulesParameters.abandonRequestsRule.graceTimeThreshold &&
fragmentInfo.bytesLoaded < fragmentInfo.bytesTotal) {

const totalSampledValue = throughputArray[mediaType].reduce((a, b) => a + b, 0);
fragmentInfo.measuredBandwidthInKbps = Math.round(totalSampledValue / throughputArray[mediaType].length);
fragmentInfo.estimatedTimeOfDownload = +((fragmentInfo.bytesTotal * 8 / fragmentInfo.measuredBandwidthInKbps) / 1000).toFixed(2);

if (fragmentInfo.estimatedTimeOfDownload < fragmentInfo.segmentDuration * ABANDON_MULTIPLIER || rulesContext.getRepresentationInfo().quality === 0 ) {
if (fragmentInfo.estimatedTimeOfDownload < fragmentInfo.segmentDuration * settings.get().streaming.abr.abrRulesParameters.abandonRequestsRule.abandonMultiplier || rulesContext.getRepresentationInfo().quality === 0 ) {
return switchRequest;
} else if (!abandonDict.hasOwnProperty(fragmentInfo.id)) {

Expand Down

0 comments on commit 3f66a52

Please sign in to comment.