Skip to content

feat(rtsp,udp): apply FrameLifecycleListener + NetworkSendError typed event (parity with RTMP/SRT)#2075

Closed
pird32 wants to merge 2 commits intopedroSG94:masterfrom
pird32:fork/rootencoder-rtsp-udp-memory
Closed

feat(rtsp,udp): apply FrameLifecycleListener + NetworkSendError typed event (parity with RTMP/SRT)#2075
pird32 wants to merge 2 commits intopedroSG94:masterfrom
pird32:fork/rootencoder-rtsp-udp-memory

Conversation

@pird32
Copy link
Copy Markdown

@pird32 pird32 commented Apr 16, 2026

Problem

RtspSender and UdpSender do not expose the frame lifecycle callback or emit typed transport events on network errors, unlike RtmpSender and SrtSender (fixed in companion PRs).

This creates protocol-inconsistent behavior: callers that implement buffer pooling or typed error handling must check which protocol is active.

Solution

Apply the same changes from RTMP/SRT PRs to RtspSender and UdpSender:

  1. Call notifyFrameConsumed(frame) from the dispatch loop after each frame's network write (inherited from BaseSender).
  2. Emit ConnectChecker.onTransportEvent(NetworkSendError) alongside onConnectionFailed() in the error path.

This PR adds zero new classes — all infrastructure is inherited from BaseSender via the companion PRs.

Backward compatibility

Fully backward-compatible. frameLifecycleListener defaults to null; no existing behavior changes.

pird32 added 2 commits April 16, 2026 17:51
- BaseSender: fix getCacheSize() to track actual capacity after resizeCache()
  (was always returning initial 400 even after resizeCache(128))
- BaseSender: add getQueueSnapshot() returning QueueSnapshot(capacity, items)
- BaseSender: add frameLifecycleListener for pooled-copy buffer recycling
- BaseSender: emit rate-limited ConnectChecker.onTransportEvent(QueueOverflow)
  when sendMediaFrame() drops a frame (cooldown: 1500 ms, no flooding)
- New: QueueSnapshot data class with usageRatio and summary()
- New: TransportEvent sealed class (QueueOverflow, NetworkSendError)
- New: FrameLifecycleListener fun interface for buffer pool integration
- ConnectChecker: add onTransportEvent(TransportEvent) default no-op method

Upstream-friendliness: onTransportEvent is a default method; existing
ConnectChecker implementors are not required to override it.

Made-with: Cursor
…all senders

All four protocol senders (RtmpSender, SrtSender, RtspSender, UdpSender) now:
- Call notifyFrameConsumed(mediaFrame) after the dispatch loop finishes
  processing each frame (after network write). Wired to frameLifecycleListener
  so buffer pools can release slots at the correct point in the lifecycle.
- Emit ConnectChecker.onTransportEvent(NetworkSendError) on send errors in
  addition to the existing onConnectionFailed(String) call (backward compatible).

Made-with: Cursor
@pird32
Copy link
Copy Markdown
Author

pird32 commented Apr 16, 2026

Closing this PR to keep only one consolidated PR for easier review/testing, as requested. All changes are included in #2072.

@pird32 pird32 closed this Apr 16, 2026
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