v0.56.1: AirPlay diagnostics — log each stream, choose the protocol

tiat.place connects but stays silent; pyatv streams to it with its AirPlay 2
path, which the fake receiver never exercised. Log every stream's start,
first audio and outcome; config.json airplay_protocol (auto/1/2) forces a
version and airplay_debug turns on pyatv's own debug log.
This commit is contained in:
2026-10-15 16:07:20 -07:00
parent c1aee48b8b
commit c2a566bf57
7 changed files with 66 additions and 4 deletions
+5
View File
@@ -839,6 +839,11 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
tile shows the sink's `glyph`. Testing streams against **pyatv's own fake tile shows the sink's `glyph`. Testing streams against **pyatv's own fake
receiver** (`tests/fake_device/raop.py` in its sdist, bound to 127.0.0.1) — receiver** (`tests/fake_device/raop.py` in its sdist, bound to 127.0.0.1) —
never a real speaker unless trav says so. never a real speaker unless trav says so.
pyatv picks AirPlay **2** for any receiver advertising its features (the
WiiM does) and the fake only exercises v1, so `config.json` takes
`airplay_protocol` ("auto"/"1"/"2") and `airplay_debug` (pyatv's logger
at DEBUG); every stream's start, first audio and outcome are logged at
INFO under `lintunes.airplay`, and the chosen protocol in the control log.
## Conventions & gotchas ## Conventions & gotchas
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux.""" """LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.56.0" __version__ = "0.56.1"
+27 -2
View File
@@ -6,11 +6,14 @@ streams, so a speaker that vanishes while paused is only noticed when the
next stream can't reach it, and Player falls back then. next stream can't reach it, and Player falls back then.
""" """
import logging
from PyQt6.QtCore import QObject, QTimer, pyqtSignal from PyQt6.QtCore import QObject, QTimer, pyqtSignal
from lintunes.airplay.discovery import AirPlayDiscovery from lintunes.airplay.discovery import AirPlayDiscovery
from lintunes.airplay.loop import AsyncLoop from lintunes.airplay.loop import AsyncLoop
from lintunes.airplay.support import is_available from lintunes.airplay.support import is_available, protocol_choice
from lintunes.config import load_config
from lintunes.eventlog import log_control from lintunes.eventlog import log_control
from lintunes.inhibit import INHIBIT_LOGOUT, INHIBIT_SUSPEND, SleepInhibitor from lintunes.inhibit import INHIBIT_LOGOUT, INHIBIT_SUSPEND, SleepInhibitor
@@ -90,6 +93,7 @@ class AirPlayController(QObject):
async def _connect(self, conf, device): async def _connect(self, conf, device):
import asyncio import asyncio
import pyatv import pyatv
from pyatv.const import Protocol
loop = asyncio.get_running_loop() loop = asyncio.get_running_loop()
if conf is None: if conf is None:
# Not seen by this session's scans (or seen long ago): ask the # Not seen by this session's scans (or seen long ago): ask the
@@ -99,8 +103,29 @@ class AirPlayController(QObject):
if str(c.identifier) == device.uuid), None) if str(c.identifier) == device.uuid), None)
if conf is None: if conf is None:
raise ConnectionError(f"{device.name} didn't answer") raise ConnectionError(f"{device.name} didn't answer")
from pyatv.protocols.airplay.utils import get_protocol_version
from pyatv.settings import AirPlayVersion
from pyatv.storage.memory_storage import MemoryStorage
config = load_config()
choice = protocol_choice(config.get("airplay_protocol"))
if config.get("airplay_debug"):
# Every RTSP request and a line per second of audio, into the
# journal: what "connected but silent" needs to be diagnosed.
logging.getLogger("pyatv").setLevel(logging.DEBUG)
storage = MemoryStorage()
settings = await storage.get_settings(conf)
settings.protocols.raop.protocol_version = {
"1": AirPlayVersion.V1, "2": AirPlayVersion.V2,
}.get(choice, AirPlayVersion.Auto)
raop = conf.get_service(Protocol.RAOP)
if raop is not None:
used = get_protocol_version(
raop, settings.protocols.raop.protocol_version)
log_control("airplay", "protocol",
f"{device.name}: {used.name} (airplay_protocol={choice})")
return await asyncio.wait_for( return await asyncio.wait_for(
pyatv.connect(raop_only(conf), loop), CONNECT_TIMEOUT_S) pyatv.connect(raop_only(conf), loop, storage=storage),
CONNECT_TIMEOUT_S)
def _on_connect_result(self, result: dict, attempt: int): def _on_connect_result(self, result: dict, attempt: int):
if attempt != self._attempt: if attempt != self._attempt:
+16 -1
View File
@@ -12,6 +12,7 @@ keeps in its PcmRequest.
""" """
import asyncio import asyncio
import logging
from contextlib import suppress from contextlib import suppress
from PyQt6.QtCore import QBuffer, QIODevice, QTimer, Qt, pyqtSignal from PyQt6.QtCore import QBuffer, QIODevice, QTimer, Qt, pyqtSignal
@@ -30,7 +31,10 @@ DECODE_ERROR = "decode_error" # this song can't be read; Player skips it
DROPPED = "dropped" # the speaker closed on us mid-song DROPPED = "dropped" # the speaker closed on us mid-song
FAILED = "failed" # couldn't reach the speaker at all FAILED = "failed" # couldn't reach the speaker at all
ART_MAX_PX = 600 # receivers show a small square; a 3000 px scan is waste ART_MAX_PX = 600
# Each stream's life in the journal: started, first audio, how it ended.
log = logging.getLogger("lintunes.airplay") # receivers show a small square; a 3000 px scan is waste
def jpeg_artwork(data: bytes | None) -> bytes | None: def jpeg_artwork(data: bytes | None) -> bytes | None:
@@ -86,6 +90,7 @@ class AirPlaySink(PlaybackSink):
self._track = None self._track = None
self._metadata: dict = {} self._metadata: dict = {}
self._first_logged = False
self._request: PcmRequest | None = None self._request: PcmRequest | None = None
self._generation = 0 self._generation = 0
self._playing = False self._playing = False
@@ -209,6 +214,9 @@ class AirPlaySink(PlaybackSink):
request = PcmRequest(self._track.location, start_ms, request = PcmRequest(self._track.location, start_ms,
self._duration_ms) self._duration_ms)
self._request = request self._request = request
self._first_logged = False
log.info("stream %d: %s from %d ms", self._generation,
self._track.name or self._track.location, start_ms)
self._set_position(start_ms) self._set_position(start_ms)
self._set_playing(True) self._set_playing(True)
self._poll.start() self._poll.start()
@@ -233,9 +241,16 @@ class AirPlaySink(PlaybackSink):
def _on_poll(self): def _on_poll(self):
request = self._request request = self._request
if request is not None: if request is not None:
if request.first_read_at is not None and not self._first_logged:
self._first_logged = True
log.info("stream %d: first audio sent %.1f s after play "
"(%d Hz)", self._generation,
request.first_read_at - request.created_at,
request.sample_rate)
self._set_position(self._heard(request)) self._set_position(self._heard(request))
def _on_stream_ended(self, generation: int, outcome: str, detail: str): def _on_stream_ended(self, generation: int, outcome: str, detail: str):
log.info("stream %d ended: %s %s", generation, outcome, detail)
if generation != self._generation or self._shutdown_done: if generation != self._generation or self._shutdown_done:
return return
self._request = None self._request = None
+1
View File
@@ -31,6 +31,7 @@ class PcmRequest:
self.duration_ms = max(0, int(duration_ms)) self.duration_ms = max(0, int(duration_ms))
self.sample_rate = 44100 self.sample_rate = 44100
self.frames_read = 0 self.frames_read = 0
self.created_at = time.monotonic()
self.first_read_at: float | None = None # time.monotonic() self.first_read_at: float | None = None # time.monotonic()
self.exhausted = False # ffmpeg reached the end of the song self.exhausted = False # ffmpeg reached the end of the song
self.decode_error = "" # ffmpeg failed before producing any audio self.decode_error = "" # ffmpeg failed before producing any audio
+8
View File
@@ -110,6 +110,14 @@ def heard_ms(start_ms: int, frames_read: int, elapsed_ms: float | None,
return start_ms + int(played) return start_ms + int(played)
def protocol_choice(value) -> str:
"""config.json's `airplay_protocol`: "auto" (pyatv picks from the
device's features), "1" or "2". Machine-local on purpose — it's about
which speakers this machine meets — and anything unrecognized is auto."""
value = str(value or "auto").strip().lower().lstrip("v")
return value if value in ("1", "2") else "auto"
_SAMPLE_FORMATS = {2: "s16be", 4: "s32be"} _SAMPLE_FORMATS = {2: "s16be", 4: "s32be"}
+8
View File
@@ -489,3 +489,11 @@ class TestIndicator:
assert vis.toolTip() == "Playing on tiat.place — click to stop" assert vis.toolTip() == "Playing on tiat.place — click to stop"
vis.mousePressEvent(None) vis.mousePressEvent(None)
airplay.disconnect.assert_called_once() airplay.disconnect.assert_called_once()
def test_protocol_choice_defaults_to_auto():
assert support.protocol_choice(None) == "auto"
assert support.protocol_choice("1") == "1"
assert support.protocol_choice("v1") == "1"
assert support.protocol_choice(2) == "2"
assert support.protocol_choice("three") == "auto"