Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A lot of optimizations to the SlimProto provider #1131

Merged
merged 9 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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