UNPKG

h264-nalu-parser

Version:
25 lines (24 loc) 889 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function* default_1(bytes) { const view = new DataView(bytes.buffer, bytes.byteOffset); const len = bytes.byteLength - 3; let start; let end = 1; do { // Check # of sync bytes (0x000001 or 0x00000001) end += view.getUint16(end + 1) ? 3 : 4; for (start = end; end < len; end++) { // Step forward until we hit another 3- or 4-byte header if (view.getUint16(end) === 0 && (bytes[end + 2] === 1 || (view.getUint16(end + 2) === 1))) { yield bytes.subarray(start, end); break; } } } while (end < len); // A packet can't end with a header, // so one last NAL Unit extends to the end yield bytes.subarray(start); } exports.default = default_1;