Skip to content

[draft] feat(rtc): pair RTX streams with their simulcast layer via rrid - #246

Open
threeseed wants to merge 15 commits into
webrtc-rs:masterfrom
harana-oss:master
Open

threeseed wants to merge 15 commits into
webrtc-rs:masterfrom
harana-oss:master

Conversation

@threeseed

Copy link
Copy Markdown

So this issue has come up whilst I am implementing a layer on top of RTC.

I had to use Claude to implement it as it is way beyond what I am comfortable with in terms of RTC internals.

Leaving it here in case it's useful but have not yet tested it in a Production app yet.

@codecov

codecov Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.41256% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.93%. Comparing base (88095f8) to head (0e5393a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
tests/simulcast_rrid_rtx_rtc_to_rtc.rs 97.47% 9 Missing ⚠️
src/peer_connection/handler/interceptor.rs 92.59% 6 Missing ⚠️
src/media_stream/track.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #246      +/-   ##
==========================================
+ Coverage   87.69%   87.93%   +0.24%     
==========================================
  Files         498      500       +2     
  Lines       71322    72986    +1664     
==========================================
+ Hits        62546    64182    +1636     
- Misses       8776     8804      +28     
Flag Coverage Δ
aws-lc-rs 87.72% <96.41%> (+0.25%) ⬆️
ring 87.93% <96.41%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

harana-bot and others added 12 commits September 21, 2026 14:39
The size check only ran in SctpHandler::handle_write, where the error is
logged and dropped, so send() returned Ok for a message that was never
sent and left its bytes charged to outstanding_bytes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The buffer was only ever read for its length, which is the negotiated
max message size. Use that directly instead of allocating and zeroing up
to 256 KiB per connection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reassembly was bounded by the negotiated send limit, the smaller of the
two peers' limits. A peer may send anything up to the max-message-size
this endpoint advertises, so a peer that advertised less than it sends
(or omitted the attribute, implying 64 KiB) had larger messages dropped
with ErrShortBuffer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The ceiling was a fixed 256 KiB. It is now the SCTP receive buffer size
(1 MiB by default), which a message must fit in to be reassembled.
Unbounded and Bounded(0) resolve to it, and the SDP advertises the same
value that is enforced, instead of 0 ("any size") for Bounded(0).

sctp_receive_buffer_deadlock now has the sender ignore the receiver's
limit, since a compliant peer can no longer send a message larger than
the receive buffer, and checks the association survives it.

BREAKING CHANGE: SctpMaxMessageSize::MAX_MESSAGE_SIZE and
SctpMaxMessageSize::as_usize are removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
scripts/bench.py lists, checks, runs and compares the workspace's
criterion benchmarks. `compare` builds a base revision in a worktree
outside the repository and alternates base and head runs on one machine;
`upstream` does the same against webrtc-rs/rtc, overlaying this tree's
benchmark sources.

benchmarks/rtc-bench is an in-memory, virtual-clock PeerPair harness
with end-to-end benches for connection setup, data-channel throughput,
the RTP path and an allocations-per-packet report. New protocol benches
cover rtc-sctp, rtc-shared's replay detector and rtc-ice. CI builds and
runs every benchmark once (`bench.py check --providers all`).

docs/benchmarking.md documents the suite. ISSUES.md is the memory and
performance analysis the framework was built to measure.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1. Rejected SRTP packets no longer retain stream state.
2. The unused SCTP working buffer is gone.
3. Application backlogs are bounded by bytes as well as message count.
4. Parsed RTP headers are reused and owned buffers encrypted in place.
5. Pipeline scratch queues are reused and redundant traversal avoided.
6. Negotiated routing metadata is cached.
7. Retransmission history is bounded by bytes and age.
8. Sample-builder storage is right-sized.
9. Pre-handshake DTLS record queues are bounded.
10. DTLS fragment metadata is bounded and reassembly is linear.
11. Copies are removed from the DTLS record path.
12. ICE binding requests are pruned in place.
13. NACK retry bookkeeping is linear.
14. Congestion-control feedback is borrowed rather than cloned.
15. DTLS handshake-cache entries are borrowed during transcript
    inspection.

Each issue's Resolution section in ISSUES.md records the change,
before/after numbers and what was left open.

Also adds SIMD.md, an analysis of SIMD opportunities, with its
exploratory kernel probes in benchmarks/simd-probes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Every section of SIMD.md is implemented, using portable abstractions
only: `wide` vectors (backend chosen at compile time), memchr's
substring search, the crc-fast CRC library, or safe Rust the compiler
vectorizes. There are no std::arch intrinsics. Each section's
Resolution records the change, how equivalence with the old code was
checked, and before/after numbers from `bench.py compare` on an Apple
M1 Max (x86-64 was not measured).

- H.264: the payloader and the Annex B reader find start codes with a
  prebuilt memmem finder; the reader copies spans in bulk (71-76x).
- Audio: mono, stereo and four-channel layout fast paths (5-17x).
- rtc-crypto moves to aes 0.9 / ctr 0.10 / ccm 0.6, so applications get
  hardware AES on aarch64 without `--cfg aes_armv8`, which they never
  inherited from this repository's config. In-repository SRTP AES-CM is
  ~12% and DTLS CBC encryption ~19% slower as a result. `bench.py
  external` builds benchmarks/external-consumer as an application would
  and checks the backend.
- CBC decryption batches 32 blocks from 512 bytes up.
- FlexFEC serializes each protected packet once per block into reused
  buffers, with a `wide` XOR (encode 1.4-1.7x).
- STUN FINGERPRINT and Ogg page checksums use crc-fast (3.8x at 100 B;
  Ogg pages up to 59x).
- RFC 8888 feedback decodes in bulk from a contiguous chunk (3.3-4.3x).
- NACK generation and response, receiver reports and the TWCC arrival
  map work a word or slice at a time (NACK generation 1.2-8.1x).
- New Sample slice conversions for PCM, bit-exact with `From`.

Fixes an H26xReader panic (usize underflow) when data arrived after end
of stream. New criterion targets: rtc-media h26x/ogg/pcm and
rtc-interceptor feedback/flexfec, plus H.264, RFC 8888 and STUN
fingerprint groups in existing targets.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Brings in the benchmark framework, the ISSUES.md memory and performance
fixes, and the SIMD.md implementation.

Conflicts, all between ISSUES.md webrtc-rs#2 on the branch and master's SCTP
max-message-size work, which removed the same unused working buffer:

- transport/sctp, handler/sctp: kept master's direction semantics.
  Inbound messages are bounded by local_max_message_size(), this
  endpoint's advertised limit capped at the SCTP receive buffer; sends
  by the negotiated max_message_size(). Dropped the branch's
  max_message_len(), which applied the negotiated size to both
  directions, and its tests. The branch's byte-bounded read backlog
  (ISSUES.md webrtc-rs#3) is kept.
- handler/interceptor: master's rid validation (drop a packet whose rid
  is not negotiated) with the branch's borrowed &str rid.
- peer_connection/mod.rs: comment wording, master's.

ISSUES.md webrtc-rs#2 now notes what the merge superseded.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

3 participants