small changes for streams handling
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 29 Aug 2024 22:36:44 +0000 (00:36 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 29 Aug 2024 22:36:44 +0000 (00:36 +0200)
music_assistant/server/controllers/streams.py
music_assistant/server/helpers/audio.py

index e35deaef2a6d13045b6291ecda8fbfeceb863972..2a179adfa802ea725f17ebed0f2ab04992a53370 100644 (file)
@@ -41,6 +41,7 @@ from music_assistant.constants import (
     CONF_OUTPUT_CHANNELS,
     CONF_PUBLISH_IP,
     CONF_SAMPLE_RATES,
+    MASS_LOGO_ONLINE,
     SILENCE_FILE,
     VERBOSE_LOG_LEVEL,
 )
@@ -77,8 +78,12 @@ DEFAULT_STREAM_HEADERS = {
     "Pragma": "no-cache",
     "Connection": "close",
     "Accept-Ranges": "none",
-    "Icy-Name": "Music Assistant",
-    "Icy-Url": "https://music-assistant.io",
+}
+ICY_HEADERS = {
+    "icy-name": "Music Assistant",
+    "icy-description": "Music Assistant - Your personal music assistant",
+    "icy-version": "1",
+    "icy-logo": MASS_LOGO_ONLINE,
 }
 FLOW_DEFAULT_SAMPLE_RATE = 48000
 FLOW_DEFAULT_BIT_DEPTH = 24
@@ -303,6 +308,7 @@ class StreamsController(CoreController):
             "Accept-Ranges": "none",
             "Cache-Control": "no-cache",
             "Connection": "close",
+            "icy-name": queue_item.name,
         }
         resp = web.StreamResponse(
             status=200,
@@ -390,6 +396,7 @@ class StreamsController(CoreController):
         # prepare request, add some DLNA/UPNP compatible headers
         headers = {
             **DEFAULT_STREAM_HEADERS,
+            **ICY_HEADERS,
             "Content-Type": f"audio/{output_format.output_format_str}",
             "Accept-Ranges": "none",
             "Cache-Control": "no-cache",
@@ -944,6 +951,9 @@ class StreamsController(CoreController):
                 player.player_id, CONF_OUTPUT_CHANNELS, "stereo"
             )
             output_channels = 1 if output_channels_str != "stereo" else 2
+        if not content_type.is_lossless():
+            output_bit_depth = 16
+            output_sample_rate = min(48000, output_sample_rate)
         return AudioFormat(
             content_type=content_type,
             sample_rate=output_sample_rate,
index b5fb21044b9740260250bb6b930a169a75a4b289..be80692846c88577ac622233e44368f3ac7e4982 100644 (file)
@@ -944,7 +944,9 @@ def get_ffmpeg_args(
     elif output_format.content_type == ContentType.UNKNOWN:
         raise RuntimeError("Invalid output format specified")
     elif output_format.content_type == ContentType.AAC:
-        output_args = ["-f", "adts", output_path]
+        output_args = ["-f", "adts", "-c:a", "aac", "-b:a", "256k", output_path]
+    elif output_format.content_type == ContentType.MP3:
+        output_args = ["-f", "mp3", "-b:a", "320k", output_path]
     else:
         if output_format.content_type.is_pcm():
             output_args += ["-acodec", output_format.content_type.name.lower()]
@@ -958,6 +960,8 @@ def get_ffmpeg_args(
             str(output_format.channels),
             output_path,
         ]
+        if output_format.output_format_str == "flac":
+            output_args += ["-compression_level", "6"]
 
     # edge case: source file is not stereo - downmix to stereo
     if input_format.channels > 2 and output_format.channels == 2: