Skip to content

Auto-launch ffplay on mirroring, fix reconnection port leak, fix audio seq wraparound, optimize CI - #6

Merged
YimingZhanshen merged 9 commits into
mainfrom
copilot/add-screen-mirror-detection
Feb 10, 2026
Merged

YimingZhanshen merged 9 commits into
mainfrom
copilot/add-screen-mirror-detection

Conversation

Copilot AI commented Feb 10, 2026

Copy link
Copy Markdown

Screen mirroring required manually launching ffplay, reconnection after stop failed (port 7000 stayed bound), audio stuttered every ~25 min at the 16-bit sequence number wraparound, and CI rebuilt FFmpeg/fdk-aac from scratch every run.

Auto-launch/kill ffplay on mirroring lifecycle

  • Added OnMirroringStarted/OnMirroringStopped events through IRtspReceiverAirPlayReceiverAirPlayService
  • VideoOutputService redesigned with StartMirroring()/StopMirroring() — creates pipe, launches ffplay, buffers frames until connection, kills ffplay on stop
  • Pre-buffers SPS/PPS+IDR frames before ffplay connects, flushes from latest keyframe on connection
  • Low-latency ffplay flags: -fflags nobuffer+discardcorrupt -flags low_delay -framedrop -avioflags direct -vf setpts=0

Fix reconnection failure (BaseTcpListener port leak)

StopAsync() only cancelled the token but never called _listener.Stop(), leaving port 7000 bound. Old dead listener accepted new connections which immediately closed → "0 frames written."

public override Task StopAsync()
{
    _cancellationTokenSource.Cancel();
    try { _listener.Stop(); } catch { }
    return Task.CompletedTask;
}

Fix audio sequence number wraparound

Three places in RaopBufferQueue used plain < on 16-bit sequence numbers, breaking at 65535→0:

// Before: seqnums 1,2,3… after wrap discarded as "old"
if (seqnum < FirstSeqNum && seqnum != 0) { ... }

// After: proper modular comparison
private static bool SeqBefore(ushort s1, ushort s2) => ((short)(s1 - s2)) < 0;

CI caching

actions/cache@v4 for FFmpeg binaries and built libfdk-aac DLL — skips ~100MB download and MSYS2 source build on cache hit.

README updated

Both EN/ZH READMEs updated: download link → GitHub Releases, simplified quick start (no manual ffplay), documented auto-launch behavior.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 10, 2026 22:08
…o-launch/kill ffplay, support reconnection

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
…t check in StopFfplay, optimize CI workflow with caching

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automatic display on screen mirroring activation Auto-launch ffplay on mirroring start/stop and cache CI dependencies Feb 10, 2026
Copilot AI requested a review from YimingZhanshen February 10, 2026 22:14
Copilot AI and others added 2 commits February 10, 2026 22:33
…g connection issues

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
…ions.Generic using

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
Copilot AI changed the title Auto-launch ffplay on mirroring start/stop and cache CI dependencies Fix audio stutter on seq wraparound and video PPS errors on mirroring start Feb 10, 2026
…y latency

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
Copilot AI changed the title Fix audio stutter on seq wraparound and video PPS errors on mirroring start Fix mirroring reconnection failure, auto-show/hide video window, reduce playback latency, and optimize CI caching Feb 10, 2026
…ration 0 to ffplay

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
Copilot AI changed the title Fix mirroring reconnection failure, auto-show/hide video window, reduce playback latency, and optimize CI caching Fix screen mirroring: port leak on reconnect, video display latency, sequence number wraparound Feb 10, 2026
…ate frame display

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
Copilot AI changed the title Fix screen mirroring: port leak on reconnect, video display latency, sequence number wraparound Fix screen mirroring: auto-launch ffplay, reconnection, latency, and audio wraparound Feb 10, 2026
…leases link, updated docs

Co-authored-by: YimingZhanshen <76594627+YimingZhanshen@users.noreply.github.com>
Copilot AI changed the title Fix screen mirroring: auto-launch ffplay, reconnection, latency, and audio wraparound Auto-launch ffplay on mirroring, fix reconnection port leak, fix audio seq wraparound, optimize CI Feb 10, 2026
@YimingZhanshen
YimingZhanshen marked this pull request as ready for review February 10, 2026 23:49
@YimingZhanshen
YimingZhanshen merged commit c84e8ba into main Feb 10, 2026
@YimingZhanshen
YimingZhanshen deleted the copilot/add-screen-mirror-detection branch February 10, 2026 23:49
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.

2 participants