Fixed ffmpeg/audio consumer synchronization upon timeout.

This commit is contained in:
Fabio Manganiello 2023-06-27 15:12:15 +02:00
parent 77f7cd8b90
commit a103ea49f1
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 10 additions and 5 deletions

View file

@ -253,12 +253,17 @@ class AudioConverter(Thread, ABC):
), 'The stdout is closed for the ffmpeg process'
self._ffmpeg_terminated.clear()
try:
data = await asyncio.wait_for(
self.ffmpeg.stdout.read(self._chunk_size), timeout
)
reader = asyncio.create_task(self.ffmpeg.stdout.read(self._chunk_size))
data = await asyncio.wait_for(reader, timeout)
self._out_queue.put(data)
except asyncio.TimeoutError:
pass
except Exception as e:
self.logger.warning('Audio proxy error: %s', e)
break
self._out_queue.put(b'')
def write(self, data: bytes):

View file

@ -324,7 +324,7 @@ class AudioThread(Thread, ABC):
"""
self.logger.debug('Timeout on converter %s', converter.__class__.__name__)
# Continue only if the converter hasn't terminated
return self._converter_terminated.is_set()
return not self._converter_terminated.is_set()
@override
def run(self):