Skip to content

refactor(whip): split whip.rs and whip_session_manager.rs into sub-modules - #854

Closed
wagenet wants to merge 1 commit into
Eyevinn:mainfrom
wagenet:wagenet/whip-split-modules
Closed

wagenet wants to merge 1 commit into
Eyevinn:mainfrom
wagenet:wagenet/whip-split-modules

Conversation

@wagenet

@wagenet wagenet commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Written by Claude (Claude Code) on behalf of @wagenet.

Description

Splits the two WHIP files that were over the 1500-line threshold into directory modules, following the pipeline/ and vision_mixer/ pattern. #756 committed to doing this separately, before #792.

Layout

File Lines Holds
blocks/builtin/whip.rs (before) 3141
whip/mod.rs 138 WHIPOutputBuilder, WHIPInputBuilder, re-exports
whip/slot_chain.rs 895 build_whipserversrc and its per-slot caps, decodebin, damage-probe and output-stamp helpers
whip/watchdog.rs 259 per-session inactivity watchdog
whip/session.rs 1097 create_whipserversrc_for_session, CreatedSession, keyframe recovery logging, the appsink→slot bridge and its video PTS ordering
whip/output.rs 464 WHIP Output (whipclientsink, whipsink, incoming-RTP handler)
whip/definition.rs 350 block definitions
whip_session_manager.rs (before) 1841
whip_session_manager/mod.rs 569 WhipSessionManager: registry, cleanup task, removal
whip_session_manager/endpoint.rs 231 WhipEndpointConfig, SlotDecodebin, slot allocation, SessionCleanupRequest
whip_session_manager/activity.rs 423 ActivityStamp, SessionActivity, StallSide, DECODE_GRACE
whip_session_manager/takeover.rs 454 allocate_slot_or_take_over, idlest_session, the TAKEOVER_* constants
whip_session_manager/test_support.rs 224 fixtures shared by the manager's test modules (#[cfg(test)])

Line counts include each file's tests. Every public item keeps its path through a pub use in mod.rs, so no caller changed.

Generated, not hand-edited

Every other open WHIP PR edits one of these two files, so a hand-made split would have to be hand-merged against each of them. The split is generated instead, and can be regenerated on whatever base it ends up landing on. The generator is on the fork, not in this PR: tools/whip-split on wagenet/whip-split-tool.

  1. split.py places every item of the two files by a manifest and moves its text unchanged. It refuses to run if a file has an item the manifest does not place.
  2. fixup.py makes the result compile from compiler output alone: it raises to pub(super) exactly the items rustc reports private at a use site, deletes the imports rustc reports unused, and runs cargo fmt.

Running both on this branch's parent reproduces this commit byte for byte.

It is a move

verify.py compares the non-blank lines of the two old files with those of the eleven new ones, leaving out use declarations, leading whitespace and a pub(super) prefix:

  • 4 old lines have no match. 2 are the register and receiving_but_stalled fixture signatures, which rustfmt wrapped once pub(super) pushed them past 100 columns. 2 are comments that named whip.rs by path (below).
  • Every added line is either those 4 rewritten, or structural: 9 mod declarations, 9 //! module headers, 4 new mod tests { wrappers with their #[cfg(test)] and closing braces, the #[cfg(test)] on mod test_support, and the impl WhipSessionManager { wrapper in takeover.rs.

pub(super) went on 17 items: build_whipclientsink, build_whipsink, wait_for_inactivity, INACTIVITY_TIMEOUT, and 13 fixtures in test_support.rs.

Four comments are the only edits that are not moves. Each named a file that no longer exists:

  • backend/static/tests/whip_reconnect.test.js: where INACTIVITY_TIMEOUT lives is now whip/watchdog.rs.
  • WhipSession::cleanup_sent doc: "the callbacks in whip.rs" is now whip/session.rs.
  • DECODE_GRACE doc: the compile-time assertion is in whip/watchdog.rs.
  • gst/pipeline_bridge.rs test_support doc: the call-site test is in whip/session.rs.

Related Issue

None. Follow-up committed to in #756.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Refactor only: no behaviour change.

Checklist

  • I have run cargo fmt --all
  • I have run cargo clippy --workspace --all-targets -- -D warnings
  • I have run cargo test --workspace (WHIP tests only, below)
  • I have updated documentation as needed (none needed)
  • I have added tests for new functionality (no new functionality)

Tests

The old files held 33 unit tests. The same 33 ran and passed in their new modules, matched by name against the test output. Each moved with the code it tests; the manager's takeover and activity tests share fixtures, so those went to test_support.rs.

Run from the workspace root on this branch:

  • cargo fmt --all -- --check: clean
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo test --lib -- whip pipeline_bridge: 44 passed, 0 failed (the 33 moved tests plus other WHIP and pipeline_bridge tests)
  • cargo test on whip_idle_slot_test, whip_session_branch_test, whip_slot_caps_reuse_test, whip_slot_decoder_reuse_test, whip_video_damage_test, whip_whep_ice_transport_policy_test, ice_preflight_test, cors_expose_headers_test, pipeline_lifecycle_test and openapi_test: 31 passed, 0 failed
  • node --test backend/static/tests/whip_reconnect.test.js: 8 passed (its comment changed)

Not run: the rest of cargo test --workspace, the suite with --features efp, and the suite on the parent commit. The unchanged test set rests on the per-name match above.

🤖 Generated with Claude Code

@srperens

Copy link
Copy Markdown
Collaborator

Noted as a draft, so I am holding off on a full review until it is marked ready for review. If you want one before then, say so here or request me as a reviewer.

Both files were past the 1500-line threshold. This is a move: no item is
renamed, no public path changes, and each test moves with the code it
covers.

blocks/builtin/whip/
  mod.rs         block builders and re-exports
  slot_chain.rs  per-slot output chains (build_whipserversrc) and their
                 caps, decodebin, damage-probe and liveness-stamp helpers
  watchdog.rs    per-session inactivity watchdog
  session.rs     per-session whipserversrc pipeline, its keyframe
                 recovery, and the appsink-to-slot bridge
  output.rs      WHIP Output (whipclientsink, whipsink)
  definition.rs  block definitions

whip_session_manager/
  mod.rs          WhipSessionManager, session registry and cleanup
  endpoint.rs     WhipEndpointConfig, SlotDecodebin and slot allocation
  activity.rs     ActivityStamp, SessionActivity, StallSide
  takeover.rs     allocate_slot_or_take_over and its constants
  test_support.rs fixtures shared by the manager's tests

Generated, not hand-edited: a manifest places every item of the two
files, the compiler decides which items become pub(super), and unused
imports are pruned from its warnings. Four comments that named whip.rs
by path now name the file the item moved to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@srperens

srperens commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Closing in favour of #1053, which is now merged. It splits whip.rs (and whep.rs) into input/ and output/ sub-modules, which covers the whip.rs part of this PR. whip_session_manager.rs is still one 1841-line file; a split of that would be welcome as a fresh PR on top of the new layout.

@srperens srperens closed this Oct 8, 2026
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.

2 participants