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AAK,KAAM,QAAS,KAAK,SAEvE,IAAK,KAAK,MAAsB,WAAd,KAAK,KAAmB,CACxC,GAAoB,IAAhB,KAAK,IAAI,IAA4B,IAAhB,KAAK,IAAI,IAA4B,IAAhB,KAAK,IAAI,GACrD,MAAO,CAAE,KAAM,SAAU,QAAS,GAC7B,GAAoB,IAAhB,KAAK,IAAI,IAA4B,IAAhB,KAAK,IAAI,IAA4B,IAAhB,KAAK,IAAI,IAA4B,IAAhB,KAAK,IAAI,GACjF,MAAO,CAAE,KAAM,SAAU,QAAS,EAEtC,CAGA,IAAK,IAAI,EAAU,EAAG,GAAW,EAAG,IAAW,CAC7C,IAAI,EAAc,EAClB,GAAI,KAAK,IAAI,QAAU,EAAS,CAC9B,GAAe,EACf,KACF,CACA,IAAI,EAAQ,KAAK,wBAAwB,KAAK,IAAK,EAAG,GACtD,OAAa,CACX,GAAI,EAAM,GAAK,EAAG,CAChB,GAAe,EACf,KACF,CACA,GAAI,EAAM,EAAI,EAAM,IAClB,IACI,GAAa,GAAe,GAAW,MAE7C,GAAI,EAAM,EAAI,EAAG,MACjB,EAAQ,KAAK,wBAAwB,KAAK,IAAK,EAAM,EAAG,EAC1D,CACA,GAAI,EAAc,EAChB,MAAO,CAAE,KAAM,SAAU,QAAS,EAEtC,CACA,GAAI,KAAK,OAAQ,MAAM,IAAI,MAAM,8DACjC,MAAO,CAAE,KAAM,UAAW,SAAU,EACtC","file":"/npm/h264-interp-utils@1.1.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/h264-interp-utils@1.1.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* eslint-disable camelcase,curly,no-fallthrough */\r\n\r\nexport const profileNames = {\r\n  66: 'BASELINE',\r\n  77: 'MAIN',\r\n  88: 'EXTENDED',\r\n  100: 'FREXT_HP',\r\n  110: 'FREXT_Hi10P',\r\n  122: 'FREXT_Hi422',\r\n  244: 'FREXT_Hi444',\r\n  44: 'FREXT_CAVLC444'\r\n}\r\n\r\nexport const chromaFormatValues = {\r\n  0: 'YUV400',\r\n  1: 'YUV420',\r\n  2: 'YUV422',\r\n  3: 'YUV444'\r\n}\r\n\r\nexport class Slice {\r\n  constructor (slice, avcc, options) {\r\n    /* we won't parse out much of this, so use subarray */\r\n    const bitstream = options?.all\r\n      ? new Bitstream(slice)\r\n      : new Bitstream(slice.subarray(0, 10))\r\n    this.bitstream = bitstream\r\n    this.nalu = slice\r\n    const forbidden_zero_bit = bitstream.u_1()\r\n    if (forbidden_zero_bit) throw new Error('NALU error: invalid NALU header')\r\n    this.nal_ref_id = bitstream.u_2()\r\n    this.nal_unit_type = bitstream.u(5)\r\n    if (this.nal_unit_type !== 1 && this.nal_unit_type !== 5)\r\n      throw new Error('Slice error: not slice_layer_without_partitioning')\r\n    this.first_mb_in_slice = bitstream.ue_v()\r\n    this.slice_type = bitstream.ue_v()\r\n    this.ppsIdPtr = bitstream.ptr\r\n    this.pic_parameter_set_id = bitstream.ue_v()\r\n    this.ppsIdLen = bitstream.ptr - this.ppsIdPtr\r\n    if (avcc && avcc.ppsDecoded[this.pic_parameter_set_id]) {\r\n      const pps = avcc.ppsDecoded[this.pic_parameter_set_id]\r\n      if (pps.separate_colour_plane_flag) {\r\n        this.colour_plane_id = bitstream.u_2()\r\n      }\r\n      const seq_parameter_set_id = pps.seq_parameter_set_id\r\n      if (avcc && avcc.spsDecoded[seq_parameter_set_id]) {\r\n        const sps = avcc.spsDecoded[seq_parameter_set_id]\r\n        this.frame_num = bitstream.u(sps.log2_max_frame_num_minus4 + 4)\r\n      }\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Set the pic_parameter_set_id in a slice to a desired number.\r\n   * This works around a bizarro bug in Chrome(ium)\r\n   * @returns {Uint8Array}\r\n   */\r\n  setPPSId (ppsId = 0) {\r\n    if (this.pic_parameter_set_id === ppsId) return this.nalu\r\n    const sourceLength = this.bitstream.buffer.byteLength << 3\r\n    const target = new Bitstream(sourceLength)\r\n    target.copyBits(this.bitstream, 0, this.ppsIdPtr)\r\n    target.put_ue_v(ppsId)\r\n    target.copyBits(this.bitstream, this.ppsIdPtr + this.ppsIdLen, sourceLength - (this.ppsIdPtr + this.ppsIdLen))\r\n    return target.stream\r\n  }\r\n}\r\n\r\nexport class SPS {\r\n  constructor (SPS) {\r\n    const bitstream = new Bitstream(SPS)\r\n    this.bitstream = bitstream\r\n    this.buffer = bitstream.buffer\r\n\r\n    const forbidden_zero_bit = bitstream.u_1()\r\n    if (forbidden_zero_bit) throw new Error('NALU error: invalid NALU header')\r\n    this.nal_ref_id = bitstream.u_2()\r\n    this.nal_unit_type = bitstream.u(5)\r\n    if (this.nal_unit_type !== 7) throw new Error('SPS error: not SPS')\r\n\r\n    this.profile_idc = bitstream.u_8()\r\n    if (profileNames[this.profile_idc]) {\r\n      this.profileName = profileNames[this.profile_idc]\r\n    } else {\r\n      throw new Error('SPS error: invalid profile_idc')\r\n    }\r\n\r\n    this.constraint_set0_flag = bitstream.u_1()\r\n    this.constraint_set1_flag = bitstream.u_1()\r\n    this.constraint_set2_flag = bitstream.u_1()\r\n    this.constraint_set3_flag = bitstream.u_1()\r\n    this.constraint_set4_flag = bitstream.u_1()\r\n    this.constraint_set5_flag = bitstream.u_1()\r\n    const reserved_zero_2bits = bitstream.u_2()\r\n    if (reserved_zero_2bits !== 0)\r\n      throw new Error('SPS error: reserved_zero_2bits must be zero')\r\n\r\n    this.level_idc = bitstream.u_8()\r\n\r\n    this.seq_parameter_set_id = bitstream.ue_v()\r\n    if (this.seq_parameter_set_id > 31)\r\n      throw new Error('SPS error: seq_parameter_set_id must be 31 or less')\r\n\r\n    this.has_no_chroma_format_idc =\r\n      (this.profile_idc === 66 || this.profile_idc === 77 || this.profile_idc === 88)\r\n\r\n    if (!this.has_no_chroma_format_idc) {\r\n      this.chroma_format_idc = bitstream.ue_v()\r\n      if (this.bit_depth_luma_minus8 > 3)\r\n        throw new Error('SPS error: chroma_format_idc must be 3 or less')\r\n      if (this.chroma_format_idc === 3) { /* 3 = YUV444 */\r\n        this.separate_colour_plane_flag = bitstream.u_1()\r\n        this.chromaArrayType = this.separate_colour_plane_flag ? 0 : this.chroma_format_idc\r\n      }\r\n      this.bit_depth_luma_minus8 = bitstream.ue_v()\r\n      if (this.bit_depth_luma_minus8 > 6)\r\n        throw new Error('SPS error: bit_depth_luma_minus8 must be 6 or less')\r\n      this.bitDepthLuma = this.bit_depth_luma_minus8 + 8\r\n      this.bit_depth_chroma_minus8 = bitstream.ue_v()\r\n      if (this.bit_depth_chroma_minus8 > 6)\r\n        throw new Error('SPS error: bit_depth_chroma_minus8 must be 6 or less')\r\n      this.lossless_qpprime_flag = bitstream.u_1()\r\n      this.bitDepthChroma = this.bit_depth_chroma_minus8 + 8\r\n      this.seq_scaling_matrix_present_flag = bitstream.u_1()\r\n      if (this.seq_scaling_matrix_present_flag) {\r\n        const n_ScalingList = (this.chroma_format_idc !== 3) ? 8 : 12\r\n        this.seq_scaling_list_present_flag = []\r\n        this.seq_scaling_list = []\r\n        for (let i = 0; i < n_ScalingList; i++) {\r\n          const seqScalingListPresentFlag = bitstream.u_1()\r\n          this.seq_scaling_list_present_flag.push(seqScalingListPresentFlag)\r\n          if (seqScalingListPresentFlag) {\r\n            const sizeOfScalingList = i < 6 ? 16 : 64\r\n            let nextScale = 8\r\n            let lastScale = 8\r\n            const delta_scale = []\r\n            for (let j = 0; j < sizeOfScalingList; j++) {\r\n              if (nextScale !== 0) {\r\n                const deltaScale = bitstream.se_v()\r\n                delta_scale.push(deltaScale)\r\n                nextScale = (lastScale + delta_scale + 256) % 256\r\n              }\r\n              lastScale = (nextScale === 0) ? lastScale : nextScale\r\n              this.seq_scaling_list.push(delta_scale)\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n\r\n    this.log2_max_frame_num_minus4 = bitstream.ue_v()\r\n    if (this.log2_max_frame_num_minus4 > 12)\r\n      throw new Error('SPS error: log2_max_frame_num_minus4 must be 12 or less')\r\n    this.maxFrameNum = 1 << (this.log2_max_frame_num_minus4 + 4)\r\n\r\n    this.pic_order_cnt_type = bitstream.ue_v()\r\n    if (this.pic_order_cnt_type > 2)\r\n      throw new Error('SPS error: pic_order_cnt_type must be 2 or less')\r\n\r\n    let expectedDeltaPerPicOrderCntCycle = 0\r\n    switch (this.pic_order_cnt_type) {\r\n      case 0:\r\n        this.log2_max_pic_order_cnt_lsb_minus4 = bitstream.ue_v()\r\n        if (this.log2_max_pic_order_cnt_lsb_minus4 > 12)\r\n          throw new Error('SPS error: log2_max_pic_order_cnt_lsb_minus4 must be 12 or less')\r\n        this.maxPicOrderCntLsb = 1 << (this.log2_max_pic_order_cnt_lsb_minus4 + 4)\r\n        break\r\n      case 1:\r\n        this.delta_pic_order_always_zero_flag = bitstream.u_1()\r\n        this.offset_for_non_ref_pic = bitstream.se_v()\r\n        this.offset_for_top_to_bottom_field = bitstream.se_v()\r\n        this.num_ref_frames_in_pic_order_cnt_cycle = bitstream.ue_v()\r\n        this.offset_for_ref_frame = []\r\n        for (let i = 0; i < this.num_ref_frames_in_pic_order_cnt_cycle; i++) {\r\n          const offsetForRefFrame = bitstream.se_v()\r\n          this.offset_for_ref_frame.push(offsetForRefFrame)\r\n          // eslint-disable-next-line no-unused-vars\r\n          expectedDeltaPerPicOrderCntCycle += offsetForRefFrame\r\n        }\r\n        break\r\n      case 2:\r\n        /* there is nothing for case 2 */\r\n        break\r\n    }\r\n\r\n    this.max_num_ref_frames = bitstream.ue_v()\r\n    this.gaps_in_frame_num_value_allowed_flag = bitstream.u_1()\r\n    this.pic_width_in_mbs_minus_1 = bitstream.ue_v()\r\n    this.picWidth = (this.pic_width_in_mbs_minus_1 + 1) << 4\r\n    this.pic_height_in_map_units_minus_1 = bitstream.ue_v()\r\n    this.frame_mbs_only_flag = bitstream.u_1()\r\n    this.interlaced = !this.frame_mbs_only_flag\r\n    if (this.frame_mbs_only_flag === 0) { /* 1 if frames rather than fields (no interlacing) */\r\n      this.mb_adaptive_frame_field_flag = bitstream.u_1()\r\n    }\r\n    this.picHeight = ((2 - this.frame_mbs_only_flag) * (this.pic_height_in_map_units_minus_1 + 1)) << 4\r\n\r\n    this.direct_8x8_inference_flag = bitstream.u_1()\r\n    this.frame_cropping_flag = bitstream.u_1()\r\n    if (this.frame_cropping_flag) {\r\n      this.frame_cropping_rect_left_offset = bitstream.ue_v()\r\n      this.frame_cropping_rect_right_offset = bitstream.ue_v()\r\n      this.frame_cropping_rect_top_offset = bitstream.ue_v()\r\n      this.frame_cropping_rect_bottom_offset = bitstream.ue_v()\r\n      this.cropRect = {\r\n        x: this.frame_cropping_rect_left_offset,\r\n        y: this.frame_cropping_rect_top_offset,\r\n        width: this.picWidth - (this.frame_cropping_rect_left_offset + this.frame_cropping_rect_right_offset),\r\n        height: this.picHeight - (this.frame_cropping_rect_top_offset + this.frame_cropping_rect_bottom_offset)\r\n      }\r\n    } else {\r\n      this.cropRect = {\r\n        x: 0,\r\n        y: 0,\r\n        width: this.picWidth,\r\n        height: this.picHeight\r\n      }\r\n    }\r\n    this.vui_parameters_present_flag = bitstream.u_1()\r\n    if (this.vui_parameters_present_flag) {\r\n      this.aspect_ratio_info_present_flag = bitstream.u_1()\r\n      if (this.aspect_ratio_info_present_flag) {\r\n        this.aspect_ratio_idc = bitstream.u_8()\r\n        if (this.aspect_ratio_idc) {\r\n          this.sar_width = bitstream.u(16)\r\n          this.sar_height = bitstream.u(16)\r\n        }\r\n      }\r\n\r\n      this.overscan_info_present_flag = bitstream.u_1()\r\n      if (this.overscan_info_present_flag)\r\n        this.overscan_appropriate_flag = bitstream.u_1()\r\n      this.video_signal_type_present_flag = bitstream.u_1()\r\n      if (this.video_signal_type_present_flag) {\r\n        this.video_format = bitstream.u(3)\r\n        this.video_full_range_flag = bitstream.u_1()\r\n        this.color_description_present_flag = bitstream.u_1()\r\n        if (this.color_description_present_flag) {\r\n          this.color_primaries = bitstream.u_8()\r\n          this.transfer_characteristics = bitstream.u_8()\r\n          this.matrix_coefficients = bitstream.u_8()\r\n        }\r\n      }\r\n      this.chroma_loc_info_present_flag = bitstream.u_1()\r\n      if (this.chroma_loc_info_present_flag) {\r\n        this.chroma_sample_loc_type_top_field = bitstream.ue_v()\r\n        this.chroma_sample_loc_type_bottom_field = bitstream.ue_v()\r\n      }\r\n      this.timing_info_present_flag = bitstream.u_1()\r\n      if (this.timing_info_present_flag) {\r\n        this.num_units_in_tick = bitstream.u(32)\r\n        this.time_scale = bitstream.u(32)\r\n        this.fixed_frame_rate_flag = bitstream.u_1()\r\n        if (this.num_units_in_tick > 0) {\r\n          this.framesPerSecond = this.time_scale / this.num_units_in_tick\r\n        }\r\n      }\r\n      this.nal_hrd_parameters_present_flag = bitstream.u_1()\r\n    }\r\n    this.success = true\r\n  }\r\n\r\n  get stream () {\r\n    return this.bitstream.stream\r\n  }\r\n\r\n  get profile_compatibility () {\r\n    let v = this.constraint_set0_flag << 7\r\n    v |= this.constraint_set1_flag << 6\r\n    v |= this.constraint_set2_flag << 5\r\n    v |= this.constraint_set3_flag << 4\r\n    v |= this.constraint_set4_flag << 3\r\n    v |= this.constraint_set5_flag << 1\r\n    return v\r\n  }\r\n\r\n  /**\r\n   * getter for the MIME type encoded in this avcC\r\n   * @returns {string}\r\n   */\r\n  get MIME () {\r\n    const f = []\r\n    f.push('avc1.')\r\n    f.push(AvcC.byte2hex(this.profile_idc).toUpperCase())\r\n    f.push(AvcC.byte2hex(this.profile_compatibility).toUpperCase())\r\n    f.push(AvcC.byte2hex(this.level_idc).toUpperCase())\r\n    return f.join('')\r\n  }\r\n}\r\n\r\nexport class PPS {\r\n  constructor (NALU) {\r\n    const bitstream = new Bitstream(NALU)\r\n\r\n    const forbidden_zero_bit = bitstream.u_1()\r\n    if (forbidden_zero_bit) throw new Error('NALU error: invalid NALU header')\r\n    this.nal_ref_id = bitstream.u_2()\r\n    this.nal_unit_type = bitstream.u(5)\r\n    if (this.nal_unit_type !== 8) throw new Error('PPS error: not PPS')\r\n    this.pic_parameter_set_id = bitstream.ue_v()\r\n    this.seq_parameter_set_id = bitstream.ue_v()\r\n    this.entropy_coding_mode_flag = bitstream.u_1()\r\n    this.entropyCodingMode = this.entropy_coding_mode_flag ? 'CABAC' : 'CAVLC'\r\n    this.bottom_field_pic_order_in_frame_present_flag = bitstream.u_1()\r\n    this.num_slice_groups_minus1 = bitstream.ue_v()\r\n    this.numSliceGroups = this.num_slice_groups_minus1 + 1\r\n    if (this.num_slice_groups_minus1 > 0) {\r\n      this.slice_group_map_type = bitstream.ue_v()\r\n      switch (this.slice_group_map_type) {\r\n        case 0:\r\n          this.run_length_minus1 = []\r\n          for (let i = 0; i <= this.num_slice_groups_minus1; i++) {\r\n            this.run_length_minus1.push(bitstream.ue_v())\r\n          }\r\n          break\r\n        case 1: /* there is no case 1 */\r\n          break\r\n        case 2:\r\n          this.top_left = []\r\n          this.bottom_right = []\r\n          for (let i = 0; i <= this.num_slice_groups_minus1; i++) {\r\n            const topLeft = bitstream.ue_v()\r\n            const bottomRight = bitstream.ue_v()\r\n            if (topLeft > bottomRight)\r\n              throw new Error('PPS error: bottom_right less than top_left when slice_group_map is 2')\r\n            this.top_left.push(topLeft)\r\n            this.bottom_right.push(bottomRight)\r\n          }\r\n          break\r\n        case 3:\r\n        case 4:\r\n        case 5:\r\n          if (this.num_slice_groups_minus1 !== 1)\r\n            throw new Error('PPS error: num_slice_groups_minus1 must be 1 when slice_group_map is 3,4,5')\r\n          this.slice_group_change_direction_flag = bitstream.u_1()\r\n          this.slice_group_change_rate_minus1 = bitstream.ue_v()\r\n          break\r\n        case 6:\r\n          if (this.num_slice_groups_minus1 + 1 > 4) {\r\n            this.numberBitsPerSliceGroupId = 3\r\n          } else if (this.num_slice_groups_minus1 + 1 > 2) {\r\n            this.numberBitsPerSliceGroupId = 2\r\n          } else {\r\n            this.numberBitsPerSliceGroupId = 1\r\n          }\r\n          this.pic_size_in_map_units_minus1 = bitstream.ue_v()\r\n          this.slice_group_id = []\r\n          for (let i = 0; i <= this.pic_size_in_map_units_minus1; i++) {\r\n            const sliceGroupId = bitstream.u(this.numberBitsPerSliceGroupId)\r\n            if (sliceGroupId > this.num_slice_groups_minus1)\r\n              throw new Error('PPS error: slice_group_id must not be greater than num_slice_groups_minus1 when slice_group_map is 6')\r\n            this.slice_group_id.push(sliceGroupId)\r\n          }\r\n          break\r\n      }\r\n    }\r\n    this.num_ref_idx_l0_active_minus1 = bitstream.ue_v()\r\n    if (this.num_ref_idx_l0_active_minus1 > 31)\r\n      throw new Error('PPS error: num_ref_idx_l0_active_minus1 may not be greater than 31')\r\n    this.num_ref_idx_l1_active_minus1 = bitstream.ue_v()\r\n    if (this.num_ref_idx_l1_active_minus1 > 31)\r\n      throw new Error('PPS error: num_ref_idx_l1_active_minus1 may not be greater than 31')\r\n    this.weighted_pred_flag = bitstream.u_1()\r\n    this.weighted_bipred_idc = bitstream.u_2()\r\n    this.pic_init_qp_minus26 = bitstream.se_v()\r\n    if (this.pic_init_qp_minus26 > 25)\r\n      throw new Error('PPS error: pic_init_qp_minus26 may not be greater than 25')\r\n    this.pic_init_qs_minus26 = bitstream.se_v()\r\n    if (this.pic_init_qs_minus26 > 25)\r\n      throw new Error('PPS error: pic_init_qs_minus26 may not be greater than 25')\r\n    this.deblocking_filter_control_present_flag = bitstream.u_1()\r\n    this.constrained_intra_pred_flag = bitstream.u_1()\r\n    this.redundant_pic_cnt_present_flag = bitstream.u_1()\r\n\r\n    this.success = true\r\n  }\r\n}\r\n\r\n// noinspection DuplicatedCode\r\n/**\r\n * Tools for handling general bitstream issues.\r\n */\r\nexport class RawBitstream {\r\n  /**\r\n   * Construct a bitstream\r\n   * @param stream  Buffer containing the stream, or length in bits\r\n   */\r\n  constructor (stream) {\r\n    this.ptr = 0\r\n    if (typeof stream === 'number') {\r\n      this.buffer = new Uint8Array((stream + 7) >> 3)\r\n      this.originalByteLength = this.buffer.byteLength\r\n      this.max = stream\r\n    } else if (typeof stream === 'undefined') {\r\n      this.buffer = new Uint8Array(8192)\r\n      this.originalByteLength = this.buffer.byteLength\r\n      this.max = 8192 << 3\r\n    } else {\r\n      this.buffer = new Uint8Array(stream, 0, stream.byteLength)\r\n      this.max = (this.buffer.byteLength << 3)\r\n      this.originalByteLength = stream.byteLength\r\n    }\r\n  }\r\n\r\n  /**\r\n   * utility  / debugging function to examine next 16 bits of stream\r\n   * @returns {string} Remaining unconsumed bits in the stream\r\n   * (Careful: getters cannot have side-effects like advancing a pointer)\r\n   */\r\n  get peek16 () {\r\n    let n = 16\r\n    let p = this.ptr\r\n    if (n + p > this.remaining) n = this.remaining\r\n    const bitstrings = []\r\n    const hexstrings = []\r\n    /* nibble accumulators */\r\n    const bits = []\r\n    let nibble = 0\r\n    for (let i = 0; i < n; i++) {\r\n      const q = (p >> 3)\r\n      const o = 0x07 - (p & 0x07)\r\n      const bit = (this.buffer[q] >> o) & 0x01\r\n      nibble = (nibble << 1) | bit\r\n      bits.push(bit)\r\n      p++\r\n      if (i === n - 1 || (i % 4) === 3) {\r\n        hexstrings.push(nibble.toString(16))\r\n        let bitstring = ''\r\n        bits.forEach(bit => { bitstring += (bit === 0) ? '0' : '1' })\r\n        bitstrings.push(bitstring)\r\n        bits.length = 0\r\n        nibble = 0\r\n      }\r\n    }\r\n    return bitstrings.join(' ') + ' ' + hexstrings.join('')\r\n  }\r\n\r\n  /**\r\n   * number of bits remaining in the present stream\r\n   * @returns {number}\r\n   */\r\n  get remaining () {\r\n    return this.max - this.ptr\r\n  }\r\n\r\n  /**\r\n   * number of bits already consumed in the present stream\r\n   * @returns {number}\r\n   */\r\n  get consumed () {\r\n    return this.ptr\r\n  }\r\n\r\n  seek (pos = 0) {\r\n    if (pos > this.max) throw new Error('cannot seek beyond end')\r\n    this.ptr = pos\r\n  }\r\n\r\n  reallocate (size) {\r\n    if (this.ptr + size <= this.max) return\r\n    const newSize = (0xff + Math.floor((this.max + size) * 1.25)) & ~0xff\r\n    const newBuf = new Uint8Array((newSize + 7) >>> 3)\r\n    this.max = newSize\r\n    newBuf.set(this.buffer)\r\n    this.buffer = newBuf\r\n  }\r\n\r\n  /**\r\n   * copy bits from some other bitstream to this one\r\n   * @param {RawBitstream} from the source of the copy\r\n   * @param {number} ptr the starting bit position of the copy in \"from\"\r\n   * @param {number} count the number of bits to copy\r\n   * @param {number|undefined} to the starting bit position to receive the copy, or the current pointer\r\n   */\r\n  copyBits (from, ptr, count, to) {\r\n    /* this is a little intricate for the sake of performance */\r\n    this.reallocate(count)\r\n    /* handle pointer saving. */\r\n    const savedFromPtr = from.ptr\r\n    const savedToPtr = this.ptr\r\n    from.ptr = ptr\r\n    if (typeof to === 'number') this.ptr = to\r\n\r\n    /* split the copy into a starting fragment of < 8 bits,\r\n     * a multiple of 8 bits,\r\n     * and an ending fragment of less than 8 bits\r\n     */\r\n    const firstFragLen = (8 - this.ptr) & 0x07\r\n    const lastFragLen = (count - firstFragLen) & 0x07\r\n    const byteCopyLen = count - (firstFragLen + lastFragLen)\r\n\r\n    /* copy first fragment bit by bit */\r\n    for (let i = 0; i < firstFragLen; i++) {\r\n      const b = from.u_1()\r\n      this.put_u_1(b)\r\n    }\r\n\r\n    /* copy whole bytes byte-by-byte */\r\n    const thisbuf = this.buffer\r\n    const frombuf = from.buffer\r\n    let q = this.ptr >> 3\r\n    const byteLen = byteCopyLen >> 3\r\n    const lshift = from.ptr & 0x07\r\n    if (lshift === 0) {\r\n      /* byte-aligned source and dest */\r\n      let r = from.ptr >> 3\r\n\r\n      /* four-way loop unroll */\r\n      let n = byteLen & 0x03\r\n      while (n-- > 0) {\r\n        thisbuf[q++] = frombuf[r++]\r\n      }\r\n      n = byteLen >> 2\r\n      while (n-- > 0) {\r\n        thisbuf[q++] = frombuf[r++]\r\n        thisbuf[q++] = frombuf[r++]\r\n        thisbuf[q++] = frombuf[r++]\r\n        thisbuf[q++] = frombuf[r++]\r\n      }\r\n    } else {\r\n      /* unaligned source, retrieve it with masks and shifts */\r\n      const rshift = 8 - lshift\r\n      const mask = (0xff << rshift) & 0xff\r\n      let p = (from.ptr >> 3) + 1\r\n      let v1 = frombuf[p - 1]\r\n      let v2 = frombuf[p]\r\n\r\n      /* 8-way loop unroll.\r\n       * This is a hot path when changing pic_parameter_set_ids in Slices. */\r\n      let n = byteLen & 0x07\r\n      while (n-- > 0) {\r\n        thisbuf[q++] = ((v1 & ~mask) << lshift) | ((v2 & mask) >> rshift)\r\n        v1 = v2\r\n        v2 = frombuf[++p]\r\n      }\r\n      n = byteLen >> 3\r\n      while (n-- > 0) {\r\n        /* flip back and forth between v1 and v2 */\r\n        thisbuf[q++] = ((v1 & ~mask) << lshift) | ((v2 & mask) >> rshift)\r\n        v1 = frombuf[++p]\r\n\r\n        thisbuf[q++] = ((v2 & ~mask) << lshift) | ((v1 & mask) >> rshift)\r\n        v2 = frombuf[++p]\r\n\r\n        thisbuf[q++] = ((v1 & ~mask) << lshift) | ((v2 & mask) >> rshift)\r\n        v1 = frombuf[++p]\r\n\r\n        thisbuf[q++] = ((v2 & ~mask) << lshift) | ((v1 & mask) >> rshift)\r\n        v2 = frombuf[++p]\r\n\r\n        thisbuf[q++] = ((v1 & ~mask) << lshift) | ((v2 & mask) >> rshift)\r\n        v1 = frombuf[++p]\r\n\r\n        thisbuf[q++] = ((v2 & ~mask) << lshift) | ((v1 & mask) >> rshift)\r\n        v2 = frombuf[++p]\r\n\r\n        thisbuf[q++] = ((v1 & ~mask) << lshift) | ((v2 & mask) >> rshift)\r\n        v1 = frombuf[++p]\r\n\r\n        thisbuf[q++] = ((v2 & ~mask) << lshift) | ((v1 & mask) >> rshift)\r\n        v2 = frombuf[++p]\r\n      }\r\n    }\r\n    from.ptr += byteCopyLen\r\n    this.ptr += byteCopyLen\r\n\r\n    /* copy the last fragment bit by bit */\r\n    for (let i = 0; i < lastFragLen; i++) {\r\n      const b = from.u_1()\r\n      this.put_u_1(b)\r\n    }\r\n\r\n    /* restore saved pointers */\r\n    from.ptr = savedFromPtr\r\n    if (typeof to === 'number') this.ptr = savedToPtr\r\n  }\r\n\r\n  /**\r\n   * put one bit\r\n   */\r\n  put_u_1 (b) {\r\n    if (this.ptr + 1 > this.max) throw new Error('NALUStream error: bitstream exhausted')\r\n    const p = (this.ptr >> 3)\r\n    const o = 0x07 - (this.ptr & 0x07)\r\n    const val = b << o\r\n    const mask = ~(1 << o)\r\n    this.buffer[p] = (this.buffer[p] & mask) | val\r\n    this.ptr++\r\n    return val\r\n  }\r\n\r\n  /**\r\n   * get one bit\r\n   * @returns {number}\r\n   */\r\n  u_1 () {\r\n    if (this.ptr + 1 > this.max)\r\n      throw new Error('NALUStream error: bitstream exhausted')\r\n    const p = (this.ptr >> 3)\r\n    const o = 0x07 - (this.ptr & 0x07)\r\n    const val = (this.buffer[p] >> o) & 0x01\r\n    this.ptr++\r\n    return val\r\n  }\r\n\r\n  /**\r\n   * get two bits\r\n   * @returns {number}\r\n   */\r\n  u_2 () {\r\n    return (this.u_1() << 1) | (this.u_1())\r\n  }\r\n\r\n  /**\r\n   * get three bits\r\n   * @returns {number}\r\n   */\r\n  u_3 () {\r\n    return (this.u_1() << 2) | (this.u_1() << 1) | (this.u_1())\r\n  }\r\n\r\n  /**\r\n   * get n bits\r\n   * @param n\r\n   * @returns {number}\r\n   */\r\n  u (n) {\r\n    if (n === 8) return this.u_8()\r\n    if (this.ptr + n >= this.max) throw new Error('NALUStream error: bitstream exhausted')\r\n    let val = 0\r\n    for (let i = 0; i < n; i++) {\r\n      val = (val << 1) | this.u_1()\r\n    }\r\n    return val\r\n  }\r\n\r\n  /**\r\n   * get one byte (as an unsigned number)\r\n   * @returns {number}\r\n   */\r\n  u_8 () {\r\n    if (this.ptr + 8 > this.max) throw new Error('NALUStream error: bitstream exhausted')\r\n    const o = this.ptr & 0x07\r\n    if (o === 0) {\r\n      const val = this.buffer[(this.ptr >> 3)]\r\n      this.ptr += 8\r\n      return val\r\n    } else {\r\n      const n = 8 - o\r\n      const rmask = (0xff << n) & 0xff\r\n      const lmask = (~rmask) & 0xff\r\n      const p = this.ptr >> 3\r\n      this.ptr += 8\r\n      return ((this.buffer[p] & lmask) << o) | ((this.buffer[p + 1] & rmask) >> n)\r\n    }\r\n  }\r\n\r\n  /**\r\n   * get an unsigned H.264-style variable-bit number\r\n   * in exponential Golomb format\r\n   * @returns {number}\r\n   */\r\n  ue_v () {\r\n    let zeros = 0\r\n    while (!this.u_1()) zeros++\r\n    let val = 1 << zeros\r\n    for (let i = zeros - 1; i >= 0; i--) {\r\n      val |= (this.u_1() << i)\r\n    }\r\n    return val - 1\r\n  }\r\n\r\n  put_u8 (val) {\r\n    this.reallocate(8)\r\n    if ((this.ptr & 0x07) === 0) {\r\n      this.buffer[this.ptr >> 3] = val\r\n      this.ptr += 8\r\n      return\r\n    }\r\n    this.put_u(val, 8)\r\n  }\r\n\r\n  put_u (val, count) {\r\n    this.reallocate(count)\r\n    if (count === 0) return\r\n    while (count > 0) {\r\n      count--\r\n      this.put_u_1((val >> count) & 0x01)\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Put an exponential-Golomb coded unsigned integer into the bitstream\r\n   * https://en.wikipedia.org/wiki/Exponential-Golomb_coding\r\n   * @param {number} val to insert\r\n   * @returns {number} count of bits inserted\r\n   */\r\n  put_ue_v (val) {\r\n    const v = val + 1\r\n    let v1 = v\r\n    let z = -1\r\n    do {\r\n      z++\r\n      v1 = v1 >> 1\r\n    } while (v1 !== 0)\r\n    this.put_u(0, z)\r\n    this.put_u(v, z + 1)\r\n    return z + z + 1\r\n  }\r\n\r\n  /**\r\n   * when done putting into a buffer, mark it complete,\r\n   * rewind it to the beginning, and shorten its contents,\r\n   * as if it had just been loaded.\r\n   * @returns {number} the number of bits in the buffer\r\n   */\r\n  put_complete () {\r\n    const newLength = this.ptr\r\n    const newByteLength = (newLength + 7) >> 3\r\n    this.buffer = this.buffer.subarray(0, newByteLength)\r\n    this.originalByteLength = newByteLength\r\n    this.max = newLength\r\n    this.ptr = 0\r\n    return newLength\r\n  }\r\n\r\n  /**\r\n   * get a signed h.264-style variable bit number\r\n   * in exponential Golomb format\r\n   * @returns {number} (without negative zeros)\r\n   */\r\n  se_v () {\r\n    const codeword = this.ue_v()\r\n    const result = codeword & 0x01 ? 1 + (codeword >> 1) : -(codeword >> 1)\r\n    return (result === 0) ? 0 : result\r\n  }\r\n\r\n  /**\r\n   * Put an exponential-Golomb coded signed integer into the bitstream\r\n   * https://en.wikipedia.org/wiki/Exponential-Golomb_coding#Extension_to_negative_numbers\r\n   * @param {number} val to insert\r\n   * @returns {number} count of bits inserted\r\n   */\r\n  put_se_v (val) {\r\n    const cw = (val <= 0) ? (-val) << 1 : (val << 1) - 1\r\n    return this.put_ue_v(cw)\r\n  }\r\n}\r\n\r\n/**\r\n * Tools for handling h264 bitstream issues.\r\n */\r\nexport class Bitstream extends RawBitstream {\r\n  /**\r\n   * Construct a bitstream\r\n   * @param stream  Buffer containing the stream, or length in bits\r\n   */\r\n  constructor (stream) {\r\n    super(stream)\r\n    if (typeof stream !== 'number' && typeof stream !== 'undefined') {\r\n      this.deemulated = this.hasEmulationPrevention(this.buffer)\r\n      this.buffer = this.deemulated ? this.deemulate(this.buffer) : this.buffer\r\n      this.max = (this.buffer.byteLength << 3)\r\n    }\r\n  }\r\n\r\n  get stream () {\r\n    return this.deemulated ? this.reemulate(this.buffer) : this.buffer\r\n  }\r\n\r\n  copyBits (from, ptr, count, to) {\r\n    this.deemulated = from.deemulated\r\n    super.copyBits(from, ptr, count, to)\r\n  }\r\n\r\n  /**\r\n   * add emulation prevention bytes\r\n   * @param {Uint8Array} buf\r\n   * @returns {Uint8Array}\r\n   */\r\n  reemulate (buf) {\r\n    const size = Math.floor(this.originalByteLength * 1.2)\r\n    const stream = new Uint8Array(size)\r\n    const len = buf.byteLength - 1\r\n    let q = 0\r\n    let p = 0\r\n    stream[p++] = buf[q++]\r\n    stream[p++] = buf[q++]\r\n    while (q < len) {\r\n      if (buf[q - 2] === 0 && buf[q - 1] === 0 && buf[q] <= 3) {\r\n        stream[p++] = 3\r\n        stream[p++] = buf[q++]\r\n      }\r\n      stream[p++] = buf[q++]\r\n    }\r\n    stream[p++] = buf[q++]\r\n    return stream.subarray(0, p)\r\n  }\r\n\r\n  hasEmulationPrevention (stream) {\r\n    /* maybe no need to remove emulation protection? scan for 00 00 */\r\n    for (let i = 1; i < stream.byteLength; i++) {\r\n      if (stream[i - 1] === 0 && stream[i] === 0) {\r\n        return true\r\n      }\r\n    }\r\n    return false\r\n  }\r\n\r\n  /**\r\n   * remove the emulation prevention bytes\r\n   * @param {Uint8Array} stream\r\n   * @returns {Uint8Array}\r\n   */\r\n  deemulate (stream) {\r\n    const buf = new Uint8Array(stream.byteLength)\r\n    let p = 0\r\n    let q = 0\r\n    const len = stream.byteLength - 1\r\n    buf[q++] = stream[p++]\r\n    buf[q++] = stream[p++]\r\n    /* remove emulation prevention:  00 00 03 00  means 00 00 00, 00 00 03 01 means 00 00 01 */\r\n    while (p < len) {\r\n      if (stream[p - 2] === 0 && stream[p - 1] === 0 && stream[p] === 3 && stream[p] <= 3) p++\r\n      else buf[q++] = stream[p++]\r\n    }\r\n    buf[q++] = stream[p++]\r\n    return buf.subarray(0, q)\r\n  }\r\n}\r\n\r\n/**\r\n * Handle the parsing and creation of \"avcC\" atoms.\r\n */\r\nexport class AvcC {\r\n  /**\r\n   * The options here:\r\n   *    options.bitstream is a bunch of NALUs, the video payload from a webm key frame.\r\n   *    options.NALUStream, a bitstream in a NALUStream object, read on.\r\n   *    options.sps and options.pps   SPS and PPS NALUs from the H.264 bitstream.\r\n   *    options.avcC. an existing avcC object.\r\n   *    options.strict  if true, this throws more errors on unexpected data.\r\n   * @param options\r\n   */\r\n  constructor (options) {\r\n    /* instance props */\r\n    this.strict = true\r\n    this.sps = []\r\n    this.pps = []\r\n    this.spsDecoded = {}\r\n    this.ppsDecoded = {}\r\n    this.configurationVersion = 1\r\n    this.profileIndication = 0xff\r\n    this.profileCompatibility = 0xff\r\n    this.avcLevelIndication = 0xff\r\n    this.boxSizeMinusOne = 3\r\n    this.cacheAvcC = null\r\n    this.extradata = null\r\n\r\n    if (typeof options.strict === 'boolean') this.strict = options.strict\r\n    if (typeof options.strictLength === 'boolean') this.strictLength = options.strictLength\r\n    /* construct avcC from NALU stream */\r\n    let stream\r\n    if (options.bitstream || options.naluStream) {\r\n      stream = options.naluStream ? options.naluStream : new NALUStream(options.bitstream, options)\r\n      this.boxSizeMinusOne = stream.boxSizeMinusOne\r\n      for (const nalu of stream) {\r\n        let pps\r\n        let sps\r\n        switch (nalu[0] & 0x1f) {\r\n          case 7:\r\n            sps = this.unpackSps(nalu)\r\n            this.spsDecoded[sps.seq_parameter_set_id] = sps\r\n            this.sps.push(nalu)\r\n            break\r\n          case 8:\r\n            pps = this.unpackPps(nalu)\r\n            this.ppsDecoded[pps.pic_parameter_set_id] = pps\r\n            this.pps.push(nalu)\r\n            break\r\n        }\r\n        if (this.pps.length > 0 && this.sps.length > 0) return\r\n      }\r\n      if (this.strict) throw new Error('avcC error: bitstream must contain both SPS and PPS')\r\n    } else if (options.sps && options.pps) {\r\n      /* construct avcC from sps and pps */\r\n      const sps = this.unpackSps(options.sps)\r\n      this.sps.push(options.sps)\r\n      this.spsDecoded[sps.seq_parameter_set_id] = sps\r\n      const pps = this.unpackPps(options.pps)\r\n      this.pps.push(options.pps)\r\n      this.ppsDecoded[pps.pic_parameter_set_id] = pps\r\n    } else if (options.avcC) {\r\n      /* construct it from avcC stream */\r\n      this.cacheAvcC = options.avcC\r\n      this.parseAvcC(options.avcC)\r\n    }\r\n    if (profileNames[this.profileIndication]) {\r\n      this.profileName = profileNames[this.profileIndication]\r\n    } else {\r\n      throw new Error('avcC error: invalid profileIndication')\r\n    }\r\n  }\r\n\r\n  /**\r\n   * getter for the avcC object\r\n   * @returns {Uint8Array}\r\n   */\r\n  get avcC () {\r\n    this.cacheAvcC = this.packAvcC()\r\n    return this.cacheAvcC\r\n  }\r\n\r\n  /**\r\n   * setter for the avcC object\r\n   * @param {Uint8Array} avcC\r\n   */\r\n  set avcC (avcC) {\r\n    this.cacheAvcC = avcC\r\n    this.parseAvcC(this.cacheAvcC)\r\n  }\r\n\r\n  get hex () {\r\n    return NALUStream.array2hex(this.cacheAvcC)\r\n  }\r\n\r\n  /**\r\n   * getter for the MIME type encoded in this avcC\r\n   * @returns {string}\r\n   */\r\n  get MIME () {\r\n    const f = []\r\n    f.push('avc1.')\r\n    f.push(AvcC.byte2hex(this.profileIndication).toUpperCase())\r\n    f.push(AvcC.byte2hex(this.profileCompatibility).toUpperCase())\r\n    f.push(AvcC.byte2hex(this.avcLevelIndication).toUpperCase())\r\n    return f.join('')\r\n  }\r\n\r\n  /**\r\n   * put NALU data (sps or pps) into output buffer\r\n   * @param {Uint8Array} buf buffer\r\n   * @param p {number} pointer to buf\r\n   * @param nalus {array}  sps[] or pps[]\r\n   * @param mask {number} mask for setting bits in nalu-count field\r\n   * @returns {number} updated pointer.\r\n   */\r\n  static appendNALUs (buf, p, nalus, mask) {\r\n    const setBits = ~mask\r\n    if (this.strict && (nalus.length <= 0 || nalus.length > mask))\r\n      throw new Error('avcC error: too many or not enough NALUs: ' + nalus.length)\r\n    buf[p++] = (setBits | (nalus.length & mask))\r\n    for (let nalui = 0; nalui < nalus.length; nalui++) {\r\n      const nalu = nalus[nalui]\r\n      const len = nalu.byteLength\r\n      if (this.strict && (len <= 0 || len > 0xffff))\r\n        throw new Error('avcC error: NALU has wrong length: ' + len)\r\n      buf[p++] = 0xff & (len >> 8)\r\n      buf[p++] = 0xff & len\r\n      buf.set(nalu, p)\r\n      p += len\r\n    }\r\n    return p\r\n  }\r\n\r\n  static readUInt16BE (buff, ptr) {\r\n    return ((buff[ptr] << 8) & 0xff00) | ((buff[ptr + 1]) & 0x00ff) // jshint ignore:line\r\n  }\r\n\r\n  static readUInt32BE (buff, ptr) {\r\n    let result = 0 | 0\r\n    for (let i = ptr; i < ptr + 4; i++) {\r\n      result = ((result << 8) | buff[i])\r\n    }\r\n    return result\r\n  }\r\n\r\n  static readUInt24BE (buff, ptr) {\r\n    let result = 0 | 0\r\n    for (let i = ptr; i < ptr + 3; i++) {\r\n      result = ((result << 8) | buff[i])\r\n    }\r\n    return result\r\n  }\r\n\r\n  static byte2hex (val) {\r\n    return ('00' + val.toString(16)).slice(-2)\r\n  }\r\n\r\n  parseAvcC (inbuff) {\r\n    const buf = new Uint8Array(inbuff, 0, inbuff.byteLength)\r\n    const buflen = buf.byteLength\r\n    if (buflen < 10) throw new Error('avcC error: object too short')\r\n    let ptr = 0\r\n    this.configurationVersion = buf[ptr++]\r\n    if (this.strict && this.configurationVersion !== 1)\r\n      throw new Error(`avcC error: configuration version must be 1: ${this.configurationVersion}`)\r\n    this.profileIndication = buf[ptr++]\r\n    this.profileCompatibility = buf[ptr++]\r\n    this.avcLevelIndication = buf[ptr++]\r\n    this.boxSizeMinusOne = buf[ptr++] & 3\r\n    let nalen = buf[ptr++] & 0x1f\r\n    ptr = this.captureNALUs(buf, ptr, nalen, this.sps)\r\n    nalen = buf[ptr++]\r\n    ptr = this.captureNALUs(buf, ptr, nalen, this.pps)\r\n    if (ptr < buflen) this.extradata = buf.subarray(ptr, buflen)\r\n    return inbuff\r\n  }\r\n\r\n  captureNALUs (buf, ptr, count, nalus) {\r\n    nalus.length = 0\r\n    if (this.strict && count <= 0)\r\n      throw new Error('avcC error: at least one NALU is required')\r\n    try {\r\n      for (let i = 0; i < count; i++) {\r\n        const len = AvcC.readUInt16BE(buf, ptr)\r\n        ptr += 2\r\n        const nalu = buf.slice(ptr, ptr + len)\r\n        nalus.push(nalu)\r\n        ptr += len\r\n      }\r\n    } catch (ex) {\r\n      throw new Error(ex)\r\n    }\r\n    return ptr\r\n  }\r\n\r\n  unpackSps (spsData) {\r\n    const sps = new SPS(spsData)\r\n    this.profileIndication = sps.profile_idc\r\n    this.profileCompatibility = sps.profile_compatibility\r\n    this.avcLevelIndication = sps.level_idc\r\n    if (sps.cropRect) this.cropRect = sps.cropRect\r\n    if (sps.picWidth) this.picWidth = sps.picWidth\r\n    if (sps.picHeight) this.picHeight = sps.picHeight\r\n    if (sps.framesPerSecond) this.framesPerSecond = sps.framesPerSecond\r\n    return sps\r\n  }\r\n\r\n  unpackPps (ppsData) {\r\n    const pps = new PPS(ppsData)\r\n    this.interlaced = pps.interlaced\r\n    this.entropyCodingMode = pps.entropyCodingMode\r\n    return pps\r\n  }\r\n\r\n  /**\r\n   * pack the avcC atom bitstream from the information in the class\r\n   * @returns {Uint8Array}\r\n   */\r\n  packAvcC () {\r\n    let length = 6\r\n    for (let spsi = 0; spsi < this.sps.length; spsi++) length += 2 + this.sps[spsi].byteLength\r\n    length += 1\r\n    for (let ppsi = 0; ppsi < this.pps.length; ppsi++) length += 2 + this.pps[ppsi].byteLength\r\n    if (this.extradata) length += this.extradata.byteLength\r\n    const buf = new Uint8Array(length)\r\n    let p = 0\r\n    buf[p++] = this.configurationVersion\r\n    buf[p++] = this.profileIndication\r\n    buf[p++] = this.profileCompatibility\r\n    buf[p++] = this.avcLevelIndication\r\n    if (this.strict && (this.boxSizeMinusOne < 0 || this.boxSizeMinusOne > 3))\r\n      throw new Error('avcC error: bad boxSizeMinusOne value: ' + this.boxSizeMinusOne)\r\n    buf[p++] = (0xfc | (0x03 & this.boxSizeMinusOne))\r\n    p = AvcC.appendNALUs(buf, p, this.sps, 0x1f)\r\n    p = AvcC.appendNALUs(buf, p, this.pps, 0xff)\r\n    if (p < length) buf.set(this.extradata, p)\r\n    return buf\r\n  }\r\n}\r\n\r\n/**\r\n * process buffers full of NALU streams\r\n */\r\nexport class NALUStream {\r\n  /**\r\n   * Construct a NALUStream from a buffer, figuring out what kind of stream it\r\n   * is when the options are omitted.\r\n   * @param {Uint8Array} buf buffer with a sequence of one or more NALUs\r\n   * @param options strict, boxSize, boxSizeMinusOne, type='packet' or 'annexB',\r\n   */\r\n  constructor (buf, options) {\r\n    this.validTypes = new Set(['packet', 'annexB', 'unknown'])\r\n    this.strict = false\r\n    this.type = null\r\n    this.buf = null\r\n    this.boxSize = null\r\n    this.cursor = 0\r\n    this.nextPacket = undefined\r\n\r\n    if (options) {\r\n      if (typeof options.strict === 'boolean') this.strict = Boolean(options.strict)\r\n      if (options.boxSizeMinusOne) this.boxSize = options.boxSizeMinusOne + 1\r\n      if (options.boxSize) this.boxSize = options.boxSize\r\n      if (options.type) this.type = options.type\r\n      if (this.type && !this.validTypes.has(this.type))\r\n        throw new Error('NALUStream error: type must be packet or annexB')\r\n    }\r\n\r\n    if (this.strict & this.boxSize && (this.boxSize < 2 || this.boxSize > 6))\r\n      throw new Error('NALUStream error: invalid boxSize')\r\n\r\n    /* don't copy this.buf from input, just project it */\r\n    this.buf = new Uint8Array(buf, 0, buf.length)\r\n\r\n    if (!this.type || !this.boxSize) {\r\n      const { type, boxSize } = this.getType(4)\r\n      this.type = type\r\n      this.boxSize = boxSize\r\n    }\r\n    this.nextPacket = this.type === 'packet'\r\n      ? this.nextLengthCountedPacket\r\n      : this.nextAnnexBPacket\r\n  }\r\n\r\n  get boxSizeMinusOne () {\r\n    return this.boxSize - 1\r\n  }\r\n\r\n  /**\r\n   * getter for number of NALUs in the stream\r\n   * @returns {number}\r\n   */\r\n  get packetCount () {\r\n    return this.iterate()\r\n  }\r\n\r\n  /**\r\n   * Returns an array of NALUs\r\n   * NOTE WELL: this yields subarrays of the NALUs in the stream, not copies.\r\n   * so changing the NALU contents also changes the stream. Beware.\r\n   * @returns {[]}\r\n   */\r\n  get packets () {\r\n    const pkts = []\r\n    this.iterate((buf, first, last) => {\r\n      const pkt = buf.subarray(first, last)\r\n      pkts.push(pkt)\r\n    })\r\n    return pkts\r\n  }\r\n\r\n  /**\r\n   * read an n-byte unsigned number\r\n   * @param buff\r\n   * @param ptr\r\n   * @param boxSize\r\n   * @returns {number}\r\n   */\r\n  static readUIntNBE (buff, ptr, boxSize) {\r\n    if (!boxSize) throw new Error('readUIntNBE error: need a boxsize')\r\n    let result = 0 | 0\r\n    for (let i = ptr; i < ptr + boxSize; i++) {\r\n      result = ((result << 8) | buff[i])\r\n    }\r\n    return result\r\n  }\r\n\r\n  static array2hex (array) { // buffer is an ArrayBuffer\r\n    return Array.prototype.map.call(new Uint8Array(array, 0, array.byteLength), x => ('00' + x.toString(16)).slice(-2)).join(' ')\r\n  }\r\n\r\n  /**\r\n   * Iterator allowing\r\n   *      for (const nalu of stream) { }\r\n   * Yields, space-efficiently, the elements of the stream\r\n   * NOTE WELL: this yields subarrays of the NALUs in the stream, not copies.\r\n   * so changing the NALU contents also changes the stream. Beware.\r\n   * @returns {{next: next}}\r\n   */\r\n  [Symbol.iterator] () {\r\n    let delim = { n: 0, s: 0, e: 0 }\r\n    return {\r\n      next: () => {\r\n        if (this.type === 'unknown' ||\r\n          this.boxSize < 1 ||\r\n          delim.n < 0)\r\n          return { value: undefined, done: true }\r\n        delim = this.nextPacket(this.buf, delim.n, this.boxSize)\r\n        while (true) {\r\n          if (delim.e > delim.s) {\r\n            const pkt = this.buf.subarray(delim.s, delim.e)\r\n            return { value: pkt, done: false }\r\n          }\r\n          if (delim.n < 0) break\r\n          delim = this.nextPacket(this.buf, delim.n, this.boxSize)\r\n        }\r\n        return { value: undefined, done: true }\r\n      }\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Iterator allowing\r\n   *      for (const n of stream.nalus()) {\r\n   *        const {rawNalu, nalu} = n\r\n   *       }\r\n   * Yields, space-efficiently, the elements of the stream\r\n   * NOTE WELL: this yields subarrays of the NALUs in the stream, not copies.\r\n   * so changing the NALU contents also changes the stream. Beware.\r\n   * @returns {{next: next}}\r\n   */\r\n  nalus () {\r\n    return {\r\n      [Symbol.iterator]: () => {\r\n        let delim = { n: 0, s: 0, e: 0 }\r\n        return {\r\n          next: () => {\r\n            if (this.type === 'unknown' ||\r\n              this.boxSize < 1 ||\r\n              delim.n < 0)\r\n              return { value: undefined, done: true }\r\n            delim = this.nextPacket(this.buf, delim.n, this.boxSize)\r\n            while (true) {\r\n              if (delim.e > delim.s) {\r\n                const nalu = this.buf.subarray(delim.s, delim.e)\r\n                const rawNalu = this.buf.subarray(delim.s - this.boxSize, delim.e)\r\n                return { value: { nalu, rawNalu }, done: false }\r\n              }\r\n              if (delim.n < 0) break\r\n              delim = this.nextPacket(this.buf, delim.n, this.boxSize)\r\n            }\r\n            return { value: undefined, done: true }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Convert an annexB stream to a packet stream in place, overwriting the buffer\r\n   * @returns {NALUStream}\r\n   */\r\n  convertToPacket () {\r\n    if (this.type === 'packet') return this\r\n    /* change 00 00 00 01 delimiters to packet lengths */\r\n    if (this.type === 'annexB' && this.boxSize === 4) {\r\n      this.iterate((buff, first, last) => {\r\n        let p = first - 4\r\n        if (p < 0) throw new Error('NALUStream error: Unexpected packet format')\r\n        const len = last - first\r\n        buff[p++] = 0xff & (len >> 24)\r\n        buff[p++] = 0xff & (len >> 16)\r\n        buff[p++] = 0xff & (len >> 8)\r\n        buff[p++] = 0xff & len\r\n      })\r\n    } else if (this.type === 'annexB' && this.boxSize === 3) {\r\n      /* change 00 00 01 delimiters to packet lengths */\r\n      this.iterate((buff, first, last) => {\r\n        let p = first - 3\r\n        if (p < 0) throw new Error('Unexpected packet format')\r\n        const len = last - first\r\n        if (this.strict && (0xff & (len >> 24) !== 0))\r\n          throw new Error('NALUStream error: Packet too long to store length when boxLenMinusOne is 2')\r\n        buff[p++] = 0xff & (len >> 16)\r\n        buff[p++] = 0xff & (len >> 8)\r\n        buff[p++] = 0xff & len\r\n      })\r\n    }\r\n    this.type = 'packet'\r\n    this.nextPacket = this.nextLengthCountedPacket\r\n\r\n    return this\r\n  }\r\n\r\n  iterate (callback) {\r\n    if (this.type === 'unknown') return 0\r\n    if (this.boxSize < 1) return 0\r\n    let packetCount = 0\r\n    let delim = this.nextPacket(this.buf, 0, this.boxSize)\r\n    while (true) {\r\n      if (delim.e > delim.s) {\r\n        packetCount++\r\n        if (typeof callback === 'function') callback(this.buf, delim.s, delim.e)\r\n      }\r\n      if (delim.n < 0) break\r\n      delim = this.nextPacket(this.buf, delim.n, this.boxSize)\r\n    }\r\n    return packetCount\r\n  }\r\n\r\n  /**\r\n   * iterator helper for delimited streams either 00 00 01  or 00 00 00 01\r\n   * @param buf\r\n   * @param p\r\n   * @returns iterator\r\n   */\r\n  nextAnnexBPacket (buf, p) {\r\n    const buflen = buf.byteLength\r\n    const start = p\r\n    if (p === buflen) return { n: -1, s: start, e: p }\r\n    while (p < buflen) {\r\n      if (p + 2 > buflen) return { n: -1, s: start, e: buflen }\r\n      if (buf[p] === 0 && buf[p + 1] === 0) {\r\n        const d = buf[p + 2]\r\n        if (d === 1) {\r\n          /* 00 00 01 found */\r\n          return { n: p + 3, s: start, e: p }\r\n        } else if (d === 0) {\r\n          if (p + 3 > buflen) return { n: -1, s: start, e: buflen }\r\n          const e = buf[p + 3]\r\n          if (e === 1) {\r\n            /* 00 00 00 01 found */\r\n            return { n: p + 4, s: start, e: p }\r\n          }\r\n        }\r\n      }\r\n      p++\r\n    }\r\n    return { n: -1, s: start, e: p }\r\n  }\r\n\r\n  /**\r\n   * iterator helper for length-counted data\r\n   * @param buf\r\n   * @param p\r\n   * @param boxSize\r\n   * @returns {{s: *, e: *, n: *}|{s: number, e: number, message: string, n: number}}\r\n   */\r\n  nextLengthCountedPacket (buf, p, boxSize) {\r\n    const buflen = buf.byteLength\r\n    if (p < buflen) {\r\n      const plength = NALUStream.readUIntNBE(buf, p, boxSize)\r\n      if (plength < 2 || plength > buflen + boxSize) {\r\n        return { n: -2, s: 0, e: 0, message: 'bad length' }\r\n      }\r\n      return { n: p + boxSize + plength, s: p + boxSize, e: p + boxSize + plength }\r\n    }\r\n    return { n: -1, s: 0, e: 0, message: 'end of buffer' }\r\n  }\r\n\r\n  /**\r\n   * figure out type of data stream\r\n   * @returns {{boxSize: number, type: string}}\r\n   */\r\n  getType (scanLimit) {\r\n    if (this.type && this.boxSize) return { type: this.type, boxSize: this.boxSize }\r\n    /* start with a delimiter? */\r\n    if (!this.type || this.type === 'annexB') {\r\n      if (this.buf[0] === 0 && this.buf[1] === 0 && this.buf[2] === 1) {\r\n        return { type: 'annexB', boxSize: 3 }\r\n      } else if (this.buf[0] === 0 && this.buf[1] === 0 && this.buf[2] === 0 && this.buf[3] === 1) {\r\n        return { type: 'annexB', boxSize: 4 }\r\n      }\r\n    }\r\n    /* possibly packet stream with lengths */\r\n    /* try various boxSize values */\r\n    for (let boxSize = 4; boxSize >= 1; boxSize--) {\r\n      let packetCount = 0\r\n      if (this.buf.length <= boxSize) {\r\n        packetCount = -1\r\n        break\r\n      }\r\n      let delim = this.nextLengthCountedPacket(this.buf, 0, boxSize)\r\n      while (true) {\r\n        if (delim.n < -1) {\r\n          packetCount = -1\r\n          break\r\n        }\r\n        if (delim.e - delim.s) {\r\n          packetCount++\r\n          if (scanLimit && packetCount >= scanLimit) break\r\n        }\r\n        if (delim.n < 0) break\r\n        delim = this.nextLengthCountedPacket(this.buf, delim.n, boxSize)\r\n      }\r\n      if (packetCount > 0) {\r\n        return { type: 'packet', boxSize: boxSize }\r\n      }\r\n    }\r\n    if (this.strict) throw new Error('NALUStream error: cannot determine stream type or box size')\r\n    return { type: 'unknown', boxSize: -1 }\r\n  }\r\n}\r\n"]}