/
/
/
1"""Constants for snapcast provider."""
2
3import pathlib
4
5from music_assistant_models.enums import ContentType
6from music_assistant_models.media_items.audio_format import AudioFormat
7
8CONF_SERVER_HOST = "snapcast_server_host"
9CONF_SERVER_CONTROL_PORT = "snapcast_server_control_port"
10CONF_USE_EXTERNAL_SERVER = "snapcast_use_external_server"
11CONF_SERVER_BUFFER_SIZE = "snapcast_server_built_in_buffer_size"
12CONF_SERVER_CHUNK_MS = "snapcast_server_built_in_chunk_ms"
13CONF_SERVER_INITIAL_VOLUME = "snapcast_server_built_in_initial_volume"
14CONF_SERVER_TRANSPORT_CODEC = "snapcast_server_built_in_codec"
15CONF_SERVER_SEND_AUDIO_TO_MUTED = "snapcast_server_built_in_send_muted"
16CONF_STREAM_IDLE_THRESHOLD = "snapcast_stream_idle_threshold"
17
18
19CONF_CATEGORY_GENERIC = "generic"
20CONF_CATEGORY_BUILT_IN = "Built-in Snapserver Settings"
21
22CONF_HELP_LINK = (
23 "https://raw.githubusercontent.com/badaix/snapcast/refs/heads/master/server/etc/snapserver.conf"
24)
25
26DEFAULT_SNAPSERVER_IP = "127.0.0.1"
27DEFAULT_SNAPSERVER_PORT = 1705
28DEFAULT_SNAPSTREAM_IDLE_THRESHOLD = 60000
29DEFAULT_SNAPSERVER_PLUGIN_DIR = "/usr/share/snapserver/plug-ins"
30DEFAULT_SNAPSERVER_CONFIG_FILE = "/etc/snapserver.conf"
31SHIPPED_SNAPSERVER_CONFIG_FILE = (
32 pathlib.Path(__file__).parent / "snapserver" / "snapserver.conf"
33).resolve()
34
35# snapserver has no TCP keepalive (https://github.com/snapcast/snapcast/issues/995) and
36# never times out abruptly powered-off clients, so we poll lastSeen freshness ourselves.
37SNAPCLIENT_LIVENESS_POLL_INTERVAL = 5 # poll_interval (seconds) for snapcast players
38SNAPCLIENT_STALE_THRESHOLD = 15 # mark unavailable if lastSeen frozen this long (seconds)
39
40# Socket path template for control script communication
41# The {queue_id} placeholder will be replaced with the actual queue ID
42CONTROL_SOCKET_PATH_TEMPLATE = "/tmp/ma-snapcast-{queue_id}.sock" # noqa: S108
43
44MASS_STREAM_PREFIX = "Music Assistant - "
45MASS_ANNOUNCEMENT_POSTFIX = " (announcement)"
46SNAPWEB_DIR = pathlib.Path(__file__).parent.resolve().joinpath("snapweb")
47CONTROL_SCRIPT = pathlib.Path(__file__).parent.resolve().joinpath("control.py")
48
49DEFAULT_SNAPCAST_FORMAT = AudioFormat(
50 content_type=ContentType.PCM_S16LE,
51 sample_rate=48000,
52 # TODO: we can also use 32 bits here
53 bit_depth=16,
54 channels=2,
55)
56
57DEFAULT_SNAPCAST_PCM_FORMAT = AudioFormat(
58 # the format that is used as intermediate pcm stream,
59 # we prefer F32 here to account for volume normalization
60 content_type=ContentType.PCM_F32LE,
61 sample_rate=48000,
62 bit_depth=16,
63 channels=2,
64)
65