From d9b052e9be84c8fbaf630ba83a2ce7eaf552c3e5 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Mon, 8 Aug 2022 00:04:47 +0200 Subject: [PATCH] Fix: Qobuz stream disconnects abruptly (#448) Fix: Qobuz stream disconnect abrubt Extend buffer size Shorten expiry Log the amount of time the we were buffering the stream --- music_assistant/controllers/streams.py | 11 ++++++++--- music_assistant/helpers/process.py | 4 ++-- music_assistant/helpers/resources/silence.mp3 | Bin 960621 -> 80919 bytes .../music_providers/qobuz/qobuz.py | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/music_assistant/controllers/streams.py b/music_assistant/controllers/streams.py index 655fadb1..98d73286 100644 --- a/music_assistant/controllers/streams.py +++ b/music_assistant/controllers/streams.py @@ -119,7 +119,7 @@ class StreamsController: http_site = web.TCPSite(runner, host=None, port=self._port) await http_site.start() - async def on_shutdown_event(*event: MassEvent): + async def on_shutdown_event(event: MassEvent): """Handle shutdown event.""" await http_site.stop() await runner.cleanup() @@ -668,6 +668,7 @@ class QueueStream: bytes_written = 0 chunk_num = 0 # handle incoming audio chunks + track_time_start = time() async for chunk in get_media_stream( self.mass, streamdetails, @@ -739,20 +740,24 @@ class QueueStream: self.total_seconds_streamed - self.queue.player.elapsed_time or 0 ) seconds_in_buffer = len(buffer) / self.sample_size_per_second + process_time = round(time() - track_time_start, 2) # log warning if received seconds are a lot less than expected if (stream_duration - chunk_num) > 20: self.logger.warning( - "Unexpected number of chunks received for track %s: %s/%s", + "Unexpected number of chunks received for track %s: %s/%s - process_time: %s", queue_track.uri, chunk_num, stream_duration, + process_time, ) self.logger.debug( - "end of track reached - chunk_num: %s - crossfade_buffer: %s - stream_duration: %s - player_buffer: %s", + "end of track reached - chunk_num: %s - crossfade_buffer: %s - " + "stream_duration: %s - player_buffer: %s - process_time: %s", chunk_num, seconds_in_buffer, stream_duration, player_buffered, + process_time, ) if buffer: diff --git a/music_assistant/helpers/process.py b/music_assistant/helpers/process.py index 997aafaa..c0ccf54e 100644 --- a/music_assistant/helpers/process.py +++ b/music_assistant/helpers/process.py @@ -52,7 +52,7 @@ class AsyncProcess: stdin=asyncio.subprocess.PIPE if self._enable_stdin else None, stdout=asyncio.subprocess.PIPE if self._enable_stdout else None, stderr=asyncio.subprocess.PIPE if self._enable_stderr else None, - limit=32 * 1024 * 1024, + limit=64 * 1024 * 1024, close_fds=True, ) else: @@ -61,7 +61,7 @@ class AsyncProcess: stdin=asyncio.subprocess.PIPE if self._enable_stdin else None, stdout=asyncio.subprocess.PIPE if self._enable_stdout else None, stderr=asyncio.subprocess.PIPE if self._enable_stderr else None, - limit=32 * 1024 * 102, + limit=64 * 1024 * 102, close_fds=True, ) return self diff --git a/music_assistant/helpers/resources/silence.mp3 b/music_assistant/helpers/resources/silence.mp3 index 24f4d721040726b3ba0665224330c2e36fc0b223..38febc1b3269814069e134f6a58ff82163782828 100644 GIT binary patch literal 80919 zcmeI)f25vu0EY2rwusCk5s9&q$ZT5E^uxv$%f_^hh@@Xj(UKU6j7UUHMI<64DiTp7 zN+J@GND`4KNhOh`^`2!sf8@RX>-w_mn4RxAH^+VM&-=W8eVx6#uUI#&er&qw;K4nM z&l{#`?Y`TO9J+GH=B?W|Z{4!xRQm6KCr=!hef8hRy@wAyut*j^X8K@SbM=qY+Oy6+ zXZ^Y7oqxfF7j4{h$)%TFzIp4m?K`fyZrASX_ujDoz>O<6-*W41cier?efJ-J@S!6Q zKl13&#~y#;$)}Dz``q&{y!g_~$6tB%^*7#p>+N^meeeAbKl=ESPe1$oi!Zc8+owODJaO!(@Z`b}kSFG-^a^`*Lzx&A(&)l{1>E%FY9?R@E zPG~m9kjI3EWSNypXg0=>$ApGtnUzXtHpY<0gob39l}czf#*oK^hGdzQN@zC5kjI3E zWSNypXg0=>$ApGtnUzXtHpY<0gob39l}czf#*oK^hGdzQN@zC5kjI3EWSNypXg0=> z$ApGtnUzXtHpY<0gob39l}czf#)wB9Xl3<6<1V<+IO1~uS0`Pl3ynaX5DcW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