Constructor
new HlsParser()
Creates an Hls Parser object.
Implements:
Source:
Members
AUDIO_EXTENSIONS_TO_MIME_TYPES_ :Object.<string, string>
Type:
Source:
EXTENSION_MAP_BY_CONTENT_TYPE_ :Object.<string, !Object.<string, string>>
Type:
Object.<string, !Object.<string, string>>
Source:
IMAGE_EXTENSIONS_TO_MIME_TYPES_ :Object.<string, string>
Type:
Source:
PresentationType_ :string
Type:
Properties:
Name
Value
Type
Description
VOD
VOD
string
EVENT
EVENT
string
LIVE
LIVE
string
Source:
TEXT_EXTENSIONS_TO_MIME_TYPES_ :Object.<string, string>
Type:
Source:
VIDEO_EXTENSIONS_TO_MIME_TYPES_ :Object.<string, string>
Type:
Source:
globalId_ :number
Type:
Source:
globalVariables_ :Map.<string, string>
Type:
Source:
groupIdToClosedCaptionsMap_ :Map.<string, Map.<string, string>>
A map from closed captions' group id, to a map of closed captions info.
{group id -> {closed captions channel id -> language}}
Type:
Map.<string, Map.<string, string>>
Source:
groupIdToCodecsMap_ :Map.<string, string>
Type:
Source:
A map from group id to stream infos created from the media tags.
Type:
Source:
lastTargetDuration_ :number
Type:
Source:
lowestSyncTime_ :number
The lowest time value for any of the streams, as defined by the
EXT-X-PROGRAM-DATE-TIME value. Measured in seconds since January 1, 1970.
Type:
Source:
lowLatencyByterangeOptimization_ :boolean
Type:
Source:
lowLatencyMode_ :boolean
Type:
Source:
lowLatencyPresentationDelay_ :number
Type:
Source:
mapTagToInitSegmentRefMap_
A cache mapping EXT-X-MAP tag info to the InitSegmentReference created
from the tag.
The key is a string combining the EXT-X-MAP tag's absolute uri, and
its BYTERANGE if available.
{!Map.}
Source:
masterPlaylistUri_ :string
The master playlist URI, after redirects.
Type:
Source:
maxTargetDuration_ :number
Type:
Source:
For media playlist lazy-loading to work in livestreams, we have to assume
that each stream of a type (video, audio, etc) has the same mappings of
sequence number to start time.
This map stores those relationships.
Only used during livestreams; we do not assume that VOD content is
aligned in that way.
Type:
Map.<string, !Map.<number, number>>
Source:
minSequenceNumber_ :number
The minimum sequence number for generated segments, when ignoring
EXT-X-PROGRAM-DATE-TIME.
Type:
Source:
partialTargetDuration_ :number
Partial segments target duration.
Type:
Source:
presentationDelay_ :number
Type:
Source:
streamsFinalized_ :boolean
Whether the streams have previously been "finalized"; that is to say,
whether we have loaded enough streams to know information about the asset
such as timing information, live status, etc.
Type:
Source:
This timer is used to trigger the start of a manifest update. A manifest
update is async. Once the update is finished, the timer will be restarted
to trigger the next update. The timer will only be started if the content
is live content.
Type:
Source:
A map from (verbatim) media playlist URI to stream infos representing the
playlists.
On update, used to iterate through and update from media playlists.
On initial parse, used to iterate through and determine minimum
timestamps, offsets, and to handle TS rollover.
During parsing, used to avoid duplicates in the async methods
createStreamInfoFromMediaTag_, createStreamInfoFromImageTag_ and
createStreamInfoFromVariantTag_.
Type:
Source:
variantUriSet_ :Set.<string>
The values are strings of the form "
- ",
where the URIs are the verbatim media playlist URIs as they appeared in
the master playlist.
Used to avoid duplicates that vary only in their text stream.
Type:
Source:
Methods
See: https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-11#section-5.1
Parameters:
Source:
Returns:
Type
shaka.extern.DrmInfo
See: https://docs.microsoft.com/en-us/playready/packaging/mp4-based-formats-supported-by-playready-clients?tabs=case4
Parameters:
Source:
Returns:
Type
shaka.extern.DrmInfo
addVideoAttributes_(stream, widthnullable , heightnullable , frameRatenullable , videoRangenullable )
Parameters:
Name
Type
Attributes
Description
stream
shaka.extern.Stream
width
string
<nullable>
height
string
<nullable>
frameRate
string
<nullable>
videoRange
string
<nullable>
Source:
changePresentationTimelineToLive_()
Source:
Called by the Player to provide an updated configuration any time the
configuration changes. Will be called at least once before start().
Parameters:
Implements:
Source:
convertParsedPlaylistIntoStreamInfo_(playlistnon-null , verbatimMediaPlaylistUri, absoluteMediaPlaylistUri, codecs, type, languageValuenullable , primary, namenullable , channelsCountnullable , closedCaptions, characteristicsnullable , forced, sampleRatenullable , spatialAudio, mimeType) → {Promise.<!shaka.hls.HlsParser.StreamInfo >}
Parameters:
Name
Type
Attributes
Description
playlist
shaka.hls.Playlist
verbatimMediaPlaylistUri
string
absoluteMediaPlaylistUri
string
codecs
string
type
string
languageValue
string
<nullable>
primary
boolean
name
string
<nullable>
channelsCount
number
<nullable>
closedCaptions
Map.<string, string>
characteristics
string
<nullable>
forced
boolean
sampleRate
number
<nullable>
spatialAudio
boolean
mimeType
string
|
undefined
Source:
Returns:
Type
Promise.<!shaka.hls.HlsParser.StreamInfo >
createSegmentReference_(initSegmentReference, previousReference, hlsSegmentnon-null , startTime, variablesnon-null , absoluteMediaPlaylistUri, type, mimeType, timestampOffset, hlsAes128Keyopt ) → {shaka.media.SegmentReference }
Parses one shaka.hls.Segment object into a shaka.media.SegmentReference.
Parameters:
Source:
Returns:
Type
shaka.media.SegmentReference
createSegments_(verbatimMediaPlaylistUri, playlistnon-null , type, mimeType, mediaSequenceToStartTimenon-null , variablesnon-null ) → {{segments: !Array.<!shaka.media.SegmentReference >, bandwidth: (number|undefined)}}
Parses shaka.hls.Segment objects into shaka.media.SegmentReferences and
get the bandwidth necessary for this segments If it's defined in the
playlist.
Parameters:
Name
Type
Description
verbatimMediaPlaylistUri
string
playlist
shaka.hls.Playlist
type
string
mimeType
string
mediaSequenceToStartTime
Map.<number, number>
variables
Map.<string, string>
Source:
Returns:
Type
{segments: !Array.<!shaka.media.SegmentReference >, bandwidth: (number|undefined)}
createStreamInfo_(verbatimMediaPlaylistUri, codecs, type, languageValuenullable , primary, namenullable , channelsCountnullable , closedCaptions, characteristicsnullable , forced, sampleRatenullable , spatialAudio) → {shaka.hls.HlsParser.StreamInfo }
Parameters:
Name
Type
Attributes
Description
verbatimMediaPlaylistUri
string
codecs
string
type
string
languageValue
string
<nullable>
primary
boolean
name
string
<nullable>
channelsCount
number
<nullable>
closedCaptions
Map.<string, string>
characteristics
string
<nullable>
forced
boolean
sampleRate
number
<nullable>
spatialAudio
boolean
Source:
Returns:
Type
shaka.hls.HlsParser.StreamInfo
createStreamInfosForVariantTag_(tagnon-null , resolutionnullable , frameRatenullable ) → {shaka.hls.HlsParser.StreamInfos }
Create audio and video streamInfos from an 'EXT-X-STREAM-INF' tag and its
related media tags.
Parameters:
Name
Type
Attributes
Description
tag
shaka.hls.Tag
resolution
string
<nullable>
frameRate
string
<nullable>
Source:
Returns:
Type
shaka.hls.HlsParser.StreamInfos
Parameters:
Name
Type
Description
mediaTags
Array.<!shaka.hls.Tag >
Media tags from the playlist.
Source:
createVariants_(audioInfosnon-null , videoInfosnon-null , bandwidth, widthnullable , heightnullable , frameRatenullable , videoRangenullable , drmInfosnon-null , keyIdsnon-null ) → {Array.<!shaka.extern.Variant >}
Parameters:
Source:
Returns:
Type
Array.<!shaka.extern.Variant >
determineDuration_()
Source:
determineLastTargetDuration_(playlistnon-null )
Parameters:
Source:
determinePresentationType_(playlistnon-null )
Parameters:
Source:
filterDuplicateCodecs_(codecsnon-null ) → {Array.<string>}
Parameters:
Name
Type
Description
codecs
Array.<string>
Source:
Returns:
codecs
Type
Array.<string>
finalizeStreams_(streamInfosnon-null )
Parameters:
Source:
getChannelsCount_(tagnon-null ) → {number}
Get the channel count information for an HLS audio track.
CHANNELS specifies an ordered, "/" separated list of parameters.
If the type is audio, the first parameter will be a decimal integer
specifying the number of independent, simultaneous audio channels.
No other channels parameters are currently defined.
Parameters:
Source:
Returns:
Type
number
getClosedCaptions_(tagnon-null , type) → {Map.<string, string>}
Get the closed captions map information for the EXT-X-STREAM-INF tag, to
create the stream info.
Parameters:
Source:
Returns:
closedCaptions
Type
Map.<string, string>
getCodecsForVariantTag_(tagnon-null ) → {Array.<string>}
Get the codecs from the 'EXT-X-STREAM-INF' tag.
Parameters:
Source:
Returns:
codecs
Type
Array.<string>
getInitSegmentReference_(playlistUri, tagsnon-null , variablesnon-null ) → {shaka.media.InitSegmentReference }
Get the InitSegmentReference for a segment if it has a EXT-X-MAP tag.
Parameters:
Name
Type
Description
playlistUri
string
The absolute uri of the media playlist.
tags
Array.<!shaka.hls.Tag >
Segment tags
variables
Map.<string, string>
Source:
Returns:
Type
shaka.media.InitSegmentReference
getLanguage_(languageValuenullable ) → {string}
Get the normalized language value.
Parameters:
Name
Type
Attributes
Description
languageValue
string
<nullable>
Source:
Returns:
Type
string
getLiveDuration_() → {number}
Source:
Returns:
Type
number
Parameters:
Source:
Returns:
Type
Map.<number, number>
getMinDuration_() → {number}
Source:
Returns:
Type
number
Get the next msn and part
Parameters:
Source:
Returns:
}
Type
{nextMediaSequence: number, nextPart:number}
getRequiredTag_(tagsnon-null , tagName) → {shaka.hls.Tag }
Returns a tag with a given name.
Throws an error if tag was not found.
Parameters:
Source:
Returns:
Type
shaka.hls.Tag
getSampleRate_(tagnon-null ) → {number}
Get the sample rate information for an HLS audio track.
Parameters:
Source:
Returns:
Type
number
getType_(tagnon-null ) → {string}
Get the type value.
Shaka recognizes the content types 'audio', 'video', 'text', and 'image'.
The HLS 'subtitles' type needs to be mapped to 'text'.
Parameters:
Source:
Returns:
Type
string
getUpdatePlaylistDelay_() → {number}
Source:
Returns:
Type
number
guessMimeType_(contentType, codecs, playlistnon-null , variablesnon-null ) → {Promise.<string>}
Attempts to guess stream's mime type based on content type, URI, and
contents of the playlist.
Parameters:
Name
Type
Description
contentType
string
codecs
string
playlist
shaka.hls.Playlist
variables
Map.<string, string>
Source:
Returns:
Type
Promise.<string>
guessMimeTypeBeforeLoading_(contentType, codecs) → {string}
Attempts to guess stream's mime type based on content type and URI.
Parameters:
Name
Type
Description
contentType
string
codecs
string
Source:
Returns:
Type
string
guessMimeTypeFallback_(contentType) → {string}
Get a fallback mime type for the content. Used if all the better methods
for determining the mime type have failed.
Parameters:
Name
Type
Description
contentType
string
Source:
Returns:
Type
string
hasEnoughInfoToFinalizeStreams_() → {boolean}
There are some values on streams that can only be set once we know about
both the video and audio content, if present.
This checks if there is at least one video downloaded (if the media has
video), and that there is at least one audio downloaded (if the media has
audio).
Source:
Returns:
Type
boolean
isLive_() → {boolean}
Source:
Returns:
Type
boolean
isSpatialAudio_(tagnon-null ) → {boolean}
Get the spatial audio information for an HLS audio track.
In HLS the channels field indicates the number of audio channels that the
stream has (eg: 2). In the case of Dolby Atmos, the complexity is
expressed with the number of channels followed by the word JOC
(eg: 16/JOC), so 16 would be the number of channels (eg: 7.3.6 layout),
and JOC indicates that the stream has spatial audio.
Parameters:
Source:
See:
Returns:
Type
boolean
makeNetworkRequest_(request, type, contextopt ) → {Promise.<shaka.extern.Response >}
Create a networking request. This will manage the request using the
parser's operation manager. If the parser has already been stopped, the
request will not be made.
Parameters:
Source:
Returns:
Type
Promise.<shaka.extern.Response >
makeStreamObject_(codecs, type, languageValuenullable , primary, namenullable , channelsCountnullable , closedCaptions, characteristicsnullable , forced, sampleRatenullable , spatialAudio) → {shaka.extern.Stream }
Creates a stream object with the given parameters.
The parameters that are passed into here are only the things that can be
known without downloading the media playlist; other values must be set
manually on the object after creation.
Parameters:
Name
Type
Attributes
Description
codecs
string
type
string
languageValue
string
<nullable>
primary
boolean
name
string
<nullable>
channelsCount
number
<nullable>
closedCaptions
Map.<string, string>
characteristics
string
<nullable>
forced
boolean
sampleRate
number
<nullable>
spatialAudio
boolean
Source:
Returns:
Type
shaka.extern.Stream
notifySegmentsForStreams_(streamsnon-null )
Parameters:
Source:
offsetStreamInfo_(streamInfonon-null , offset)
Parameters:
Source:
onExpirationUpdated(sessionId, expiration)
Tells the parser that the expiration time of an EME session has changed.
Implementing this is optional.
Parameters:
Name
Type
Description
sessionId
string
expiration
number
Implements:
Source:
onUpdate_() → {Promise}
Called when the update timer ticks. Because parsing a manifest is async,
this method is async. To work with this, this method will schedule the next
update when it finished instead of using a repeating-start.
Source:
Returns:
Type
Promise
parseByteRange_(previousReference, byterangenullable ) → {Array.<number>}
Parse the startByte and endByte.
Parameters:
Source:
Returns:
An array with the start byte and end byte.
Type
Array.<number>
parseClosedCaptions_(mediaTagsnon-null )
Parses an array of EXT-X-MEDIA tags, then stores the values of all tags
with TYPE="CLOSED-CAPTIONS" into a map of group id to closed captions.
Parameters:
Source:
parseCodecs_(tagsnon-null )
Get the codecs of each variant tag, and store in a map from
audio/video/subtitle group id to the codecs arraylist.
Parameters:
Name
Type
Description
tags
Array.<!shaka.hls.Tag >
Variant tags from the playlist.
Source:
parseDrmInfo_(playlistnon-null , mimeType) → {{drmInfos: !Array.<shaka.extern.DrmInfo >, keyIds: !Set.<string>, encrypted: boolean, aesEncrypted: boolean}}
Parameters:
Source:
Returns:
Type
{drmInfos: !Array.<shaka.extern.DrmInfo >, keyIds: !Set.<string>, encrypted: boolean, aesEncrypted: boolean}
parseManifest_(data, uri) → {Promise}
Parses the manifest.
Parameters:
Name
Type
Description
data
BufferSource
uri
string
Source:
Returns:
Type
Promise
parseMasterVariables_(tagsnon-null )
Get the variables of each variant tag, and store in a map.
Parameters:
Name
Type
Description
tags
Array.<!shaka.hls.Tag >
Variant tags from the playlist.
Source:
Get the variables of each variant tag, and store in a map.
Parameters:
Name
Type
Description
tags
Array.<!shaka.hls.Tag >
Variant tags from the playlist.
Source:
Returns:
Type
Map.<string, string>
parseTexts_(mediaTagsnon-null ) → {Array.<!shaka.extern.Stream >}
Parse Subtitles and Closed Captions from 'EXT-X-MEDIA' tags.
Create text streams for Subtitles, but not Closed Captions.
Parameters:
Name
Type
Description
mediaTags
Array.<!shaka.hls.Tag >
Media tags from the playlist.
Source:
Returns:
Type
Array.<!shaka.extern.Stream >
requestManifest_(absoluteUri, isPlaylistopt ) → {Promise.<!shaka.extern.Response >}
Makes a network request for the manifest and returns a Promise
with the resulting data.
Parameters:
Name
Type
Attributes
Description
absoluteUri
string
isPlaylist
boolean
<optional>
Source:
Returns:
Type
Promise.<!shaka.extern.Response >
setPresentationType_(type)
Parameters:
Source:
Initialize and start the parser. When |start| resolves, it should return
the initial version of the manifest. |start| will only be called once. If
|stop| is called while |start| is pending, |start| should reject.
Parameters:
Name
Type
Description
uri
string
The URI of the manifest.
playerInterface
shaka.extern.ManifestParser.PlayerInterface
The player interface contains the callbacks and members that the parser
can use to communicate with the player and outside world.
Implements:
Source:
Returns:
Type
Promise.<shaka.extern.Manifest >
stop() → {Promise}
Tell the parser that it must stop and free all internal resources as soon
as possible. Only once all internal resources are stopped and freed will
the promise resolve. Once stopped a parser will not be started again.
The parser should support having |stop| called multiple times and the
promise should always resolve.
Implements:
Source:
Returns:
Type
Promise
syncStreamsWithProgramDateTime_(streamInfosnon-null )
Synchronize streams by the EXT-X-PROGRAM-DATE-TIME tags attached to their
segments. Also normalizes segment times so that the earliest segment in
any stream is at time 0.
Parameters:
Source:
syncStreamsWithSequenceNumber_(streamInfosnon-null )
Align the streams by sequence number by dropping early segments. Then
offset the streams to begin at presentation time 0.
Parameters:
Source:
update()
Tells the parser to do a manual manifest update. Implementing this is
optional. This is only called when 'emsg' boxes are present.
Implements:
Source:
updateStream_(streamInfonon-null ) → {Promise}
Updates a stream.
Parameters:
Source:
Returns:
Type
Promise
variableSubstitution_(uri, variablesnon-null ) → {string}
Replaces the variables of a given URI.
Parameters:
Name
Type
Description
uri
string
variables
Map.<string, string>
Source:
Returns:
Type
string
Type Definitions
BasicInfo
Type:
{type: string, mimeType: string, codecs: string, language: ?string, height: ?string, width: ?string, channelCount: ?number, sampleRate: ?number}
Properties:
Name
Type
Attributes
Description
type
string
mimeType
string
codecs
string
language
string
<nullable>
height
string
<nullable>
width
string
<nullable>
channelCount
number
<nullable>
sampleRate
number
<nullable>
Source:
DrmParser_
Type:
function(!shaka.hls.Tag, string):?shaka.extern.DrmInfo
Source:
StreamInfo
Contains a stream and information about it.
Type:
{stream : !shaka.extern.Stream , type: string, verbatimMediaPlaylistUri: string, absoluteMediaPlaylistUri: string, minTimestamp: number, maxTimestamp: number, mediaSequenceToStartTime: !Map.<number, number>, canSkipSegments: boolean, canBlockReload: boolean, hasEndList: boolean, firstSequenceNumber: number, nextMediaSequence: number, nextPart: number, loadedOnce: boolean}
Properties:
Name
Type
Description
stream
shaka.extern.Stream
The Stream itself.
type
string
The type value. Could be 'video', 'audio', 'text', or 'image'.
verbatimMediaPlaylistUri
string
The verbatim media playlist URI, as it appeared in the master playlist.
This has not been canonicalized into an absolute URI. This gives us a
consistent key for this playlist, even if redirects cause us to update
from different origins each time.
absoluteMediaPlaylistUri
string
The absolute media playlist URI, resolved relative to the master playlist
and updated to reflect any redirects.
minTimestamp
number
The minimum timestamp found in the stream.
maxTimestamp
number
The maximum timestamp found in the stream.
mediaSequenceToStartTime
Map.<number, number>
A map of media sequence numbers to media start times.
Only used for VOD content.
canSkipSegments
boolean
True if the server supports delta playlist updates, and we can send a
request for a playlist that can skip older media segments.
canBlockReload
boolean
True if the server supports blocking playlist reload, and we can send a
request for a playlist that can block reload until some segments are
present.
hasEndList
boolean
True if the stream has an EXT-X-ENDLIST tag.
firstSequenceNumber
number
The sequence number of the first reference. Only calculated if needed.
nextMediaSequence
number
The next media sequence.
nextPart
number
The next part.
loadedOnce
boolean
True if the stream has been loaded at least once.
Source:
StreamInfos
Audio and video stream infos.
Type:
Properties:
Source: