mediabunny 1.0.6 → 1.1.1

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.
@@ -7369,18 +7369,52 @@ ${cue.notes ?? ""}`;
7369
7369
  });
7370
7370
  }
7371
7371
  }
7372
- /**
7373
- * Draws the video sample to a 2D canvas context. Rotation metadata will be taken into account.
7374
- *
7375
- * @param dx - The x-coordinate in the destination canvas at which to place the top-left corner of the source image.
7376
- * @param dy - The y-coordinate in the destination canvas at which to place the top-left corner of the source image.
7377
- * @param dWidth - The width in pixels with which to draw the image in the destination canvas.
7378
- * @param dHeight - The height in pixels with which to draw the image in the destination canvas.
7379
- */
7380
- draw(context, dx, dy, dWidth = this.displayWidth, dHeight = this.displayHeight) {
7372
+ draw(context, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
7373
+ let sx = 0;
7374
+ let sy = 0;
7375
+ let sWidth = this.displayWidth;
7376
+ let sHeight = this.displayHeight;
7377
+ let dx = 0;
7378
+ let dy = 0;
7379
+ let dWidth = this.displayWidth;
7380
+ let dHeight = this.displayHeight;
7381
+ if (arg5 !== void 0) {
7382
+ sx = arg1;
7383
+ sy = arg2;
7384
+ sWidth = arg3;
7385
+ sHeight = arg4;
7386
+ dx = arg5;
7387
+ dy = arg6;
7388
+ if (arg7 !== void 0) {
7389
+ dWidth = arg7;
7390
+ dHeight = arg8;
7391
+ } else {
7392
+ dWidth = sWidth;
7393
+ dHeight = sHeight;
7394
+ }
7395
+ } else {
7396
+ dx = arg1;
7397
+ dy = arg2;
7398
+ if (arg3 !== void 0) {
7399
+ dWidth = arg3;
7400
+ dHeight = arg4;
7401
+ }
7402
+ }
7381
7403
  if (!(typeof CanvasRenderingContext2D !== "undefined" && context instanceof CanvasRenderingContext2D || typeof OffscreenCanvasRenderingContext2D !== "undefined" && context instanceof OffscreenCanvasRenderingContext2D)) {
7382
7404
  throw new TypeError("context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.");
7383
7405
  }
7406
+ if (!Number.isFinite(sx)) {
7407
+ throw new TypeError("sx must be a number.");
7408
+ }
7409
+ if (!Number.isFinite(sy)) {
7410
+ throw new TypeError("sy must be a number.");
7411
+ }
7412
+ if (!Number.isFinite(sWidth) || sWidth < 0) {
7413
+ throw new TypeError("sWidth must be a non-negative number.");
7414
+ }
7415
+ if (!Number.isFinite(sHeight) || sHeight < 0) {
7416
+ throw new TypeError("sHeight must be a non-negative number.");
7417
+ }
7384
7418
  if (!Number.isFinite(dx)) {
7385
7419
  throw new TypeError("dx must be a number.");
7386
7420
  }
@@ -7396,6 +7430,26 @@ ${cue.notes ?? ""}`;
7396
7430
  if (this._closed) {
7397
7431
  throw new Error("VideoSample is closed.");
7398
7432
  }
7433
+ if (this.rotation === 90) {
7434
+ [sx, sy, sWidth, sHeight] = [
7435
+ sy,
7436
+ this.codedHeight - sx - sWidth,
7437
+ sHeight,
7438
+ sWidth
7439
+ ];
7440
+ } else if (this.rotation === 180) {
7441
+ [sx, sy] = [
7442
+ this.codedWidth - sx - sWidth,
7443
+ this.codedHeight - sy - sHeight
7444
+ ];
7445
+ } else if (this.rotation === 270) {
7446
+ [sx, sy, sWidth, sHeight] = [
7447
+ this.codedWidth - sy - sHeight,
7448
+ sx,
7449
+ sHeight,
7450
+ sWidth
7451
+ ];
7452
+ }
7399
7453
  const source = this.toCanvasImageSource();
7400
7454
  context.save();
7401
7455
  const centerX = dx + dWidth / 2;
@@ -7406,6 +7460,10 @@ ${cue.notes ?? ""}`;
7406
7460
  context.scale(1 / aspectRatioChange, aspectRatioChange);
7407
7461
  context.drawImage(
7408
7462
  source,
7463
+ sx,
7464
+ sy,
7465
+ sWidth,
7466
+ sHeight,
7409
7467
  -dWidth / 2,
7410
7468
  -dHeight / 2,
7411
7469
  dWidth,
@@ -8370,6 +8428,7 @@ ${cue.notes ?? ""}`;
8370
8428
  finalizeAndEmitSample(sample) {
8371
8429
  sample.setTimestamp(Math.round(sample.timestamp * this.timeResolution) / this.timeResolution);
8372
8430
  sample.setDuration(Math.round(sample.duration * this.timeResolution) / this.timeResolution);
8431
+ sample.setRotation(this.rotation);
8373
8432
  this.onSample(sample);
8374
8433
  }
8375
8434
  getDecodeQueueSize() {
@@ -13590,7 +13649,7 @@ ${cue.notes ?? ""}`;
13590
13649
  return this.readMetadataPromise ??= (async () => {
13591
13650
  this.metadataReader.pos = 0;
13592
13651
  const fileSize = await this.input.source.getSize();
13593
- while (this.metadataReader.pos < fileSize - MIN_HEADER_SIZE) {
13652
+ while (this.metadataReader.pos <= fileSize - MIN_HEADER_SIZE) {
13594
13653
  await this.metadataReader.reader.loadRange(
13595
13654
  this.metadataReader.pos,
13596
13655
  this.metadataReader.pos + MAX_HEADER_SIZE
@@ -13839,7 +13898,7 @@ ${cue.notes ?? ""}`;
13839
13898
  }
13840
13899
  readContiguousElements(reader, totalSize) {
13841
13900
  const startIndex = reader.pos;
13842
- while (reader.pos - startIndex < totalSize) {
13901
+ while (reader.pos - startIndex <= totalSize - MIN_HEADER_SIZE) {
13843
13902
  this.traverseElement(reader);
13844
13903
  }
13845
13904
  }
@@ -14653,7 +14712,7 @@ ${cue.notes ?? ""}`;
14653
14712
  size = (nextElementPos ?? segment.elementEndPos) - dataStartPos;
14654
14713
  }
14655
14714
  const endPos = dataStartPos + size;
14656
- if (endPos >= segment.elementEndPos - MIN_HEADER_SIZE) {
14715
+ if (endPos > segment.elementEndPos - MIN_HEADER_SIZE) {
14657
14716
  break;
14658
14717
  } else {
14659
14718
  clusterReader.pos = endPos;