refactor: clear too_many_arguments and large_enum_variant warnings
Oracle P2 batch 2 (refactor items). Drops both remaining design-shape
clippy warnings to zero without behavior change.
- avhw.rs build_filter_graph: drop unused _enc_width/_enc_height params
(Oracle caught them during P2 review — passed by EncState::new but
never read inside the function; the filter graph uses width/height
only). Signature: 8 args -> 6 args (under clippy's 7 threshold).
- state.rs InFlightSurface::CopyQueued: Box the drm_map field.
AVDRMFrameDescriptor is ~592 bytes (4 objects + 4 layers); the enum
size was being dominated by this variant, ballooning every
InFlightSurface value to 592 bytes even for the None/AllocQueued
variants. Box<AVDRMFrameDescriptor> shrinks the enum to ~32 bytes
regardless of variant. The drm_map field is currently destructured
under _drm_map (unused), so the boxing has no consumer-side impact.
- state_portal.rs webrtc_thread_loop: 10 args -> 4 args via two new
structs:
* WebRtcThreadConfig { fps, enc_width, enc_height, max_bitrate }
— immutable for the thread's lifetime; a tier change spawns a
new thread rather than mutating.
* WebRtcThreadChannels { webrtc_rx, sent_gap_tx, bitrate_tx,
resolution_tx } — channel endpoints owned exclusively by the
sender thread after spawn.
wrtc (WebRtcState) and paused (Arc<AtomicBool>) stay as separate
args because they have different ownership semantics (moved-in
state vs shared atomic). Documented as doc comments on the new
types so the next reader understands the bundle rationale.
All 79 unit tests + 3 integration tests pass. clippy: 0 errors.
Per-file warning counts: state_portal.rs down from 3 to 0; state.rs
down from 8 to 4 (remaining are unrelated dead-code on OutputInfo /
starting_timestamp).
This commit is contained in:
@@ -391,8 +391,6 @@ impl EncState {
|
|||||||
&frames_rgb,
|
&frames_rgb,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
enc_width,
|
|
||||||
enc_height,
|
|
||||||
fps,
|
fps,
|
||||||
transform,
|
transform,
|
||||||
)?;
|
)?;
|
||||||
@@ -2005,8 +2003,6 @@ fn build_filter_graph(
|
|||||||
frames_rgb: &AvHwFrameCtx,
|
frames_rgb: &AvHwFrameCtx,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
_enc_width: u32,
|
|
||||||
_enc_height: u32,
|
|
||||||
fps: u32,
|
fps: u32,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
) -> Result<ff::filter::Graph> {
|
) -> Result<ff::filter::Graph> {
|
||||||
|
|||||||
+5
-2
@@ -193,7 +193,10 @@ pub enum InFlightSurface<S: CaptureSource> {
|
|||||||
AllocQueued,
|
AllocQueued,
|
||||||
CopyQueued {
|
CopyQueued {
|
||||||
surface: ff::frame::Video,
|
surface: ff::frame::Video,
|
||||||
drm_map: ff::ffi::AVDRMFrameDescriptor,
|
// Boxed: AVDRMFrameDescriptor is ~592 bytes (4 objects + 4 layers),
|
||||||
|
// which would balloon every InFlightSurface variant via enum alignment.
|
||||||
|
// The box shrinks the enum to ~32 bytes regardless of variant.
|
||||||
|
drm_map: Box<ff::ffi::AVDRMFrameDescriptor>,
|
||||||
frame: S::Frame,
|
frame: S::Frame,
|
||||||
buffer: WlBuffer,
|
buffer: WlBuffer,
|
||||||
},
|
},
|
||||||
@@ -568,7 +571,7 @@ impl<S: CaptureSource> State<S> {
|
|||||||
);
|
);
|
||||||
self.in_flight_surface = InFlightSurface::CopyQueued {
|
self.in_flight_surface = InFlightSurface::CopyQueued {
|
||||||
surface,
|
surface,
|
||||||
drm_map: desc,
|
drm_map: Box::new(desc),
|
||||||
frame,
|
frame,
|
||||||
buffer: wl_buffer,
|
buffer: wl_buffer,
|
||||||
};
|
};
|
||||||
|
|||||||
+40
-10
@@ -42,6 +42,26 @@ struct WebrtcThread {
|
|||||||
sent_gap_rx: crossbeam_channel::Receiver<(f64, Option<f64>)>,
|
sent_gap_rx: crossbeam_channel::Receiver<(f64, Option<f64>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Static configuration handed to the WebRTC sender thread. Immutable for the
|
||||||
|
/// thread's lifetime; a resolution tier change rebuilds the whole pipeline
|
||||||
|
/// (and spawns a new thread) rather than mutating this.
|
||||||
|
struct WebRtcThreadConfig {
|
||||||
|
fps: u32,
|
||||||
|
enc_width: u32,
|
||||||
|
enc_height: u32,
|
||||||
|
max_bitrate: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Channel endpoints owned exclusively by the WebRTC sender thread after spawn.
|
||||||
|
/// The reverse endpoints stay with StatePortal (or the encode thread) for
|
||||||
|
/// inbound/outbound traffic.
|
||||||
|
struct WebRtcThreadChannels {
|
||||||
|
webrtc_rx: crossbeam_channel::Receiver<EncodedH264Frame>,
|
||||||
|
sent_gap_tx: crossbeam_channel::Sender<(f64, Option<f64>)>,
|
||||||
|
bitrate_tx: crossbeam_channel::Sender<BitrateCommand>,
|
||||||
|
resolution_tx: crossbeam_channel::Sender<BitrateCommand>,
|
||||||
|
}
|
||||||
|
|
||||||
/// 门户模式的主状态机
|
/// 门户模式的主状态机
|
||||||
///
|
///
|
||||||
/// 负责管理从 PipeWire 采集屏幕帧、通过 VAAPI 硬件编码的完整生命周期。
|
/// 负责管理从 PipeWire 采集屏幕帧、通过 VAAPI 硬件编码的完整生命周期。
|
||||||
@@ -288,15 +308,19 @@ impl StatePortal {
|
|||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
webrtc_thread_loop(
|
webrtc_thread_loop(
|
||||||
wrtc,
|
wrtc,
|
||||||
webrtc_rx,
|
WebRtcThreadConfig {
|
||||||
fps,
|
fps,
|
||||||
enc_width,
|
enc_width,
|
||||||
enc_height,
|
enc_height,
|
||||||
max_bitrate,
|
max_bitrate,
|
||||||
paused,
|
},
|
||||||
|
WebRtcThreadChannels {
|
||||||
|
webrtc_rx,
|
||||||
sent_gap_tx,
|
sent_gap_tx,
|
||||||
bitrate_tx,
|
bitrate_tx,
|
||||||
resolution_tx,
|
resolution_tx,
|
||||||
|
},
|
||||||
|
paused,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
self.webrtc_thread = Some(WebrtcThread {
|
self.webrtc_thread = Some(WebrtcThread {
|
||||||
@@ -695,16 +719,22 @@ fn encode_thread_loop(
|
|||||||
|
|
||||||
fn webrtc_thread_loop(
|
fn webrtc_thread_loop(
|
||||||
mut wrtc: WebRtcState,
|
mut wrtc: WebRtcState,
|
||||||
webrtc_rx: crossbeam_channel::Receiver<EncodedH264Frame>,
|
config: WebRtcThreadConfig,
|
||||||
fps: u32,
|
channels: WebRtcThreadChannels,
|
||||||
enc_width: u32,
|
|
||||||
enc_height: u32,
|
|
||||||
max_bitrate: u64,
|
|
||||||
paused: Arc<AtomicBool>,
|
paused: Arc<AtomicBool>,
|
||||||
sent_gap_tx: crossbeam_channel::Sender<(f64, Option<f64>)>,
|
|
||||||
bitrate_tx: crossbeam_channel::Sender<BitrateCommand>,
|
|
||||||
resolution_tx: crossbeam_channel::Sender<BitrateCommand>,
|
|
||||||
) {
|
) {
|
||||||
|
let WebRtcThreadConfig {
|
||||||
|
fps,
|
||||||
|
enc_width,
|
||||||
|
enc_height,
|
||||||
|
max_bitrate,
|
||||||
|
} = config;
|
||||||
|
let WebRtcThreadChannels {
|
||||||
|
webrtc_rx,
|
||||||
|
sent_gap_tx,
|
||||||
|
bitrate_tx,
|
||||||
|
resolution_tx,
|
||||||
|
} = channels;
|
||||||
let mut frames_sent: u64 = 0;
|
let mut frames_sent: u64 = 0;
|
||||||
let mut last_send: Option<std::time::Instant> = None;
|
let mut last_send: Option<std::time::Instant> = None;
|
||||||
let mut last_sent_bitrate: Option<u64> = None;
|
let mut last_sent_bitrate: Option<u64> = None;
|
||||||
|
|||||||
Reference in New Issue
Block a user