Skip to content

Commit

Permalink
A lot of optimizations to the SlimProto provider (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Mar 10, 2024
1 parent c9eee26 commit 3989699
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 2,238 deletions.
13 changes: 13 additions & 0 deletions music_assistant/common/models/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CONF_HIDE_PLAYER,
CONF_LOG_LEVEL,
CONF_OUTPUT_CHANNELS,
CONF_SYNC_ADJUST,
CONF_VOLUME_NORMALIZATION,
CONF_VOLUME_NORMALIZATION_TARGET,
SECURE_STRING_SUBSTITUTE,
Expand Down Expand Up @@ -421,3 +422,15 @@ class CoreConfig(Config):
"Only enable when needed. Saves some bandwidth at the cost of audio quality.",
advanced=True,
)

CONF_ENTRY_SYNC_ADJUST = ConfigEntry(
key=CONF_SYNC_ADJUST,
type=ConfigEntryType.INTEGER,
range=(-500, 500),
default_value=0,
label="Audio synchronization delay correction",
description="If this player is playing audio synced with other players "
"and you always hear the audio too early or late on this player, "
"you can shift the audio a bit.",
advanced=True,
)
7 changes: 6 additions & 1 deletion music_assistant/common/models/media_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class AudioFormat(DataClassDictMixin):

def __post_init__(self):
"""Execute actions after init."""
if not self.output_format_str:
if not self.output_format_str and self.content_type.is_pcm():
self.output_format_str = (
f"pcm;codec=pcm;rate={self.sample_rate};"
f"bitrate={self.bit_depth};channels={self.channels}"
)
elif not self.output_format_str:
self.output_format_str = self.content_type.value

@property
Expand Down
1 change: 1 addition & 0 deletions music_assistant/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
CONF_GROUP_MEMBERS: Final[str] = "group_members"
CONF_HIDE_PLAYER: Final[str] = "hide_player"
CONF_ENFORCE_MP3: Final[str] = "enforce_mp3"
CONF_SYNC_ADJUST: Final[str] = "sync_adjust"

# config default values
DEFAULT_HOST: Final[str] = "0.0.0.0"
Expand Down
7 changes: 3 additions & 4 deletions music_assistant/server/controllers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,9 @@ async def resolve_stream_url(
) -> str:
"""Resolve the stream URL for the given QueueItem."""
fmt = output_codec.value
# handle raw pcm
if output_codec.is_pcm():
msg = "PCM is not possible as output format"
raise RuntimeError(msg)
# handle raw pcm without exact format specifiers
if output_codec.is_pcm() and ";" not in fmt:
fmt += f";codec=pcm;rate={44100};bitrate={16};channels={2}"
query_params = {}
base_path = "flow" if flow_mode else "single"
url = f"{self._server.base_url}/{queue_item.queue_id}/{base_path}/{queue_item.queue_item_id}.{fmt}" # noqa: E501
Expand Down
19 changes: 6 additions & 13 deletions music_assistant/server/providers/airplay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from music_assistant.common.models.config_entries import (
CONF_ENTRY_CROSSFADE,
CONF_ENTRY_CROSSFADE_DURATION,
CONF_ENTRY_SYNC_ADJUST,
ConfigEntry,
ConfigValueType,
)
Expand All @@ -35,6 +36,7 @@
from music_assistant.common.models.media_items import AudioFormat
from music_assistant.common.models.player import DeviceInfo, Player
from music_assistant.common.models.player_queue import PlayerQueue
from music_assistant.constants import CONF_SYNC_ADJUST
from music_assistant.server.helpers.process import check_output
from music_assistant.server.models.player_provider import PlayerProvider

Expand All @@ -51,8 +53,9 @@
CONF_ENCRYPTION = "encryption"
CONF_ALAC_ENCODE = "alac_encode"
CONF_VOLUME_START = "volume_start"
CONF_SYNC_ADJUST = "sync_adjust"
CONF_PASSWORD = "password"


PLAYER_CONFIG_ENTRIES = (
CONF_ENTRY_CROSSFADE,
CONF_ENTRY_CROSSFADE_DURATION,
Expand All @@ -74,20 +77,10 @@
"(lossless) ALAC at the cost of a bit CPU.",
advanced=True,
),
ConfigEntry(
key=CONF_SYNC_ADJUST,
type=ConfigEntryType.INTEGER,
range=(-500, 500),
default_value=0,
label="Audio synchronization delay correction",
description="If this player is playing audio synced with other players "
"and you always hear the audio too early or late on this player, "
"you can shift the audio a bit.",
advanced=True,
),
CONF_ENTRY_SYNC_ADJUST,
ConfigEntry(
key=CONF_PASSWORD,
type=ConfigEntryType.STRING,
type=ConfigEntryType.SECURE_STRING,
default_value=None,
required=False,
label="Device password",
Expand Down
Loading

0 comments on commit 3989699

Please sign in to comment.