Skip to content

Commit

Permalink
comments and descriptive var
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Feb 6, 2023
1 parent 5c8397c commit 1d621d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 10 additions & 4 deletions lib/mp4/probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,22 @@ getTracks = function(init) {
};

/**
* Returns an array of emsg ID3 data from the provided segmentData
* ptOffset can also be provided if necessary.
* Returns an array of emsg ID3 data from the provided segmentData.
* An offset can also be provided as the Latest Arrival Time to calculate
* the Event Start Time of v0 EMSG boxes.
* See: https://dashif-documents.azurewebsites.net/Events/master/event.html#Inband-event-timing
*
* @param {Uint8Array} segmentData the segment byte array.
* @param {number} offset the segment start time or Latest Arrival Time,
* @return {Object[]} an array of ID3 parsed from EMSG boxes
*/
getEmsgID3 = function(segmentData, ptOffset = 0) {
getEmsgID3 = function(segmentData, offset = 0) {
var emsgBoxes = findBox(segmentData, ['emsg']);
return emsgBoxes.map((data) => {
var parsedBox = emsg.parseEmsgBox(new Uint8Array(data));
var parsedId3Frames = parseId3Frames(parsedBox.message_data);
return {
cueTime: emsg.scaleTime(parsedBox.presentation_time, parsedBox.timescale, parsedBox.presentation_time_delta, ptOffset),
cueTime: emsg.scaleTime(parsedBox.presentation_time, parsedBox.timescale, parsedBox.presentation_time_delta, offset),
duration: emsg.scaleTime(parsedBox.event_duration, parsedBox.timescale),
frames: parsedId3Frames
};
Expand Down
8 changes: 5 additions & 3 deletions lib/tools/parse-id3.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ var
}
};

// TODO add dispatch type parsing
var parseId3Frames = function(data) {
var frameSize, frameHeader,
frameStart = 10,
tagSize = 0,
frames = [];

// if not valid id3 return early.
// If we don't have enough data for a header, 10 bytes,
// or 'ID3' in the first 3 bytes this is not a valid ID3 tag.
if (data.length < 10 ||
data[0] !== 'I'.charCodeAt(0) ||
data[1] !== 'D'.charCodeAt(0) ||
Expand All @@ -196,7 +196,9 @@ var parseId3Frames = function(data) {
// ID3 reports the tag size excluding the header but it's more
// convenient for our comparisons to include it
tagSize += 10;
if (data[5] & 0x40) {
// check bit 6 of byte 5 for the extended header flag.
var hasExtendedHeader = data[5] & 0x40;
if (hasExtendedHeader) {
// advance the frame start past the extended header
frameStart += 4; // header size field
frameStart += parseSyncSafeInteger(data.subarray(10, 14));
Expand Down

0 comments on commit 1d621d4

Please sign in to comment.