Repository navigation
Negotiate NACK for Opus audio - #1683
Merged
Merged
Conversation
libwebrtc advertises only transport-cc feedback for Opus, so no audio NACK is negotiated. Without RED (for example with E2EE), lost subscribed audio packets are never retransmitted. Single PC offers add `a=rtcp-fb:<opus pt> nack` to recvonly audio sections, including the initial offer sent with the join. Dual PC answers mirror Opus NACK from the remote offer by mid. This ports livekit/client-sdk-js#2270. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Changeset ✓This PR includes a changeset covering all affected packages:
|
The server takes audio feedback from the first audio section of the first offer only. That section can be the client's own sendonly mic, so single PC offers now add Opus NACK to every audio section, whatever its direction. This matches the final behavior of livekit/client-sdk-js#2270. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add NACK to every Opus payload type, not only the first. Treat `a=rtcp-fb:* nack` and whitespace other than one space as existing NACK, and keep treating `nack pli` as a different feedback type. - Drop the extra NACK munge in `create_initial_offer`, since `munge_offer` from main already applies it. - Add tests that run the munges on SDP that libwebrtc writes: the initial offer, later offers in both modes, and the dual PC answer. - Add `v1_opus_nack_negotiates_initial_offer`, an e2e test that checks NACK in the initial offer and in the server answer. The real-SDP tests and the e2e test are adapted from #1695. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the five loose helpers that passed `&[&str]` slices around with `SdpSection`, a borrowed view of one SDP section. Its methods give the mid, the Opus payload types and whether a payload type has plain NACK. The munge now reads lines with `split_inclusive`, so every line keeps its own line ending, and it writes into one `String` instead of a `Vec<String>` that it joins again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The extra 64 bytes were an unexplained guess. The buffer grows at most once when NACK lines are added, once per negotiation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `munge_opus_nack*` return `None` when there is nothing to add, so the SDP is no longer copied and compared just to find no change. - `munge_offer` keeps the munged string instead of serializing the parsed offer again. `parse_munged` replaces `reparse_munged`. - `SdpSection<'s, 'a>` borrows the line slice and the SDP text with separate lifetimes, so the strings it returns outlive the slice. - Add one-line docs to `is_audio`, `mid` and `opus_pts`. - Test the NACK line after a last line that has no line ending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xianshijing-lk
approved these changes
Nov 19, 2026
lukasIO
pushed a commit
that referenced
this pull request
Nov 24, 2026
…1735) <!-- verwalter release --> Merging this PR releases: ## livekit `0.12.0` → `0.12.1` ### Patch Changes - Negotiate NACK for Opus. If RED is off, for example with E2EE, lost audio packets are now retransmitted. - [#1683](#1683) ([@lukasIO](https://github.com/lukasIO)) Changesets: `opus_nack.md` ## livekit-capture `0.3.0` → `0.3.1` ### Patch Changes - Negotiate NACK for Opus. If RED is off, for example with E2EE, lost audio packets are now retransmitted. - [#1683](#1683) ([@lukasIO](https://github.com/lukasIO)) - Updated dependencies: livekit@0.12.1 Changesets: `opus_nack.md` ## livekit-ffi `0.15.0` → `0.16.0` ### Minor Changes - Expose `LocalDataTrack`, `RemoteDataTrack` and `DataTrackStream` over UniFFI in room-apis builds too, as the same objects core-modules exports. - [#1620](#1620) ([@1egoman](https://github.com/1egoman)) ### Patch Changes - Negotiate NACK for Opus. If RED is off, for example with E2EE, lost audio packets are now retransmitted. - [#1683](#1683) ([@lukasIO](https://github.com/lukasIO)) - Updated dependencies: livekit@0.12.1, livekit-capture@0.3.1 Changesets: `data_tracks_shared_uniffi_objects.md`, `opus_nack.md` Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Subscribed audio gets no NACK today, so lost packets are not retransmitted. libwebrtc advertises only
transport-ccfeedback for Opus. In single PC mode the client sends the offer, and the server answer keeps only feedback that both sides offer. The server also takes audio feedback only from the first audio section of the first offer. The server wants NACK for tracks without RED (livekit/livekit#3889), but no audio NACK is negotiated. Rust turns RED off for E2EE (#706), so Rust E2EE users get neither RED nor NACK. This ports livekit/client-sdk-js#2270, which fixes livekit/client-sdk-js#2277.Change
a=rtcp-fb:<pt> nackfor every Opus payload type in every audio section, whatever its direction. This includes the initial offer sent with the join, which is the one that counts. The first audio section can be the client's ownsendonlymic, sorecvonlysections alone are not enough. This matches the final commit of fix: negotiate Opus NACK for received audio in single peer connection mode client-sdk-js#2270. Dual PC publisher offers do not change.*wildcard counts as existing NACK.nack pliis a different feedback type and does not count as NACK.munge_offer, so the initial offer gets it too. The SDP sent with the join is the SDP set as the local description.Verified
cargo test -p livekit --lib: 91 passed. The new tests cover these cases:v1_opus_nack_negotiates_initial_offeragainst a locallivekit-server --dev(1.13.10): the initial offer and the server answer both carry Opus NACK. It fails with the munge disabled.audio_testalso passes.cargo fmt --all --checkpasses.cargo clippy -p livekit --no-depshas no new findings in the changed code.The tests with real peer connections and the e2e test are adapted from #1695.
Not done yet
nack_countin the inbound audio stats. Loss injection on macOS needs root, so it did not run. The JS SDK test under 10% loss went from about 300 lost packets per 30 s to 0.🤖 Generated with Claude Code