Class: shaka.text.TtmlTextParser

Constructor

new TtmlTextParser()

Implements:
Source:

Classes

RateInfo_
Contains information about frame/subframe rate and frame rate multiplier for time in frame format.

Members

parameterNs_ :Array.<string>

The namespace URL for TTML parameters. Can be assigned any name in the TTML document, not just "ttp:", so we use this with getAttributeNS() to ensure that we support arbitrary namespace names.
Type:
  • Array.<string>
Source:

percentValue_ :RegExp

Type:
  • RegExp
Source:
Example
0.6% 90% 300% 1000%

percentValues_ :RegExp

Type:
  • RegExp
Source:
Example
50.17% 10%

pixelValues_ :RegExp

Type:
  • RegExp
Source:
Example
100px

smpteNsList_ :Array.<string>

The supported namespace URLs for SMPTE fields.
Type:
  • Array.<string>
Source:

styleEbuttsNs_ :string

The namespace URL for EBU TTML styles. Can be assigned any name in the TTML document, not just "ebutts:", so we use this with getAttributeNS() to ensure that we support arbitrary namespace names.
Type:
  • string
Source:

styleNs_ :Array.<string>

The namespace URL for TTML styles. Can be assigned any name in the TTML document, not just "tts:", so we use this with getAttributeNS() to ensure that we support arbitrary namespace names.
Type:
  • Array.<string>
Source:

textAlignToLineAlign_ :Object.<string, shaka.text.Cue.lineAlign>

Type:
Source:

textAlignToPositionAlign_ :Object.<string, shaka.text.Cue.positionAlign>

Type:
Source:

timeColonFormat_ :RegExp

Type:
  • RegExp
Source:
Example
00:00:40 or 00:40

timeColonFormatFrames_ :RegExp

Type:
  • RegExp
Source:
Example
00:00:40:07 (7 frames) or 00:00:40:07.1 (7 frames, 1 subframe)

timeColonFormatMilliseconds_ :RegExp

Type:
  • RegExp
Source:
Example
01:02:43.0345555 or 02:43.03 or 02:45.5

timeFramesFormat_ :RegExp

Type:
  • RegExp
Source:
Example
75f or 75.5f

timeHMSFormat_ :RegExp

Type:
  • RegExp
Source:
Example
3.45h, 3m or 4.20s

timeTickFormat_ :RegExp

Type:
  • RegExp
Source:
Example
50t or 50.5t

unitValues_ :RegExp

Type:
  • RegExp
Source:
Example
100px, 8em, 0.80c

Methods

addStyle_(cuenon-null, cueElementnon-null, region, imageElement, imageUrinullable, stylesnon-null, isNested, isLeaf)

Adds applicable style properties to a cue.
Parameters:
Name Type Attributes Description
cue shaka.text.Cue
cueElement shaka.extern.xml.Node
region shaka.extern.xml.Node
imageElement shaka.extern.xml.Node
imageUri string <nullable>
styles Array.<!shaka.extern.xml.Node>
isNested boolean
isLeaf boolean
Source:

addTextDecoration_(cuenon-null, decoration)

Parses text decoration values and adds/removes them to/from the cue.
Parameters:
Name Type Description
cue shaka.text.Cue
decoration string
Source:

getCellResolution_(cellResolutionnullable) → {?{columns: number, rows: number}}

If ttp:cellResolution provided returns cell resolution info with number of columns and rows into which the Root Container Region area is divided
Parameters:
Name Type Attributes Description
cellResolution string <nullable>
Source:
Returns:
Type
?{columns: number, rows: number}

getElementsFromCollection_(element, attributeName, collectionnon-null, prefixName, nsNameopt) → {Array.<!shaka.extern.xml.Node>}

Selects items from |collection| whose id matches |attributeName| from |element|.
Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node
attributeName string
collection Array.<shaka.extern.xml.Node>
prefixName string
nsName string <optional>
Source:
Returns:
Type
Array.<!shaka.extern.xml.Node>

getInheritedAttribute_(elementnon-null, attributeName, nsNameopt) → {string}

Traverses upwards from a given node until a given attribute is found.
Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node
attributeName string
nsName string <optional>
Source:
Returns:
Type
string

getInheritedStyleAttribute_(elementnon-null, stylesnon-null, attribute) → {string}

Finds a specified attribute on an element's styles and the styles those styles inherit from.
Parameters:
Name Type Description
element shaka.extern.xml.Node
styles Array.<!shaka.extern.xml.Node>
attribute string
Source:
Returns:
Type
string

getStyleAttribute_(cueElementnon-null, region, stylesnon-null, attribute, shouldInheritRegionStylesopt) → {string}

Finds a specified attribute on either the original cue element or its associated region and returns the value if the attribute was found.
Parameters:
Name Type Attributes Default Description
cueElement shaka.extern.xml.Node
region shaka.extern.xml.Node
styles Array.<!shaka.extern.xml.Node>
attribute string
shouldInheritRegionStyles boolean <optional>
true
Source:
Returns:
Type
string

getStyleAttributeFromElement_(cueElementnon-null, stylesnon-null, attribute) → {string}

Finds a specified attribute on the cue element and returns the value if the attribute was found.
Parameters:
Name Type Description
cueElement shaka.extern.xml.Node
styles Array.<!shaka.extern.xml.Node>
attribute string
Source:
Returns:
Type
string

getStyleAttributeFromRegion_(region, stylesnon-null, attribute) → {string}

Finds a specified attribute on the element's associated region and returns the value if the attribute was found.
Parameters:
Name Type Description
region shaka.extern.xml.Node
styles Array.<!shaka.extern.xml.Node>
attribute string
Source:
Returns:
Type
string

parseColonTimeWithFrames_(rateInfonon-null, text) → {number}

Parses a TTML colon formatted time containing frames.
Parameters:
Name Type Description
rateInfo shaka.text.TtmlTextParser.RateInfo_
text string
Source:
Returns:
Type
number

parseCue_(cueNodenon-null, timeContext, rateInfonon-null, metadataElementsnon-null, stylesnon-null, regionElementsnon-null, cueRegionsnon-null, collapseMultipleSpaces, cellResolutionnullable, parentCueElementnullable, isContent, urinullable, imagesnon-null) → {shaka.text.Cue}

Parses a TTML node into a Cue.
Parameters:
Name Type Attributes Description
cueNode shaka.extern.xml.Node
timeContext shaka.extern.TextParser.TimeContext
rateInfo shaka.text.TtmlTextParser.RateInfo_
metadataElements Array.<!shaka.extern.xml.Node>
styles Array.<!shaka.extern.xml.Node>
regionElements Array.<!shaka.extern.xml.Node>
cueRegions Array.<!shaka.text.CueRegion>
collapseMultipleSpaces boolean
cellResolution ?{columns: number, rows: number} <nullable>
parentCueElement shaka.extern.xml.Node <nullable>
isContent boolean
uri string | undefined <nullable>
images Array.<string>
Source:
Returns:
Type
shaka.text.Cue

parseCueRegion_(regionElementnon-null, stylesnon-null, globalExtentnullable) → {shaka.text.CueRegion}

Parses an Element into a TextTrackCue or VTTCue.
Parameters:
Name Type Attributes Description
regionElement shaka.extern.xml.Node
styles Array.<!shaka.extern.xml.Node> Defined in the top of tt element and used principally for images.
globalExtent string <nullable>
Source:
Returns:
Type
shaka.text.CueRegion

parseFramesTime_(rateInfonon-null, text) → {number}

Parses a TTML time in frame format.
Parameters:
Name Type Description
rateInfo shaka.text.TtmlTextParser.RateInfo_
text string
Source:
Returns:
Type
number

parseTickTime_(rateInfonon-null, text) → {number}

Parses a TTML time in tick format.
Parameters:
Name Type Description
rateInfo shaka.text.TtmlTextParser.RateInfo_
text string
Source:
Returns:
Type
number

parseTime_(elementnon-null, rateInfonon-null) → {{start: ?number, end: ?number}}

Parse TTML time attributes from the given element.
Parameters:
Name Type Description
element shaka.extern.xml.Node
rateInfo shaka.text.TtmlTextParser.RateInfo_
Source:
Returns:
Type
{start: ?number, end: ?number}

parseTimeAttribute_(text, rateInfonon-null) → {number}

Parses a TTML time from the given attribute text.
Parameters:
Name Type Description
text string
rateInfo shaka.text.TtmlTextParser.RateInfo_
Source:
Returns:
Type
number

parseTimeFromRegex_(regexnon-null, text) → {number}

Parses a TTML time with a given regex. Expects regex to be some sort of a time-matcher to match hours, minutes, seconds and milliseconds
Parameters:
Name Type Description
regex RegExp
text string
Source:
Returns:
Type
number

resolveTime_(parentElementnon-null, rateInfonon-null, startnullable, endnullable) → {{start: ?number, end: ?number}}

Factor parent/ancestor time attributes into the parsed time of a child/descendent.
Parameters:
Name Type Attributes Description
parentElement shaka.extern.xml.Node
rateInfo shaka.text.TtmlTextParser.RateInfo_
start number <nullable>
The child's start time
end number <nullable>
The child's end time
Source:
Returns:
Type
{start: ?number, end: ?number}

parseInit(datanon-null)

Parse an initialization segment. Some formats do not have init segments so this won't always be called.
Parameters:
Name Type Description
data Uint8Array The data that makes up the init segment.
Implements:
Source:

parseMedia(datanon-null, timeContext, urinullable, imagesnon-null) → {Array.<!shaka.text.Cue>}

Parse a media segment and return the cues that make up the segment.
Parameters:
Name Type Attributes Description
data Uint8Array The next section of buffer.
timeContext shaka.extern.TextParser.TimeContext The time information that should be used to adjust the times values for each cue.
uri string | undefined <nullable>
The media uri.
images Array.<string>
Implements:
Source:
Returns:
Type
Array.<!shaka.text.Cue>

setManifestType(manifestType)

Notifies the manifest type.
Parameters:
Name Type Description
manifestType string
Implements:
Source:

setSequenceMode(sequenceMode)

Notifies the stream if the manifest is in sequence mode or not.
Parameters:
Name Type Description
sequenceMode boolean
Implements:
Source: