mediabunny 1.25.3 → 1.25.4

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.
@@ -2783,6 +2783,55 @@ var Mediabunny = (() => {
2783
2783
  }
2784
2784
  }
2785
2785
  }
2786
+ const frameWidthBitsMinus1 = bitstream.readBits(4);
2787
+ const frameHeightBitsMinus1 = bitstream.readBits(4);
2788
+ const n1 = frameWidthBitsMinus1 + 1;
2789
+ bitstream.skipBits(n1);
2790
+ const n2 = frameHeightBitsMinus1 + 1;
2791
+ bitstream.skipBits(n2);
2792
+ let frameIdNumbersPresentFlag = 0;
2793
+ if (reducedStillPictureHeader) {
2794
+ frameIdNumbersPresentFlag = 0;
2795
+ } else {
2796
+ frameIdNumbersPresentFlag = bitstream.readBits(1);
2797
+ }
2798
+ if (frameIdNumbersPresentFlag) {
2799
+ bitstream.skipBits(4);
2800
+ bitstream.skipBits(3);
2801
+ }
2802
+ bitstream.skipBits(1);
2803
+ bitstream.skipBits(1);
2804
+ bitstream.skipBits(1);
2805
+ if (!reducedStillPictureHeader) {
2806
+ bitstream.skipBits(1);
2807
+ bitstream.skipBits(1);
2808
+ bitstream.skipBits(1);
2809
+ bitstream.skipBits(1);
2810
+ const enableOrderHint = bitstream.readBits(1);
2811
+ if (enableOrderHint) {
2812
+ bitstream.skipBits(1);
2813
+ bitstream.skipBits(1);
2814
+ }
2815
+ const seqChooseScreenContentTools = bitstream.readBits(1);
2816
+ let seqForceScreenContentTools = 0;
2817
+ if (seqChooseScreenContentTools) {
2818
+ seqForceScreenContentTools = 2;
2819
+ } else {
2820
+ seqForceScreenContentTools = bitstream.readBits(1);
2821
+ }
2822
+ if (seqForceScreenContentTools > 0) {
2823
+ const seqChooseIntegerMv = bitstream.readBits(1);
2824
+ if (!seqChooseIntegerMv) {
2825
+ bitstream.skipBits(1);
2826
+ }
2827
+ }
2828
+ if (enableOrderHint) {
2829
+ bitstream.skipBits(3);
2830
+ }
2831
+ }
2832
+ bitstream.skipBits(1);
2833
+ bitstream.skipBits(1);
2834
+ bitstream.skipBits(1);
2786
2835
  const highBitdepth = bitstream.readBits(1);
2787
2836
  let bitDepth = 8;
2788
2837
  if (seqProfile === 2 && highBitdepth) {
@@ -3700,11 +3749,40 @@ var Mediabunny = (() => {
3700
3749
 
3701
3750
  // src/sample.ts
3702
3751
  polyfillSymbolDispose();
3752
+ var lastVideoGcErrorLog = -Infinity;
3753
+ var lastAudioGcErrorLog = -Infinity;
3754
+ var finalizationRegistry = null;
3755
+ if (typeof FinalizationRegistry !== "undefined") {
3756
+ finalizationRegistry = new FinalizationRegistry((value) => {
3757
+ const now = Date.now();
3758
+ if (value.type === "video") {
3759
+ if (now - lastVideoGcErrorLog >= 1e3) {
3760
+ console.error(
3761
+ `A VideoSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your VideoSamples as soon as you're done using them.`
3762
+ );
3763
+ lastVideoGcErrorLog = now;
3764
+ }
3765
+ if (typeof VideoFrame !== "undefined" && value.data instanceof VideoFrame) {
3766
+ value.data.close();
3767
+ }
3768
+ } else {
3769
+ if (now - lastAudioGcErrorLog >= 1e3) {
3770
+ console.error(
3771
+ `An AudioSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your AudioSamples as soon as you're done using them.`
3772
+ );
3773
+ lastAudioGcErrorLog = now;
3774
+ }
3775
+ if (typeof AudioData !== "undefined" && value.data instanceof AudioData) {
3776
+ value.data.close();
3777
+ }
3778
+ }
3779
+ });
3780
+ }
3703
3781
  var VideoSample = class _VideoSample {
3704
3782
  constructor(data, init) {
3705
3783
  /** @internal */
3706
3784
  this._closed = false;
3707
- if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
3785
+ if (data instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && data instanceof SharedArrayBuffer || ArrayBuffer.isView(data)) {
3708
3786
  if (!init || typeof init !== "object") {
3709
3787
  throw new TypeError("init must be an object.");
3710
3788
  }
@@ -3814,6 +3892,7 @@ var Mediabunny = (() => {
3814
3892
  } else {
3815
3893
  throw new TypeError("Invalid data type: Must be a BufferSource or CanvasImageSource.");
3816
3894
  }
3895
+ finalizationRegistry?.register(this, { type: "video", data: this._data }, this);
3817
3896
  }
3818
3897
  /** The width of the frame in pixels after rotation. */
3819
3898
  get displayWidth() {
@@ -3880,6 +3959,7 @@ var Mediabunny = (() => {
3880
3959
  if (this._closed) {
3881
3960
  return;
3882
3961
  }
3962
+ finalizationRegistry?.unregister(this);
3883
3963
  if (isVideoFrame(this._data)) {
3884
3964
  this._data.close();
3885
3965
  } else {
@@ -4258,6 +4338,7 @@ var Mediabunny = (() => {
4258
4338
  }
4259
4339
  this._data = dataBuffer;
4260
4340
  }
4341
+ finalizationRegistry?.register(this, { type: "audio", data: this._data }, this);
4261
4342
  }
4262
4343
  /** The presentation timestamp of the sample in microseconds. */
4263
4344
  get microsecondTimestamp() {
@@ -4402,7 +4483,7 @@ var Mediabunny = (() => {
4402
4483
  }
4403
4484
  } else {
4404
4485
  const uint8Data = this._data;
4405
- const srcView = new DataView(uint8Data.buffer, uint8Data.byteOffset, uint8Data.byteLength);
4486
+ const srcView = toDataView(uint8Data);
4406
4487
  const srcFormat = this.format;
4407
4488
  const readFn = getReadFunction(srcFormat);
4408
4489
  const srcBytesPerSample = getBytesPerSample(srcFormat);
@@ -4463,6 +4544,7 @@ var Mediabunny = (() => {
4463
4544
  if (this._closed) {
4464
4545
  return;
4465
4546
  }
4547
+ finalizationRegistry?.unregister(this);
4466
4548
  if (isAudioData(this._data)) {
4467
4549
  this._data.close();
4468
4550
  } else {
@@ -25106,7 +25188,10 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
25106
25188
  targetSampleRate,
25107
25189
  startTime: this._startTimestamp,
25108
25190
  endTime: this._endTimestamp,
25109
- onSample: (sample) => this._registerAudioSample(track, trackOptions, source, sample)
25191
+ onSample: async (sample) => {
25192
+ await this._registerAudioSample(track, trackOptions, source, sample);
25193
+ sample.close();
25194
+ }
25110
25195
  });
25111
25196
  const sink = new AudioSampleSink(track);
25112
25197
  const iterator = sink.samples(this._startTimestamp, this._endTimestamp);
@@ -25115,6 +25200,7 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
25115
25200
  return;
25116
25201
  }
25117
25202
  await resampler.add(sample);
25203
+ sample.close();
25118
25204
  }
25119
25205
  await resampler.finalize();
25120
25206
  source.close();