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

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.
@@ -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,6 +58655,7 @@ ${baseUrl}${p.getFileName()}`;
58653
58655
  }
58654
58656
  }
58655
58657
  }
58658
+ return resolved;
58656
58659
  };
58657
58660
  var boxType = (bytes2, offset) => String.fromCharCode(bytes2[offset], bytes2[offset + 1], bytes2[offset + 2], bytes2[offset + 3]);
58658
58661
  var parseBoxes = (bytes2, start, end) => {
@@ -62955,14 +62958,10 @@ ${baseUrl}${p.getFileName()}`;
62955
62958
  };
62956
62959
  var measureForkBox = (box2) => 8 + (box2.contents?.byteLength ?? 0) + (box2.children ?? []).filter((c) => c != null).reduce((s, c) => s + measureForkBox(c), 0);
62957
62960
  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
62961
  var SENC_ENTRIES_OFFSET = 8 + 4 + 4;
62961
- var TRUN_DATA_OFFSET_PRESENT2 = 1;
62962
- var TRUN_DATA_OFFSET_POSITION2 = 4 + 4;
62963
62962
  var parseTrun = (data, defaultSampleSize, defaultSampleDuration) => {
62964
62963
  const flags = boxFlags(data);
62965
- const sampleCount = u324(data, 4);
62964
+ const sampleCount = readU323(data, 4);
62966
62965
  let offset = 8;
62967
62966
  let dataOffsetPos = -1;
62968
62967
  if (flags & 1) {
@@ -62977,13 +62976,13 @@ ${baseUrl}${p.getFileName()}`;
62977
62976
  for (let i = 0; i < sampleCount; i++) {
62978
62977
  let duration = defaultSampleDuration;
62979
62978
  if (flags & 256) {
62980
- duration = u324(data, offset);
62979
+ duration = readU323(data, offset);
62981
62980
  offset += 4;
62982
62981
  }
62983
62982
  durations.push(duration);
62984
62983
  let size = defaultSampleSize;
62985
62984
  if (flags & 512) {
62986
- size = u324(data, offset);
62985
+ size = readU323(data, offset);
62987
62986
  offset += 4;
62988
62987
  }
62989
62988
  sizes.push(size);
@@ -63035,8 +63034,8 @@ ${baseUrl}${p.getFileName()}`;
63035
63034
  var trexSampleDuration = (moov2, trackId) => {
63036
63035
  const mvex2 = (moov2.children ?? []).find((box2) => box2.type === "mvex");
63037
63036
  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);
63037
+ if (trex2.data !== void 0 && readU323(trex2.data, 4) === trackId) {
63038
+ return readU323(trex2.data, 12);
63040
63039
  }
63041
63040
  }
63042
63041
  return 0;
@@ -63050,7 +63049,7 @@ ${baseUrl}${p.getFileName()}`;
63050
63049
  }
63051
63050
  const handlerType = String.fromCharCode(...hdlr2.data.subarray(8, 12));
63052
63051
  const tkhd2 = findBox([trak2], "tkhd");
63053
- const trackId = u324(tkhd2.data, tkhd2.data[0] === 1 ? 20 : 12);
63052
+ const trackId = readU323(tkhd2.data, tkhd2.data[0] === 1 ? 20 : 12);
63054
63053
  const sampleEntry = findBox([trak2], "stsd").children[0];
63055
63054
  const defaultSampleDuration = trexSampleDuration(moov2, trackId);
63056
63055
  if (handlerType === "vide") {
@@ -63376,7 +63375,7 @@ ${baseUrl}${p.getFileName()}`;
63376
63375
  const referenceCount = view2.getUint16(offset + 2);
63377
63376
  offset += 4;
63378
63377
  for (let i = 0; i < referenceCount; i++) {
63379
- const raw = u324(data, offset);
63378
+ const raw = readU323(data, offset);
63380
63379
  const next = cursor + (raw & 2147483647);
63381
63380
  if (next > endOfInput) {
63382
63381
  Logging._warn(
@@ -63384,7 +63383,7 @@ ${baseUrl}${p.getFileName()}`;
63384
63383
  );
63385
63384
  return;
63386
63385
  }
63387
- setU32(data, offset, raw & 2147483648 | restated(next) - restated(cursor));
63386
+ writeU32(data, offset, raw & 2147483648 | restated(next) - restated(cursor));
63388
63387
  cursor = next;
63389
63388
  offset += 12;
63390
63389
  }
@@ -63465,7 +63464,7 @@ ${baseUrl}${p.getFileName()}`;
63465
63464
  };
63466
63465
  var findTrafByTrackId = (moof2, trackId) => (moof2.children ?? []).filter((b) => b.type === "traf").find((traf2) => {
63467
63466
  const tfhd2 = findBox([traf2], "tfhd");
63468
- return tfhd2?.data !== void 0 && u324(tfhd2.data, 4) === trackId;
63467
+ return tfhd2?.data !== void 0 && readU323(tfhd2.data, 4) === trackId;
63469
63468
  });
63470
63469
  var defaultSampleSizeOf2 = (tfhd2) => {
63471
63470
  const flags = boxFlags(tfhd2.data);
@@ -63479,10 +63478,9 @@ ${baseUrl}${p.getFileName()}`;
63479
63478
  if (flags & 8) {
63480
63479
  offset += 4;
63481
63480
  }
63482
- return flags & 16 ? u324(tfhd2.data, offset) : 0;
63481
+ return flags & 16 ? readU323(tfhd2.data, offset) : 0;
63483
63482
  };
63484
- var trunsOf2 = (traf2) => (traf2.children ?? []).filter((box2) => box2.type === "trun");
63485
- var trunDataOffset2 = (trun2, position) => u324(trun2.data, position) | 0;
63483
+ var trunDataOffset2 = (trun2, position) => readU323(trun2.data, position) | 0;
63486
63484
  var cmafEncryptedLayout = (init, segment, options) => {
63487
63485
  const scheme = options.scheme ?? "cbcs";
63488
63486
  const tracks = requireTracks(requireMoov(parseBoxes(init, 0, init.length)));
@@ -63525,7 +63523,7 @@ ${baseUrl}${p.getFileName()}`;
63525
63523
  const periodPerSample = [];
63526
63524
  let decodeTime = rotation === void 0 ? 0 : baseMediaDecodeTime2(traf2, track.trackId);
63527
63525
  let cursor = moofSizeBefore + 8 - (mdatDataStart - base);
63528
- for (const trun2 of trunsOf2(traf2)) {
63526
+ for (const trun2 of trunsOf(traf2)) {
63529
63527
  const parsed = parseTrun(trun2.data, defaultSampleSize, track.defaultSampleDuration);
63530
63528
  if (parsed.dataOffsetPos >= 0) {
63531
63529
  cursor = base + trunDataOffset2(trun2, parsed.dataOffsetPos) - mdatDataStart;
@@ -63581,9 +63579,9 @@ ${baseUrl}${p.getFileName()}`;
63581
63579
  }
63582
63580
  const delta = measureBox(moof2) - moofSizeBefore;
63583
63581
  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);
63582
+ for (const trun2 of trunsOf(traf2)) {
63583
+ if (boxFlags(trun2.data) & TRUN_DATA_OFFSET_PRESENT) {
63584
+ writeU32(trun2.data, TRUN_DATA_OFFSET_POSITION, readU323(trun2.data, TRUN_DATA_OFFSET_POSITION) + delta);
63587
63585
  }
63588
63586
  }
63589
63587
  }
@@ -63599,15 +63597,15 @@ ${baseUrl}${p.getFileName()}`;
63599
63597
  break;
63600
63598
  }
63601
63599
  }
63602
- setU32(findBox([traf2], "saio").data, 8, trafEnd - measureBox(senc2) + SENC_ENTRIES_OFFSET);
63600
+ writeU32(findBox([traf2], "saio").data, 8, trafEnd - measureBox(senc2) + SENC_ENTRIES_OFFSET);
63603
63601
  }
63604
63602
  };
63605
63603
  var sampleSizes = (stbl2) => {
63606
63604
  const stsz2 = findBox([stbl2], "stsz");
63607
63605
  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));
63606
+ const uniform = readU323(stsz2.data, 4);
63607
+ const count2 = readU323(stsz2.data, 8);
63608
+ return Array.from({ length: count2 }, (_, i) => uniform !== 0 ? uniform : readU323(stsz2.data, 12 + i * 4));
63611
63609
  }
63612
63610
  const stz2 = findBox([stbl2], "stz2");
63613
63611
  if (stz2?.data === void 0) {
@@ -63617,7 +63615,7 @@ ${baseUrl}${p.getFileName()}`;
63617
63615
  }
63618
63616
  const data = stz2.data;
63619
63617
  const fieldSize = data[7];
63620
- const count = u324(data, 8);
63618
+ const count = readU323(data, 8);
63621
63619
  const view2 = new DataView(data.buffer, data.byteOffset, data.byteLength);
63622
63620
  if (fieldSize === 16) {
63623
63621
  return Array.from({ length: count }, (_, i) => view2.getUint16(12 + i * 2));
@@ -63642,12 +63640,12 @@ ${baseUrl}${p.getFileName()}`;
63642
63640
  "The sample table has no stsc, so its samples cannot be located in their chunks."
63643
63641
  );
63644
63642
  }
63645
- const entryCount = u324(stsc2, 4);
63643
+ const entryCount = readU323(stsc2, 4);
63646
63644
  const counts = [];
63647
63645
  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;
63646
+ const firstChunk = readU323(stsc2, 8 + i * 12);
63647
+ const perChunk = readU323(stsc2, 12 + i * 12);
63648
+ const nextFirstChunk = i + 1 < entryCount ? readU323(stsc2, 8 + (i + 1) * 12) : chunkCount + 1;
63651
63649
  for (let chunk = firstChunk; chunk < nextFirstChunk; chunk++) {
63652
63650
  counts.push(perChunk);
63653
63651
  }
@@ -63665,13 +63663,13 @@ ${baseUrl}${p.getFileName()}`;
63665
63663
  }
63666
63664
  const wide = stco2 === null;
63667
63665
  const view2 = new DataView(box2.data.buffer, box2.data.byteOffset, box2.data.byteLength);
63668
- const count = u324(box2.data, 4);
63666
+ const count = readU323(box2.data, 4);
63669
63667
  return {
63670
63668
  box: box2,
63671
63669
  wide,
63672
63670
  offsets: Array.from(
63673
63671
  { length: count },
63674
- (_, i) => wide ? Number(view2.getBigUint64(8 + i * 8)) : u324(box2.data, 8 + i * 4)
63672
+ (_, i) => wide ? Number(view2.getBigUint64(8 + i * 8)) : readU323(box2.data, 8 + i * 4)
63675
63673
  )
63676
63674
  };
63677
63675
  };
@@ -63785,7 +63783,7 @@ ${baseUrl}${p.getFileName()}`;
63785
63783
  "The senc lies beyond 4 GiB into the file, which a version 0 saio cannot state."
63786
63784
  );
63787
63785
  }
63788
- setU32((stbl2.children ?? []).filter((b) => b.type === "saio").slice(-1)[0].data, 8, at);
63786
+ writeU32((stbl2.children ?? []).filter((b) => b.type === "saio").slice(-1)[0].data, 8, at);
63789
63787
  }
63790
63788
  };
63791
63789
  var iterateFragmentSamples = function* (segment, trackIds) {
@@ -63811,7 +63809,7 @@ ${baseUrl}${p.getFileName()}`;
63811
63809
  const base = bases.get(trackId);
63812
63810
  const defaultSampleSize = defaultSampleSizeOf2(tfhd2);
63813
63811
  let cursor = measureBox(moof2) + 8 - (mdatDataStart - base);
63814
- for (const trun2 of trunsOf2(traf2)) {
63812
+ for (const trun2 of trunsOf(traf2)) {
63815
63813
  const parsed = parseTrun(trun2.data, defaultSampleSize, 0);
63816
63814
  if (parsed.dataOffsetPos >= 0) {
63817
63815
  cursor = base + trunDataOffset2(trun2, parsed.dataOffsetPos) - mdatDataStart;
@@ -65743,10 +65741,9 @@ ${baseUrl}${p.getFileName()}`;
65743
65741
  mdatDataStart: moofEnd + 8,
65744
65742
  mdatLength: readU323(segment, moofEnd) - 8
65745
65743
  };
65746
- shiftTrunDataOffsets(moof2, added, geometry);
65747
- const follows = offsetsFollowMoof(moof2, geometry);
65744
+ const resolved = shiftTrunDataOffsets(moof2, added, geometry);
65748
65745
  for (let index = trafs.indexOf(traf2); index < trafs.length; index++) {
65749
- if (follows[index]) {
65746
+ if (resolved[index].followsMoof) {
65750
65747
  shiftSaioOffsets(trafs[index], added);
65751
65748
  }
65752
65749
  }