mediabunny 1.43.0 → 1.44.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.
@@ -881,6 +881,8 @@ var Mediabunny = (() => {
881
881
  return maxIndex;
882
882
  };
883
883
  var simplifyRational = (rational) => {
884
+ assert(Number.isInteger(rational.num));
885
+ assert(Number.isInteger(rational.den));
884
886
  assert(rational.den !== 0);
885
887
  let a = Math.abs(rational.num);
886
888
  let b = Math.abs(rational.den);
@@ -2069,6 +2071,21 @@ var Mediabunny = (() => {
2069
2071
  "Video chunk metadata decoder configuration must specify a valid codedHeight (positive integer)."
2070
2072
  );
2071
2073
  }
2074
+ if (metadata.decoderConfig.displayAspectWidth !== void 0 && (!Number.isInteger(metadata.decoderConfig.displayAspectWidth) || metadata.decoderConfig.displayAspectWidth <= 0)) {
2075
+ throw new TypeError(
2076
+ "Video chunk metadata decoder configuration displayAspectWidth, when defined, must be a positive integer."
2077
+ );
2078
+ }
2079
+ if (metadata.decoderConfig.displayAspectHeight !== void 0 && (!Number.isInteger(metadata.decoderConfig.displayAspectHeight) || metadata.decoderConfig.displayAspectHeight <= 0)) {
2080
+ throw new TypeError(
2081
+ "Video chunk metadata decoder configuration displayAspectHeight, when defined, must be a positive integer."
2082
+ );
2083
+ }
2084
+ if (metadata.decoderConfig.displayAspectWidth !== void 0 !== (metadata.decoderConfig.displayAspectHeight !== void 0)) {
2085
+ throw new TypeError(
2086
+ "Video chunk metadata decoder configuration must specify both displayAspectWidth and displayAspectHeight, or neither."
2087
+ );
2088
+ }
2072
2089
  if (metadata.decoderConfig.description !== void 0) {
2073
2090
  if (!isAllowSharedBufferSource(metadata.decoderConfig.description)) {
2074
2091
  throw new TypeError(
@@ -6354,10 +6371,12 @@ var Mediabunny = (() => {
6354
6371
  assert(track.info?.type === "video");
6355
6372
  const num = readU32Be(slice);
6356
6373
  const den = readU32Be(slice);
6357
- if (num > den) {
6358
- track.info.squarePixelWidth = Math.round(track.info.width * num / den);
6359
- } else {
6360
- track.info.squarePixelHeight = Math.round(track.info.height * den / num);
6374
+ if (num > 0 && den > 0) {
6375
+ if (num > den) {
6376
+ track.info.squarePixelWidth = Math.round(track.info.width * num / den);
6377
+ } else {
6378
+ track.info.squarePixelHeight = Math.round(track.info.height * den / num);
6379
+ }
6361
6380
  }
6362
6381
  }
6363
6382
  ;
@@ -9488,14 +9507,16 @@ var Mediabunny = (() => {
9488
9507
  if (this.currentTrack.info.displayWidth !== null && this.currentTrack.info.displayHeight !== null) {
9489
9508
  const num = this.currentTrack.info.displayWidth * this.currentTrack.info.height;
9490
9509
  const den = this.currentTrack.info.displayHeight * this.currentTrack.info.width;
9491
- if (num > den) {
9492
- this.currentTrack.info.squarePixelWidth = Math.round(
9493
- this.currentTrack.info.width * num / den
9494
- );
9495
- } else {
9496
- this.currentTrack.info.squarePixelHeight = Math.round(
9497
- this.currentTrack.info.height * den / num
9498
- );
9510
+ if (num > 0 && den > 0) {
9511
+ if (num > den) {
9512
+ this.currentTrack.info.squarePixelWidth = Math.round(
9513
+ this.currentTrack.info.width * num / den
9514
+ );
9515
+ } else {
9516
+ this.currentTrack.info.squarePixelHeight = Math.round(
9517
+ this.currentTrack.info.height * den / num
9518
+ );
9519
+ }
9499
9520
  }
9500
9521
  }
9501
9522
  if (this.currentTrack.codecId === CODEC_STRING_MAP.avc) {
@@ -13711,16 +13732,20 @@ var Mediabunny = (() => {
13711
13732
  const spsInfo = parseAvcSps(spsUnit);
13712
13733
  elementaryStream.info.width = spsInfo.displayWidth;
13713
13734
  elementaryStream.info.height = spsInfo.displayHeight;
13714
- if (spsInfo.pixelAspectRatio.num > spsInfo.pixelAspectRatio.den) {
13715
- elementaryStream.info.squarePixelWidth = Math.round(
13716
- elementaryStream.info.width * spsInfo.pixelAspectRatio.num / spsInfo.pixelAspectRatio.den
13717
- );
13718
- elementaryStream.info.squarePixelHeight = elementaryStream.info.height;
13719
- } else {
13720
- elementaryStream.info.squarePixelWidth = elementaryStream.info.width;
13721
- elementaryStream.info.squarePixelHeight = Math.round(
13722
- elementaryStream.info.height * spsInfo.pixelAspectRatio.den / spsInfo.pixelAspectRatio.num
13723
- );
13735
+ const num = spsInfo.pixelAspectRatio.num;
13736
+ const den = spsInfo.pixelAspectRatio.den;
13737
+ if (num > 0 && den > 0) {
13738
+ if (num > den) {
13739
+ elementaryStream.info.squarePixelWidth = Math.round(
13740
+ elementaryStream.info.width * num / den
13741
+ );
13742
+ elementaryStream.info.squarePixelHeight = elementaryStream.info.height;
13743
+ } else {
13744
+ elementaryStream.info.squarePixelWidth = elementaryStream.info.width;
13745
+ elementaryStream.info.squarePixelHeight = Math.round(
13746
+ elementaryStream.info.height * den / num
13747
+ );
13748
+ }
13724
13749
  }
13725
13750
  elementaryStream.info.colorSpace = {
13726
13751
  primaries: COLOR_PRIMARIES_MAP_INVERSE[spsInfo.colourPrimaries],
@@ -15800,10 +15825,14 @@ var Mediabunny = (() => {
15800
15825
  if (options.maxCacheSize !== void 0 && (!isNumber(options.maxCacheSize) || options.maxCacheSize < 0)) {
15801
15826
  throw new TypeError("options.maxCacheSize, when provided, must be a non-negative number.");
15802
15827
  }
15828
+ if (options.useStreamReader !== void 0 && typeof options.useStreamReader !== "boolean") {
15829
+ throw new TypeError("options.useStreamReader, when provided, must be a boolean.");
15830
+ }
15803
15831
  super();
15804
15832
  /** @internal */
15805
15833
  this._readers = /* @__PURE__ */ new WeakMap();
15806
15834
  this._blob = blob;
15835
+ this._options = options;
15807
15836
  this._orchestrator = new ReadOrchestrator({
15808
15837
  maxCacheSize: options.maxCacheSize ?? 8 * 2 ** 20,
15809
15838
  maxWorkerCount: 4,
@@ -15825,7 +15854,7 @@ var Mediabunny = (() => {
15825
15854
  assert(worker.strictTarget);
15826
15855
  let reader = this._readers.get(worker);
15827
15856
  if (reader === void 0) {
15828
- if ("stream" in this._blob && !isWebKit()) {
15857
+ if ("stream" in this._blob && !isWebKit() && this._options.useStreamReader !== false) {
15829
15858
  const slice = this._blob.slice(worker.currentPos);
15830
15859
  reader = slice.stream().getReader();
15831
15860
  } else {