sendspin #1

Merged
joeri merged 7 commits from sendspin into main 2026-11-08 07:58:03 +01:00
Owner
No description provided.
Android-free (host-testable) implementation of the client side of
Sendspin 1.0.0-rc1, the protocol Music Assistant 2.10.7+ uses:

- WsConnection: server side of RFC 6455 (servers dial the player),
  rejects upgrades with an Origin header, answers pings itself
- Noise: Noise_KKpsk2_25519_AESGCM_SHA256 responder over javax.crypto,
  with a pure-Java X25519 (RFC 7748) since platform XDH needs API 33
- SendspinSession: init/handshake/hello/activate, Sentinel PSK
  (unpaired access), clock-sync bursts into the spec's Kalman
  TimeFilter, client/state after convergence, streams, player commands,
  server/state, group/update, controller commands, fragments
- SendspinServer: accept loop and the multiple-server admission rules
- FlacFrames: splits chunks into single FLAC frames for MediaCodec
- Minimal Json and B64 (java.util.Base64 needs API 26)

SendspinUnitTest checks RFC 7748 vectors, the Sentinel psk_id, the
time filter and FLAC splitting; SendspinHostTest runs the core for an
aiosendspin server to dial.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second toggle runs SendspinService: a mediaPlayback foreground service
that advertises _sendspin._tcp on port 8928 (TXT path=/sendspin), lets
Music Assistant dial in and plays the admitted server's stream in sync.

- SendspinAudio: fast AudioTrack, 10 ms blocks placed by server time;
  snaps when out of sync, else drops/duplicates single frames (<=0.42%).
  The SHIELD's HDMI HAL gives no usable presentation timestamps, so it
  times by the playback head (median of 100 ms lower-envelope points)
  plus the HAL latency the timestamps show on average (~47 ms there).
- FlacDecoder: MediaCodec audio/flac on its own thread, one FLAC frame
  per input buffer; FLAC is listed first when a decoder exists.
- Player commands: volume/mute as stream gain ((v/100)^1.5) or, with the
  'controls TV volume' switch, as STREAM_MUSIC; on full-volume HDMI that
  becomes HDMI-CEC volume steps. Output delay is persisted.
- MediaSession fed by the metadata/controller roles (artwork fetched
  from artwork_url); its transport controls send controller commands, so
  the remote's media keys control Music Assistant. MediaStyle
  notification and a full-screen NowPlayingActivity.
- BootReceiver starts both services after boot and after an update
  (MY_PACKAGE_REPLACED), so adb install -r no longer leaves them off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Controller commands from the MediaSession callback, the notification
  and the now-playing buttons ran on the main thread and wrote to the
  socket there: NetworkOnMainThreadException took the whole app down.
  They now go through the service's worker thread.
- Music Assistant sends metadata right after activation, before the
  first clock measurement; its timestamp then looked months ahead and
  the update was scheduled for then. Apply it at once until the time
  filter has a measurement, and schedule at most 20 s ahead (the spec's
  limit for servers).
- Log volume changes made on the TV side in TV-volume mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sendspin_server_harness.py plays the Music Assistant side with the real
aiosendspin 10.2.0 server: it dials a player URL (no mDNS, no listening
port), approves it for unpaired playback the way MA approves guest
devices, streams a tone, round-trips volume/mute/output-delay commands,
sends metadata, waits for a controller command, clears and ends the
stream, and fails on any spec deviation aiosendspin reports.

run_sendspin_tests.sh runs the core's unit checks and then the harness
against SendspinHostTest (the shipped core on a plain JVM) with PCM and
FLAC: both pass all 26 checks in --strict mode, with contiguous audio
timestamps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Timestamps are judged erratic after three jumps over 1 ms (not only
  by spread), and the verdict and the measured output latency (~47 ms on
  the SHIELD) are persisted. Later streams start on the playback head
  right away: no snaps at stream start or resume, and no audio dropped
  while waiting for the latency estimate.
- README: Music Assistant player section (discovery, security, roles,
  multiple servers, sync, volume modes, now playing, limitations), the
  Sendspin host and device tests, and verification status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joeri merged commit a3c5b63509 into main 2026-11-08 07:58:03 +01:00
joeri deleted branch sendspin 2026-11-08 07:58:03 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hydrogen/tv-bridge!1
No description provided.