mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-30 12:23:52 +02:00
Make samples disposable
This commit is contained in:
+15
-2
@@ -16,8 +16,11 @@ import {
|
||||
toUint8Array,
|
||||
SetRequired,
|
||||
isFirefox,
|
||||
polyfillSymbolDispose,
|
||||
} from './misc';
|
||||
|
||||
polyfillSymbolDispose();
|
||||
|
||||
/**
|
||||
* Metadata used for VideoSample initialization.
|
||||
* @group Samples
|
||||
@@ -49,7 +52,7 @@ export type VideoSampleInit = {
|
||||
* @group Samples
|
||||
* @public
|
||||
*/
|
||||
export class VideoSample {
|
||||
export class VideoSample implements Disposable {
|
||||
/** @internal */
|
||||
_data!: VideoFrame | OffscreenCanvas | Uint8Array | null;
|
||||
/** @internal */
|
||||
@@ -736,6 +739,11 @@ export class VideoSample {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
(this.duration as number) = newDuration;
|
||||
}
|
||||
|
||||
/** Calls `.close()`. */
|
||||
[Symbol.dispose]() {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
const isVideoFrame = (x: unknown): x is VideoFrame => {
|
||||
@@ -840,7 +848,7 @@ export type AudioSampleCopyToOptions = {
|
||||
* @group Samples
|
||||
* @public
|
||||
*/
|
||||
export class AudioSample {
|
||||
export class AudioSample implements Disposable {
|
||||
/** @internal */
|
||||
_data: AudioData | Uint8Array;
|
||||
/** @internal */
|
||||
@@ -1276,6 +1284,11 @@ export class AudioSample {
|
||||
(this.timestamp as number) = newTimestamp;
|
||||
}
|
||||
|
||||
/** Calls `.close()`. */
|
||||
[Symbol.dispose]() {
|
||||
this.close();
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static* _fromAudioBuffer(audioBuffer: AudioBuffer, timestamp: number) {
|
||||
if (!(audioBuffer instanceof AudioBuffer)) {
|
||||
|
||||
Reference in New Issue
Block a user