1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 18:29:39 +02:00
Daniel Neto 2023-06-30 08:55:17 -03:00
parent 746e163d01
commit 1c7ea28b46
808 changed files with 316395 additions and 381162 deletions

View file

@ -311,9 +311,70 @@ var sampleMoov =
0x00, 0x00, 0x00, 0x01, // entry_count
0x00, 0x00, 0x00, 0x01)))))); // chunk_offset
/**
* Generates generic emsg box data for both v0 and v1 boxes concats the messageData
* and returns the result as a Uint8Array. Passing any version other than 0 or 1 will
* return an invalid EMSG box.
*/
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
]);
} else if (version === 2) {
// Invalid version only
emsgProps = new Uint8Array([
0x02, // 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
]);
} else {
emsgProps = new Uint8Array([
// malformed emsg data
0x00, 0x00, 0x00, 0x64, // timescale = 100
// no presentation_time
0x00, 0x00, 0x00, 0x01, // event_duration = 1
// no id
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;
};
module.exports = {
typeBytes,
sampleMoov,
unityMatrix,
box
box,
generateEmsgBoxData
};