Remove setTimestamp for AudioSample, add override options to its clone method

This commit is contained in:
Vanilagy
2025-12-28 18:11:04 +01:00
parent eed49ee1d0
commit 0530c91ecd
3 changed files with 12 additions and 14 deletions
+2 -1
View File
@@ -650,7 +650,8 @@ export class AudioDecoderWrapper extends DecoderWrapper<AudioSample> {
// Round the timestamp to the sample rate // Round the timestamp to the sample rate
const sampleRate = decoderConfig.sampleRate; const sampleRate = decoderConfig.sampleRate;
sample.setTimestamp(Math.round(preciseTimestamp * sampleRate) / sampleRate); // @ts-expect-error Readonly
sample.timestamp = Math.round(preciseTimestamp * sampleRate) / sampleRate;
onSample(sample); onSample(sample);
}; };
+2 -1
View File
@@ -2003,7 +2003,8 @@ export class MediaStreamAudioTrackSource extends AudioSource {
return; return;
} }
audioSample.setTimestamp(currentTimestamp + this._pauseOffset); // @ts-expect-error Readonly
audioSample.timestamp = currentTimestamp + this._pauseOffset;
void this._encoder.add(audioSample, true) void this._encoder.add(audioSample, true)
.catch((error) => { .catch((error) => {
+8 -12
View File
@@ -1217,14 +1217,20 @@ export class AudioSample implements Disposable {
} }
/** Clones this audio sample. */ /** Clones this audio sample. */
clone(): AudioSample { clone(override?: {
timestamp?: number;
}): AudioSample {
if (this._closed) { if (this._closed) {
throw new Error('AudioSample is closed.'); throw new Error('AudioSample is closed.');
} }
const timestamp = override?.timestamp ?? this.timestamp;
if (isAudioData(this._data)) { if (isAudioData(this._data)) {
const sample = new AudioSample(this._data.clone()); 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; return sample;
} else { } else {
@@ -1342,16 +1348,6 @@ export class AudioSample implements Disposable {
return audioBuffer; 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()`. */ /** Calls `.close()`. */
[Symbol.dispose]() { [Symbol.dispose]() {
this.close(); this.close();