/
/
/
1"""Constants for snapcast provider."""
2
3import pathlib
4from enum import StrEnum
5
6from music_assistant_models.enums import ContentType
7from music_assistant_models.media_items.audio_format import AudioFormat
8
9from music_assistant.constants import create_sample_rates_config_entry
10
11CONF_SERVER_HOST = "snapcast_server_host"
12CONF_SERVER_CONTROL_PORT = "snapcast_server_control_port"
13CONF_USE_EXTERNAL_SERVER = "snapcast_use_external_server"
14CONF_SERVER_BUFFER_SIZE = "snapcast_server_built_in_buffer_size"
15CONF_SERVER_CHUNK_MS = "snapcast_server_built_in_chunk_ms"
16CONF_SERVER_INITIAL_VOLUME = "snapcast_server_built_in_initial_volume"
17CONF_SERVER_TRANSPORT_CODEC = "snapcast_server_built_in_codec"
18CONF_SERVER_SEND_AUDIO_TO_MUTED = "snapcast_server_built_in_send_muted"
19CONF_STREAM_IDLE_THRESHOLD = "snapcast_stream_idle_threshold"
20
21
22CONF_CATEGORY_GENERIC = "generic"
23CONF_CATEGORY_BUILT_IN = "Built-in Snapserver Settings"
24
25CONF_HELP_LINK = (
26 "https://raw.githubusercontent.com/badaix/snapcast/refs/heads/master/server/etc/snapserver.conf"
27)
28
29# snapcast has fixed sample rate/bit depth so make this config entry static and hidden
30CONF_ENTRY_SAMPLE_RATES_SNAPCAST = create_sample_rates_config_entry(
31 supported_sample_rates=[48000], supported_bit_depths=[16], hidden=True
32)
33
34DEFAULT_SNAPSERVER_IP = "127.0.0.1"
35DEFAULT_SNAPSERVER_PORT = 1705
36DEFAULT_SNAPSTREAM_IDLE_THRESHOLD = 60000
37
38# Socket path template for control script communication
39# The {queue_id} placeholder will be replaced with the actual queue ID
40CONTROL_SOCKET_PATH_TEMPLATE = "/tmp/ma-snapcast-{queue_id}.sock" # noqa: S108
41
42MASS_STREAM_PREFIX = "Music Assistant - "
43MASS_ANNOUNCEMENT_POSTFIX = " (announcement)"
44SNAPWEB_DIR = pathlib.Path(__file__).parent.resolve().joinpath("snapweb")
45CONTROL_SCRIPT = pathlib.Path(__file__).parent.resolve().joinpath("control.py")
46
47DEFAULT_SNAPCAST_FORMAT = AudioFormat(
48 content_type=ContentType.PCM_S16LE,
49 sample_rate=48000,
50 # TODO: we can also use 32 bits here
51 bit_depth=16,
52 channels=2,
53)
54
55DEFAULT_SNAPCAST_PCM_FORMAT = AudioFormat(
56 # the format that is used as intermediate pcm stream,
57 # we prefer F32 here to account for volume normalization
58 content_type=ContentType.PCM_F32LE,
59 sample_rate=48000,
60 bit_depth=16,
61 channels=2,
62)
63
64
65class SnapCastStreamType(StrEnum):
66 """Enum for Snapcast Stream Type."""
67
68 MUSIC = "MUSIC"
69 ANNOUNCEMENT = "ANNOUNCEMENT"
70