Repository navigation
feat(whip output): send H.264, VP8 and VP9 video alongside audio - #1086
Conversation
srperens
left a comment
There was a problem hiding this comment.
Area: WHIP Output, video and track layout
Adds num_audio_tracks/num_video_tracks. Encoded H.264 is checked in a caps probe and refused with an element error otherwise. Sink pads are now requested in a setup hook, only for linked inputs. The approach follows the Output Block Inputs rule and WHEP Output's layout. The new tests drive the real block, including through PipelineManager, and Check (Linux) ran them.
Neighbours: the sibling is #1085 (the WHEP Input half of #839). Pre-encoded H.264 over WebRTC has a history on WHEP Output: the profile in #896/#899 and the level in #900. This block takes the same input. #1087 found WHIP Output to be the consumer that blocks an AES67 Input, and that stays true with a video chain added.
- Silent audio loss, a new behaviour for this block (inline on
mod.rs:198). Before,audio_inwas always linked to the sink. Now a link that construction defers topending_linksreads as unconnected, so no pad is requested. The flow then publishes without that track and logs only atinfo!. The PR documents this limit, but there is nothing for an operator to see. - Only the profile is checked; level and B-frames are not (inline on
video.rs:50). A pre-encoded feed passed through (SRT, RTMP) can carry B-frames or a level change mid-stream. That is the #900 failure, here on the publish side. Not verified against whipsink or webrtcsink.
| let mut linked_video = 0usize; | ||
|
|
||
| for track in &tracks { | ||
| if !input_is_connected(&track.input) { |
There was a problem hiding this comment.
This is new for audio on this block. Before this PR, audio_in was always linked into sink_0/audio_0. Now an input fed through a link deferred to pending_links reads as unconnected. That happens with a sometimes pad, such as a raw decodebin element placed before the block. The track is then skipped, and only an info! line records it, so the flow plays and publishes without that audio. A warn!, or a block-level error when a declared and linked-in-the-flow track gets no pad, would make it visible. Not verified which flows in use hit this.
| pub(super) fn video_plan(caps_name: &str, profile: Option<&str>) -> Result<(), String> { | ||
| match caps_name { | ||
| "video/x-h264" => match profile { | ||
| Some(p) if !WEBRTC_H264_PROFILES.contains(&p) => Err(format!( |
There was a problem hiding this comment.
Only profile is checked. Fed by builtin.videoenc, B-frames are off. Fed by passthrough H.264 (an SRT or RTMP input), the input can carry B-frames, which WebRTC receivers handle badly. It can also raise its level mid-stream: #900 is that failure on WHEP Output, where it ends in not-negotiated. Not verified for whipsink/webrtcsink. If it reproduces, it belongs in the same refusal path.
ae2eaed to
9c4db75
Compare
srperens
left a comment
There was a problem hiding this comment.
Area: WHIP Output, video input and track layout
Adds H.264 video tracks and num_audio_tracks/num_video_tracks, and requests sink pads only for inputs the flow feeds. The new commit closes my earlier finding 1: FlowLinkTargets counts a link still waiting for a sometimes pad as connected (inputs.rs:38-46, filled at block_expansion.rs:173-175). It is per-flow, so there is no cross-flow key. The *_through_sometimes_pads tests drive that path through PipelineManager.
Neighbours: #1085 is the sibling (WHEP Input video) for #839. #899, now on main, strips profile and level on WHEP Output's webrtcsink chain; this PR shares whep/output/mod.rs with it, and GitHub reports it mergeable. #1057 (recorder.rs) and draft #1025 (block_expansion.rs) touch shared files; conflicts not verified.
- Raw video is refused, unlike WHEP Output, though BLOCK_GUIDELINES exempts WebRTC outputs from the encoded-video rule (inline on
video.rs:58). - The new tests have not run in CI at this head.
Check (Linux)failed invision_mixer_input_format_test::gpu_converter_comes_out_when_the_format_switches_back, a GPU vision mixer test this PR does not touch (same family as #1092).cargo testinci.ymlhas no--no-fail-fast, so it stopped beforewhip_output_video_testand the new sometimes-pad tests. Re-run before merge. - Still open from the last review: only
profileis checked on pre-encoded input, not level or B-frames (video.rs:49-57).
| )), | ||
| _ => Ok(()), | ||
| }, | ||
| other => Err(video_refusal("WHIP Output", "H.264", other)), |
There was a problem hiding this comment.
This refuses raw video. docs/BLOCK_GUIDELINES.md (Output Block Inputs): "WebRTC outputs (WHEP, WHIP) are exempt from the video rule below: codec negotiation is part of the protocol, and the sink encodes." WHEP Output takes raw video and lets webrtcsink encode it (whepserversink.rs:25, :575). So the two WebRTC outputs now take different inputs, and an operator feeding a raw source to WHIP must insert builtin.videoenc, which the Block Input Contract tries to avoid. With whipclientsink (webrtcsink), raw video could pass through and the sink would encode and negotiate the codec; only whipsink would need an encoder in the block. Not verified which sink the block uses in every mode. My earlier review called this refusal consistent with the rule; that was wrong.
WHIP Output was audio only. It now takes num_audio_tracks (default 1) and num_video_tracks (default 0), with pads computed like WHEP Output's: audio_in / video_in for slot 0, suffixed for the rest. The defaults keep every saved flow unchanged, so no migration is needed. Video must arrive encoded. An identity probe on each video input accepts H.264 in the profiles WebRTC receivers decode and refuses anything else with an element error naming builtin.videoenc. whipsink gets h264parse -> rtph264pay (config-interval=-1, its own payload type); whipclientsink gets the stream directly and its video-caps narrowed to the detected codec. Sink pads are now requested from a setup hook, only for inputs the flow links, so a declared but unlinked track no longer holds the session back. input_is_connected and explicit_track_count move to a shared blocks::builtin::inputs module used by RTMP, Recorder, Media Player, WHEP Output and WHIP Output. Part of #839 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The setup hooks of WHIP Output, RTMP Output and Recorder request a sink or muxer pad only for inputs that are linked. A link from a sometimes pad (decodebin, parsebin) waits in pending_links until data flows, after the hooks have run, so such an input read as unconnected and got no pad. For WHIP Output's audio_in that was a regression: it always had a pad before. Block expansion now records the element each resolved flow link points into, in a FlowLinkTargets handle on BlockBuildContext. input_is_connected takes that handle and counts an input as connected when its sink pad is linked or a flow link targets it. The late link lands on the input element, which the hook has already wired to the pad. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9c4db75 to
b52cebc
Compare
srperens
left a comment
There was a problem hiding this comment.
Area: WHIP Output, video input and track layout
Head b52cebc is a rebase of 9c4db75 onto main. The only conflict was the mod profile_filter; context line in whep/output/mod.rs, and the PR's own code is unchanged (range-diff). The approach still looks right.
Previous findings:
- Fixed: the new tests now run in CI.
Check (Linux)ran all 15 ofwhip_output_video_test, including the*_through_sometimes_padsand*_refuses_raw_video_*tests, and they passed. - Still open: raw video is refused, although the WebRTC exemption and the Block Input Contract point the other way (inline,
video.rs:58). - Still open: only
profileis checked on pre-encoded H.264, not level or B-frames (video.rs:49-57; compare #900).
Neighbours: #1085 (WHEP Input video, the other half of #839) is still open. #1057 (recorder.rs) and #1025 (builder.rs, block_expansion.rs) touch shared files. GitHub reports this PR as mergeable now.
- While
whip_output_video_testran on Linux CI, the log showsGStreamer-CRITICAL: Trying to dispose element webrtcbin1 / rtpbin / rtpfunnel1 / bin5, but it is in PAUSED. This was seen in no other test binary in that job. ThePipelineManagertests assert that nothing leaks (whip_output_video_test.rs:651-668) and passed, so this is probably webrtcsink's own session teardown or the test'swhipserversrc. Not verified which.
| )), | ||
| _ => Ok(()), | ||
| }, | ||
| other => Err(video_refusal("WHIP Output", "H.264", other)), |
There was a problem hiding this comment.
Still open from the last review. BLOCK_GUIDELINES exempts WebRTC outputs from the encoded-video rule ("codec negotiation is part of the protocol, and the sink encodes"), and the Block Input Contract says the operator never has to insert a converter just to make two blocks link. whipclientsink can encode raw video itself, as WHEP Output's sink does. If refusing raw is deliberate (one explicit encoder block), say so in the guideline or the PR.
…64 level rises WHIP Output now takes the codecs WebRTC receivers decode: H.264 in the WebRTC profiles, VP8, and VP9 profile 0. On whipsink each video track has a payloader per codec behind a funnel, and the input probe links the one that arrives. Raw video is still refused: WHIP Output publishes one session, so it takes encoded video like any other output (BLOCK_GUIDELINES updated). A pre-encoded H.264 source whose level rises mid-publish ended the whipclientsink session: webrtcsink pins the level on its session filters and refuses a caps change to a higher level. The block now drops level from the caps it hands the sink and installs WHEP Output's profile filter, moved to a shared module, on whipclientsink. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…puts #1086 moved it there from whep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(whep input): decode video to video_out outputs WHEP Input received the video track and threw it away. A new num_video_tracks property (default 0, so saved flows keep their pads) adds video_out, video_out_1, ... outputs, each a tee the flow links to. Video streams take the outputs in arrival order and are decoded with decodebin into the tee, in whatever memory the decoder produces. A stream whose output is not linked, or beyond the declared count, is still discarded undecoded; connectivity is decided in an element-setup hook before the pipeline starts. Depayloaders and decoders in the video decodebin are set to request a keyframe after loss, which webrtcbin turns into a PLI to the sender. Part of #839 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(whep input): free a video slot when its stream ends, and probe caps before linking A video stream claimed its slot from a counter that never went down, so a stream that came back within one run (a session that ends and starts again) found every slot taken and was discarded, and the old decoder still fed the tee. Slots are now taken and released: when the source unlinks a stream's pad, the slot is freed and the stream's identity and decoder are removed from the pipeline, so the new stream decodes into the same output. The caps probe on a stream's identity was installed after the source pad was linked to it. A caps event that passed in between left the stream unrouted. The probe now goes in first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(whep input): import explicit_track_count from blocks::builtin::inputs #1086 moved it there from whep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Refs #839. Part of #839: a second PR adds video to WHEP Input.
Problem
WHIP Output sent audio only. Its description said so, and there was no way to publish video to a WHIP server from a flow. It also linked its one audio input to the sink at build time, so the sink always had a pad, linked or not.
Change
Track counts, like WHEP Output. New properties
num_audio_tracks(UInt, default 1) andnum_video_tracks(UInt, default 0, "0 = audio only"). Default 1/0 is deliberate: saved flows leave out properties at their default value, so a 1/1 default could not be migrated reliably. With 1/0 every existing flow is unchanged and nothing needs migrating. Pads come fromWHIPOutputBuilder::get_external_pads, with WHEP Output's naming: slot 0 isaudio_in/video_in(so existing links survive), thenaudio_in_1,video_in_1, ... Slot 0 also keeps its internal element (audioconvert).prepare_flowand the state code callget_external_padsgenerically, so nothing else needed changing.Video must arrive encoded (Output Block Inputs rule). Each video track starts with an
identityand an EVENT_DOWNSTREAM caps probe on its src pad. There is no BUFFER probe. The probe accepts the codecs WebRTC receivers decode: H.264 in the profiles they support (constrained-baseline through High; the same list RTMP Output uses), VP8, and VP9 profile 0. Anything else postsgst::element_error!from the input through the sharedrefusal::refuse_input/video_refusal:builtin.videoenc's codecbuiltin.videoenc's profilewhipsinkonly: a codec change mid-publish (the published session cannot change codec)Per implementation:
whipsink(default): each video track has one chain per codec, all into afunnelthat feedssink_N:h264parse -> rtph264pay (config-interval=-1, aggregate-mode=zero-latency),rtpvp8pay,rtpvp9pay. The probe links the identity to the chain for the codec that arrives, only once the caps are accepted. If it were linked at build time,h264parsewould answer the caps query and the link from a raw source would fail during flow construction, before the block could say why. Each stream gets its own payload type from 96 upward, in pad order; a video track's three payloaders share its PT. Audio comes first, so an audio-only session still uses PT 96.whipclientsink:identity -> video_N. The probe setsvideo-capsto the codec that arrives. On H.264 it strips the caps fields webrtcsink's chain does not take (coded-picture-structure,chroma-format,bit-depth-*), as WHEP Output does, and alsolevel(see below).video-capsstays empty whennum_video_tracksis 0 or no video input is linked.whipsink, webrtcsink's own forwhipclientsink), now one chain per audio track.Request pads only for linked inputs. Sink pads are requested from a
ctx.register_element_setuphook, the same window RTMP and Recorder use: after construction has linked every block, before the pipeline leaves NULL. Only inputs the flow feeds get a pad. A declared video track left unlinked would otherwise make the sink wait for its caps and never negotiate the session, audio included. The build-timeinternal_linksintosink_0/audio_0moved into the hook.A pending link counts as connected (second commit, applies to RTMP and Recorder too). A link from a sometimes pad (
decodebin,parsebin) cannot be made at construction. It waits inpending_linksuntil data flows, after the hooks have run, so it used to read as unconnected and its track got no pad. For WHIP'saudio_inthat would have been a regression, since it always had a pad before. Block expansion now records the element each resolved flow link points into, in aFlowLinkTargetshandle onBlockBuildContext.input_is_connected(input, &targets)is true when the input's sink pad is linked or a flow link targets it. The late link lands on the block's input element (audioconvert/identity), which the hook has already wired to the sink pad, so the pending-link resolver ingst/pipeline/linking.rsneeds no change. The tests below show media arriving through it.Shared helpers.
input_is_connectedexisted twice (rtmp, recorder) andexplicit_track_countlived in WHEP Output and was also used by Media Player. Both moved to a newblocks::builtin::inputsmodule, which RTMP, Recorder, Media Player, WHEP Output and WHIP Output now use.A rising H.264 level keeps publishing on
whipclientsink. The same failure as #900 on WHEP Output, here on the publish side: a pre-encoded source that goes from 320x240 (level 1.2) to 1280x720 (level 3.1) mid-publish ended the session. Two things in webrtcsink stop it: its input caps check refuses a caps change to a higher level than the session started with, and its per-session encoder filter carries alevellist up to the starting level. The probe now dropslevelfrom the caps it hands the sink (webrtcsink's ownh264parseputs it back from the stream), and the block installs WHEP Output's profile filter on whipclientsink. That filter moved fromwhep/output/profile_filter.rsto a sharedblocks::builtin::webrtcsink_profile_filter. Once the session ends, gst-plugins-rs 0.15.2's WHIP signaller also panics interminate_session("Cannot start a runtime from within a runtime"), which aborts the process. That is an upstream bug; this change stops this block from reaching it on a level change.BLOCK_GUIDELINES. The Output Block Inputs section exempted WHEP and WHIP from the encoded-video rule. Only WHEP Output keeps the exemption now: each viewer negotiates its own codec. WHIP Output publishes one session to one server, so it takes encoded video like any other output and needs a Video Encoder in front. This was decided on review.
The block description now says what the block does, and that video needs a Video Encoder in front.
Rejected: encoding video inside the block (the triage's option A). Codec, profile and bitrate stay the operator's choice in
builtin.videoenc, which already disables B-frames for RTP. Rejected: requesting pads from the caps probe. webrtcsink refuses pad requests once it has started, and whipsink does not renegotiate.Evidence
whipsink_requests_no_pad_for_an_unlinked_video_track,whipclientsink_requests_no_pad_for_an_unlinked_video_track. With the connectivity check disabled in the hook they fail withleft: [("sink_0", true), ("sink_1", true)] right: [("sink_0", true)]andleft: [("audio_0", true), ("video_0", true)] right: [("audio_0", true)].whipsink_publishes_audio_with_a_video_track_left_unlinkedandwhipclientsink_publishes_audio_with_a_video_track_left_unlinkedpublish to a standalonewhipserversrcon localhost. With the connectivity check disabled both fail:the server received 0 audio buffers.whipsink_publishes_h264_to_a_whip_server,whipclientsink_publishes_h264_to_a_whip_server(>= 10 buffers of each atwhipserversrc).whipsink_flow_publishes_video_and_tears_downandwhipclientsink_flow_publishes_video_and_tears_downbuild a stored flow (elements -> block with computed pads) throughPipelineManager, so they cover expansion, the manager's linking and setup hooks. They check that video reaches the server and that, after stop and drop, the pipeline and every element are finalized (no strong refs in closures).whipsink_flow_publishes_through_sometimes_padsandwhipclientsink_flow_publishes_through_sometimes_padsfeedaudio_inthroughdecodebinandvideo_inthroughparsebinin a stored flow run byPipelineManager. Both links are pending when the hook runs. With the flow-link check removed frominput_is_connectedboth fail:the WHIP server received 0 video and 0 audio buffers from the flow (whipsink, SometimesPads) in 20 s(same for whipclientsink).whipsink_refuses_raw_video_by_failing_the_flow,whipclientsink_refuses_raw_video_by_failing_the_flow. Each asserts exactly one error, fromwhip:video_input, namingbuiltin.videoenc, and none from the test source. An earlier draft that statically linked identity -> h264parse failed this test at link time (Failed to link elements 'capsfilter2' and 'whip:video_input').videotestsrc, and the block refused it. The test now pins I420.sink_0, PT 96):whipsink_audio_only_flow_is_unchanged. This one passes before and after: it guards the rewrite, not a new claim.whip/output/mod.rs(defaults_keep_the_block_audio_only_with_the_existing_pad,video_tracks_add_video_pads_and_keep_audio_in,more_audio_tracks_suffix_from_slot_one,the_static_definition_matches_the_default_pads) callWHIPOutputBuilder::get_external_pads. Codec and profile decisions: unit tests inwhip/output/video.rs.whipsink_publishes_vp8_to_a_whip_server,whipclientsink_publishes_vp8_to_a_whip_server, and the same for VP9 (vp8enc/vp9enc into the block,whipserversrcoffering H264, VP8 and VP9).whipsink_keeps_publishing_when_the_h264_level_risesandwhipclientsink_keeps_publishing_when_the_h264_level_riseschange the source from 320x240 to 1280x720 mid-publish and need 50 more video buffers at the server. Withoutlevelin the stripped fields the whipclientsink test fails (video stopped after the level rose). Without the profile filter it aborts the test binary with the upstream signaller panic above.builtin.videoencturns them off. This is a known limit, not a guard.Tests
Ran, on macOS (Apple Silicon), GStreamer from Homebrew, with my own target dir:
cargo fmt,cargo clippy --all-targets -- -D warnings: cleanRebased on main before the second commit, and the commands rerun after it:
cargo test --lib: 979 passed, 6 ignored (pre-existing)cargo test --test whip_output_video_test21 passed (parallel and--test-threads=1),cargo test --lib whip68 passed,cargo test --test whep_output_profile_filter_test3 passed (the filter moved),cargo test --test openapi_testpassed, clippy clean. Not rerun for the third commit: the other suites listed below.cargo test --test whip_output_video_test: 15 passed. Before the second commit, the 13 tests that existed then were also run 3 more times; all passed, about 4 s each.cargo test --test whip_output_latency_test: 2 passed. Updated: it linked whipclientsink'saudio_0throughinternal_links, which no longer exist. It now links a source toaudio_inand runs the setup hook, as the manager does.cargo test --test pipeline_lifecycle_test: 4 passedcargo test --test openapi_test: passed. The schema did not change (block definitions are not in it).cargo test --test output_refusal_test --test rtmp_output_test --test recorder_test --test recorder_stall_test --test whip_whep_ice_transport_policy_test: all passedice_preflight_test,media_player_control_test: passedSkipped: none. No test returned early here. All new tests need only elements already in the CI package lists (
whipsink,whipclientsinkandwhipserversrcare linked in statically;x264encis plugins-ugly,vp8enc/vp9enc,rtpvp8pay/rtpvp9payandfunnelare plugins-good and core,parsebinanddecodebinplugins-base,h264parseplugins-bad,rtph264payandrtpopuspayplugins-good,nicefrom gstreamer1.0-nice / libnice-gstreamer). UnderSTROM_REQUIRE_GST_PLUGINS=1they fail rather than skip.Not run: Linux and Windows locally (CI covers them), and a third-party WHIP server or browser. The loopback uses gst-plugins-rs's own
whipserversrc, not Strom's WHIP Input (whose HTTP side sits behind the axum proxy) and not an external server.For the reviewer
FlowLinkTargetsadds one public type and accessor onBlockBuildContext. Expansion fills it after every block has built. A test that builds a block on its own and runs its hooks without expansion gets an empty set, so only real GStreamer links count there, as before.num_audio_tracks> 1 is new too. Each audio track gets its own Opus chain and PT. Only one audio track is exercised in the tests.Out of scope
video_planand the whipsink codec chains are where to extend.GStreamer-CRITICAL: Trying to dispose element webrtcbin1 / rtpbin / rtpfunnel1 / bin5seen in CI. Locally it shows only when the test binary runs in parallel, never with--test-threads=1. The element is awebrtcbininside a plainbinN, which is howwebrtcsrclays out a session, so it comes from the test'swhipserversrc, the same teardown issue as WHEP Input: whepclientsrc may leave a removed session bin above NULL, as whipserversrc did #953. The block's own sinks hold their webrtcbin inwhipsinkitself or in webrtcsink'ssession-pipeline-*. The PipelineManager tests assert that nothing the block built outlives the flow, and they pass.🤖 Generated with Claude Code