Constructor
new LOCMAFParser(codecnon-null, paramsnon-null)
Parameters:
| Name |
Type |
Description |
codec |
shaka.extern.MsfCodec
|
The negotiated draft's primitive
codec, used to read the variable-length integers the spec calls vi64.
It defines them by reference to MOQT's own encoding, which changed in
draft-17, so the same header bytes mean different numbers depending on
which draft delivered them. |
params |
shaka.msf.LOCMAFParser.TrackParams
|
Everything read out
of the track's CMAF Header. |
- Source:
- See:
-
Members
CENC_FIELDS_ :Array<number>
The fields that only a protected track may carry.
Type:
- Source:
ElementType_ :number
The LOCMAF element types, which tag each element of an object payload.
Type:
Properties:
| Name |
Value |
Type |
Description |
GEN_BOX |
1
|
number
|
|
FULL_HEADER |
2
|
number
|
|
DELTA_HEADER |
3
|
number
|
|
RAW_BOXES |
4
|
number
|
|
- Source:
Field :number
The LOCMAF header field IDs. Every scalar has an even ID and every list or
byte field an odd one, which is what makes the parity rule a framing rule.
Type:
Properties:
| Name |
Value |
Type |
Description |
TRUN_SAMPLE_SIZES |
1
|
number
|
|
TFHD_SAMPLE_DESCRIPTION_INDEX |
2
|
number
|
|
TRUN_SAMPLE_DURATIONS |
3
|
number
|
|
TFHD_DEFAULT_SAMPLE_DURATION |
4
|
number
|
|
TRUN_SAMPLE_COMPOSITION_TIME_OFFSETS |
5
|
number
|
|
TFHD_DEFAULT_SAMPLE_SIZE |
6
|
number
|
|
TRUN_SAMPLE_FLAGS |
7
|
number
|
|
TFHD_DEFAULT_SAMPLE_FLAGS |
8
|
number
|
|
SENC_INITIALIZATION_VECTOR |
9
|
number
|
|
TFDT_BASE_MEDIA_DECODE_TIME |
10
|
number
|
|
SENC_SUBSAMPLE_COUNT |
11
|
number
|
|
TRUN_FIRST_SAMPLE_FLAGS |
12
|
number
|
|
SENC_BYTES_OF_CLEAR_DATA |
13
|
number
|
|
TRUN_SAMPLE_COUNT |
14
|
number
|
|
SENC_BYTES_OF_PROTECTED_DATA |
15
|
number
|
|
SENC_PER_SAMPLE_IV_SIZE |
16
|
number
|
|
DELTA_DELETED_LOCMAF_IDS |
27
|
number
|
|
- Source:
KNOWN_FIELDS_ :Set<number>
The fields this parser stores as reference state. An unknown field is
skipped by the parity rule and otherwise ignored, so that new ones can be
added without breaking older receivers.
Type:
- Source:
MDAT_ :Uint8Array
Type:
- Source:
TfhdFlags_ :number
Type:
Properties:
| Name |
Value |
Type |
Description |
SAMPLE_DESCRIPTION_INDEX_PRESENT |
2
|
number
|
|
DEFAULT_SAMPLE_DURATION_PRESENT |
8
|
number
|
|
DEFAULT_SAMPLE_SIZE_PRESENT |
16
|
number
|
|
DEFAULT_SAMPLE_FLAGS_PRESENT |
32
|
number
|
|
DEFAULT_BASE_IS_MOOF |
131072
|
number
|
|
- Source:
TrunFlags_ :number
Type:
Properties:
| Name |
Value |
Type |
Description |
DATA_OFFSET_PRESENT |
1
|
number
|
|
FIRST_SAMPLE_FLAGS_PRESENT |
4
|
number
|
|
SAMPLE_DURATION_PRESENT |
256
|
number
|
|
SAMPLE_SIZE_PRESENT |
512
|
number
|
|
SAMPLE_FLAGS_PRESENT |
1024
|
number
|
|
SAMPLE_COMPOSITION_TIME_OFFSETS_PRESENT |
2048
|
number
|
|
- Source:
fields_ :Map<number, (number|!Array<number>|!Uint8Array)>
The in-group reference state: the represented field values of the
previous chunk, keyed by LOCMAF field ID. Not the effective values --
a delta applies to what the previous chunk carried, so a field the
previous chunk left to a default has a previous value of zero.
Type:
-
Map<number, (number|!Array<number>|!Uint8Array)>
- Source:
group_ :bigint
Type:
- Source:
hasReference_ :boolean
True once a full header has established a reference the deltas in this
group can be applied to.
Type:
- Source:
previousDurationSum_ :number
The sum of the previous chunk's effective sample durations, which is
the only thing a delta chunk's decode time can be derived from.
Type:
- Source:
previousObjectId_ :bigint
Type:
- Source:
Methods
Decides which values become `tfhd` defaults and which become per-sample
`trun` entries. This is where the canonical form is pinned down: the
decision is made from the effective values alone, so a chunk that carried
redundant defaults on the wire reconstructs to the same bytes as its
minimal counterpart.
Parameters:
- Source:
Returns:
-
Type
-
shaka.msf.LOCMAFParser.Layout_
zigzagToSigned_(value) → {number}
Undoes the zigzag mapping, which interleaves the signs so that a small
negative delta encodes as compactly as a small positive one.
Parameters:
| Name |
Type |
Description |
value |
bigint
|
|
- Source:
Returns:
-
Type
-
number
applyDelta_(propertiesnon-null)
Folds a delta header into the reference state. Deletions are applied
first, so that a field the current chunk drops falls back to its default
instead of being differenced against a value that no longer applies.
Parameters:
| Name |
Type |
Description |
properties |
Map<number, (number|!Array<number>|!Uint8Array)>
|
|
- Source:
applyFull_(propertiesnon-null)
Replaces the reference state with a full header's absolute values.
Parameters:
| Name |
Type |
Description |
properties |
Map<number, (number|!Array<number>|!Uint8Array)>
|
|
- Source:
- Source:
Returns:
-
Type
-
number
buildCencBoxes_(effectivenon-null) → {Array<!Uint8Array>}
Recomputes the three CENC boxes, in the order the canonical form fixes
them in, or returns nothing when the chunk carries no per-sample
encryption metadata. Only senc travels; saiz and saio follow from it.
Parameters:
- Source:
Returns:
-
Type
-
Array<!Uint8Array>
buildMoof_(effectivenon-null) → {Uint8Array}
Builds the `moof`. The two offsets it has to carry -- `trun.data_offset`
and `saio.offset` -- both depend on the finished size of the box that
holds them, so the boxes are built with the offsets left at zero and
patched once every size is known.
Parameters:
- Source:
Returns:
-
Type
-
Uint8Array
buildSaio_() → {Uint8Array}
- Source:
Returns:
-
Type
-
Uint8Array
buildSaiz_(effectivenon-null) → {Uint8Array}
Recomputes `saiz`, which LOCMAF never carries: every sample's auxiliary
information size follows from the IV size and the subsample count.
Parameters:
- Source:
Returns:
-
Type
-
Uint8Array
buildSenc_(effectivenon-null) → {Uint8Array}
Parameters:
- Source:
Returns:
-
Type
-
Uint8Array
buildTfdt_(effectivenon-null) → {Uint8Array}
Parameters:
- Source:
Returns:
-
Type
-
Uint8Array
buildTfhd_(layoutnon-null) → {Uint8Array}
Parameters:
- Source:
Returns:
-
Type
-
Uint8Array
buildTrun_(effectivenon-null, layoutnon-null) → {Uint8Array}
Parameters:
- Source:
Returns:
-
Type
-
Uint8Array
checkContinuity_(objnon-null)
Notices the two things that invalidate the delta chain: a new group, and
a hole in the object IDs of the current one.
Parameters:
- Source:
Gathers the per-sample encryption metadata, or returns null when the
chunk carries none.
Parameters:
| Name |
Type |
Description |
sampleCount |
number
|
|
- Source:
Returns:
-
Type
-
shaka.msf.LOCMAFParser.Cenc_
Expands the reference state into the chunk's effective values: what each
sample's duration, size, flags and composition offset actually are, once
the `tfhd` and `trex` defaults have been resolved. Everything downstream
reads these arrays and nothing reads the fields, which is what makes the
output independent of how the encoder chose to distribute the values.
Parameters:
| Name |
Type |
Description |
payloadLength |
number
|
|
- Source:
Returns:
-
Type
-
shaka.msf.LOCMAFParser.Effective_
decodeList_(bytesnon-null, signed) → {Array<number>}
Decodes a vi64 list. The element count is never needed: a list always
carries exactly as many values as the chunk's list has entries, so the
byte-length prefix delimits it on its own. That holds through length
changes too -- a list that grows carries absolute values for the new
tail, and one that shrinks simply emits fewer values.
Parameters:
| Name |
Type |
Description |
bytes |
Uint8Array
|
|
signed |
boolean
|
|
- Source:
Returns:
-
Type
-
Array<number>
decodeProperties_(blocknon-null, isDelta) → {Map<number, (number|!Array<number>|!Uint8Array)>}
Decodes a property block into field values.
The parity of a field ID decides how its value is framed -- an even ID is
one bare vi64, an odd ID is length-prefixed bytes -- which is what lets a
receiver step over a field it does not know. That framing rule is fixed;
how the value bytes are read is per-field, and three fields do not follow
the plain absolute-in-full, delta-in-delta pattern.
Parameters:
| Name |
Type |
Description |
block |
Uint8Array
|
|
isDelta |
boolean
|
|
- Source:
Returns:
-
Type
-
Map<number, (number|!Array<number>|!Uint8Array)>
deriveSizes_(sampleCount, payloadLength) → {Array<number>}
Derives every sample's size. The last one is never on the wire: it is
whatever is left of the payload, which saves a vi64 on every chunk and
makes the payload length authoritative.
Parameters:
| Name |
Type |
Description |
sampleCount |
number
|
|
payloadLength |
number
|
|
- Source:
Returns:
-
Type
-
Array<number>
Reconstructs the CMAF chunk one LOCMAF object carries, or returns null
when the object carries no appendable media -- an object status, a
rawBoxes object holding initialization bytes -- or when it cannot be
read.
Parameters:
- Source:
Returns:
-
Type
-
shaka.msf.LOCMAFParser.Chunk
A rawBoxes object is reconstructed verbatim, but it resets the delta
chain: deriving reference state from it would mean parsing a `moof` back
out of the bytes, which reconstruction never otherwise needs.
Parameters:
| Name |
Type |
Description |
boxes |
Uint8Array
|
|
- Source:
Returns:
-
Type
-
shaka.msf.LOCMAFParser.Chunk
readGenBox_(datanon-null, offset) → {!{box: !Uint8Array, offset: number}}
Reads one genBox element and rebuilds the ISO box it carries. The wire
form drops the 4-byte size, so `box_size` covers the FourCC and the
contents, and the reconstructed box is four bytes longer.
Parameters:
| Name |
Type |
Description |
data |
Uint8Array
|
|
offset |
number
|
|
- Source:
Returns:
-
Type
-
!{box: !Uint8Array, offset: number}
readVarInt_(bytesnon-null, offset) → {!{value: number, raw: bigint, bytesRead: number}}
Reads one vi64, reporting both its value as a number and the raw unsigned
value the zigzag decoding needs.
Parameters:
| Name |
Type |
Description |
bytes |
Uint8Array
|
|
offset |
number
|
|
- Source:
Returns:
-
Type
-
!{value: number, raw: bigint, bytesRead: number}
reset_()
Drops the in-group reference, so that nothing is decoded until the next
full header or rawBoxes object.
- Source:
writeUint16_(bytesnon-null, offset, value)
Parameters:
| Name |
Type |
Description |
bytes |
Uint8Array
|
|
offset |
number
|
|
value |
number
|
|
- Source:
writeUint32_(bytesnon-null, offset, value)
Parameters:
| Name |
Type |
Description |
bytes |
Uint8Array
|
|
offset |
number
|
|
value |
number
|
|
- Source:
writeUint64_(bytesnon-null, offset, value)
Parameters:
| Name |
Type |
Description |
bytes |
Uint8Array
|
|
offset |
number
|
|
value |
number
|
|
- Source:
Type Definitions
Cenc_
The per-sample encryption metadata of one chunk.
Type:
-
{perSampleIvSize: number, ivs: !Uint8Array, subsampleCounts: ?Array<number>, clearBytes: !Array<number>, protectedBytes: !Array<number>}
- Source:
Chunk
One reconstructed CMAF chunk.
Type:
-
{startTime: number, duration: number, data: !Uint8Array}
- Source:
Effective_
What one chunk works out to, per sample, once every default is resolved.
Type:
-
{sampleCount: number, baseMediaDecodeTime: number, sampleDescriptionIndex: number, durations: !Array<number>, sizes: !Array<number>, flags: !Array<number>, compositionTimeOffsets: !Array<number>, cenc: ?shaka.msf.LOCMAFParser.Cenc_}
- Source:
Layout_
Which values go in the `tfhd` and which are written per sample.
Type:
-
{sampleDescriptionIndex: ?number, defaultSampleDuration: ?number, defaultSampleSize: ?number, defaultSampleFlags: ?number, firstSampleFlags: ?number, perSampleDurations: boolean, perSampleSizes: boolean, perSampleFlags: boolean, perSampleOffsets: boolean, signedOffsets: boolean}
- Source:
TrackParams
Everything the track's CMAF Header contributes to reconstruction. The
`trex` defaults and the `tenc` per-sample IV size are what every omitted
field falls back to, so they are read once per track rather than per chunk.
Type:
-
{trackId: number, timescale: number, trexSampleDescriptionIndex: number, trexSampleDuration: number, trexSampleSize: number, trexSampleFlags: number, isProtected: boolean, defaultPerSampleIvSize: number}
- Source: