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

Add support for replacing a text node via MPD patching #4278

Merged
merged 2 commits into from
Sep 11, 2023
Merged
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
12 changes: 6 additions & 6 deletions src/dash/DashAdapter.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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