Skip to content

Commit

Permalink
Add support for replacing a text node via MPD patching (#4278)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed Sep 11, 2023
1 parent 455796d commit e9f7778
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/dash/DashAdapter.js
Expand Up @@ -906,8 +906,8 @@ function DashAdapter() {

let { name, target, leaf } = result;

// short circuit for attribute selectors
if (operation.xpath.findsAttribute()) {
// short circuit for attribute selectors and text replacement
if (operation.xpath.findsAttribute() || name === '__text') {
switch (operation.action) {
case 'add':
case 'replace':
Expand Down Expand Up @@ -1045,7 +1045,7 @@ function DashAdapter() {
viewpoint = dashManifestModel.getViewpointForAdaptation(realAdaptation);
mediaInfo.viewpoint = viewpoint.length ? viewpoint[0].value : undefined;
mediaInfo.viewpointsWithSchemeIdUri = viewpoint;

accessibility = dashManifestModel.getAccessibilityForAdaptation(realAdaptation);
mediaInfo.accessibility = accessibility.map(function (accessibility) {
let accessibilityValue = accessibility.value;
Expand Down Expand Up @@ -1075,13 +1075,13 @@ function DashAdapter() {
});
mediaInfo.audioChannelConfigurationsWithSchemeIdUri = acc_rep;
}

roles = dashManifestModel.getRolesForAdaptation(realAdaptation);
mediaInfo.roles = roles.map(function (role) {
return role.value;
});
mediaInfo.rolesWithSchemeIdUri = roles;

mediaInfo.codec = dashManifestModel.getCodec(realAdaptation);
mediaInfo.mimeType = dashManifestModel.getMimeType(realAdaptation);
mediaInfo.contentProtection = dashManifestModel.getContentProtectionData(realAdaptation);
Expand Down Expand Up @@ -1120,7 +1120,7 @@ function DashAdapter() {
mediaInfo.supplementalPropertiesAsArray = arr[0];
}
}

mediaInfo.isFragmented = dashManifestModel.getIsFragmented(realAdaptation);
mediaInfo.isEmbedded = false;

Expand Down
2 changes: 1 addition & 1 deletion src/dash/models/PatchManifestModel.js
Expand Up @@ -97,7 +97,7 @@ function PatchManifestModel() {
}

let value = null;
if (xpath.findsAttribute()) {
if (xpath.findsAttribute() || xpath.findsTextReplace()) {
value = node.__text || '';
} else if (action !== 'remove') {
value = node.__children.reduce((groups, child) => {
Expand Down
17 changes: 15 additions & 2 deletions src/dash/vo/SimpleXPath.js
Expand Up @@ -89,6 +89,10 @@ class SimpleXPath {
return this.path[this.path.length - 1].name.startsWith('@');
}

findsTextReplace() {
return this.path[this.path.length - 1].name === 'text()';
}

getMpdTarget(root, isSiblingOperation) {
let parent = null;
let leaf = root;
Expand All @@ -104,8 +108,8 @@ class SimpleXPath {
let component = this.path[level];
name = component.name;

// stop one early if this is the last element and an attribute
if (level !== this.path.length - 1 || !name.startsWith('@')) {
// stop one early if this is the last element and an attribute or a text selector
if (level !== this.path.length - 1 || (!name.startsWith('@') && name !== 'text()')) {
let children = parent[name + '_asArray'] || [];
if (children.length === 0 && parent[name]) {
children.push(parent[name]);
Expand Down Expand Up @@ -139,6 +143,15 @@ class SimpleXPath {
};
}

// for replacing a text node the target is the leaf node, the name is __text
else if (name === 'text()') {
return {
name: '__text',
leaf: leaf,
target: leaf
};
}

// otherwise we target the parent for sibling operations and leaf for child operations
return {
name: name,
Expand Down

0 comments on commit e9f7778

Please sign in to comment.