mediabunny 1.31.0 → 1.32.0

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.
@@ -16372,9 +16372,6 @@ var Mediabunny = (() => {
16372
16372
  var Mp3InputFormat = class extends InputFormat {
16373
16373
  /** @internal */
16374
16374
  async _canReadInput(input) {
16375
- let slice = input._reader.requestSlice(0, 10);
16376
- if (slice instanceof Promise) slice = await slice;
16377
- if (!slice) return false;
16378
16375
  let currentPos = 0;
16379
16376
  while (true) {
16380
16377
  let slice2 = input._reader.requestSlice(currentPos, ID3_V2_HEADER_SIZE);
@@ -16390,12 +16387,21 @@ var Mediabunny = (() => {
16390
16387
  if (!firstResult) {
16391
16388
  return false;
16392
16389
  }
16390
+ const firstHeader = firstResult.header;
16391
+ const xingOffset = getXingOffset(firstHeader.mpegVersionId, firstHeader.channel);
16392
+ let slice = input._reader.requestSlice(firstResult.startPos + xingOffset, 4);
16393
+ if (slice instanceof Promise) slice = await slice;
16394
+ if (!slice) return false;
16395
+ const word = readU32Be(slice);
16396
+ const isXing = word === XING || word === INFO;
16397
+ if (isXing) {
16398
+ return true;
16399
+ }
16393
16400
  currentPos = firstResult.startPos + firstResult.header.totalSize;
16394
16401
  const secondResult = await readNextMp3FrameHeader(input._reader, currentPos, currentPos + FRAME_HEADER_SIZE);
16395
16402
  if (!secondResult) {
16396
16403
  return false;
16397
16404
  }
16398
- const firstHeader = firstResult.header;
16399
16405
  const secondHeader = secondResult.header;
16400
16406
  if (firstHeader.channel !== secondHeader.channel || firstHeader.sampleRate !== secondHeader.sampleRate) {
16401
16407
  return false;
@@ -16765,6 +16771,9 @@ var Mediabunny = (() => {
16765
16771
  if (options.maxCacheSize !== void 0 && (!isNumber(options.maxCacheSize) || options.maxCacheSize < 0)) {
16766
16772
  throw new TypeError("options.maxCacheSize, when provided, must be a non-negative number.");
16767
16773
  }
16774
+ if (options.parallelism !== void 0 && (!Number.isInteger(options.parallelism) || options.parallelism < 1)) {
16775
+ throw new TypeError("options.parallelism, when provided, must be a positive number.");
16776
+ }
16768
16777
  if (options.fetchFn !== void 0 && typeof options.fetchFn !== "function") {
16769
16778
  throw new TypeError("options.fetchFn, when provided, must be a function.");
16770
16779
  }
@@ -16774,11 +16783,10 @@ var Mediabunny = (() => {
16774
16783
  this._url = url2;
16775
16784
  this._options = options;
16776
16785
  this._getRetryDelay = options.getRetryDelay ?? DEFAULT_RETRY_DELAY;
16786
+ const DEFAULT_PARALLELISM = 2;
16777
16787
  this._orchestrator = new ReadOrchestrator({
16778
16788
  maxCacheSize: options.maxCacheSize ?? 64 * 2 ** 20,
16779
- // Most files in the real-world have a single sequential access pattern, but having two in parallel can
16780
- // also happen
16781
- maxWorkerCount: 2,
16789
+ maxWorkerCount: options.parallelism ?? DEFAULT_PARALLELISM,
16782
16790
  runWorker: this._runWorker.bind(this),
16783
16791
  prefetchProfile: PREFETCH_PROFILES.network
16784
16792
  });
@@ -27742,9 +27750,11 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
27742
27750
  }
27743
27751
  this._executed = true;
27744
27752
  if (this.onProgress) {
27753
+ const durationPromises = this.utilizedTracks.map((x) => x.computeDuration());
27754
+ const duration = Math.max(0, ...await Promise.all(durationPromises));
27745
27755
  this._computeProgress = true;
27746
27756
  this._totalDuration = Math.min(
27747
- await this.input.computeDuration() - this._startTimestamp,
27757
+ duration - this._startTimestamp,
27748
27758
  this._endTimestamp - this._startTimestamp
27749
27759
  );
27750
27760
  for (const track of this.utilizedTracks) {