mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Make samples disposable
This commit is contained in:
@@ -12,7 +12,7 @@ Here's a long list of stuff this library does:
|
|||||||
- Converting media files
|
- Converting media files
|
||||||
- Hardware-accelerated decoding & encoding (via the WebCodecs API)
|
- Hardware-accelerated decoding & encoding (via the WebCodecs API)
|
||||||
- Support for multiple video, audio and subtitle tracks
|
- Support for multiple video, audio and subtitle tracks
|
||||||
- Read & write support for many container formats (.mp4, .mov, .webm, .mkv, .mp3, .wav, .ogg, .aac, .flac), including variations such as MP4 with Fast Start, fragmented MP4, or streamable Matroska
|
- Read & write support for many container formats (.mp4, .mov, .webm, .mkv, .mp3, .wav, .ogg, .aac, .flac), including variations such as MP4 with Fast Start, fragmented MP4, streamable Matroska, transparent WebM, etc.
|
||||||
- Support for 25 different codecs
|
- Support for 25 different codecs
|
||||||
- Lazy, optimized, on-demand file reading
|
- Lazy, optimized, on-demand file reading
|
||||||
- Input and output streaming, arbitrary file size support
|
- Input and output streaming, arbitrary file size support
|
||||||
|
|||||||
+3
-5
@@ -8,10 +8,12 @@
|
|||||||
|
|
||||||
import { Demuxer } from './demuxer';
|
import { Demuxer } from './demuxer';
|
||||||
import { InputFormat } from './input-format';
|
import { InputFormat } from './input-format';
|
||||||
import { assert } from './misc';
|
import { assert, polyfillSymbolDispose } from './misc';
|
||||||
import { Reader } from './reader';
|
import { Reader } from './reader';
|
||||||
import { Source } from './source';
|
import { Source } from './source';
|
||||||
|
|
||||||
|
polyfillSymbolDispose();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The options for creating an Input object.
|
* The options for creating an Input object.
|
||||||
* @group Input files & tracks
|
* @group Input files & tracks
|
||||||
@@ -24,10 +26,6 @@ export type InputOptions<S extends Source = Source> = {
|
|||||||
source: S;
|
source: S;
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
|
||||||
// @ts-expect-error Readonly
|
|
||||||
Symbol.dispose ??= Symbol('Symbol.dispose');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an input media file. This is the root object from which all media read operations start.
|
* Represents an input media file. This is the root object from which all media read operations start.
|
||||||
* @group Input files & tracks
|
* @group Input files & tracks
|
||||||
|
|||||||
@@ -780,3 +780,9 @@ export const uint8ArraysAreEqual = (a: Uint8Array, b: Uint8Array) => {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const polyfillSymbolDispose = () => {
|
||||||
|
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
|
||||||
|
// @ts-expect-error Readonly
|
||||||
|
Symbol.dispose ??= Symbol('Symbol.dispose');
|
||||||
|
};
|
||||||
|
|||||||
+15
-2
@@ -16,8 +16,11 @@ import {
|
|||||||
toUint8Array,
|
toUint8Array,
|
||||||
SetRequired,
|
SetRequired,
|
||||||
isFirefox,
|
isFirefox,
|
||||||
|
polyfillSymbolDispose,
|
||||||
} from './misc';
|
} from './misc';
|
||||||
|
|
||||||
|
polyfillSymbolDispose();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metadata used for VideoSample initialization.
|
* Metadata used for VideoSample initialization.
|
||||||
* @group Samples
|
* @group Samples
|
||||||
@@ -49,7 +52,7 @@ export type VideoSampleInit = {
|
|||||||
* @group Samples
|
* @group Samples
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export class VideoSample {
|
export class VideoSample implements Disposable {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_data!: VideoFrame | OffscreenCanvas | Uint8Array | null;
|
_data!: VideoFrame | OffscreenCanvas | Uint8Array | null;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
@@ -736,6 +739,11 @@ export class VideoSample {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||||
(this.duration as number) = newDuration;
|
(this.duration as number) = newDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Calls `.close()`. */
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isVideoFrame = (x: unknown): x is VideoFrame => {
|
const isVideoFrame = (x: unknown): x is VideoFrame => {
|
||||||
@@ -840,7 +848,7 @@ export type AudioSampleCopyToOptions = {
|
|||||||
* @group Samples
|
* @group Samples
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export class AudioSample {
|
export class AudioSample implements Disposable {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_data: AudioData | Uint8Array;
|
_data: AudioData | Uint8Array;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
@@ -1276,6 +1284,11 @@ export class AudioSample {
|
|||||||
(this.timestamp as number) = newTimestamp;
|
(this.timestamp as number) = newTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Calls `.close()`. */
|
||||||
|
[Symbol.dispose]() {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
static* _fromAudioBuffer(audioBuffer: AudioBuffer, timestamp: number) {
|
static* _fromAudioBuffer(audioBuffer: AudioBuffer, timestamp: number) {
|
||||||
if (!(audioBuffer instanceof AudioBuffer)) {
|
if (!(audioBuffer instanceof AudioBuffer)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user