Skip to content

Commit

Permalink
🐛 Fix bug with local device audio push chunks before having synchroni…
Browse files Browse the repository at this point in the history
…zed timedelta with peer leading to silence
  • Loading branch information
geekuillaume committed Oct 17, 2020
1 parent 53dc37d commit 43f54b2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/audio/sinks/localdevice_sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class LocalDeviceSink extends AudioSink {

const flushDriftHistory = () => {
// in some situation (audio source latency change, peer timedelta big change), we flush the drift history so that we can correct quickly for this change
this.audioBufferTransformer.ignoreDriftFor = 0;
this.audioClockDriftHistory.flush();
};
// we keep a reference here instead of using this.pipedSource to always be able remove the event listeners in the clean stream
Expand Down Expand Up @@ -112,6 +113,13 @@ export class LocalDeviceSink extends AudioSink {
this.audioBufferTransformer.ignoreDriftFor = 0;
}
const { bufferTimestamp, buffer } = this.audioBufferTransformer.transformChunk(chunk, (data.i * OPUS_ENCODER_CHUNK_SAMPLES_COUNT));

const bufferTimestampDelta = ((bufferTimestamp - this.audioStream.getPosition()) / this.rate) * 1000;
if (bufferTimestampDelta < 0 || bufferTimestampDelta > this.latency + this.latencyCorrection + 1000) {
// if we are trying to push a buffer already in the past or too far in the future, do nothing
return;
}

try {
this.audioStream.pushAudioChunk(bufferTimestamp, buffer);
} catch (e) {
Expand Down

0 comments on commit 43f54b2

Please sign in to comment.