mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-01 04:43:51 +02:00
Remove setTimestamp for AudioSample, add override options to its clone method
This commit is contained in:
+2
-1
@@ -650,7 +650,8 @@ export class AudioDecoderWrapper extends DecoderWrapper<AudioSample> {
|
||||
|
||||
// Round the timestamp to the sample rate
|
||||
const sampleRate = decoderConfig.sampleRate;
|
||||
sample.setTimestamp(Math.round(preciseTimestamp * sampleRate) / sampleRate);
|
||||
// @ts-expect-error Readonly
|
||||
sample.timestamp = Math.round(preciseTimestamp * sampleRate) / sampleRate;
|
||||
|
||||
onSample(sample);
|
||||
};
|
||||
|
||||
+2
-1
@@ -2003,7 +2003,8 @@ export class MediaStreamAudioTrackSource extends AudioSource {
|
||||
return;
|
||||
}
|
||||
|
||||
audioSample.setTimestamp(currentTimestamp + this._pauseOffset);
|
||||
// @ts-expect-error Readonly
|
||||
audioSample.timestamp = currentTimestamp + this._pauseOffset;
|
||||
|
||||
void this._encoder.add(audioSample, true)
|
||||
.catch((error) => {
|
||||
|
||||
+8
-12
@@ -1217,14 +1217,20 @@ export class AudioSample implements Disposable {
|
||||
}
|
||||
|
||||
/** Clones this audio sample. */
|
||||
clone(): AudioSample {
|
||||
clone(override?: {
|
||||
timestamp?: number;
|
||||
}): AudioSample {
|
||||
if (this._closed) {
|
||||
throw new Error('AudioSample is closed.');
|
||||
}
|
||||
|
||||
const timestamp = override?.timestamp ?? this.timestamp;
|
||||
|
||||
if (isAudioData(this._data)) {
|
||||
const sample = new AudioSample(this._data.clone());
|
||||
sample.setTimestamp(this.timestamp); // Make sure the timestamp is precise (beyond microsecond accuracy)
|
||||
|
||||
// @ts-expect-error Readonly
|
||||
sample.timestamp = timestamp; // Make sure the timestamp is precise (beyond microsecond accuracy)
|
||||
|
||||
return sample;
|
||||
} else {
|
||||
@@ -1342,16 +1348,6 @@ export class AudioSample implements Disposable {
|
||||
return audioBuffer;
|
||||
}
|
||||
|
||||
/** Sets the presentation timestamp of this audio sample, in seconds. */
|
||||
setTimestamp(newTimestamp: number) {
|
||||
if (!Number.isFinite(newTimestamp)) {
|
||||
throw new TypeError('newTimestamp must be a number.');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
(this.timestamp as number) = newTimestamp;
|
||||
}
|
||||
|
||||
/** Calls `.close()`. */
|
||||
[Symbol.dispose]() {
|
||||
this.close();
|
||||
|
||||
Reference in New Issue
Block a user