Skip to content

Sending RTCP sender reports at the set interval on interleaved tracks - #99

Open
erkin-io wants to merge 1 commit into
OpenIPC:masterfrom
erkin-io:fix/rtsp-tcp-sender-reports
Open

erkin-io wants to merge 1 commit into
OpenIPC:masterfrom
erkin-io:fix/rtsp-tcp-sender-reports

Conversation

@erkin-io

Copy link
Copy Markdown
Contributor

What was wrong

A client that plays over RTSP/TCP ("interleaved" transport) gets an RTCP sender report with every RTP packet instead of one every 150 packets. Players that use the reports to line up audio and video (FFmpeg, and so everything built on it) then re-time every packet by the moment it was sent. On a Ruision F8 board (FH8856V200) with MP3 audio over TCP, the audio timestamps in an FFmpeg capture moved in steps of 40 and 80 ms instead of the steady frame length; over UDP they were steady.

Also, a client that sets up only one of the two tracks (for example video only) makes the report poll fail its postcondition once for the other track, which logs an assertion failure.

Why

__method_play() (src/rtsp/rtsp.c) sets rtcp_tick_org = 150 and rtcp_tick only for tracks that have a UDP server port (if (!p->trans[i].server_port_rtp) continue;). Interleaved tracks have no server port, so both stay 0. __rtcp_poll() (src/rtsp/rtp.c) sends a report when the tick reaches 0 and reloads it from rtcp_tick_org, which is 0 again: a report with every packet.

For a track that was never set up, __rtcp_send_sr() returns early without reloading the tick, so the tick goes from 0 to -1 and the DASSERT after it (rtcp_tick == rtcp_tick_org) fails.

What this changes

  • __method_play(): for an interleaved track, clear the report counters and set rtcp_tick_org = 150 with rtcp_tick = 0, so the first packet still brings a report at once and then one follows every 150 packets, as on UDP.
  • __rtcp_poll(): skip a track that has neither a UDP port nor TCP transport, the same test __rtcp_send_sr() already makes.

How it was checked

  • Built with ./build.sh fhan-v2, no new warnings; ./test.sh -a passes.
  • On a Ruision F8 board, with the interval part of this change inside the firmware that normally runs on the board: an FFmpeg capture over RTSP/TCP had 233 of 234 audio steps exactly one frame long (the other one at a report); before, the steps were 40 and 80 ms. The firmware on the board also pairs the audio stamp with a smoothed time in the report, which is not part of this pull request.
  • The poll part: on the same board a client that set up video only logged assertion failure ((__rtcp_poll)...) once; with the change, no assertion in two runs.

Effect on other platforms

Shared RTSP code, used by every target. UDP clients: no change. TCP clients: one report every 150 packets per track instead of one per packet, which is what UDP clients already get, and less traffic.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Restore RTCP sender-report intervals for interleaved RTSP tracks

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Initialize TCP tracks to send an immediate report, then one every 150 RTP packets.
• Skip unconfigured tracks during report polling to prevent assertion failures.
Diagram

graph TD
  PLAY["RTSP PLAY"] --> INIT["Initialize TCP ticks"] --> GATE{"Track configured?"} -->|Yes| TICK{"Tick expired?"} -->|Yes| REPORT["Send RTCP SR"] --> CLIENT["RTSP client"]
  GATE -->|No| SKIP["Skip polling"]
  TICK -->|No| SKIP
Loading
High-Level Assessment

The focused fix preserves UDP setup and its immediate report while giving TCP tracks the same recurring interval. Consolidating transport initialization was considered, but would broaden the change and risk altering those distinct first-report paths.

Files changed (2) +17 / -1

Bug fix (2) +17 / -1
rtp.cExclude unconfigured tracks from RTCP polling +5/-0

Exclude unconfigured tracks from RTCP polling

• Returns before decrementing the report tick when a track has neither UDP nor TCP transport. This prevents the postcondition assertion for clients that set up only one track.

src/rtsp/rtp.c

rtsp.cInitialize sender-report timing for interleaved tracks +12/-1

Initialize sender-report timing for interleaved tracks

• On PLAY, resets TCP track report counters and sets a 150-packet interval with an initial tick of zero. The first RTP packet still triggers a report; subsequent packets no longer trigger one each time.

src/rtsp/rtsp.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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