File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 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
7878from music_assistant .helpers .webserver import Webserver
7979from music_assistant .models .core_controller import CoreController
8080from music_assistant .models .music_provider import MusicProvider
9595CONF_ALLOW_BUFFER : Final [str ] = "allow_buffering"
9696CONF_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
99102def 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 "
Original file line number Diff line number Diff line change 5050CALLBACK_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+
5365keyword_pattern = re .compile ("title=|artist=" )
5466title_pattern = re .compile (r"title=\"(?P<title>.*?)\"" )
5567artist_pattern = re .compile (r"artist=\"(?P<artist>.*?)\"" )
You can’t perform that action at this time.
0 commit comments