Skip to content

Commit

Permalink
feat(DASH): Allow PeriodCombiner for using streams once (#6097)
Browse files Browse the repository at this point in the history
In our streams we have guarantee that every track will have a single
match in every period. This change allows `PeriodCombiner` to take
benefit of this knowledge.

I was testing `PeriodCombiner.combinePeriods()` performance of mentioned
changes on Tizen 2021 on 2 streams and I've got following results:

| content | upstream | proposed changes |
| - | -: | -: |
| stream 1 | 17 ms | 12 ms |
| stream 2 | 191 ms | 98 ms |

Both streams are VOD.
Stream 1 has 18 periods with 6 video & audio tracks in each.
Stream 2 has 18 periods with 6 video tracks & 36 audio tracks in each.
  • Loading branch information
tykus160 committed Jan 15, 2024
1 parent f064811 commit 5e3db78
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ shakaDemo.Config = class {
/* canBeUnset= */ true)
.addBoolInput_('Enable DASH sequence mode',
'manifest.dash.sequenceMode')
.addBoolInput_('Use stream once in period flattening',
'manifest.dash.useStreamOnceInPeriodFlattening')
.addBoolInput_('Disable Audio', 'manifest.disableAudio')
.addBoolInput_('Disable Video', 'manifest.disableVideo')
.addBoolInput_('Disable Text', 'manifest.disableText')
Expand Down
9 changes: 8 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ shaka.extern.InitDataTransform;
* manifestPreprocessor: function(!Element),
* sequenceMode: boolean,
* enableAudioGroups: boolean,
* multiTypeVariantsAllowed: boolean
* multiTypeVariantsAllowed: boolean,
* useStreamOnceInPeriodFlattening: boolean
* }}
*
* @property {string} clockSyncUri
Expand Down Expand Up @@ -928,6 +929,12 @@ shaka.extern.InitDataTransform;
* Might result in undesirable behavior if mediaSource.codecSwitchingStrategy
* is not set to SMOOTH.
* Defaults to true if SMOOTH codec switching is supported, RELOAD overwise.
* @property {boolean} useStreamOnceInPeriodFlattening
* If period combiner is used, this option ensures every stream is used
* only once in period flattening. It speeds up underlying algorithm
* but may raise issues if manifest does not have stream consistency
* between periods.
* Defaults to <code>false</code>.
* @exportDoc
*/
shaka.extern.DashManifestConfiguration;
Expand Down
2 changes: 2 additions & 0 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ shaka.dash.DashParser = class {
this.periodCombiner_.setAllowMultiTypeVariants(
this.config_.dash.multiTypeVariantsAllowed &&
shaka.media.Capabilities.isChangeTypeSupported());
this.periodCombiner_.setUseStreamOnce(
this.config_.dash.useStreamOnceInPeriodFlattening);
}
}

Expand Down
19 changes: 19 additions & 0 deletions lib/util/periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ shaka.util.PeriodCombiner = class {
/** @private {boolean} */
this.multiTypeVariantsAllowed_ = false;

/** @private {boolean} */
this.useStreamOnce_ = false;

/**
* The IDs of the periods we have already used to generate streams.
* This helps us identify the periods which have been added when a live
Expand Down Expand Up @@ -1037,6 +1040,12 @@ shaka.util.PeriodCombiner = class {
}
}

// Remove just found stream if configured to, so possible future linear
// searches can be faster.
if (this.useStreamOnce_ && !shaka.util.PeriodCombiner.isDummy_(best)) {
streams.delete(getKey(best));
}

return best;
}

Expand Down Expand Up @@ -1071,11 +1080,21 @@ shaka.util.PeriodCombiner = class {
/**
* @param {boolean} allowed If set to true, multi-mimeType or multi-codec
* variants will be allowed.
* @export
*/
setAllowMultiTypeVariants(allowed) {
this.multiTypeVariantsAllowed_ = allowed;
}

/**
* @param {boolean} useOnce if true, stream will be used only once in period
* flattening algoritnm.
* @export
*/
setUseStreamOnce(useOnce) {
this.useStreamOnce_ = useOnce;
}

/**
* @param {T} outputStream An audio or video output stream
* @param {T} candidate A candidate stream to be combined with the output
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 @@ -144,6 +144,7 @@ shaka.util.PlayerConfiguration = class {
sequenceMode: false,
enableAudioGroups: false,
multiTypeVariantsAllowed,
useStreamOnceInPeriodFlattening: false,
},
hls: {
ignoreTextStreamFailures: false,
Expand Down

0 comments on commit 5e3db78

Please sign in to comment.