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 untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 10 additions and 5 deletions

View file

@ -253,13 +253,18 @@ class AudioConverter(Thread, ABC):
), 'The stdout is closed for the ffmpeg process' ), 'The stdout is closed for the ffmpeg process'
self._ffmpeg_terminated.clear() self._ffmpeg_terminated.clear()
try: try:
data = await asyncio.wait_for( reader = asyncio.create_task(self.ffmpeg.stdout.read(self._chunk_size))
self.ffmpeg.stdout.read(self._chunk_size), timeout data = await asyncio.wait_for(reader, timeout)
)
self._out_queue.put(data) self._out_queue.put(data)
except asyncio.TimeoutError: except asyncio.TimeoutError:
self._out_queue.put(b'') pass
except Exception as e:
self.logger.warning('Audio proxy error: %s', e)
break
self._out_queue.put(b'')
def write(self, data: bytes): 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__) self.logger.debug('Timeout on converter %s', converter.__class__.__name__)
# Continue only if the converter hasn't terminated # Continue only if the converter hasn't terminated
return self._converter_terminated.is_set() return not self._converter_terminated.is_set()
@override @override
def run(self): def run(self):