Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
update according to PR Dash-Industry-Forum#3451 (update xml parser an…
Browse files Browse the repository at this point in the history
…d remove _asArray nodes)
  • Loading branch information
bbert committed Feb 10, 2021
1 parent f4830da commit eb87794
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 136 deletions.
16 changes: 6 additions & 10 deletions src/dash/DashAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ function DashAdapter() {
}

// determine the relative insert position prior to possible removal
let relativePosition = (target[name + '_asArray'] || []).indexOf(leaf);
let relativePosition = (target[name] || []).indexOf(leaf);
let insertBefore = (operation.position === 'prepend' || operation.position === 'before');

// perform removal operation first, we have already capture the appropriate relative position
Expand All @@ -881,16 +881,13 @@ function DashAdapter() {

// if we did have a positional reference we need to purge from array set and restore X2JS proper semantics
if (relativePosition != -1) {
let targetArray = target[name + '_asArray'];
let targetArray = target[name];
targetArray.splice(relativePosition, 1);
if (targetArray.length > 1) {
if (targetArray.length > 0) {
target[name] = targetArray;
} else if (targetArray.length == 1) {
// xml parsing semantics, singular asArray must be non-array in the unsuffixed key
target[name] = targetArray[0];
} else {
// all nodes of this type deleted, remove entry
delete target[name + '_asArray'];
delete target[name];
}
}
}
Expand All @@ -904,7 +901,7 @@ function DashAdapter() {
Object.keys(operation.value).forEach((insert) => {
let insertNodes = operation.value[insert];

let updatedNodes = target[insert + '_asArray'] || [];
let updatedNodes = target[insert] || [];
if (updatedNodes.length === 0 && target[insert]) {
updatedNodes.push(target[insert]);
}
Expand All @@ -930,8 +927,7 @@ function DashAdapter() {
}

// now we properly reset the element keys on the target to match parsing semantics
target[insert + '_asArray'] = updatedNodes;
target[insert] = updatedNodes.length == 1 ? updatedNodes[0] : updatedNodes;
target[insert] = updatedNodes;
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/dash/models/DashManifestModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function DashManifestModel() {
}

function getRealPeriods(manifest) {
return manifest && manifest.Period_asArray ? manifest.Period_asArray : [];
return manifest && manifest.Period ? manifest.Period : [];
}

function getRealPeriodForIndex(index, manifest) {
Expand Down Expand Up @@ -1055,7 +1055,7 @@ function DashManifestModel() {
function getPatchLocation(manifest) {
if (manifest && manifest.hasOwnProperty(DashConstants.PATCH_LOCATION)) {
// only include support for single patch location currently
manifest.PatchLocation = manifest.PatchLocation_asArray[0];
manifest.PatchLocation = manifest.PatchLocation[0];

return manifest.PatchLocation;
}
Expand Down
18 changes: 14 additions & 4 deletions src/dash/parser/DashParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,23 @@ function DashParser(config) {
}


function parseXml(data, tagName) {
function parseXml(data) {
try {
let root = tXml(data, { parseNode: true }, matchers, arrayNodes);
if (tagName && root.tagName !== tagName) {
root = root[tagName];
let ret = {};
// If root element is xml node, then get first child node as root
if (root.tagName.toLowerCase().indexOf('xml') !== -1) {
for (let key in root) {
if (Array.isArray(root[key])) {
ret[key] = root[key][0];
break;
}
}
} else {
ret[root.tagName] = root;
delete root.tagName;
}
return root;
return ret;
} catch (e) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dash/parser/objectiron.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function ObjectIron(mappers) {
return source;
}

if (source.Period_asArray && 'period' in mappers) {
if (source.Period && 'period' in mappers) {
const periodMapper = mappers.period;
const periods = source.Period;
for (let i = 0, len = periods.length; i < len; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/dash/vo/SimpleXPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class SimpleXPath {

// stop one early if this is the last element and an attribute
if (level !== this.path.length - 1 || !name.startsWith('@')) {
let children = parent[name + '_asArray'] || [];
let children = parent[name] || [];
if (children.length === 0 && parent[name]) {
children.push(parent[name]);
}
Expand Down
3 changes: 1 addition & 2 deletions src/streaming/controllers/XlinkController.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ function XlinkController(config) {
index = element.resolvedContent.indexOf('?>') + 2; //find the closing position of the xml declaration, if it exists.
}
mergedContent = element.resolvedContent.substr(0,index) + openingTag + element.resolvedContent.substr(index) + closingTag;
// element.resolvedContent = converter.xml_str2json(mergedContent);
element.resolvedContent = parser.parseXml(mergedContent);
element.resolvedContent = parser.parseXml(mergedContent).response;
}
if (isResolvingFinished(resolveObject)) {
onXlinkAllElementsLoaded(resolveObject);
Expand Down
20 changes: 10 additions & 10 deletions src/streaming/utils/CapabilitiesFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ function CapabilitiesFilter() {
function _filterUnsupportedCodecs(type, streamInfo) {
const realPeriod = adapter.getRealPeriodByIndex(streamInfo ? streamInfo.index : null);

if (!realPeriod || !realPeriod.AdaptationSet_asArray || realPeriod.AdaptationSet_asArray.length === 0) {
if (!realPeriod || !realPeriod.AdaptationSet || realPeriod.AdaptationSet.length === 0) {
return;
}

realPeriod.AdaptationSet_asArray = realPeriod.AdaptationSet_asArray.filter((as) => {
realPeriod.AdaptationSet = realPeriod.AdaptationSet.filter((as) => {

if (!as.Representation_asArray || as.Representation_asArray.length === 0 || !adapter.getIsTypeOf(as, type)) {
if (!as.Representation || as.Representation.length === 0 || !adapter.getIsTypeOf(as, type)) {
return true;
}

as.Representation_asArray = as.Representation_asArray.filter((_, i) => {
as.Representation = as.Representation.filter((_, i) => {
const codec = adapter.getCodec(as, i, true);
if (!capabilities.supportsCodec(codec)) {
logger.error('[Stream] codec not supported: ' + codec);
Expand All @@ -66,25 +66,25 @@ function CapabilitiesFilter() {
return true;
});

return as.Representation_asArray && as.Representation_asArray.length > 0;
return as.Representation && as.Representation.length > 0;
});

}

function _filterUnsupportedEssentialProperties(streamInfo) {
const realPeriod = adapter.getRealPeriodByIndex(streamInfo ? streamInfo.index : null);

if (!realPeriod || !realPeriod.AdaptationSet_asArray || realPeriod.AdaptationSet_asArray.length === 0) {
if (!realPeriod || !realPeriod.AdaptationSet || realPeriod.AdaptationSet.length === 0) {
return;
}

realPeriod.AdaptationSet_asArray = realPeriod.AdaptationSet_asArray.filter((as) => {
realPeriod.AdaptationSet = realPeriod.AdaptationSet.filter((as) => {

if (!as.Representation_asArray || as.Representation_asArray.length === 0) {
if (!as.Representation || as.Representation.length === 0) {
return true;
}

as.Representation_asArray = as.Representation_asArray.filter((rep) => {
as.Representation = as.Representation.filter((rep) => {
const essentialProperties = adapter.getEssentialPropertiesForRepresentation(rep);

if (essentialProperties && essentialProperties.length > 0) {
Expand All @@ -101,7 +101,7 @@ function CapabilitiesFilter() {
return true;
});

return as.Representation_asArray && as.Representation_asArray.length > 0;
return as.Representation && as.Representation.length > 0;
});

}
Expand Down
Loading

0 comments on commit eb87794

Please sign in to comment.