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

feat(DASH): Add support for <dashif:Laurl> #4849

Merged
merged 4 commits into from
Jan 31, 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
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
joeyparrish marked this conversation as resolved.
Show resolved Hide resolved
*
* @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