Skip to content

Commit

Permalink
feat(DASH): Add support for <dashif:Laurl> (#4849)
Browse files Browse the repository at this point in the history
Closes #4748
  • Loading branch information
avelad authored Jan 31, 2023
1 parent f456318 commit b441518
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 5 deletions.
34 changes: 32 additions & 2 deletions lib/dash/content_protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,19 @@ shaka.dash.ContentProtection = class {

/**
* Gets a Widevine license URL from a content protection element
* containing a custom `ms:laurl` element
* containing a custom `ms:laurl` or 'dashif:Laurl' elements
*
* @param {shaka.dash.ContentProtection.Element} element
* @return {string}
*/
static getWidevineLicenseUrl(element) {
const dashIfLaurlNode = shaka.util.XmlUtils.findChildNS(
element.node, shaka.dash.ContentProtection.DashIfNamespaceUri_,
'Laurl',
);
if (dashIfLaurlNode && dashIfLaurlNode.textContent) {
return dashIfLaurlNode.textContent;
}
const mslaurlNode = shaka.util.XmlUtils.findChildNS(
element.node, 'urn:microsoft', 'laurl');
if (mslaurlNode) {
Expand All @@ -182,12 +189,19 @@ shaka.dash.ContentProtection = class {

/**
* Gets a ClearKey license URL from a content protection element
* containing a custom `clearkey::Laurl` element
* containing a custom `clearkey::Laurl` or 'dashif:Laurl' elements
*
* @param {shaka.dash.ContentProtection.Element} element
* @return {string}
*/
static getClearKeyLicenseUrl(element) {
const dashIfLaurlNode = shaka.util.XmlUtils.findChildNS(
element.node, shaka.dash.ContentProtection.DashIfNamespaceUri_,
'Laurl',
);
if (dashIfLaurlNode && dashIfLaurlNode.textContent) {
return dashIfLaurlNode.textContent;
}
const clearKeyLaurlNode = shaka.util.XmlUtils.findChildNS(
element.node, shaka.dash.ContentProtection.ClearKeyNamespaceUri_,
'Laurl',
Expand Down Expand Up @@ -307,6 +321,14 @@ shaka.dash.ContentProtection = class {
* @return {string}
*/
static getPlayReadyLicenseUrl(element) {
const dashIfLaurlNode = shaka.util.XmlUtils.findChildNS(
element.node, shaka.dash.ContentProtection.DashIfNamespaceUri_,
'Laurl',
);
if (dashIfLaurlNode && dashIfLaurlNode.textContent) {
return dashIfLaurlNode.textContent;
}

const proNode = shaka.util.XmlUtils.findChildNS(
element.node, 'urn:microsoft:playready', 'pro');

Expand Down Expand Up @@ -657,3 +679,11 @@ shaka.dash.ContentProtection.ClearKeyNamespaceUri_ =
*/
shaka.dash.ContentProtection.ClearKeySchemeUri_ =
'urn:uuid:e2719d58-a985-b3c9-781a-b030af78d30e';


/**
* @const {string}
* @private
*/
shaka.dash.ContentProtection.DashIfNamespaceUri_ =
'https://dashif.org/CPS';
96 changes: 93 additions & 3 deletions test/dash/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,37 @@ describe('DashParser ContentProtection', () => {
expect(actual).toBe('');
});

it('no ms:laurl node', () => {
it('valid dashif:Laurl node', () => {
const input = {
init: null,
keyId: null,
schemeUri: '',
node: strToXml([
'<test xmlns:dashif="https://dashif.org/CPS">',
' <dashif:Laurl>www.example.com</dashif:Laurl>',
'</test>',
].join('\n')),
};
const actual = ContentProtection.getWidevineLicenseUrl(input);
expect(actual).toBe('www.example.com');
});

it('dashif:Laurl without license url', () => {
const input = {
init: null,
keyId: null,
schemeUri: '',
node: strToXml([
'<test xmlns:dashif="https://dashif.org/CPS">',
' <dashif:Laurl></dashif:Laurl>',
'</test>',
].join('\n')),
};
const actual = ContentProtection.getWidevineLicenseUrl(input);
expect(actual).toBe('');
});

it('no ms:laurl node or dashif:Laurl node', () => {
const input = {
init: null,
keyId: null,
Expand Down Expand Up @@ -839,7 +869,37 @@ describe('DashParser ContentProtection', () => {
expect(actual).toBe('');
});

it('no clearkey:Laurl node', () => {
it('valid dashif:Laurl node', () => {
const input = {
init: null,
keyId: null,
schemeUri: '',
node: strToXml([
'<test xmlns:dashif="https://dashif.org/CPS">',
' <dashif:Laurl>www.example.com</dashif:Laurl>',
'</test>',
].join('\n')),
};
const actual = ContentProtection.getClearKeyLicenseUrl(input);
expect(actual).toBe('www.example.com');
});

it('dashif:Laurl without license url', () => {
const input = {
init: null,
keyId: null,
schemeUri: '',
node: strToXml([
'<test xmlns:dashif="https://dashif.org/CPS">',
' <dashif:Laurl></dashif:Laurl>',
'</test>',
].join('\n')),
};
const actual = ContentProtection.getClearKeyLicenseUrl(input);
expect(actual).toBe('');
});

it('no clearkey:Laurl or dashif:Laurl node', () => {
const input = {
init: null,
keyId: null,
Expand Down Expand Up @@ -892,7 +952,37 @@ describe('DashParser ContentProtection', () => {
expect(actual).toBe('www.example.com');
});

it('no mspro', () => {
it('valid dashif:Laurl node', () => {
const input = {
init: null,
keyId: null,
schemeUri: '',
node: strToXml([
'<test xmlns:dashif="https://dashif.org/CPS">',
' <dashif:Laurl>www.example.com</dashif:Laurl>',
'</test>',
].join('\n')),
};
const actual = ContentProtection.getPlayReadyLicenseUrl(input);
expect(actual).toBe('www.example.com');
});

it('dashif:Laurl without license url', () => {
const input = {
init: null,
keyId: null,
schemeUri: '',
node: strToXml([
'<test xmlns:dashif="https://dashif.org/CPS">',
' <dashif:Laurl></dashif:Laurl>',
'</test>',
].join('\n')),
};
const actual = ContentProtection.getPlayReadyLicenseUrl(input);
expect(actual).toBe('');
});

it('no mspro or dashif:Laurl node', () => {
const input = {
init: null,
keyId: null,
Expand Down

0 comments on commit b441518

Please sign in to comment.