Screen share 12: core-codec-negotiation (#159) #235
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "screenshare-12-core-codec-negotiation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on: screenshare-11-core-stream-params
What this builds
fluxer-core::voice::stream::codec(spec §3.4, §6.3 "Codec negotiation (sharer)"):rank_codecs(caps, &VideoSettings) -> Vec<VideoCodec>: port ofrankScreenShareCodecs(default order, software-H.264 order, clamped-H.264 order; hardware first except on the software encoder path; AV1/H.265 opt-ins; H.265 only in hardware or pinned; pin in front; VP8 last resort).select_codec(local, viewers, published, previous, suppressed) -> Selection { codec, reason: Unchanged | Changed | Deferred { wanted } }: the fork'scomputeNegotiatedVideoCodec+ never-upgrade + suppression rules.CodecNegotiationinStreams.negotiation: adverts per identity (op 1 and op 14 codecs), per-participant 3000 ms grace timers, selected codec,media_session_id(derived likertc_connection_id, new per change), 10 000 ms suppression timer and the deferred reason.PublishScreenShare { codec }); it is re-evaluated on adverts, participant join/leave (kept when the last one leaves), grace end, deferred change,Reconnected,CodecCapabilities, settings change and voice-state change. A change sends op 14, thenRepublishScreenShare { codec }and the capture/encoder updates for the new codec (layers, software-H.264 clamp). The republished video keeps the share live under its new sid without a new op 4.codec_advert:voice_onlyuntilCodecCapabilitiesarrived, thenwith_capabilities(encode = ranked codecs actually reported, decode = exactly the reported decoders, so no H.264 decode is ever claimed); re-advertised when this changes (capabilities, settings).Tests
crates/fluxer-core/tests/stream_codec.rs:selection_matches_fork_rules(18 table cases),ranking_hardware_first_and_h264_not_hardware_order,advert_switches_to_capabilities_and_never_claims_missing_decoder,op14_on_change_only,republish_command_on_codec_change,viewers_are_those_watching_or_unknown,migration_messages_ignored.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally. No real-device tests apply.Deviations from the plan
select_codectakesprevious: Option<VideoCodec>, suppressed: boolandViewerCaps { decode, grace_over }instead ofnow, last_change/recheck_at: Option<Instant>: the store has no clock (#109), so the grace and suppression windows areEffect::Scheduletimers, as intyping.rsandaudio_prefs.rs.Selection.reasonsays Unchanged/Changed/Deferred.isVideoCodecAllowedForPublish, and the "frozen" ranking while published (the ranking is recomputed; it changes only with settings).tests/voice_connection.rs::events_of_later_tasks_are_acceptednow also expects the grace timer onParticipantJoined.Closes #159
🤖 Generated with Claude Code
Independent review: Screen share 12 (core codec negotiation)
Scope:
git diff 63b98de..origin/screenshare-12-core-codec-negotiation(a944662). I checked it against the fork'sScreenShareCodecSelection.tsandScreenShareCodecNegotiation.ts.Local gate:
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciin a fresh worktree: all steps passed (fmt, clippy, deny, core isolation, parity, tests, screenshot tests; livekit-interop skipped as usual).Checks
selection_matches_fork_rules(18 cases, at least 12 required),ranking_hardware_first_and_h264_not_hardware_order,advert_switches_to_capabilities_and_never_claims_missing_decoder,op14_on_change_only,republish_command_on_codec_changeandmigration_messages_ignored, plusviewers_are_those_watching_or_unknown. The table covers every case the plan lists: all advertised, unknown viewer inside and after its grace, an H264-less native viewer forcing VP9, opt-ins off, a pinned codec, the suppression window, never upgrade, and the last viewer leaving.rank_codecs(&[CodecCap], &VideoSettings) -> Vec<VideoCodec>matches the plan exactly.select_codectakespreviousandsuppressedinstead ofnowandlast_change,ViewerCapsholds{decode, grace_over}, andSelectionhas norecheck_at. This is justified because the merged store has no clock (#109), and no other task's Interfaces block uses these names.CodecNegotiationis inStreams.negotiation,RepublishScreenShare { codec }is sent on each change, andPublishScreenShareuses the codecselect_codecpicks.fluxer-coregets no iced, wgpu, winit, reqwest or tokio-tungstenite. No pixels or samples reach the core. No LiveKit types appear in a public signature. Server data cannot cause a panic here: payloads go throughCodecMessage::parse, unknown identities are dropped, and there is no unwrap or indexing on server data. The code and fixtures contain no secrets.decodeflags are exactly the reported decoders, andencodelists only codecs the build reported, with the VP8 last-resort entry filtered out. The test asserts(H264, encode=true, decode=false). Voice-only is advertised untilCodecCapabilitiesarrives.viewer_stream_keys; a participant with no list or no voice state counts as a viewer, and every participant counts before publication;is_upgradeuses the same rank comparison as the fork;live.participants()lists remote participants only and is reduced first);rankScreenShareCodecsand the fork'sisH264SoftwareClamped.Findings
CODEC_ADVERTISEMENT_GRACEandCODEC_CHANGE_SUPPRESSIONappear only by name (timers(&effects, CODEC_ADVERTISEMENT_GRACE)). If someone changed either constant, the tests would still pass. Addassert_eq!(CODEC_ADVERTISEMENT_GRACE, Duration::from_millis(3000))and the matching assertion for 10 000 ms. The constants themselves are correct.isVideoCodecAllowedForPublishand the frozen ranking while published.CLAUDE.mdasks for deferred work to becomefollow-upissues linked from the PR before merge.VoiceStateUpdate(the fork does not), and sending op 14 only while sharing. Both are reasonable and listed in the PR body, but Review Focus 4 asks for an exact port. Record them in the spec's divergence list, or in a follow-up issue, so the acceptance checks expect them.Stoppingwaits for the old sid'sLocalTrackUnpublished, which has already arrived, so it runs intoSTOP_TIMEOUT(5 s). A lateLocalTrackPublishedof the new track is then ignored by the core. The runtime should drop a republish that is still in flight when it getsUnpublishScreenShare.Verdict: approve. No blocking findings and the local CI is green.