MCPcopy
hub / github.com/fanmingming/live / findBox

Function findBox

m3u8/mux-mp4.js:3437–3474  ·  view source on GitHub ↗
(data, path)

Source from the content-addressed store, hash-verified

3435var parseType = require(19);
3436
3437var findBox = function(data, path) {
3438 var results = [],
3439 i, size, type, end, subresults;
3440
3441 if (!path.length) {
3442 // short-circuit the search for empty paths
3443 return null;
3444 }
3445
3446 for (i = 0; i < data.byteLength;) {
3447 size = toUnsigned(data[i] << 24 |
3448 data[i + 1] << 16 |
3449 data[i + 2] << 8 |
3450 data[i + 3]);
3451
3452 type = parseType(data.subarray(i + 4, i + 8));
3453
3454 end = size > 1 ? i + size : data.byteLength;
3455
3456 if (type === path[0]) {
3457 if (path.length === 1) {
3458 // this is the end of the path and we've found the box we were
3459 // looking for
3460 results.push(data.subarray(i + 8, end));
3461 } else {
3462 // recursively search for the next box along the path
3463 subresults = findBox(data.subarray(i + 8, end), path.slice(1));
3464 if (subresults.length) {
3465 results = results.concat(subresults);
3466 }
3467 }
3468 }
3469 i = end;
3470 }
3471
3472 // we've finished searching all of data
3473 return results;
3474};
3475
3476module.exports = findBox;
3477

Callers 2

parseCaptionNalsFunction · 0.85
mux-mp4.jsFile · 0.85

Calls 2

toUnsignedFunction · 0.85
parseTypeFunction · 0.85

Tested by

no test coverage detected