Add license headers, add @mediabunny/server to build process, add doc blocks, small fixes

This commit is contained in:
Vanilagy
2026-05-12 15:04:32 +02:00
parent 633d1bc235
commit af43f67835
15 changed files with 197 additions and 27 deletions
+39 -11
View File
@@ -1,22 +1,49 @@
/*!
* Copyright (c) 2026-present, Vanilagy and contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { AudioSampleResource } from 'mediabunny';
import * as NodeAv from 'node-av';
import { toAudioSampleFormat } from './misc';
import { assert, toUint8Array } from '../../../src/misc';
/**
* A custom `AudioSampleResource` backed by NodeAV's
* [`Frame`](https://seydx.github.io/node-av/api/lib/classes/Frame.html), which in turn is backed by FFmpeg's
* [`AVFrame`](https://ffmpeg.org/doxygen/2.7/structAVFrame.html). You can use this resource to create `AudioSample`
* instances that are directly backed by FFmpeg's `AVFrame` without data having to be copied.
*
* @group \@mediabunny/server
* @public
*/
export class NodeAvFrameAudioSampleResource extends AudioSampleResource {
frame: NodeAv.Frame;
timestamp: number;
/** @internal */
_frame: NodeAv.Frame | null;
constructor(frame: NodeAv.Frame, timestamp: number) {
super();
const clone = frame.clone();
if (!clone) {
throw new Error('Allocation failure during frame clone.');
/**
* The NodeAV [`Frame`](https://seydx.github.io/node-av/api/lib/classes/Frame.html) instance backing this resource.
* Access throws if the resource has already been closed.
*/
get frame() {
if (!this._frame) {
throw new Error('NodeAvFrameAudioSampleResource has been closed.');
}
this.frame = clone;
this.timestamp = timestamp;
return this._frame;
}
constructor(frame: NodeAv.Frame) {
super();
if (frame.getMediaType() !== NodeAv.AVMEDIA_TYPE_AUDIO) {
throw new Error('NodeAvFrameAudioSampleResource must be initialized with an audio frame.');
}
this._frame = frame;
}
getFormat(): AudioSampleFormat {
@@ -41,11 +68,12 @@ export class NodeAvFrameAudioSampleResource extends AudioSampleResource {
}
getTimestamp(): number {
return this.timestamp;
return Number(this.frame.pts) / this.frame.timeBase.den;
}
close(): void {
this.frame.free();
this._frame = null;
}
getDataPlane(planeIndex: number): Uint8Array {