Skip to content

Commit

Permalink
feat(ttml): Add support for SMPTE namespace 2013 (shaka-project#3062)
Browse files Browse the repository at this point in the history
We have TTML SMPTE XML Namespaces support for 2010.
Add SMPTE namespace support for 2013.

Closes shaka-project#3061 .
  • Loading branch information
david-hm-morgan authored Dec 26, 2020
1 parent 2bebfd3 commit df74eab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/text/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,16 @@ shaka.text.TtmlTextParser = class {
const regionId = regionElement.getAttribute('xml:id');
cue.region = cueRegions.filter((region) => region.id == regionId)[0];
}
const imageElement = shaka.text.TtmlTextParser.getElementsFromCollection_(
cueElement, 'backgroundImage', metadataElements, '#',
shaka.text.TtmlTextParser.smpteNs_)[0];

let imageElement = null;
for (const nameSpace of shaka.text.TtmlTextParser.smpteNsList_) {
imageElement = shaka.text.TtmlTextParser.getElementsFromCollection_(
cueElement, 'backgroundImage', metadataElements, '#',
nameSpace)[0];
if (imageElement) {
break;
}
}

const isLeaf = nestedCues.length == 0;

Expand Down Expand Up @@ -1243,12 +1250,14 @@ shaka.text.TtmlTextParser.styleNs_ = 'http://www.w3.org/ns/ttml#styling';
shaka.text.TtmlTextParser.styleEbuttsNs_ = 'urn:ebu:tt:style';

/**
* The namespace URL for SMPTE fields.
* @const {string}
* The supported namespace URLs for SMPTE fields.
* @const {!Array.<string>}
* @private
*/
shaka.text.TtmlTextParser.smpteNs_ =
'http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt';
shaka.text.TtmlTextParser.smpteNsList_ = [
'http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt',
'http://www.smpte-ra.org/schemas/2052-1/2013/smpte-tt',
];

shaka.text.TextEngine.registerParser(
'application/ttml+xml', () => new shaka.text.TtmlTextParser());
24 changes: 24 additions & 0 deletions test/text/ttml_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,30 @@ describe('TtmlTextParser', () => {
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

it('supports smpte:backgroundImage attribute alt namespace', () => {
verifyHelper(
[
{
startTime: 62.05,
endTime: 3723.2,
payload: '',
backgroundImage: 'data:image/png;base64,base64EncodedImage',
},
],
'<tt ' +
'xmlns:ttm="http://www.w3.org/ns/ttml#metadata" ' +
'xmlns:smpte="http://www.smpte-ra.org/schemas/2052-1/2013/smpte-tt">' +
'<metadata>' +
'<smpte:image imagetype="PNG" encoding="Base64" xml:id="img_0">' +
'base64EncodedImage</smpte:image>' +
'</metadata>' +
'<body><div>' +
'<p begin="01:02.05" end="01:02:03.200" ' +
'smpte:backgroundImage="#img_0" />' +
'</div></body></tt>',
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

it('inserts line breaks for <br> tags', () => {
verifyHelper(
[{
Expand Down

0 comments on commit df74eab

Please sign in to comment.