Fix: Qobuz stream disconnects abruptly (#448)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 7 Aug 2022 22:04:47 +0000 (00:04 +0200)
committerGitHub <noreply@github.com>
Sun, 7 Aug 2022 22:04:47 +0000 (00:04 +0200)
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
music_assistant/helpers/process.py
music_assistant/helpers/resources/silence.mp3
music_assistant/music_providers/qobuz/qobuz.py

index 655fadb12a854d1f3a313c53c8e4c780e6f91fe8..98d7328662980692ec9fe60893bb05c9de7c46a3 100644 (file)
@@ -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:
index 997aafaadd23486dad476528e3f893b1a30e4cbc..c0ccf54e88355405be428d5c1357d2a12b68c1c9 100644 (file)
@@ -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
index 24f4d721040726b3ba0665224330c2e36fc0b223..38febc1b3269814069e134f6a58ff82163782828 100644 (file)
Binary files a/music_assistant/helpers/resources/silence.mp3 and b/music_assistant/helpers/resources/silence.mp3 differ
index 55a224431203cecb07d4f53c5ec7cc5d58835ca9..099a748b51da5bc0993d926d1a756e181b0c9bee 100644 (file)
@@ -361,7 +361,7 @@ class QobuzProvider(MusicProvider):
             sample_rate=int(streamdata["sampling_rate"] * 1000),
             bit_depth=streamdata["bit_depth"],
             data=streamdata,  # we need these details for reporting playback
-            expires=time.time() + 1800,  # not sure about the real allowed value
+            expires=time.time() + 600,  # not sure about the real allowed value
             direct=streamdata["url"],
             callback=self._report_playback_stopped,
         )