Skip to content

Commit

Permalink
merge in master
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-nicholas committed Jan 23, 2024
1 parent ec50dc0 commit a7071c1
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions lib/util/periods.js
Expand Up @@ -460,9 +460,7 @@ shaka.util.PeriodCombiner = class {
outputStreams, streamsPerPeriod, firstNewPeriodIndex, clone, concat,
periodsMissing) {
const unusedStreamsPerPeriod = [];
for (let i = 0; i < periodsMissing; i++) {
unusedStreamsPerPeriod.push(new Set());
}

for (let i = 0; i < streamsPerPeriod.length; i++) {
if (i >= firstNewPeriodIndex) {
// This periods streams are all new.
Expand All @@ -478,7 +476,7 @@ shaka.util.PeriodCombiner = class {
// eslint-disable-next-line no-await-in-loop
const ok = await this.extendExistingOutputStream_(
outputStream, streamsPerPeriod, firstNewPeriodIndex, concat,
unusedStreamsPerPeriod, periodsMissing > 0);
unusedStreamsPerPeriod, periodsMissing);
if (!ok) {
// This output Stream was not properly extended to include streams from
// the new period. This is likely a bug in our algorithm, so throw an
Expand Down Expand Up @@ -509,11 +507,6 @@ shaka.util.PeriodCombiner = class {
} // for (const unusedStreams of unusedStreamsPerPeriod)

for (const unusedStreams of unusedStreamsPerPeriod) {
// eslint-disable-next-line no-restricted-syntax
if (unusedStreamsPerPeriod.indexOf(unusedStreams) <
periodsMissing && unusedStreams.size == 0) {
continue;
}
for (const stream of unusedStreams) {
if (shaka.util.PeriodCombiner.isDummy_(stream)) {
// This is one of our dummy streams, so ignore it. We may not use
Expand Down Expand Up @@ -554,7 +547,7 @@ shaka.util.PeriodCombiner = class {
* of the first.
* @param {!Array.<!Set.<T>>} unusedStreamsPerPeriod An array of sets of
* unused streams from each period.
* @param {boolean} shouldAppend shall extend existing matching streams.
* @param {number} periodsMissing How many periods are missing in this update.
*
* @return {!Promise.<boolean>}
*
Expand All @@ -566,9 +559,9 @@ shaka.util.PeriodCombiner = class {
*/
async extendExistingOutputStream_(
outputStream, streamsPerPeriod, firstNewPeriodIndex, concat,
unusedStreamsPerPeriod, shouldAppend) {
unusedStreamsPerPeriod, periodsMissing) {
this.findMatchesInAllPeriods_(streamsPerPeriod,
outputStream, shouldAppend);
outputStream, periodsMissing > 0);

// This only exists where T == Stream, and this should only ever be called
// on Stream types. StreamDB should not have pre-existing output streams.
Expand All @@ -589,7 +582,7 @@ shaka.util.PeriodCombiner = class {
}

shaka.util.PeriodCombiner.extendOutputStream_(outputStream,
firstNewPeriodIndex, concat, unusedStreamsPerPeriod);
firstNewPeriodIndex, concat, unusedStreamsPerPeriod, periodsMissing);
return true;
}

Expand Down Expand Up @@ -696,7 +689,8 @@ shaka.util.PeriodCombiner = class {
return null;
}
shaka.util.PeriodCombiner.extendOutputStream_(outputStream,
/* firstNewPeriodIndex= */ 0, concat, unusedStreamsPerPeriod);
/* firstNewPeriodIndex= */ 0, concat, unusedStreamsPerPeriod,
/* periodsMissing= */ 0);

return outputStream;
}
Expand All @@ -710,14 +704,16 @@ shaka.util.PeriodCombiner = class {
* of the first.
* @param {!Array.<!Set.<T>>} unusedStreamsPerPeriod An array of sets of
* unused streams from each period.
* @param {number} periodsMissing How many periods are missing in this update
*
* @template T
* Accepts either a StreamDB or Stream type.
*
* @private
*/
static extendOutputStream_(
outputStream, firstNewPeriodIndex, concat, unusedStreamsPerPeriod) {
outputStream, firstNewPeriodIndex, concat, unusedStreamsPerPeriod,
periodsMissing) {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const LanguageUtils = shaka.util.LanguageUtils;
const matches = outputStream.matchedStreams;
Expand All @@ -729,7 +725,8 @@ shaka.util.PeriodCombiner = class {

// Concatenate the new matches onto the stream, starting at the first new
// period.
for (let i = firstNewPeriodIndex; i < matches.length; i++) {
const start = firstNewPeriodIndex + periodsMissing;
for (let i = start; i < matches.length; i++) {
const match = matches[i];
concat(outputStream, match);

Expand All @@ -747,7 +744,7 @@ shaka.util.PeriodCombiner = class {
}

if (used) {
unusedStreamsPerPeriod[i].delete(match);
unusedStreamsPerPeriod[i - periodsMissing].delete(match);
// Add the codec of this stream to the output stream's codecs.
const codecs = new Set(outputStream.codecs.split(','));
for (const codec of match.codecs.split(',')) {
Expand Down

0 comments on commit a7071c1

Please sign in to comment.