SmartFadesMixer,
SmartFadesMode,
)
-from music_assistant.helpers.util import get_ip_addresses, select_free_port
+from music_assistant.helpers.util import get_ip_addresses, get_total_system_memory, select_free_port
from music_assistant.helpers.webserver import Webserver
from music_assistant.models.core_controller import CoreController
from music_assistant.models.music_provider import MusicProvider
CONF_ALLOW_BUFFER: Final[str] = "allow_buffering"
CONF_ALLOW_CROSSFADE_SAME_ALBUM: Final[str] = "allow_crossfade_same_album"
+# Calculate total system memory once at module load time
+TOTAL_SYSTEM_MEMORY_GB: Final[float] = get_total_system_memory()
+
def parse_pcm_info(content_type: str) -> tuple[int, int, int]:
"""Parse PCM info from a codec/content_type string."""
ConfigEntry(
key=CONF_ALLOW_BUFFER,
type=ConfigEntryType.BOOLEAN,
- default_value=False,
+ default_value=TOTAL_SYSTEM_MEMORY_GB >= 8.0,
label="Allow (in-memory) buffering of (track) audio",
description="By default, Music Assistant tries to be as resource "
"efficient as possible when streaming audio, especially considering "
CALLBACK_TYPE = Callable[[], None]
+def get_total_system_memory() -> float:
+ """Get total system memory in GB."""
+ try:
+ # Works on Linux and macOS
+ total_memory_bytes = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
+ return total_memory_bytes / (1024**3) # Convert to GB
+ except (AttributeError, ValueError):
+ # Fallback if sysconf is not available (e.g., Windows)
+ # Return a conservative default to disable buffering by default
+ return 0.0
+
+
keyword_pattern = re.compile("title=|artist=")
title_pattern = re.compile(r"title=\"(?P<title>.*?)\"")
artist_pattern = re.compile(r"artist=\"(?P<artist>.*?)\"")