mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
digest -> add
This commit is contained in:
+5
-5
@@ -33,7 +33,7 @@
|
||||
output.start();
|
||||
|
||||
for await (const { data } of sink.data()) {
|
||||
await mediaSource.digest(data);
|
||||
await mediaSource.add(data);
|
||||
}
|
||||
|
||||
await output.finalize();
|
||||
@@ -137,16 +137,16 @@
|
||||
// //sample.timestamp *= 2;
|
||||
// //console.log(sample);
|
||||
// //console.log(sample)
|
||||
// await sampleSource.digest(sample, { decoderConfig });
|
||||
// await sampleSource.add(sample, { decoderConfig });
|
||||
//}
|
||||
for await (const { data, timestamp } of new Metamuxer.AudioDataSink(audioTrack).data()) {
|
||||
//console.log("wow", data.timestamp);
|
||||
//console.log(sample)
|
||||
await audioDataSource.digest(data);
|
||||
await audioDataSource.add(data);
|
||||
}
|
||||
//for await (const sample of new Metamuxer.EncodedVideoSampleSink(videoTrack).samples()) {
|
||||
// //console.log(sample)
|
||||
// await videoSampleSource.digest(sample, { decoderConfig: videoDecoderConfig });
|
||||
// await videoSampleSource.add(sample, { decoderConfig: videoDecoderConfig });
|
||||
//}
|
||||
|
||||
await output.finalize();
|
||||
@@ -265,7 +265,7 @@
|
||||
output.start();
|
||||
|
||||
for await (const frame of drain.frames(0, 10)) {
|
||||
await mediaSource.digest(frame);
|
||||
await mediaSource.add(frame);
|
||||
frame.close();
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -69,7 +69,7 @@
|
||||
duration: 1e6 * 0.25,
|
||||
data: new Uint8Array(1024)
|
||||
});
|
||||
videoSource.digest(encodedVideoChunk, {
|
||||
videoSource.add(encodedVideoChunk, {
|
||||
decoderConfig: {
|
||||
codedWidth: 64,
|
||||
codedHeight: 64,
|
||||
@@ -155,14 +155,14 @@ Testing... <00:17.350>One... <00:18.125>Two...
|
||||
9. <b>justify (bottom, right)</b>.
|
||||
`;
|
||||
|
||||
//subtitleSource.digest(simpleWebvttFile);
|
||||
//subtitleSource.add(simpleWebvttFile);
|
||||
//subtitleSource.close();
|
||||
|
||||
for (let i = 0; i < 100; i++) {
|
||||
context.fillStyle = ['red', 'green', 'blue', 'yellow'][i % 4];
|
||||
context.fillRect(canvas.width * Math.random(), canvas.height * Math.random(), canvas.width * Math.random(), canvas.height * Math.random());
|
||||
|
||||
//await videoSource.digest(i / 10, 1 / 10);
|
||||
//await videoSource.add(i / 10, 1 / 10);
|
||||
}
|
||||
|
||||
let audioContext = new AudioContext();
|
||||
@@ -170,7 +170,7 @@ Testing... <00:17.350>One... <00:18.125>Two...
|
||||
let length = 10;
|
||||
let slicedAudioBuffer = sliceAudioBuffer(audioBuffer, length, audioContext);
|
||||
|
||||
await audioSource.digest(slicedAudioBuffer);
|
||||
await audioSource.add(slicedAudioBuffer);
|
||||
|
||||
await output.finalize();
|
||||
|
||||
|
||||
+7
-7
@@ -384,7 +384,7 @@ class Conversion {
|
||||
return;
|
||||
}
|
||||
|
||||
await source.digest(sample, meta);
|
||||
await source.add(sample, meta);
|
||||
this.reportProgress(track.id, sample.timestamp + sample.duration);
|
||||
}
|
||||
|
||||
@@ -470,7 +470,7 @@ class Conversion {
|
||||
return;
|
||||
}
|
||||
|
||||
await source.digest(Math.max(timestamp - this.startTimestamp, 0), duration);
|
||||
await source.add(Math.max(timestamp - this.startTimestamp, 0), duration);
|
||||
}
|
||||
|
||||
await source.close();
|
||||
@@ -498,7 +498,7 @@ class Conversion {
|
||||
return;
|
||||
}
|
||||
|
||||
await source.digest(clone);
|
||||
await source.add(clone);
|
||||
clone.close();
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ class Conversion {
|
||||
return;
|
||||
}
|
||||
|
||||
await source.digest(sample, meta);
|
||||
await source.add(sample, meta);
|
||||
this.reportProgress(track.id, sample.timestamp + sample.duration);
|
||||
}
|
||||
|
||||
@@ -663,7 +663,7 @@ class Conversion {
|
||||
return;
|
||||
}
|
||||
|
||||
await source.digest(data);
|
||||
await source.add(data);
|
||||
data.close();
|
||||
}
|
||||
|
||||
@@ -751,7 +751,7 @@ class Conversion {
|
||||
return;
|
||||
}
|
||||
|
||||
await source.digest(renderedBuffer);
|
||||
await source.add(renderedBuffer);
|
||||
|
||||
currentContextStartFrame += currentContext.length;
|
||||
|
||||
@@ -779,7 +779,7 @@ class Conversion {
|
||||
return;
|
||||
}
|
||||
|
||||
await source.digest(renderedBuffer);
|
||||
await source.add(renderedBuffer);
|
||||
}
|
||||
|
||||
await source.close();
|
||||
|
||||
+23
-23
@@ -39,7 +39,7 @@ export abstract class MediaSource {
|
||||
_offsetTimestamps = false;
|
||||
|
||||
/** @internal */
|
||||
_ensureValidDigest() {
|
||||
_ensureValidAdd() {
|
||||
if (!this._connectedTrack) {
|
||||
throw new Error('Source is not connected to an output track.');
|
||||
}
|
||||
@@ -129,15 +129,15 @@ export class EncodedVideoSampleSource extends VideoSource {
|
||||
super(codec);
|
||||
}
|
||||
|
||||
digest(sample: EncodedVideoSample, meta?: EncodedVideoChunkMetadata) {
|
||||
add(sample: EncodedVideoSample, meta?: EncodedVideoChunkMetadata) {
|
||||
if (!(sample instanceof EncodedVideoSample)) {
|
||||
throw new TypeError('sample must be an EncodedVideoSample.');
|
||||
}
|
||||
if (sample.isMetadataOnly) {
|
||||
throw new TypeError('Metadata-only samples cannot be digested.');
|
||||
throw new TypeError('Metadata-only samples cannot be added.');
|
||||
}
|
||||
|
||||
this._ensureValidDigest();
|
||||
this._ensureValidAdd();
|
||||
return this._connectedTrack!.output._muxer.addEncodedVideoSample(this._connectedTrack!, sample, meta);
|
||||
}
|
||||
}
|
||||
@@ -194,8 +194,8 @@ class VideoEncoderWrapper {
|
||||
|
||||
constructor(private source: VideoSource, private encodingConfig: VideoEncodingConfig) {}
|
||||
|
||||
async digest(videoFrame: VideoFrame, shouldClose: boolean, encodeOptions?: VideoEncoderEncodeOptions) {
|
||||
this.source._ensureValidDigest();
|
||||
async add(videoFrame: VideoFrame, shouldClose: boolean, encodeOptions?: VideoEncoderEncodeOptions) {
|
||||
this.source._ensureValidAdd();
|
||||
|
||||
// Ensure video frame size remains constant
|
||||
if (this.lastWidth !== null && this.lastHeight !== null) {
|
||||
@@ -374,12 +374,12 @@ export class VideoFrameSource extends VideoSource {
|
||||
this._encoder = new VideoEncoderWrapper(this, encodingConfig);
|
||||
}
|
||||
|
||||
digest(videoFrame: VideoFrame, encodeOptions?: VideoEncoderEncodeOptions) {
|
||||
add(videoFrame: VideoFrame, encodeOptions?: VideoEncoderEncodeOptions) {
|
||||
if (!(videoFrame instanceof VideoFrame)) {
|
||||
throw new TypeError('videoFrame must be a VideoFrame.');
|
||||
}
|
||||
|
||||
return this._encoder.digest(videoFrame, false, encodeOptions);
|
||||
return this._encoder.add(videoFrame, false, encodeOptions);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -406,7 +406,7 @@ export class CanvasSource extends VideoSource {
|
||||
this._canvas = canvas;
|
||||
}
|
||||
|
||||
digest(timestamp: number, duration = 0, encodeOptions?: VideoEncoderEncodeOptions) {
|
||||
add(timestamp: number, duration = 0, encodeOptions?: VideoEncoderEncodeOptions) {
|
||||
if (!Number.isFinite(timestamp) || timestamp < 0) {
|
||||
throw new TypeError('timestamp must be a non-negative number.');
|
||||
}
|
||||
@@ -420,7 +420,7 @@ export class CanvasSource extends VideoSource {
|
||||
alpha: 'discard',
|
||||
});
|
||||
|
||||
return this._encoder.digest(frame, true, encodeOptions);
|
||||
return this._encoder.add(frame, true, encodeOptions);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -470,7 +470,7 @@ export class MediaStreamVideoTrackSource extends VideoSource {
|
||||
return;
|
||||
}
|
||||
|
||||
void this._encoder.digest(videoFrame, true);
|
||||
void this._encoder.add(videoFrame, true);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -519,15 +519,15 @@ export class EncodedAudioSampleSource extends AudioSource {
|
||||
super(codec);
|
||||
}
|
||||
|
||||
digest(sample: EncodedAudioSample, meta?: EncodedAudioChunkMetadata) {
|
||||
add(sample: EncodedAudioSample, meta?: EncodedAudioChunkMetadata) {
|
||||
if (!(sample instanceof EncodedAudioSample)) {
|
||||
throw new TypeError('chunk must be an EncodedAudioSample.');
|
||||
}
|
||||
if (sample.isMetadataOnly) {
|
||||
throw new TypeError('Metadata-only samples cannot be digested.');
|
||||
throw new TypeError('Metadata-only samples cannot be added.');
|
||||
}
|
||||
|
||||
this._ensureValidDigest();
|
||||
this._ensureValidAdd();
|
||||
return this._connectedTrack!.output._muxer.addEncodedAudioSample(this._connectedTrack!, sample, meta);
|
||||
}
|
||||
}
|
||||
@@ -582,8 +582,8 @@ class AudioEncoderWrapper {
|
||||
|
||||
constructor(private source: AudioSource, private encodingConfig: AudioEncodingConfig) {}
|
||||
|
||||
async digest(audioData: AudioData, shouldClose: boolean) {
|
||||
this.source._ensureValidDigest();
|
||||
async add(audioData: AudioData, shouldClose: boolean) {
|
||||
this.source._ensureValidAdd();
|
||||
|
||||
// Ensure audio parameters remain constant
|
||||
if (this.lastNumberOfChannels !== null && this.lastSampleRate !== null) {
|
||||
@@ -907,12 +907,12 @@ export class AudioDataSource extends AudioSource {
|
||||
this._encoder = new AudioEncoderWrapper(this, encodingConfig);
|
||||
}
|
||||
|
||||
digest(audioData: AudioData) {
|
||||
add(audioData: AudioData) {
|
||||
if (!(audioData instanceof AudioData)) {
|
||||
throw new TypeError('audioData must be an AudioData.');
|
||||
}
|
||||
|
||||
return this._encoder.digest(audioData, false);
|
||||
return this._encoder.add(audioData, false);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -935,7 +935,7 @@ export class AudioBufferSource extends AudioSource {
|
||||
this._encoder = new AudioEncoderWrapper(this, encodingConfig);
|
||||
}
|
||||
|
||||
digest(audioBuffer: AudioBuffer) {
|
||||
add(audioBuffer: AudioBuffer) {
|
||||
if (!(audioBuffer instanceof AudioBuffer)) {
|
||||
throw new TypeError('audioBuffer must be an AudioBuffer.');
|
||||
}
|
||||
@@ -974,7 +974,7 @@ export class AudioBufferSource extends AudioSource {
|
||||
data: chunkData,
|
||||
});
|
||||
|
||||
promises.push(this._encoder.digest(audioData, true));
|
||||
promises.push(this._encoder.add(audioData, true));
|
||||
|
||||
currentRelativeFrame += framesToCopy;
|
||||
remainingFrames -= framesToCopy;
|
||||
@@ -1026,7 +1026,7 @@ export class MediaStreamAudioTrackSource extends AudioSource {
|
||||
return;
|
||||
}
|
||||
|
||||
void this._encoder.digest(audioData, true);
|
||||
void this._encoder.add(audioData, true);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1084,12 +1084,12 @@ export class TextSubtitleSource extends SubtitleSource {
|
||||
});
|
||||
}
|
||||
|
||||
digest(text: string) {
|
||||
add(text: string) {
|
||||
if (typeof text !== 'string') {
|
||||
throw new TypeError('text must be a string.');
|
||||
}
|
||||
|
||||
this._ensureValidDigest();
|
||||
this._ensureValidAdd();
|
||||
this._parser.parse(text);
|
||||
|
||||
return this._connectedTrack!.output._muxer.mutex.currentPromise;
|
||||
|
||||
Reference in New Issue
Block a user