Skip to content

Commit

Permalink
🔊 Fix out-of-order log
Browse files Browse the repository at this point in the history
  • Loading branch information
geekuillaume committed Oct 17, 2020
1 parent 3f6776d commit 53dc37d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/audio/sinks/audio_sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ export abstract class AudioSink extends EventEmitter {
}

_handleAudioChunk = (chunk: AudioChunkStreamOutput) => {
const outOfOrder = this.lastReceivedChunkIndex === -1 || chunk.i !== this.lastReceivedChunkIndex + 1;
if (outOfOrder && this.lastReceivedChunkIndex !== -1) {
this.log(`Received out-of-order chunk, received chunk index: ${chunk.i}, last chunk index: ${this.lastReceivedChunkIndex}`);
}
this.lastReceivedChunkIndex = chunk.i;
const timeDelta = this.pipedSource.peer.getCurrentTime() - (chunk.i * OPUS_ENCODER_CHUNK_DURATION + this.pipedSource.startedAt);
if (timeDelta > this.pipedSource.latency) {
this.log(`Received old chunk, discarding it: ${chunk.i}, current playing chunk is ${Math.floor((this.pipedSource.peer.getCurrentTime() - this.pipedSource.startedAt) / OPUS_ENCODER_CHUNK_DURATION)}`);
// we received old chunks, discard them
return;
}
const outOfOrder = this.lastReceivedChunkIndex === -1 || chunk.i !== this.lastReceivedChunkIndex + 1;
if (outOfOrder && this.lastReceivedChunkIndex !== -1) {
this.log(`Received out-of-order chunk, received chunk index: ${chunk.i}, last chunk index: ${this.lastReceivedChunkIndex}`);
}

this.handleAudioChunk(chunk, outOfOrder);
if ((chunk.i * OPUS_ENCODER_CHUNK_DURATION) % AUDIO_SINK_EVENT_INTERVAL === 0 && chunk.i !== 0) {
Expand Down

0 comments on commit 53dc37d

Please sign in to comment.