Hopefully fixed lockup bug.
This commit is contained in:
@@ -161,14 +161,27 @@ class SoundOutput:
|
||||
samples = int(self.encoder_framesize * PYMUMBLE_SAMPLERATE * 2 * self.channels) # number of samples in an encoder frame
|
||||
|
||||
self.lock.acquire()
|
||||
if len(self.pcm) and len(self.pcm[-1]) < samples:
|
||||
initial_offset = samples - len(self.pcm[-1])
|
||||
self.pcm[-1] += pcm[:initial_offset]
|
||||
else:
|
||||
initial_offset = 0
|
||||
for i in range(initial_offset, len(pcm), samples):
|
||||
self.pcm.append(pcm[i:i + samples])
|
||||
self.lock.release()
|
||||
try:
|
||||
# Prevent unbounded buffer growth - limit to 10 seconds of audio
|
||||
max_buffer_seconds = 10.0
|
||||
max_buffer_frames = int(max_buffer_seconds / self.encoder_framesize)
|
||||
|
||||
# If buffer is too full, drop oldest frames to prevent memory leak
|
||||
if len(self.pcm) > max_buffer_frames:
|
||||
frames_to_drop = len(self.pcm) - max_buffer_frames
|
||||
self.pcm = self.pcm[frames_to_drop:]
|
||||
if hasattr(self, 'Log'):
|
||||
self.Log.warning(f"Audio buffer overflow, dropped {frames_to_drop} frames")
|
||||
|
||||
if len(self.pcm) and len(self.pcm[-1]) < samples:
|
||||
initial_offset = samples - len(self.pcm[-1])
|
||||
self.pcm[-1] += pcm[:initial_offset]
|
||||
else:
|
||||
initial_offset = 0
|
||||
for i in range(initial_offset, len(pcm), samples):
|
||||
self.pcm.append(pcm[i:i + samples])
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
def clear_buffer(self):
|
||||
self.lock.acquire()
|
||||
|
||||
Reference in New Issue
Block a user