/
/
/
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_ADVANCED = "advanced"
24CONF_CATEGORY_BUILT_IN = "Built-in Snapserver Settings"
25
26CONF_HELP_LINK = (
27 "https://raw.githubusercontent.com/badaix/snapcast/refs/heads/master/server/etc/snapserver.conf"
28)
29
30# snapcast has fixed sample rate/bit depth so make this config entry static and hidden
31CONF_ENTRY_SAMPLE_RATES_SNAPCAST = create_sample_rates_config_entry(
32 supported_sample_rates=[48000], supported_bit_depths=[16], hidden=True
33)
34
35DEFAULT_SNAPSERVER_IP = "127.0.0.1"
36DEFAULT_SNAPSERVER_PORT = 1705
37DEFAULT_SNAPSTREAM_IDLE_THRESHOLD = 60000
38
39# Socket path template for control script communication
40# The {queue_id} placeholder will be replaced with the actual queue ID
41CONTROL_SOCKET_PATH_TEMPLATE = "/tmp/ma-snapcast-{queue_id}.sock" # noqa: S108
42
43MASS_STREAM_PREFIX = "Music Assistant - "
44MASS_ANNOUNCEMENT_POSTFIX = " (announcement)"
45SNAPWEB_DIR = pathlib.Path(__file__).parent.resolve().joinpath("snapweb")
46CONTROL_SCRIPT = pathlib.Path(__file__).parent.resolve().joinpath("control.py")
47
48DEFAULT_SNAPCAST_FORMAT = AudioFormat(
49 content_type=ContentType.PCM_S16LE,
50 sample_rate=48000,
51 # TODO: we can also use 32 bits here
52 bit_depth=16,
53 channels=2,
54)
55
56DEFAULT_SNAPCAST_PCM_FORMAT = AudioFormat(
57 # the format that is used as intermediate pcm stream,
58 # we prefer F32 here to account for volume normalization
59 content_type=ContentType.PCM_F32LE,
60 sample_rate=48000,
61 bit_depth=16,
62 channels=2,
63)
64
65
66class SnapCastStreamType(StrEnum):
67 """Enum for Snapcast Stream Type."""
68
69 MUSIC = "MUSIC"
70 ANNOUNCEMENT = "ANNOUNCEMENT"
71