mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-09 16:53:47 +02:00
Add license headers, add @mediabunny/server to build process, add doc blocks, small fixes
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user