Skip to content

Commit

Permalink
small changes for streams handling
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Aug 29, 2024
1 parent bfae4b1 commit 67db76f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions music_assistant/server/controllers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
CONF_OUTPUT_CHANNELS,
CONF_PUBLISH_IP,
CONF_SAMPLE_RATES,
MASS_LOGO_ONLINE,
SILENCE_FILE,
VERBOSE_LOG_LEVEL,
)
Expand Down Expand Up @@ -77,8 +78,12 @@
"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
Expand Down Expand Up @@ -303,6 +308,7 @@ async def serve_queue_item_stream(self, request: web.Request) -> web.Response:
"Accept-Ranges": "none",
"Cache-Control": "no-cache",
"Connection": "close",
"icy-name": queue_item.name,
}
resp = web.StreamResponse(
status=200,
Expand Down Expand Up @@ -390,6 +396,7 @@ async def serve_queue_flow_stream(self, request: web.Request) -> web.Response:
# 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",
Expand Down Expand Up @@ -944,6 +951,9 @@ async def _get_output_format(
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,
Expand Down
6 changes: 5 additions & 1 deletion music_assistant/server/helpers/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -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:
Expand Down

0 comments on commit 67db76f

Please sign in to comment.