Skip to content

Stabilize live audio and session lifecycle - #31

Open
serezhka wants to merge 16 commits into
release/1.1.2from
fix/live-audio-lifecycle
Open

serezhka wants to merge 16 commits into
release/1.1.2from
fix/live-audio-lifecycle

Conversation

@serezhka

@serezhka serezhka commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Summary

This PR stabilizes live audio playback and the transitions between Music, screen mirroring, and HLS.

Live audio

  • Added a bounded RTP reorder window for out-of-order audio packets.
  • Missing packets are held only briefly (~40 ms), then skipped and reported as an audio gap. This preserves low latency on a poor network instead of waiting for retransmissions or building seconds of delay.
  • Removed the RTP retransmission request/reply implementation entirely. The audio control UDP port remains for inbound control/synchronization packets only.
  • Increased the audio UDP receive buffer to reduce kernel drops during Wi-Fi bursts.
  • Preserved RTP-Info sequence/timestamp handling on FLUSH/RECORD.
  • Kept small-gap concealment and large-gap codec discontinuity handling through the Playback API.

Session lifecycle

  • Stop foreign audio sessions before a new audio or mirror setup, preventing an old Music UDP stream from feeding the new codec.
  • Centralized audio/control UDP shutdown for foreign sessions, stream TEARDOWN, full TEARDOWN, and dropped control connections.
  • Keep the presentation briefly after audio-only TEARDOWN so track changes can reconnect; end it after the idle window only when no audio, video, or HLS session remains.
  • Keep mirror/HLS presentation policy decisions in PresentationEndPolicy and cover the edge cases with unit tests.

Player and MSE reliability

  • Restored live GStreamer audio operation with bounded leaky queues instead of multi-second buffering.
  • Ensure only one GStreamer audio codec pipeline is active during Music↔mirror transitions.
  • Replay late MSE audio configuration and bound pending audio access units until the browser audio socket is ready.
  • Keep Chromium launch configuration portable and deterministic for the MSE player.

Artwork

  • Keep RTSP artwork reception and the Playback hook, plus MSE storage/HTTP access for the future vertical.
  • No artwork is rendered by the MSE page in this PR.

Validation

  • Local :server:test
  • Local :app:mse:test
  • Kali :server:test and :app:mse:test
  • GitHub Actions unit and playback matrix
  • RTP reorder, wraparound, late-fill, short-gap, large-gap, FLUSH/RECORD, and decrypt-failure tests
  • Session presentation policy and audio lifecycle edge-case tests

The local GStreamer HLS position smoke test can be timing-sensitive on macOS; the supported CI GStreamer matrix is green.

serezhka and others added 16 commits November 25, 2026 16:02
Mark missing packets, request retransmission on the control UDP port, and
reopen stateful codecs after give-up; keep presentation across track TEARDOWN
and buffer AUs until the browser /audio socket is ready. Also run CI on
release/** PRs.

Co-authored-by: Cursor <cursoragent@cursor.com>
Force audio-sink=fakesink under airplay.gst.hls.headless (same as mirror appsink CI) so pulse/autoaudiosink cannot block preroll, and trust wall clock after first picture or 1s PLAYING when playbin3 never exposes POSITION.

Co-authored-by: Cursor <cursoragent@cursor.com>
Wire control-port 0x56 replies into the RTP reorder buffer, share RTP parse with the data decoder, and remove the no-op afterAudioTeardown KEEP path that never ended presentation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Parse seq/rtptime, re-anchor the reorder window at seq, drop packets before rtptime, and keep a pending filter so late pre-flush datagrams cannot re-enter the timeline.

Co-authored-by: Cursor <cursoragent@cursor.com>
Derive the missing-packet deadline from stream latency minus a 250 ms tail margin (default ~2 s lead), stop useless late resends, and only re-init codecs when eight or more packets are skipped.

Co-authored-by: Cursor <cursoragent@cursor.com>
Point tray/README/funding at a new Payment Link; the old €1-min link is deactivated so card-testing probes cannot keep using it.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Live Kali capture showed socket drops (d172) and pulsesink underruns with
prebuf=0 while RTP seq was intact — WiFi bursts hit a 8-buffer leaky queue.

Co-authored-by: Cursor <cursoragent@cursor.com>
Mirror was inheriting the Music 2s buffered appsrc, and the old Music
session UDP ports stayed open — sounded like ~0.25×. Split queue/live
settings by codec and tear down foreign audio servers on SETUP.

Co-authored-by: Cursor <cursoragent@cursor.com>
Resend requests only help with multi-second playout delay; leave the
code and tests, default them off, skip holes after a short reorder
window, and restore leaky live GST appsrc/queues.

Co-authored-by: Cursor <cursoragent@cursor.com>
Live give-up is shorter than the first resend check, so dueResends
stays empty unless the buffered-resend path is explicitly on.

Co-authored-by: Cursor <cursoragent@cursor.com>
Port the local WIP cover path (SET_PARAMETER → Playback → MSE
/artwork) onto fix/audio-rtp-resend without regressing live
low-latency audio / foreign-session cleanup.

Co-authored-by: Cursor <cursoragent@cursor.com>
Cover is still accepted from RTSP and held/served at GET /artwork,
but the page no longer draws a Now Playing image.

Co-authored-by: Cursor <cursoragent@cursor.com>
Drop unused resend request/reply code and keep a short reorder window
that skips holes. Centralize foreign/session audio stop and express
audio-only idle end through PresentationEndPolicy.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep audio/control UDP shutdown consistent with foreign-session and
control-drop cleanup.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant