perf: do not hold the audio buffer lock during disk writes
_flush_buffer_to_file wrote (and for FLAC, encoded) every chunk while holding buffer_lock, blocking the capture callback for the duration of each disk flush. Swap the buffer out under the lock and write outside. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -714,11 +714,12 @@ class SoundcardRecorder(BaseRecorder):
|
|||||||
if self.current_file is None:
|
if self.current_file is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Swap the buffer under the lock, write outside it — disk writes (and
|
||||||
|
# FLAC encoding) must not block the capture callback.
|
||||||
with self.buffer_lock:
|
with self.buffer_lock:
|
||||||
if self.audio_buffer:
|
buffered, self.audio_buffer = self.audio_buffer, []
|
||||||
for data in self.audio_buffer:
|
for data in buffered:
|
||||||
self.current_file.write(data)
|
self.current_file.write(data)
|
||||||
self.audio_buffer.clear()
|
|
||||||
|
|
||||||
def close_current_file(self):
|
def close_current_file(self):
|
||||||
"""Flush any buffered audio, then close the current recording file."""
|
"""Flush any buffered audio, then close the current recording file."""
|
||||||
|
|||||||
Reference in New Issue
Block a user