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

fix: Fix support for scte214:supplementalCodecs and SUPPLEMENTAL-CODECS #7456

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 17 additions & 7 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1967,8 +1967,23 @@ shaka.dash.DashParser = class {

const label = context.adaptationSet.label;

// Duplicate representations with their supplementalCodecs
let representations = TXml.findChildren(elem, 'Representation');
let supplementalRepresentations = representations.filter((rep) => {
return TXml.getAttributeNS(
rep, shaka.dash.DashParser.SCTE214_, 'supplementalCodecs') != null;
});
supplementalRepresentations = supplementalRepresentations.map((rep) => {
const supplementalCodecs =
TXml.getAttributeNS(
rep, shaka.dash.DashParser.SCTE214_, 'supplementalCodecs');
const obj = shaka.util.ObjectUtils.cloneObject(rep);
obj.attributes['codecs'] = supplementalCodecs.split(' ').join(',');
return obj;
});
representations = [...representations, ...supplementalRepresentations];

// Parse Representations into Streams.
const representations = TXml.findChildren(elem, 'Representation');
const streams = representations.map((representation) => {
const parsedRepresentation = this.parseRepresentation_(context,
contentProtection, kind, language, label, main, roleValues,
Expand Down Expand Up @@ -2539,7 +2554,6 @@ shaka.dash.DashParser = class {
createFrame_(elem, parent, getBaseUris) {
goog.asserts.assert(parent || getBaseUris,
'Must provide either parent or getBaseUris');
const SCTE214 = shaka.dash.DashParser.SCTE214_;
const SegmentUtils = shaka.media.SegmentUtils;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
const TXml = shaka.util.TXml;
Expand Down Expand Up @@ -2597,11 +2611,7 @@ shaka.dash.DashParser = class {
const allCodecs = [
elem.attributes['codecs'] || parent.codecs,
];
const supplementalCodecs =
TXml.getAttributeNS(elem, SCTE214, 'supplementalCodecs');
if (supplementalCodecs) {
allCodecs.push(supplementalCodecs);
}

const codecs = SegmentUtils.codecsFiltering(allCodecs).join(',');
const frameRate =
TXml.parseAttr(elem, 'frameRate', evalDivision) || parent.frameRate;
Expand Down
39 changes: 28 additions & 11 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ goog.provide('shaka.hls.HlsParser');
goog.require('goog.Uri');
goog.require('goog.asserts');
goog.require('shaka.abr.Ewma');
goog.require('shaka.hls.Attribute');
goog.require('shaka.hls.ManifestTextParser');
goog.require('shaka.hls.Playlist');
goog.require('shaka.hls.PlaylistType');
Expand Down Expand Up @@ -949,6 +950,33 @@ shaka.hls.HlsParser = class {
this.processSessionData_(sessionDataTags);
await this.processContentSteering_(contentSteeringTags);

/* duplicate variant tags with supplementalCodecs */
const newVariantTags = [];
for (const tag of variantTags) {
const supplementalCodecsString =
tag.getAttributeValue('SUPPLEMENTAL-CODECS');
if (!supplementalCodecsString) {
continue;
}
const supplementalCodecs = supplementalCodecsString.split(/\s*,\s*/)
.map((codec) => {
return codec.split('/')[0];
});
const newAttributes = tag.attributes.map((attr) => {
const name = attr.name;
let value = attr.value;
if (name == 'CODECS') {
value = supplementalCodecs.join(',');
}
return new shaka.hls.Attribute(name, value);
});
newVariantTags.push(
new shaka.hls.Tag(tag.id, tag.name, newAttributes, null));
}
for (const v of newVariantTags) {
variantTags.push(v);
}

this.parseCodecs_(variantTags);

this.parseClosedCaptions_(mediaTags);
Expand Down Expand Up @@ -1806,9 +1834,6 @@ shaka.hls.HlsParser = class {
getCodecsForVariantTag_(tag) {
let codecsString = tag.getAttributeValue('CODECS') || '';

const supplementalCodecsString =
tag.getAttributeValue('SUPPLEMENTAL-CODECS');

this.codecInfoInManifest_ = codecsString.length > 0;

if (!this.codecInfoInManifest_ && !this.config_.hls.disableCodecGuessing) {
Expand All @@ -1829,14 +1854,6 @@ shaka.hls.HlsParser = class {
/** @type {!Array.<string>} */
const codecs = codecsString.split(/\s*,\s*/);

if (supplementalCodecsString) {
const supplementalCodecs = supplementalCodecsString.split(/\s*,\s*/)
.map((codec) => {
return codec.split('/')[0];
});
codecs.push(...supplementalCodecs);
}

return shaka.media.SegmentUtils.codecsFiltering(codecs);
}

Expand Down
Loading