@ahmedrowaihi/mediabunny 1.65.2-beta.577 → 1.65.2-beta.581

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46798,9 +46798,9 @@ ${cue.notes ?? ""}`;
46798
46798
  let offset = 0;
46799
46799
  const size = view2.getUint32(offset, false);
46800
46800
  offset += 4;
46801
- const boxType2 = view2.getUint32(offset, false);
46801
+ const boxType = view2.getUint32(offset, false);
46802
46802
  offset += 4;
46803
- if (boxType2 !== 1886614376) {
46803
+ if (boxType !== 1886614376) {
46804
46804
  return null;
46805
46805
  }
46806
46806
  if (size > pssh.length) {
@@ -58574,10 +58574,10 @@ ${baseUrl}${p.getFileName()}`;
58574
58574
  }
58575
58575
  return readU323(tfhd2, offset);
58576
58576
  };
58577
- var trafDataSpan = (traf2, base) => {
58577
+ var trafDataSpan = (traf2) => {
58578
58578
  const tfhd2 = tfhdOf(traf2);
58579
58579
  const defaultSampleSize = tfhd2?.data === void 0 ? 0 : defaultSampleSizeOf(tfhd2.data);
58580
- let cursor = base;
58580
+ let cursor = 0;
58581
58581
  let start = Infinity;
58582
58582
  for (const trun2 of trunsOf(traf2)) {
58583
58583
  const data = trun2.data;
@@ -58586,7 +58586,7 @@ ${baseUrl}${p.getFileName()}`;
58586
58586
  }
58587
58587
  const flags = boxFlags(data);
58588
58588
  if (flags & TRUN_DATA_OFFSET_PRESENT) {
58589
- cursor = base + trunDataOffset(data);
58589
+ cursor = trunDataOffset(data);
58590
58590
  }
58591
58591
  start = Math.min(start, cursor);
58592
58592
  const count = readU323(data, 4);
@@ -58609,7 +58609,7 @@ ${baseUrl}${p.getFileName()}`;
58609
58609
  }
58610
58610
  }
58611
58611
  }
58612
- return { start: start === Infinity ? base : start, end: cursor };
58612
+ return { start: start === Infinity ? 0 : start, end: cursor };
58613
58613
  };
58614
58614
  var baseDataOffsetsOf = (moof2, geometry) => {
58615
58615
  const { moofOffset, mdatDataStart, mdatLength } = geometry;
@@ -58619,28 +58619,30 @@ ${baseUrl}${p.getFileName()}`;
58619
58619
  const tfhd2 = tfhdOf(traf2);
58620
58620
  const data = tfhd2?.data;
58621
58621
  const flags = data === void 0 ? 0 : boxFlags(data);
58622
+ const span = trafDataSpan(traf2);
58623
+ const fits = (candidate) => candidate + span.start >= mdatDataStart && candidate + span.end <= mdatDataStart + mdatLength;
58622
58624
  let base;
58623
58625
  if (data !== void 0 && flags & TFHD_BASE_DATA_OFFSET_PRESENT) {
58624
58626
  base = Number(new DataView(data.buffer, data.byteOffset, data.byteLength).getBigUint64(8));
58625
58627
  } else if (flags & TFHD_DEFAULT_BASE_IS_MOOF) {
58626
58628
  base = moofOffset;
58627
58629
  } else {
58628
- const fits = (candidate) => {
58629
- const span = trafDataSpan(traf2, candidate);
58630
- return span.start >= mdatDataStart && span.end <= mdatDataStart + mdatLength;
58631
- };
58632
58630
  base = previousEnd !== moofOffset && !fits(previousEnd) && fits(moofOffset) ? moofOffset : previousEnd;
58633
58631
  }
58634
- resolved.push({ trackId: data === void 0 ? 0 : readU323(data, 4), base });
58635
- previousEnd = trafDataSpan(traf2, base).end;
58632
+ resolved.push({
58633
+ trackId: data === void 0 ? 0 : readU323(data, 4),
58634
+ base,
58635
+ // Only a base that is the moof moves what its offsets point at when that moof grows
58636
+ followsMoof: base === moofOffset
58637
+ });
58638
+ previousEnd = base + span.end;
58636
58639
  }
58637
58640
  return resolved;
58638
58641
  };
58639
- var offsetsFollowMoof = (moof2, geometry) => baseDataOffsetsOf(moof2, geometry).map(({ base }) => base === geometry.moofOffset);
58640
58642
  var shiftTrunDataOffsets = (moof2, delta, geometry) => {
58641
- const follows = offsetsFollowMoof(moof2, geometry);
58643
+ const resolved = baseDataOffsetsOf(moof2, geometry);
58642
58644
  for (const [index, traf2] of trafsOf(moof2).entries()) {
58643
- if (!follows[index]) {
58645
+ if (!resolved[index].followsMoof) {
58644
58646
  continue;
58645
58647
  }
58646
58648
  for (const trun2 of trunsOf(traf2)) {
@@ -58653,23 +58655,12 @@ ${baseUrl}${p.getFileName()}`;
58653
58655
  }
58654
58656
  }
58655
58657
  }
58658
+ return resolved;
58656
58659
  };
58657
- var boxType = (bytes2, offset) => String.fromCharCode(bytes2[offset], bytes2[offset + 1], bytes2[offset + 2], bytes2[offset + 3]);
58658
58660
  var parseBoxes = (bytes2, start, end) => {
58659
58661
  const boxes = [];
58660
- let offset = start;
58661
- while (offset + 8 <= end) {
58662
- let size = readU323(bytes2, offset);
58663
- const type = boxType(bytes2, offset + 4);
58664
- let headerSize = 8;
58665
- if (size === 1) {
58666
- size = readU323(bytes2, offset + 12);
58667
- headerSize = 16;
58668
- } else if (size === 0) {
58669
- size = end - offset;
58670
- }
58671
- const contentStart = offset + headerSize;
58672
- const contentEnd = offset + size;
58662
+ const view2 = new DataView(bytes2.buffer, bytes2.byteOffset, bytes2.byteLength);
58663
+ eachBox(view2, start, end, (type, contentStart, contentEnd) => {
58673
58664
  const sampleEntryPrefix = SAMPLE_ENTRY_PREFIX[type];
58674
58665
  if (CONTAINERS.has(type)) {
58675
58666
  boxes.push({ type, children: parseBoxes(bytes2, contentStart, contentEnd) });
@@ -58689,8 +58680,7 @@ ${baseUrl}${p.getFileName()}`;
58689
58680
  } else {
58690
58681
  boxes.push({ type, data: copyOf(bytes2, contentStart, contentEnd) });
58691
58682
  }
58692
- offset = contentEnd;
58693
- }
58683
+ });
58694
58684
  return boxes;
58695
58685
  };
58696
58686
  var measureBox = (box2) => {
@@ -62955,14 +62945,10 @@ ${baseUrl}${p.getFileName()}`;
62955
62945
  };
62956
62946
  var measureForkBox = (box2) => 8 + (box2.contents?.byteLength ?? 0) + (box2.children ?? []).filter((c) => c != null).reduce((s, c) => s + measureForkBox(c), 0);
62957
62947
  var toMutable = (box2) => parseBoxes(forkBoxToBytes(box2), 0, measureForkBox(box2))[0];
62958
- var u324 = (data, offset) => new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(offset);
62959
- var setU32 = (data, offset, value) => new DataView(data.buffer, data.byteOffset, data.byteLength).setUint32(offset, value);
62960
62948
  var SENC_ENTRIES_OFFSET = 8 + 4 + 4;
62961
- var TRUN_DATA_OFFSET_PRESENT2 = 1;
62962
- var TRUN_DATA_OFFSET_POSITION2 = 4 + 4;
62963
62949
  var parseTrun = (data, defaultSampleSize, defaultSampleDuration) => {
62964
62950
  const flags = boxFlags(data);
62965
- const sampleCount = u324(data, 4);
62951
+ const sampleCount = readU323(data, 4);
62966
62952
  let offset = 8;
62967
62953
  let dataOffsetPos = -1;
62968
62954
  if (flags & 1) {
@@ -62977,13 +62963,13 @@ ${baseUrl}${p.getFileName()}`;
62977
62963
  for (let i = 0; i < sampleCount; i++) {
62978
62964
  let duration = defaultSampleDuration;
62979
62965
  if (flags & 256) {
62980
- duration = u324(data, offset);
62966
+ duration = readU323(data, offset);
62981
62967
  offset += 4;
62982
62968
  }
62983
62969
  durations.push(duration);
62984
62970
  let size = defaultSampleSize;
62985
62971
  if (flags & 512) {
62986
- size = u324(data, offset);
62972
+ size = readU323(data, offset);
62987
62973
  offset += 4;
62988
62974
  }
62989
62975
  sizes.push(size);
@@ -63035,8 +63021,8 @@ ${baseUrl}${p.getFileName()}`;
63035
63021
  var trexSampleDuration = (moov2, trackId) => {
63036
63022
  const mvex2 = (moov2.children ?? []).find((box2) => box2.type === "mvex");
63037
63023
  for (const trex2 of (mvex2?.children ?? []).filter((box2) => box2.type === "trex")) {
63038
- if (trex2.data !== void 0 && u324(trex2.data, 4) === trackId) {
63039
- return u324(trex2.data, 12);
63024
+ if (trex2.data !== void 0 && readU323(trex2.data, 4) === trackId) {
63025
+ return readU323(trex2.data, 12);
63040
63026
  }
63041
63027
  }
63042
63028
  return 0;
@@ -63050,7 +63036,7 @@ ${baseUrl}${p.getFileName()}`;
63050
63036
  }
63051
63037
  const handlerType = String.fromCharCode(...hdlr2.data.subarray(8, 12));
63052
63038
  const tkhd2 = findBox([trak2], "tkhd");
63053
- const trackId = u324(tkhd2.data, tkhd2.data[0] === 1 ? 20 : 12);
63039
+ const trackId = readU323(tkhd2.data, tkhd2.data[0] === 1 ? 20 : 12);
63054
63040
  const sampleEntry = findBox([trak2], "stsd").children[0];
63055
63041
  const defaultSampleDuration = trexSampleDuration(moov2, trackId);
63056
63042
  if (handlerType === "vide") {
@@ -63376,7 +63362,7 @@ ${baseUrl}${p.getFileName()}`;
63376
63362
  const referenceCount = view2.getUint16(offset + 2);
63377
63363
  offset += 4;
63378
63364
  for (let i = 0; i < referenceCount; i++) {
63379
- const raw = u324(data, offset);
63365
+ const raw = readU323(data, offset);
63380
63366
  const next = cursor + (raw & 2147483647);
63381
63367
  if (next > endOfInput) {
63382
63368
  Logging._warn(
@@ -63384,7 +63370,7 @@ ${baseUrl}${p.getFileName()}`;
63384
63370
  );
63385
63371
  return;
63386
63372
  }
63387
- setU32(data, offset, raw & 2147483648 | restated(next) - restated(cursor));
63373
+ writeU32(data, offset, raw & 2147483648 | restated(next) - restated(cursor));
63388
63374
  cursor = next;
63389
63375
  offset += 12;
63390
63376
  }
@@ -63465,7 +63451,7 @@ ${baseUrl}${p.getFileName()}`;
63465
63451
  };
63466
63452
  var findTrafByTrackId = (moof2, trackId) => (moof2.children ?? []).filter((b) => b.type === "traf").find((traf2) => {
63467
63453
  const tfhd2 = findBox([traf2], "tfhd");
63468
- return tfhd2?.data !== void 0 && u324(tfhd2.data, 4) === trackId;
63454
+ return tfhd2?.data !== void 0 && readU323(tfhd2.data, 4) === trackId;
63469
63455
  });
63470
63456
  var defaultSampleSizeOf2 = (tfhd2) => {
63471
63457
  const flags = boxFlags(tfhd2.data);
@@ -63479,10 +63465,9 @@ ${baseUrl}${p.getFileName()}`;
63479
63465
  if (flags & 8) {
63480
63466
  offset += 4;
63481
63467
  }
63482
- return flags & 16 ? u324(tfhd2.data, offset) : 0;
63468
+ return flags & 16 ? readU323(tfhd2.data, offset) : 0;
63483
63469
  };
63484
- var trunsOf2 = (traf2) => (traf2.children ?? []).filter((box2) => box2.type === "trun");
63485
- var trunDataOffset2 = (trun2, position) => u324(trun2.data, position) | 0;
63470
+ var trunDataOffset2 = (trun2, position) => readU323(trun2.data, position) | 0;
63486
63471
  var cmafEncryptedLayout = (init, segment, options) => {
63487
63472
  const scheme = options.scheme ?? "cbcs";
63488
63473
  const tracks = requireTracks(requireMoov(parseBoxes(init, 0, init.length)));
@@ -63525,7 +63510,7 @@ ${baseUrl}${p.getFileName()}`;
63525
63510
  const periodPerSample = [];
63526
63511
  let decodeTime = rotation === void 0 ? 0 : baseMediaDecodeTime2(traf2, track.trackId);
63527
63512
  let cursor = moofSizeBefore + 8 - (mdatDataStart - base);
63528
- for (const trun2 of trunsOf2(traf2)) {
63513
+ for (const trun2 of trunsOf(traf2)) {
63529
63514
  const parsed = parseTrun(trun2.data, defaultSampleSize, track.defaultSampleDuration);
63530
63515
  if (parsed.dataOffsetPos >= 0) {
63531
63516
  cursor = base + trunDataOffset2(trun2, parsed.dataOffsetPos) - mdatDataStart;
@@ -63581,9 +63566,9 @@ ${baseUrl}${p.getFileName()}`;
63581
63566
  }
63582
63567
  const delta = measureBox(moof2) - moofSizeBefore;
63583
63568
  for (const traf2 of (moof2.children ?? []).filter((b) => b.type === "traf")) {
63584
- for (const trun2 of trunsOf2(traf2)) {
63585
- if (boxFlags(trun2.data) & TRUN_DATA_OFFSET_PRESENT2) {
63586
- setU32(trun2.data, TRUN_DATA_OFFSET_POSITION2, u324(trun2.data, TRUN_DATA_OFFSET_POSITION2) + delta);
63569
+ for (const trun2 of trunsOf(traf2)) {
63570
+ if (boxFlags(trun2.data) & TRUN_DATA_OFFSET_PRESENT) {
63571
+ writeU32(trun2.data, TRUN_DATA_OFFSET_POSITION, readU323(trun2.data, TRUN_DATA_OFFSET_POSITION) + delta);
63587
63572
  }
63588
63573
  }
63589
63574
  }
@@ -63599,15 +63584,15 @@ ${baseUrl}${p.getFileName()}`;
63599
63584
  break;
63600
63585
  }
63601
63586
  }
63602
- setU32(findBox([traf2], "saio").data, 8, trafEnd - measureBox(senc2) + SENC_ENTRIES_OFFSET);
63587
+ writeU32(findBox([traf2], "saio").data, 8, trafEnd - measureBox(senc2) + SENC_ENTRIES_OFFSET);
63603
63588
  }
63604
63589
  };
63605
63590
  var sampleSizes = (stbl2) => {
63606
63591
  const stsz2 = findBox([stbl2], "stsz");
63607
63592
  if (stsz2?.data !== void 0) {
63608
- const uniform = u324(stsz2.data, 4);
63609
- const count2 = u324(stsz2.data, 8);
63610
- return Array.from({ length: count2 }, (_, i) => uniform !== 0 ? uniform : u324(stsz2.data, 12 + i * 4));
63593
+ const uniform = readU323(stsz2.data, 4);
63594
+ const count2 = readU323(stsz2.data, 8);
63595
+ return Array.from({ length: count2 }, (_, i) => uniform !== 0 ? uniform : readU323(stsz2.data, 12 + i * 4));
63611
63596
  }
63612
63597
  const stz2 = findBox([stbl2], "stz2");
63613
63598
  if (stz2?.data === void 0) {
@@ -63617,7 +63602,7 @@ ${baseUrl}${p.getFileName()}`;
63617
63602
  }
63618
63603
  const data = stz2.data;
63619
63604
  const fieldSize = data[7];
63620
- const count = u324(data, 8);
63605
+ const count = readU323(data, 8);
63621
63606
  const view2 = new DataView(data.buffer, data.byteOffset, data.byteLength);
63622
63607
  if (fieldSize === 16) {
63623
63608
  return Array.from({ length: count }, (_, i) => view2.getUint16(12 + i * 2));
@@ -63642,12 +63627,12 @@ ${baseUrl}${p.getFileName()}`;
63642
63627
  "The sample table has no stsc, so its samples cannot be located in their chunks."
63643
63628
  );
63644
63629
  }
63645
- const entryCount = u324(stsc2, 4);
63630
+ const entryCount = readU323(stsc2, 4);
63646
63631
  const counts = [];
63647
63632
  for (let i = 0; i < entryCount; i++) {
63648
- const firstChunk = u324(stsc2, 8 + i * 12);
63649
- const perChunk = u324(stsc2, 12 + i * 12);
63650
- const nextFirstChunk = i + 1 < entryCount ? u324(stsc2, 8 + (i + 1) * 12) : chunkCount + 1;
63633
+ const firstChunk = readU323(stsc2, 8 + i * 12);
63634
+ const perChunk = readU323(stsc2, 12 + i * 12);
63635
+ const nextFirstChunk = i + 1 < entryCount ? readU323(stsc2, 8 + (i + 1) * 12) : chunkCount + 1;
63651
63636
  for (let chunk = firstChunk; chunk < nextFirstChunk; chunk++) {
63652
63637
  counts.push(perChunk);
63653
63638
  }
@@ -63665,13 +63650,13 @@ ${baseUrl}${p.getFileName()}`;
63665
63650
  }
63666
63651
  const wide = stco2 === null;
63667
63652
  const view2 = new DataView(box2.data.buffer, box2.data.byteOffset, box2.data.byteLength);
63668
- const count = u324(box2.data, 4);
63653
+ const count = readU323(box2.data, 4);
63669
63654
  return {
63670
63655
  box: box2,
63671
63656
  wide,
63672
63657
  offsets: Array.from(
63673
63658
  { length: count },
63674
- (_, i) => wide ? Number(view2.getBigUint64(8 + i * 8)) : u324(box2.data, 8 + i * 4)
63659
+ (_, i) => wide ? Number(view2.getBigUint64(8 + i * 8)) : readU323(box2.data, 8 + i * 4)
63675
63660
  )
63676
63661
  };
63677
63662
  };
@@ -63785,7 +63770,7 @@ ${baseUrl}${p.getFileName()}`;
63785
63770
  "The senc lies beyond 4 GiB into the file, which a version 0 saio cannot state."
63786
63771
  );
63787
63772
  }
63788
- setU32((stbl2.children ?? []).filter((b) => b.type === "saio").slice(-1)[0].data, 8, at);
63773
+ writeU32((stbl2.children ?? []).filter((b) => b.type === "saio").slice(-1)[0].data, 8, at);
63789
63774
  }
63790
63775
  };
63791
63776
  var iterateFragmentSamples = function* (segment, trackIds) {
@@ -63811,7 +63796,7 @@ ${baseUrl}${p.getFileName()}`;
63811
63796
  const base = bases.get(trackId);
63812
63797
  const defaultSampleSize = defaultSampleSizeOf2(tfhd2);
63813
63798
  let cursor = measureBox(moof2) + 8 - (mdatDataStart - base);
63814
- for (const trun2 of trunsOf2(traf2)) {
63799
+ for (const trun2 of trunsOf(traf2)) {
63815
63800
  const parsed = parseTrun(trun2.data, defaultSampleSize, 0);
63816
63801
  if (parsed.dataOffsetPos >= 0) {
63817
63802
  cursor = base + trunDataOffset2(trun2, parsed.dataOffsetPos) - mdatDataStart;
@@ -65743,10 +65728,9 @@ ${baseUrl}${p.getFileName()}`;
65743
65728
  mdatDataStart: moofEnd + 8,
65744
65729
  mdatLength: readU323(segment, moofEnd) - 8
65745
65730
  };
65746
- shiftTrunDataOffsets(moof2, added, geometry);
65747
- const follows = offsetsFollowMoof(moof2, geometry);
65731
+ const resolved = shiftTrunDataOffsets(moof2, added, geometry);
65748
65732
  for (let index = trafs.indexOf(traf2); index < trafs.length; index++) {
65749
- if (follows[index]) {
65733
+ if (resolved[index].followsMoof) {
65750
65734
  shiftSaioOffsets(trafs[index], added);
65751
65735
  }
65752
65736
  }