Skip to content

Commit 92d7634

Browse files
authored
Remove timeout and empty frame processing in Audio Source (#467)
* init * update * changeset * format
1 parent 271b0fb commit 92d7634

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.changeset/shiny-flies-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@livekit/rtc-node': patch
3+
---
4+
5+
bugfix: no more negative timeouts being set on AudioSource

packages/livekit-rtc/src/audio_source.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,19 @@ export class AudioSource {
9999
this.lastCapture = 0;
100100
this.currentQueueSize = 0;
101101
this.promise = this.newPromise();
102+
this.timeout = undefined;
102103
});
103104
}
104105

105106
async captureFrame(frame: AudioFrame) {
106107
if (this.closed) {
107108
throw new Error('AudioSource is closed');
108109
}
110+
111+
if (frame.samplesPerChannel === 0) {
112+
return;
113+
}
114+
109115
const now = Number(process.hrtime.bigint() / BigInt(1000000));
110116
const elapsed = this.lastCapture === 0 ? 0 : now - this.lastCapture;
111117
const frameDurationMs = (frame.samplesPerChannel / frame.sampleRate) * 1000;
@@ -117,9 +123,7 @@ export class AudioSource {
117123
clearTimeout(this.timeout);
118124
}
119125

120-
// remove 50ms to account for processing time
121-
// (e.g. using wait_for_playout for very small chunks)
122-
this.timeout = setTimeout(this.release, this.currentQueueSize - 50);
126+
this.timeout = setTimeout(this.release, this.currentQueueSize);
123127

124128
const req = new CaptureAudioFrameRequest({
125129
sourceHandle: this.ffiHandle.handle,

0 commit comments

Comments
 (0)