Skip to content

Commit

Permalink
add setting to change mediasource duration from infinity to math.pow(…
Browse files Browse the repository at this point in the history
…2,32) (#4274)
  • Loading branch information
bwallberg committed Sep 5, 2023
1 parent 1c8312a commit 39efb18
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Expand Up @@ -987,6 +987,7 @@ declare namespace dashjs {
setStallState?: boolean
avoidCurrentTimeRangePruning?: boolean
useChangeTypeForTrackSwitch?: boolean
mediaSourceDurationInfinity?: boolean
},
gaps?: {
jumpGaps?: boolean,
Expand Down
13 changes: 13 additions & 0 deletions samples/dash-if-reference-player/app/main.js
Expand Up @@ -302,6 +302,7 @@ app.controller('DashController', ['$scope', '$window', 'sources', 'contributors'
$scope.scheduleWhilePausedSelected = true;
$scope.calcSegmentAvailabilityRangeFromTimelineSelected = false;
$scope.reuseExistingSourceBuffersSelected = true;
$scope.mediaSourceDurationInfinitySelected = true;
$scope.saveLastMediaSettingsSelected = true;
$scope.localStorageSelected = true;
$scope.jumpGapsSelected = true;
Expand Down Expand Up @@ -670,6 +671,17 @@ app.controller('DashController', ['$scope', '$window', 'sources', 'contributors'
});
};

$scope.toggleMediaSourceDurationInfinity = function () {
$scope.player.updateSettings({
streaming: {
buffer: {
mediaSourceDurationInfinity: $scope.mediaSourceDurationInfinitySelected
}
}
});
};


$scope.toggleSaveLastMediaSettings = function () {
$scope.player.updateSettings({
'streaming': {
Expand Down Expand Up @@ -2134,6 +2146,7 @@ app.controller('DashController', ['$scope', '$window', 'sources', 'contributors'
$scope.scheduleWhilePausedSelected = currentConfig.streaming.scheduling.scheduleWhilePaused;
$scope.calcSegmentAvailabilityRangeFromTimelineSelected = currentConfig.streaming.timeShiftBuffer.calcFromSegmentTimeline;
$scope.reuseExistingSourceBuffersSelected = currentConfig.streaming.buffer.reuseExistingSourceBuffers;
$scope.mediaSourceDurationInfinitySelected = currentConfig.streaming.buffer.mediaSourceDurationInfinity;
$scope.saveLastMediaSettingsSelected = currentConfig.streaming.saveLastMediaSettingsForCurrentStreamingSession;
$scope.localStorageSelected = currentConfig.streaming.lastBitrateCachingInfo.enabled;
$scope.jumpGapsSelected = currentConfig.streaming.gaps.jumpGaps;
Expand Down
7 changes: 7 additions & 0 deletions samples/dash-if-reference-player/index.html
Expand Up @@ -188,6 +188,13 @@
ng-checked="reuseExistingSourceBuffersSelected">
Reuse SourceBuffers
</label>
<label class="topcoat-checkbox" data-toggle="tooltip" data-placement="right"
title="Allows duration to be set to Infinity on the MediaSource">
<input type="checkbox" ng-model="mediaSourceDurationInfinitySelected"
ng-change="toggleMediaSourceDurationInfinity()"
ng-checked="mediaSourceDurationInfinitySelected">
MediaSource duration Infinity
</label>
<label class="topcoat-checkbox" data-toggle="tooltip" data-placement="right"
title="Enable media settings from last selected track to be used for incoming track selection.">
<input type="checkbox" ng-model="saveLastMediaSettingsSelected"
Expand Down
9 changes: 7 additions & 2 deletions src/core/Settings.js
Expand Up @@ -107,7 +107,8 @@ import Events from './events/Events';
* useAppendWindow: true,
* setStallState: true,
* avoidCurrentTimeRangePruning: false,
* useChangeTypeForTrackSwitch: true
* useChangeTypeForTrackSwitch: true,
* mediaSourceDurationInfinity: true
* },
* gaps: {
* jumpGaps: true,
Expand Down Expand Up @@ -329,6 +330,9 @@ import Events from './events/Events';
* @property {boolean} [useChangeTypeForTrackSwitch=true]
* 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.
* Some platforms such as WebOS 4.x have issues with seeking when duration is set to `Infinity`, setting this flag to false resolve this.
*/

/**
Expand Down Expand Up @@ -875,7 +879,8 @@ function Settings() {
useAppendWindow: true,
setStallState: true,
avoidCurrentTimeRangePruning: false,
useChangeTypeForTrackSwitch: true
useChangeTypeForTrackSwitch: true,
mediaSourceDurationInfinity: true
},
gaps: {
jumpGaps: true,
Expand Down
21 changes: 20 additions & 1 deletion src/streaming/controllers/MediaSourceController.js
Expand Up @@ -35,6 +35,7 @@ function MediaSourceController() {

let instance,
mediaSource,
settings,
logger;

const context = this.context;
Expand Down Expand Up @@ -75,6 +76,10 @@ function MediaSourceController() {
if (value === null && isNaN(value)) return;
if (mediaSource.duration === value) return;

if (value === Infinity && !settings.get().streaming.buffer.mediaSourceDurationInfinity) {
value = Math.pow(2, 32);
}

if (!isBufferUpdating(mediaSource)) {
logger.info('Set MediaSource duration:' + value);
mediaSource.duration = value;
Expand Down Expand Up @@ -120,13 +125,27 @@ function MediaSourceController() {
return false;
}

/**
* Set the config of the MediaSourceController
* @param {object} config
*/
function setConfig(config) {
if (!config) {
return;
}
if (config.settings) {
settings = config.settings;
}
}

instance = {
createMediaSource,
attachMediaSource,
detachMediaSource,
setDuration,
setSeekable,
signalEndOfStream
signalEndOfStream,
setConfig
};

setup();
Expand Down
2 changes: 2 additions & 0 deletions src/streaming/controllers/StreamController.js
Expand Up @@ -105,6 +105,8 @@ function StreamController() {
});
timeSyncController.initialize();

mediaSourceController.setConfig({ settings });

if (protectionController) {
eventBus.trigger(Events.PROTECTION_CREATED, {
controller: protectionController
Expand Down

0 comments on commit 39efb18

Please sign in to comment.