Skip to content

Commit

Permalink
more indentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Jan 24, 2023
1 parent 8bfc3ce commit e92f776
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 90 deletions.
100 changes: 50 additions & 50 deletions lib/mp4/emsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,61 @@ var uint8ToCString = require('../utils/string.js').uint8ToCString;
* @returns A parsed emsg box object
*/
var parseEmsgBox = function(boxData) {
// version + flags
var offset = 4;
var version = boxData[0];
var scheme_id_uri,
value, timescale,
presentation_time,
presentation_time_delta,
event_duration,
id;
if (version === 0) {
scheme_id_uri = uint8ToCString(boxData.subarray(offset));
offset += scheme_id_uri.length;
value = uint8ToCString(boxData.subarray(offset));
offset += value.length;
var dv = new DataView(boxData.buffer);
timescale = dv.getUint32(offset);
offset += 4;
presentation_time_delta = dv.getUint32(offset);
offset += 4;
event_duration = dv.getUint32(offset);
offset += 4;
id = dv.getUint32(offset);
offset += 4;
} else if (version === 1) {
var dv = new DataView(boxData.buffer);
timescale = dv.getUint32(offset);
offset += 4;
presentation_time = Number(dv.getBigUint64(offset));
offset += 8;
event_duration = dv.getUint32(offset);
offset += 4;
id = dv.getUint32(offset);
offset += 4;
scheme_id_uri = uint8ToCString(boxData.subarray(offset));
offset += scheme_id_uri.length;
value = uint8ToCString(boxData.subarray(offset));
offset += value.length;
}
// version + flags
var offset = 4;
var version = boxData[0];
var scheme_id_uri,
value, timescale,
presentation_time,
presentation_time_delta,
event_duration,
id;
if (version === 0) {
scheme_id_uri = uint8ToCString(boxData.subarray(offset));
offset += scheme_id_uri.length;
value = uint8ToCString(boxData.subarray(offset));
offset += value.length;
var dv = new DataView(boxData.buffer);
timescale = dv.getUint32(offset);
offset += 4;
presentation_time_delta = dv.getUint32(offset);
offset += 4;
event_duration = dv.getUint32(offset);
offset += 4;
id = dv.getUint32(offset);
offset += 4;
} else if (version === 1) {
var dv = new DataView(boxData.buffer);
timescale = dv.getUint32(offset);
offset += 4;
presentation_time = Number(dv.getBigUint64(offset));
offset += 8;
event_duration = dv.getUint32(offset);
offset += 4;
id = dv.getUint32(offset);
offset += 4;
scheme_id_uri = uint8ToCString(boxData.subarray(offset));
offset += scheme_id_uri.length;
value = uint8ToCString(boxData.subarray(offset));
offset += value.length;
}

var message_data = new Uint8Array(boxData.subarray(offset, boxData.byteLength));
return { scheme_id_uri,
value,
timescale,
presentation_time,
presentation_time_delta,
event_duration,
id,
message_data };
var message_data = new Uint8Array(boxData.subarray(offset, boxData.byteLength));
return { scheme_id_uri,
value,
timescale,
presentation_time,
presentation_time_delta,
event_duration,
id,
message_data };
};

var scaleTime = function(presentationTime, timescale, timeDelta, offset) {
return presentationTime || presentationTime === 0 ? presentationTime / timescale : offset + timeDelta / timescale;
return presentationTime || presentationTime === 0 ? presentationTime / timescale : offset + timeDelta / timescale;
};

module.exports = {
parseEmsgBox: parseEmsgBox,
scaleTime: scaleTime
parseEmsgBox: parseEmsgBox,
scaleTime: scaleTime
};
20 changes: 10 additions & 10 deletions lib/utils/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
* @returns the string with the null char
*/
var uint8ToCString = function(data) {
var index = 0;
var curChar = String.fromCharCode(data[index]);
var retString = '';
while (curChar !== '\0') {
retString += curChar;
index++;
curChar = String.fromCharCode(data[index]);
}
// Add nullChar
var index = 0;
var curChar = String.fromCharCode(data[index]);
var retString = '';
while (curChar !== '\0') {
retString += curChar;
return retString;
index++;
curChar = String.fromCharCode(data[index]);
}
// Add nullChar
retString += curChar;
return retString;
};

module.exports = { uint8ToCString };
61 changes: 31 additions & 30 deletions test/utils/mp4-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,39 +312,40 @@ var sampleMoov =
0x00, 0x00, 0x00, 0x01)))))); // chunk_offset

/**
* Generates generic emsg box data for both v0 and v1 boxes concats the messageData and returns the result
* Generates generic emsg box data for both v0 and v1 boxes concats the messageData
* and returns the result as a Uint8Array
*/
var generateEmsgBoxData = function(version, messageData) {
var emsgProps;
if (version === 0) {
emsgProps = new Uint8Array([
0x00, // version
0x00, 0x00, 0x00, //flags
0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F, 0x3A, 0x62, 0x61, 0x72, 0x3A, 0x32, 0x30, 0x32, 0x33, 0x00, // urn:foo:bar:2023\0
0x66, 0x6F, 0x6F, 0x2E, 0x62, 0x61, 0x72, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x00, // foo.bar.value\0
0x00, 0x00, 0x00, 0x64, // timescale = 100
0x00, 0x00, 0x03, 0xE8, // presentation_time_delta = 1000
0x00, 0x00, 0x00, 0x00, // event_duration = 0
0x00, 0x00, 0x00, 0x01 // id = 1
]);
} else if (version === 1) {
emsgProps = new Uint8Array([
0x01, // version
0x00, 0x00, 0x00, //flags
0x00, 0x00, 0x00, 0x64, // timescale = 100
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0x10, // presentation_time = 10000
0x00, 0x00, 0x00, 0x01, // event_duration = 1
0x00, 0x00, 0x00, 0x02, // id = 2
0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F, 0x3A, 0x62, 0x61, 0x72, 0x3A, 0x32, 0x30, 0x32, 0x33, 0x00, // urn:foo:bar:2023\0
0x66, 0x6F, 0x6F, 0x2E, 0x62, 0x61, 0x72, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x00 // foo.bar.value\0
]);
}
var emsgProps;
if (version === 0) {
emsgProps = new Uint8Array([
0x00, // version
0x00, 0x00, 0x00, //flags
0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F, 0x3A, 0x62, 0x61, 0x72, 0x3A, 0x32, 0x30, 0x32, 0x33, 0x00, // urn:foo:bar:2023\0
0x66, 0x6F, 0x6F, 0x2E, 0x62, 0x61, 0x72, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x00, // foo.bar.value\0
0x00, 0x00, 0x00, 0x64, // timescale = 100
0x00, 0x00, 0x03, 0xE8, // presentation_time_delta = 1000
0x00, 0x00, 0x00, 0x00, // event_duration = 0
0x00, 0x00, 0x00, 0x01 // id = 1
]);
} else if (version === 1) {
emsgProps = new Uint8Array([
0x01, // version
0x00, 0x00, 0x00, //flags
0x00, 0x00, 0x00, 0x64, // timescale = 100
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0x10, // presentation_time = 10000
0x00, 0x00, 0x00, 0x01, // event_duration = 1
0x00, 0x00, 0x00, 0x02, // id = 2
0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F, 0x3A, 0x62, 0x61, 0x72, 0x3A, 0x32, 0x30, 0x32, 0x33, 0x00, // urn:foo:bar:2023\0
0x66, 0x6F, 0x6F, 0x2E, 0x62, 0x61, 0x72, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x00 // foo.bar.value\0
]);
}

// concat the props and messageData
var retArr = new Uint8Array(emsgProps.length + messageData.length);
retArr.set(emsgProps);
retArr.set(messageData, emsgProps.length);
return retArr;
// concat the props and messageData
var retArr = new Uint8Array(emsgProps.length + messageData.length);
retArr.set(emsgProps);
retArr.set(messageData, emsgProps.length);
return retArr;
};

module.exports = {
Expand Down

0 comments on commit e92f776

Please sign in to comment.