Merge branch 'main' into server

This commit is contained in:
Vanilagy
2026-05-11 21:36:38 +02:00
22 changed files with 104 additions and 75 deletions
+8 -17
View File
@@ -78,11 +78,6 @@ export abstract class MediaSource {
_closingPromise: Promise<void> | null = null;
/** @internal */
_closed = false;
/**
* @internal
* A time offset in seconds that is added to all timestamps generated by this source.
*/
_timestampOffset = 0;
/** @internal */
_ensureValidAdd() {
@@ -1664,7 +1659,7 @@ export class MediaStreamVideoTrackSource extends VideoSource {
let frameCount = 0;
let errored = false;
let lastSampleTimestamp: number | null = null;
let pauseOffset = 0;
let timestampOffset = 0;
const tick = () => {
assert(frameRate !== null);
@@ -1732,9 +1727,7 @@ export class MediaStreamVideoTrackSource extends VideoSource {
// pause. Doing it like this instead of simply keeping track of the paused time is better since
// it retains the frame rate of the underlying source.
const timeDelta = currentTimestamp - lastSampleTimestamp;
// We modify this field instead of _timestampOffset since we still might have data in flight
// in the encoder, with which we don't want to mess.
pauseOffset -= timeDelta;
timestampOffset -= timeDelta;
}
lastSampleTimestamp = currentTimestamp;
}
@@ -1762,7 +1755,7 @@ export class MediaStreamVideoTrackSource extends VideoSource {
}
}
this._timestampOffset = target - firstVideoFrameTimestamp;
timestampOffset = target - firstVideoFrameTimestamp;
}
lastSampleTimestamp = currentTimestamp;
@@ -1774,7 +1767,7 @@ export class MediaStreamVideoTrackSource extends VideoSource {
}
const sample = new VideoSample(videoFrame, {
timestamp: currentTimestamp + pauseOffset,
timestamp: currentTimestamp + timestampOffset,
});
void this._encoder.add(sample, true)
@@ -2763,7 +2756,7 @@ export class MediaStreamAudioTrackSource extends AudioSource {
let firstAudioDataTimestamp: number | null = null;
let errored = false;
let lastSampleTimestamp: number | null = null;
let pauseOffset = 0;
let timestampOffset = 0;
const onAudioSample = (audioSample: AudioSample) => {
if (errored) {
@@ -2781,9 +2774,7 @@ export class MediaStreamAudioTrackSource extends AudioSource {
// the pause. Doing it like this instead of simply keeping track of the paused time is better
// since it retains the sample rate of the underlying source.
const timeDelta = currentTimestamp - lastSampleTimestamp;
// We modify this field instead of _timestampOffset since we still might have data in flight
// in the encoder, with which we don't want to mess.
pauseOffset -= timeDelta;
timestampOffset -= timeDelta;
}
lastSampleTimestamp = currentTimestamp;
}
@@ -2811,7 +2802,7 @@ export class MediaStreamAudioTrackSource extends AudioSource {
}
}
this._timestampOffset = target - firstAudioDataTimestamp;
timestampOffset = target - firstAudioDataTimestamp;
}
lastSampleTimestamp = currentTimestamp;
@@ -2822,7 +2813,7 @@ export class MediaStreamAudioTrackSource extends AudioSource {
return;
}
audioSample.setTimestamp(currentTimestamp + pauseOffset);
audioSample.setTimestamp(currentTimestamp + timestampOffset);
void this._encoder.add(audioSample, true)
.catch((error) => {