Repository navigation
Add FlexFEC negotiation and subscriber FEC protection - #1071
cloudwebrtc wants to merge 7 commits into
Conversation
LiveKit.enableFlexFec turns on the FlexFEC field trials when libwebrtc is initialized, so flexfec-03 is negotiated. Codec preferences already keep unmatched codecs, so the repair codec is offered without further changes. RemoteTrackPublication.setFecProtection requests FlexFEC repair packets from the server for a subscribed video track through the new UpdateTrackSettings.fec field, which requires livekit/protocol#1987. FecProtection is a sealed class mirroring the protocol's modes: Disabled, Adaptive, and Fixed and Minimum, which carry a FecProtectionLevel (low, medium or high). The protection is only sent once requested, so other settings updates leave the server's setting unchanged. Unlike quality and dimensions it also applies while adaptive stream manages the track. FlexFecOnDeviceTest subscribes to a video track on a real server and checks the repairs received for each mode through the inbound-rtp FEC counters. It is skipped unless the lkUrl and lkToken instrumentation arguments are given. The protocol submodule points at livekit/protocol#1987 applied on top of the current protocol commit.
🦋 Changeset detectedLatest commit: fce3183 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
End-to-end test resultsRan Setup
Server config: rtc:
flexfec:
upstream_enabled: true
downstream_enabled: trueRun with: The test has since moved to livekit/e2e-android#17 as The server's own FlexFEC tests ( ResultsEach row is a 6 s window, after a 2 s settle following
An earlier run gave the same picture (LOW 17.1%, HIGH 25.1%, Minimum MEDIUM 18.6%, Adaptive and Disabled 0). What this shows:
Note on the ratios
libwebrtc versionThe results above were measured with Not coveredNo loss was simulated, so recovery of lost packets and adaptive protection rising with loss were not exercised on device. The server's Upstream (publish) resultsRan Negotiation
libwebrtc only protects a single media stream with FlexFEC ( With Under lossUpstream loss was added with a userspace UDP proxy between the device and the server that drops only RTP. With 5% and 20% upstream loss the server's While doing this I found that the server's receiver reports to the publisher always carried
Run with: This test has also moved to livekit/e2e-android#17, as |
|
Diffuse output: AARJAR |
libwebrtc only protects a single media stream with FlexFEC, so it signals no FlexFEC SSRC for a sender with simulcast layers.
FlexFecPublishOnDeviceTest publishes a synthetic video track to a real server and checks the publisher negotiation: without simulcast the offer includes flexfec-03 and a FEC-FR SSRC and the server accepts flexfec-03, and with simulcast no FlexFEC SSRC is signaled. The track can be held for a while to watch the repairs arrive at the server under upstream loss. It is skipped unless the lkUrl and lkPublisherToken instrumentation arguments are given.
davidliu
left a comment
There was a problem hiding this comment.
LGTM, just needs moving the integrated tests over to e2e-android.
FlexFecOnDeviceTest and FlexFecPublishOnDeviceTest now live in livekit/e2e-android as FlexFecSubscribeTest and FlexFecPublishTest, next to the other instrumented tests. The androidTest manifest only existed to allow cleartext connections for them.
|
Dependency diff: -\--- io.github.webrtc-sdk:android-prefixed:150.7871.04
+\--- io.github.webrtc-sdk:android-prefixed:150.7871.08 |
There was a problem hiding this comment.
Devin Review found 2 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| fun setFecProtection(protection: FecProtection) { | ||
| if (!subscribed || track !is VideoTrack || protection == requestedFecProtection) { | ||
| return | ||
| } | ||
| requestedFecProtection = protection | ||
| sendUpdateTrackSettings.invoke() |
There was a problem hiding this comment.
🟡 Lost FlexFEC protection after resubscribe
After a completed unsubscribe, setFecProtection drops an identical request when the app resubscribes without adaptive stream. The server starts the new subscription with repairs off, but fecProtection still reports the previous request.
Learn more
The server deletes the subscription and its settings when an explicit unsubscribe finishes. In the companion server implementation, SubscriptionManager.reconcileMediaTrackSubscriptions removes subscriptions once needsCleanup reports that the closed track is no longer desired. However, setSubscribed leaves the client's publication and its cached request intact. On resubscribe, addSubscribedMediaTrack looks up the same publication by SID and attaches the track. With adaptive stream off, the track setter does not send settings, and repeating the request hits the equality check.
Example: Set Fixed(HIGH) on a subscribed camera. Unsubscribe long enough for the server to finish removing the subscription, then resubscribe and apply Fixed(HIGH) again. The getter still reports Fixed(HIGH), but the new subscription gets no repair packets until another setting sends the cached request.
Recommended fix: Replay a non-null FEC request when resubscribing, including with adaptive stream disabled, or scope request deduplication to the current subscription. Add a test that unsubscribes and resubscribes to the same SID, then checks that the prior mode and level are sent again.
Was this helpful? React with 👍 or 👎 to provide feedback.
| private val fieldTrials: String | ||
| get() = if (LiveKit.enableFlexFec) DEFAULT_FIELD_TRIALS + FLEXFEC_FIELD_TRIALS else DEFAULT_FIELD_TRIALS |
There was a problem hiding this comment.
🟡 Downstream FlexFEC bypasses opt-in
With enableFlexFec off, libwebrtc still accepts flexfec-03 in receive-only video offers. On a downstream-enabled server, setFecProtection can start repair traffic despite the app leaving the flag off.
Learn more
In the pinned libwebrtc build, GetDefaultSupportedFormats adds flexfec-03 for decoders even when the advertisement trial is unset. CodecVendor::GetVideoCodecsForAnswer uses that receive codec list for receive-only answers on the default SDP path. WebRtcVideoReceiveChannel::ConfigureReceiverRtp also accepts a negotiated repair stream when the trial is unset. The SDK's answerServerOffer applies the native answer unchanged, and the track settings request sends FEC without checking the flag latched at initialization.
Example: Leave the flag at its default, join a two-peer-connection room on a server that offers downstream FlexFEC, and request Fixed(HIGH) on a subscribed video. The downstream codec can negotiate and the request can activate repairs instead of being a no-op.
Recommended fix: If the flag is meant to gate negotiation, exclude flexfec-03 from the subscriber's negotiated codecs when disabled. If receive negotiation is intentionally native-default, document that distinction and gate outgoing FEC requests on the latched opt-in if they must remain a no-op. Cover the default-off receive case with an integration test.
Was this helpful? React with 👍 or 👎 to provide feedback.
libwebrtc 150.7871.08 adds a fecProtection parameter to the RtpParameters constructor.
Note
Draft until livekit/protocol#1987 is merged. The
protocolsubmodule currently points atduan/fec-subscribe-presets-android(3a115c89), which is #1987 cherry-picked onto the protocol commitmainpins (30d320b7). Once #1987 lands, the submodule should be moved to the merged commit.Adds FlexFEC negotiation and per-track subscriber FEC protection.
FlexFEC negotiation
LiveKit.enableFlexFecturns on theWebRTC-FlexFEC-03-AdvertisedandWebRTC-FlexFEC-03field trials when libwebrtc is initialized, soflexfec-03is negotiated. It is process-wide and must be set before the firstRoomis created. Disabled by default.Subscriber FEC protection
RemoteTrackPublication.setFecProtectionasks the server to send FlexFEC repair packets for a subscribed video track throughUpdateTrackSettings.fec:FecProtectionis a sealed class mirroring the protocol modes:FecProtection.Disabled(default)FEC_MODE_DISABLEDFecProtection.AdaptiveFEC_MODE_ADAPTIVEFecProtection.Fixed(level)FEC_MODE_FIXED+ levelFecProtection.Minimum(level)FEC_MODE_MINIMUM+ levelFecProtectionLevelisLOW/MEDIUM/HIGH(about 15/25/35% repair overhead). Only the modes that use a level carry one, so invalid combinations cannot be expressed.fecis only sent aftersetFecProtectionhas been called. That follows theoptionalsemantics in #1987: omitting the field keeps the server's setting, so other settings updates do not reset it.Tests
RemoteTrackPublicationTest:fecis omitted until requested, it is kept on later updates, every mode and level maps to the right proto values, and it is sent under adaptive stream.FlexFecSubscribeTestandFlexFecPublishTest. They check the repairs received in each mode through the inbound-rtp FEC counters, and the publisher's FlexFEC negotiation with and without simulcast. They are skipped unless run with theflexFec=trueinstrumentation argument against a server with FlexFEC enabled. Results from the earlier on-device runs are in the comment below.libwebrtc
Updates libwebrtc to
150.7871.08.