Repository navigation
fix(whep): pin raw audio before whepserversink so a start-up renegotiation cannot fail the flow - #1030
fix(whep): pin raw audio before whepserversink so a start-up renegotiation cannot fail the flow#1030Lufftre wants to merge 1 commit into
Conversation
…ation cannot fail the flow A flow started while an SRT input is already receiving intermittently failed to reach Playing with "There is no codec present that can handle the stream's type" from the WHEP Output's whepserversink. The WHEP Output passed raw audio straight to the sink, so it got whatever upstream negotiated. An audio mixer in front of it settles on F32LE at 44.1 kHz and switches to S32LE about 100 ms later. webrtcsink starts a codec discovery for each set of caps and feeds every buffer to both; around the switch the timestamps step back, the Opus encoder in one discovery fails with "buffer going too far back in time", and a failed discovery is fatal. A new audio_input_bridge splices audioconvert ! audioresample ! capsfilter (S16LE, 48 kHz, stereo) in front of the sink on the first raw CAPS event, so the sink sees one set of caps for the life of the pad. Encoded audio passes through untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
srperens
left a comment
There was a problem hiding this comment.
Verdict: Comment. The bridge is the right consumer-side shape. It mirrors video_input_bridge, and it follows BLOCK_GUIDELINES: decide from the negotiated caps, pass encoded audio through. Two gaps keep this at Comment. The WHEP wiring has no test, and the rig evidence comes from an image built before the mixer's rate pin landed.
Requested changes
- Add a block-level test in
backend/src/blocks/builtin/whep.rs, next to the existing video one:
backend/src/blocks/builtin/whep.rs:2876—fn video_input_is_converted_before_the_sink() {
It should buildbuild_whepserversinkwith one audio track, feed raw F32LE/44.1 kHz into:audio_queue, and assert that:audio_queue_pin_capssits in front ofaudio_0. Today, deleting this line fails no test:
backend/src/blocks/builtin/whep.rs:1604—audio_input_bridge::install_audio_input_bridge(&audio_queue_src, &audio_queue_id);
The two module tests guardaudio_input_bridge.rsitself, and they run (Check (Linux): bothok).
Claims
| Claim | Verdict | Evidence |
|---|---|---|
| Splice decided per CAPS event, never per buffer | CONFIRMED |
EVENT_DOWNSTREAM probe. The Mutex is taken per event only, which CLAUDE.md allows outside BUFFER probes. The closure holds no element |
| An upstream format switch no longer reaches the sink | CONFIRMED |
upstream_format_switch_does_not_reach_the_sink asserts that the unbridged run sees ≥2 caps, so it fails if the bridge goes inert |
| The start-up failure reproduces on current main | UNVERIFIED |
The rig ran strom-full:0.6.11. v0.6.11 (f1a46dd, 2026-09-29) does not contain d78c3ee (#946, 2026-10-02), which pins every mixer bus to one rate. So the 44.1 kHz leg seen in the log cannot appear on main. A format-only switch still can, because the pin fixes the rate and nothing else |
| webrtcsink discovery is fatal on a caps change | EXTERNAL |
Upstream gst-plugins-rs, taken from the author's trace |
backend/src/blocks/builtin/mixer/elements.rs:121 — .field("rate", rate as i32)
Diagnosis. Coverage is BOUNDED. It closes the "second caps during discovery" trigger for every raw producer, which is the consumer-side fix the guidelines ask for. It does not explain why the mixer renegotiates, or why timestamps step back by about 2^64 ns. Those still reach our own audioresample, which resyncs on a discontinuity rather than failing. Neither is worse after this change. The mixer side deserves an issue; the body's "Out of scope" already names it.
Behaviour change (disclosed). Every raw WHEP audio track is now S16LE/48 kHz/stereo: F32 input loses its float headroom before Opus, and multichannel input is downmixed once. PINNED_RAW_AUDIO is a pub const and not a block property, which matches the stereo-Opus target. It is a deliberate hardcode, though, so say so if a property is wanted later.
Radius. SHARED: every WHEP Output with raw audio, on every slot (audio_queue_N_pin_*), on CPU and GPU images alike. Opus input is untouched. The spliced elements live in the block's bin and are torn down with the pipeline. No thread, no timer.
Overlaps. #896, #899 and #814 edit whep.rs in the per-viewer video and appsink paths, not the audio queue, so none of them is on this code path. No open issue owns the audio format.
Tests & CI. At f0d2943: Linux, ARM64, WASM, API contract and JS are green. macOS and Windows are skipped, which is fine: the code here is platform-neutral.
Confidence: HIGH
Problem
A flow that starts while an SRT input is already receiving sometimes fails to reach Playing.
whepserversinkposts:Strom then answers 500 "Failed to start flow". Open Live passes that through, so the production falls back to inactive. A real encoder that is already sending when the operator clicks Activate hits the same failure. In the Open Live testbed,
ingest_early_caller_delayfailed this way in 6 of 7 CI runs on Oct 7, against 1 of 10 runs before Oct 3.The cause, from a
GST_DEBUG=webrtcsink:5log of a failing start:F32LEat 44.1 kHz, thenS32LEabout 100 ms later. Every start does this, including the ones that succeed.webrtcsinkstarts a codec discovery for each set of caps and feeds every incoming buffer to both.audioresamplereports a discontinuity of 813501413649709 samples, which is about 2^64 ns. The Opus encoder in a discovery pipeline then fails withbuffer going too far back in time.Change
A new
gst::audio_input_bridge, installed on each WHEP Output audio queue's src pad. On the first raw CAPS event, it splicesaudioconvert ! audioresample ! capsfilterbetween the queue and the sink. The capsfilter is fixed to S16LE, 48 kHz, stereo, which is what WebRTC Opus carries anyway. After that, an upstream renegotiation is absorbed by the converters, and the sink sees one set of caps for the life of the pad. Encoded audio (Opus) is left linked straight to the sink. If the stream switches between raw and encoded mid-stream, the bridge posts an element error rather than failing silently with not-negotiated. It's the audio counterpart ofvideo_input_bridge, and it follows the BLOCK_GUIDELINES rule to decide from negotiated caps when the input is only known at runtime.Rejected alternatives:
Evidence
gst::audio_input_bridge::tests::upstream_format_switch_does_not_reach_the_sinkchecks this. With the bridge disabled, it fails with:the sink saw more than one caps: [... "F32LE" ... 44100 ..., ... "S32LE" ... 44100 ...].encoded_audio_passes_throughchecks this. It passes before and after the change, so it guards against a regression, not the fix itself.strom-full:0.6.11image, Open Livemain, with an SRT caller already sending into source 0 before activation:audio_0caps event wasS16LE, 48000.Tests
cargo test --lib: 898 passed, 5 ignored.cargo test --test pipeline_lifecycle_test: 4 passed.cargo fmt --checkandcargo clippy --all-targets: clean in the changed files.audiotestsrc,audioconvert,audioresampleandopusenc, whichgstreamer1.0-plugins-baseprovides in CI.For the reviewer
webrtcsinkconverted per consumer to whatever Opus negotiated, which was stereo in practice.<audio_queue id>_pin_{convert,resample,caps}.Out of scope
🤖 Generated with Claude Code