Skip to content

Commit

Permalink
use process.hrtime.bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp committed Sep 19, 2024
1 parent 3120dcb commit 23511a9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/livekit-rtc/src/audio_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export class AudioSource {
}

get queuedDuration(): number {
return Math.max(this.currentQueueSize - Date.now() + this.lastCapture, 0);
return Math.max(
this.currentQueueSize - Number(process.hrtime.bigint() / 1000000n) + this.lastCapture,
0,
);
}

clearQueue() {
Expand All @@ -90,7 +93,7 @@ export class AudioSource {
}

async captureFrame(frame: AudioFrame) {
const now = Date.now();
const now = Number(process.hrtime.bigint() / 1000000n);
const elapsed = this.lastCapture === 0 ? 0 : now - this.lastCapture;
this.currentQueueSize += (frame.samplesPerChannel / frame.sampleRate - elapsed) * 1000;

Expand Down

0 comments on commit 23511a9

Please sign in to comment.