v0.59.0: LinTunes' own AirPlay 1 sender for third-party speakers

pyatv's handshakes play nothing on a WiiM; Music Assistant's cliairplay
plays on it through libraop's RAOP client. airplay/raop.py reproduces that
client's behaviour on the wire: one RTSP session with auth-setup, an
AppleLossless ANNOUNCE and RECORD carrying RTP-Info, OPTIONS keepalives,
a 2 s buffer, NTP-locked timestamps, a start that sends the first two
seconds at once, the timing responder and resends. Non-Apple speakers
stream through it; pyatv only finds them. Verified against shairport-sync
(decoded tone, flush on pause/seek, volume, metadata). Round 88's pyatv
compat hooks are gone.
This commit is contained in:
2026-10-16 23:12:38 -07:00
parent ab25a6381b
commit efbee5c465
9 changed files with 902 additions and 181 deletions
+5 -64
View File
@@ -1,10 +1,7 @@
"""Round 88: a repeat button, the streaming tile's click, and AirPlay's
compatibility handshake for third-party speakers (a WiiM played nothing)."""
compatibility mode for third-party speakers (a WiiM played nothing). Round 90
replaced its pyatv hooks with raop.py; those tests are in test_round90."""
import asyncio
import os
import random
from types import SimpleNamespace
from unittest.mock import MagicMock
import pytest
@@ -169,71 +166,15 @@ class TestAlacVerbatim:
assert frame[2] >> 1 == 0b0000001
class _Conn:
def __init__(self, ip):
self.remote_ip = ip
self.local_ip = "10.0.0.2"
@pytest.fixture
def shim():
stream.install_shim()
yield
stream._compat_hosts.clear()
class TestCompatHooks:
def test_announce_says_apple_lossless_only_for_compat_hosts(self, shim):
from pyatv.support import rtsp
sent = []
async def exchange(self, method, **kw):
sent.append(kw["body"])
return SimpleNamespace(code=200, headers={})
session = rtsp.RtspSession(_Conn("10.0.0.9"))
session.exchange = exchange.__get__(session)
stream.set_compat("10.0.0.9", True)
asyncio.run(session.announce(2, 2, 44100, None))
stream.set_compat("10.0.0.9", False)
asyncio.run(session.announce(2, 2, 44100, None))
assert "a=rtpmap:96 AppleLossless" in sent[0]
assert "a=fmtp:96 352 0 16 40 10 14 2 255 0 0 44100" in sent[0]
assert "L16/44100/2" in sent[1]
def test_no_pairing_and_auth_setup_for_compat_hosts(self, shim):
from pyatv.protocols.raop import stream_client
from pyatv.protocols.raop.protocols import airplayv1
from pyatv.protocols.raop.parsers import EncryptionType
stream.set_compat("10.0.0.9", True)
assert isinstance(airplayv1.pair_verify(None, _Conn("10.0.0.9")),
stream._NoPairing)
client = SimpleNamespace(rtsp=SimpleNamespace(
connection=_Conn("10.0.0.9")), _properties={"am": "WiiM"},
_encryption_types=EncryptionType.Unencrypted)
assert stream_client.StreamClient._requires_auth_setup.fget(client)
client.rtsp.connection = _Conn("10.0.0.10")
assert not stream_client.StreamClient._requires_auth_setup.fget(client)
def test_audio_is_wrapped_as_alac_for_compat_hosts(self, shim):
from pyatv.protocols.raop.protocols import airplayv1
sent = []
proto = SimpleNamespace(
rtsp=SimpleNamespace(connection=_Conn("10.0.0.9")),
context=SimpleNamespace(bytes_per_channel=2, channels=2, rtpseq=7))
transport = SimpleNamespace(sendto=sent.append)
pcm = os.urandom(1408)
stream.set_compat("10.0.0.9", True)
asyncio.run(airplayv1.AirPlayV1.send_audio_packet(
proto, transport, b"H" * 12, pcm))
stream.set_compat("10.0.0.9", False)
asyncio.run(airplayv1.AirPlayV1.send_audio_packet(
proto, transport, b"H" * 12, pcm))
assert sent[0] == b"H" * 12 + alac_verbatim(pcm)
assert sent[1] == b"H" * 12 + pcm
class TestShim:
def test_install_is_idempotent(self, shim):
from pyatv.support import rtsp
announce = rtsp.RtspSession.announce
info = rtsp.RtspSession.info
stream.install_shim()
assert rtsp.RtspSession.announce is announce
assert rtsp.RtspSession.info is info