music-assistant-server

3.2 KBPY
constants.py
3.2 KB93 lines • python
1"""Constants for the AirPlay provider."""
2
3from __future__ import annotations
4
5from enum import IntEnum
6from typing import Final
7
8from music_assistant_models.enums import ContentType
9from music_assistant_models.media_items import AudioFormat
10
11from music_assistant.constants import INTERNAL_PCM_FORMAT
12
13DOMAIN = "airplay"
14
15
16class StreamingProtocol(IntEnum):
17    """AirPlay streaming protocol versions."""
18
19    RAOP = 1  # AirPlay 1 (RAOP)
20    AIRPLAY2 = 2  # AirPlay 2
21
22
23CACHE_CATEGORY_PREV_VOLUME: Final[int] = 1
24
25CONF_ENCRYPTION: Final[str] = "encryption"
26CONF_ALAC_ENCODE: Final[str] = "alac_encode"
27CONF_VOLUME_START: Final[str] = "volume_start"
28CONF_PASSWORD: Final[str] = "password"
29CONF_IGNORE_VOLUME: Final[str] = "ignore_volume"
30CONF_CREDENTIALS: Final[str] = "credentials"
31CONF_AIRPLAY_PROTOCOL: Final[str] = "airplay_protocol"
32
33AIRPLAY_DISCOVERY_TYPE: Final[str] = "_airplay._tcp.local."
34RAOP_DISCOVERY_TYPE: Final[str] = "_raop._tcp.local."
35DACP_DISCOVERY_TYPE: Final[str] = "_dacp._tcp.local."
36
37AIRPLAY_OUTPUT_BUFFER_DURATION_MS: Final[int] = (
38    2000  # Read ahead buffer for cliraop. Output buffer duration for cliap2.
39)
40AIRPLAY2_MIN_LOG_LEVEL: Final[int] = 3  # Min loglevel to ensure stderr output contains what we need
41AIRPLAY2_CONNECT_TIME_MS: Final[int] = 2500  # Time in ms to allow AirPlay2 device to connect
42RAOP_CONNECT_TIME_MS: Final[int] = 1000  # Time in ms to allow RAOP device to connect
43
44# Per-protocol credential storage keys
45CONF_RAOP_CREDENTIALS: Final[str] = "raop_credentials"
46CONF_AIRPLAY_CREDENTIALS: Final[str] = "airplay_credentials"
47
48# Legacy credential key (for migration)
49CONF_AP_CREDENTIALS: Final[str] = "ap_credentials"
50
51# Pairing action keys
52CONF_ACTION_START_PAIRING: Final[str] = "start_pairing"
53CONF_ACTION_FINISH_PAIRING: Final[str] = "finish_pairing"
54CONF_ACTION_RESET_PAIRING: Final[str] = "reset_pairing"
55CONF_PAIRING_PIN: Final[str] = "pairing_pin"
56CONF_ENABLE_LATE_JOIN: Final[str] = "enable_late_join"
57
58BACKOFF_TIME_LOWER_LIMIT: Final[int] = 15  # seconds
59BACKOFF_TIME_UPPER_LIMIT: Final[int] = 300  # Five minutes
60ENABLE_LATE_JOIN_DEFAULT: Final[bool] = True
61
62FALLBACK_VOLUME: Final[int] = 20
63
64AIRPLAY_FLOW_PCM_FORMAT = AudioFormat(
65    content_type=INTERNAL_PCM_FORMAT.content_type,
66    sample_rate=44100,
67    bit_depth=INTERNAL_PCM_FORMAT.bit_depth,
68)
69AIRPLAY_PCM_FORMAT = AudioFormat(
70    content_type=ContentType.from_bit_depth(16), sample_rate=44100, bit_depth=16
71)
72
73BROKEN_AIRPLAY_MODELS = (
74    # A recent fw update of newer gen Sonos speakers have AirPlay issues,
75    # basically rendering our (both AP2 and RAOP) implementation useless on these devices.
76    # This list contains the models that are known to have this issue.
77    # Hopefully the issue won't spread to other models.
78    ("Sonos", "Era 100"),
79    ("Sonos", "Era 300"),
80    ("Sonos", "Move 2"),
81    ("Sonos", "Roam 2"),
82    ("Sonos", "Arc Ultra"),
83    # Samsung has been repeatedly being reported as having issues with AirPlay (raop and AP2)
84    ("Samsung", "*"),
85)
86
87AIRPLAY_2_DEFAULT_MODELS = (
88    # Models that are known to work better with AirPlay 2 protocol instead of RAOP
89    # These use the translated/friendly model names from get_model_info()
90    ("Ubiquiti Inc.", "*"),
91    ("Juke Audio", "*"),
92)
93