Skip to content

Commit b4c4438

Browse files
committed
Enable buffering by default on beefy hardware
1 parent 03e503d commit b4c4438

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

music_assistant/controllers/streams.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
SmartFadesMixer,
7575
SmartFadesMode,
7676
)
77-
from music_assistant.helpers.util import get_ip_addresses, select_free_port
77+
from music_assistant.helpers.util import get_ip_addresses, get_total_system_memory, select_free_port
7878
from music_assistant.helpers.webserver import Webserver
7979
from music_assistant.models.core_controller import CoreController
8080
from music_assistant.models.music_provider import MusicProvider
@@ -95,6 +95,9 @@
9595
CONF_ALLOW_BUFFER: Final[str] = "allow_buffering"
9696
CONF_ALLOW_CROSSFADE_SAME_ALBUM: Final[str] = "allow_crossfade_same_album"
9797

98+
# Calculate total system memory once at module load time
99+
TOTAL_SYSTEM_MEMORY_GB: Final[float] = get_total_system_memory()
100+
98101

99102
def parse_pcm_info(content_type: str) -> tuple[int, int, int]:
100103
"""Parse PCM info from a codec/content_type string."""
@@ -181,7 +184,7 @@ async def get_config_entries(
181184
ConfigEntry(
182185
key=CONF_ALLOW_BUFFER,
183186
type=ConfigEntryType.BOOLEAN,
184-
default_value=False,
187+
default_value=TOTAL_SYSTEM_MEMORY_GB >= 8.0,
185188
label="Allow (in-memory) buffering of (track) audio",
186189
description="By default, Music Assistant tries to be as resource "
187190
"efficient as possible when streaming audio, especially considering "

music_assistant/helpers/util.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@
5050
CALLBACK_TYPE = Callable[[], None]
5151

5252

53+
def get_total_system_memory() -> float:
54+
"""Get total system memory in GB."""
55+
try:
56+
# Works on Linux and macOS
57+
total_memory_bytes = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
58+
return total_memory_bytes / (1024**3) # Convert to GB
59+
except (AttributeError, ValueError):
60+
# Fallback if sysconf is not available (e.g., Windows)
61+
# Return a conservative default to disable buffering by default
62+
return 0.0
63+
64+
5365
keyword_pattern = re.compile("title=|artist=")
5466
title_pattern = re.compile(r"title=\"(?P<title>.*?)\"")
5567
artist_pattern = re.compile(r"artist=\"(?P<artist>.*?)\"")

0 commit comments

Comments
 (0)