Repository navigation
feat: RTSP over UDP unicast, with fallback to TCP (#67) - #70
Conversation
|
/review |
Code Review by Qodo
1.
|
|
Code done, CI green, Qodo findings addressed. Waiting for the device round in #74. |
Every camera slot gets a transport setting: TCP (as before, the default), UDP, or Auto (UDP, falling back to TCP). It is chosen in the URL dialog and can be passed with a shared link (--es transport udp|tcp|auto). - UdpReceiver binds an even RTP port and the RTCP port above it per track, always ephemeral (fixed ports were the bug of #40), and receives every track on the network thread through one selector, so callbacks keep coming from a single thread as over TCP. Only datagrams from the camera (the RTSP peer or the reply's "source") are accepted. - RtpReorder puts packets back in sequence order. In-order packets pass straight through; a gap is waited for at most 40 ms or 64 packets, then skipped; late duplicates are dropped. - Transport parses the SETUP reply, which decides what is received: Majestic answers "RTP/AVP/UDP;...", XM cameras "RTP/AVP;...;source=...; ssrc=...", and a server may answer with interleaved TCP. - Over UDP a second thread reads the RTSP replies (keepalives). Closing a UDP session sends TEARDOWN, since the server otherwise keeps sending until the session times out, and XM cameras allow one client only. - Auto falls back to TCP on a refused UDP SETUP (in the same connection) or when no video datagram arrives within 3 s after PLAY, and stays on TCP until the slot is reconfigured.
- A multicast reply, or one naming other client ports, is a UDP failure: Auto falls back to TCP, UDP reports the error, instead of waiting for datagrams that cannot arrive. - Audio answered with a different transport than UDP video is not set up; the audio reply's source is accepted as a sender too. - A finished connection clears the UDP state only if it still owns it, so a quick restart keeps the new session's TEARDOWN. - Auto remembers a fallback per URL for 10 minutes across sessions, so a resume or a rebuilt grid does not try UDP again at once.
a2c5fd0 to
0378d9c
Compare
|
Re Malformed UDP replies stall playback: declined for now. With Auto, a SETUP reply whose transport cannot deliver falls back to TCP after the 3 s silence timeout, which is the safety net designed for this. Strict client/server port validation would reject servers behind NAT or with port rewriting that still deliver. With UDP (no fallback) the user chose UDP explicitly. If a real camera turns up with a broken Transport header, it gets its own issue. Device test (CI build of the full stack, rebased onto v2): all applicable #70 items pass, see #74 run 1. Auto with UDP blocked could not be tested (no |
feat: RTSP over UDP unicast, with fallback to TCP (#67)
Closes #67. Stacked on #64 (8 slots), because the transport is a per-slot setting.
What changes
Every camera slot gets a transport: TCP (as before, the default), UDP, or Auto (UDP, falling back to TCP). It is set in the URL dialog (radio buttons under the URL) and can come with a shared link:
--es transport udp|tcp|auto.UdpReceiverbinds an even RTP port and the RTCP port above it per track. Ports are always ephemeral (the fixed 5000/5002 were the bug of basic: track URLs, payload types and UDP ports are hard-coded #40). Every track is received on the network thread through oneSelector, soonPacketis still called from a single thread, as over TCP. Only datagrams from the camera are accepted (the RTSP peer, or the reply'ssource). RTCP is read and discarded.RtpReorderputs packets back in sequence order. In-order packets pass straight through, so a clean LAN gets no extra delay. A gap is waited for at most 40 ms or 64 packets, then skipped (NalAssemblerdrops the broken access unit as before). Late duplicates are dropped.Transportparses the SETUP reply, and the reply decides what is received. Majestic answersRTP/AVP/UDP;unicast;client_port;server_port, XMRTP/AVP;unicast;mode=PLAY;source;client_port;server_port;ssrc. Both silently downgrade a multicast request to unicast (RTSP multicast and other RTSP transports (research: Majestic RTSP has no multicast) #69). A server answering with interleaved TCP is followed.Tests
TransportTest: Majestic, XM, interleaved and multicast replies; malformed values; settings values.RtpReorderTest: in order, swapped, lost (hold time and held-count limit), duplicates, 16-bit wrap, jumps and restarts.RtspSessionTest(scripted server, now with UDP): UDP handshake with video and audio over even/odd port pairs, Auto fallback on 461 and on silence, UDP without fallback, TEARDOWN on stop, datagrams from another address ignored.Device test
To do on the AG-216 with the CI build, using the methodology of #53, on group A cameras (Majestic H.264 and H.265 + Opus, XM H.264):
/proc/<pid>/net/udp*), TEARDOWN sent