Skip to content

Commit 1736790

Browse files
fix: resolve clippy lint errors in video nodes
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
1 parent 49d6163 commit 1736790

9 files changed

Lines changed: 106 additions & 96 deletions

File tree

crates/nodes/src/containers/webm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl ProcessorNode for WebMMuxerNode {
418418
let mut video_rx: Option<tokio::sync::mpsc::Receiver<Packet>> = None;
419419

420420
for (pin_name, rx) in context.inputs.drain() {
421-
let is_video = context.input_types.get(&pin_name).map_or(false, |ty| {
421+
let is_video = context.input_types.get(&pin_name).is_some_and(|ty| {
422422
matches!(ty, PacketType::EncodedVideo(_) | PacketType::RawVideo(_))
423423
});
424424

crates/nodes/src/video/colorbars.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ fn parse_pixel_format(s: &str) -> Result<PixelFormat, StreamKitError> {
7070
"i420" => Ok(PixelFormat::I420),
7171
"rgba8" | "rgba" => Ok(PixelFormat::Rgba8),
7272
other => Err(StreamKitError::Configuration(format!(
73-
"Unsupported pixel format '{}'. Use 'i420' or 'rgba8'.",
74-
other
73+
"Unsupported pixel format '{other}'. Use 'i420' or 'rgba8'."
7574
))),
7675
}
7776
}
@@ -143,7 +142,7 @@ impl ProcessorNode for ColorBarsNode {
143142
let mut template = vec![0u8; total_bytes];
144143
match pixel_format {
145144
PixelFormat::I420 => {
146-
generate_smpte_colorbars_i420(width, height, &mut template, &layout)
145+
generate_smpte_colorbars_i420(width, height, &mut template, &layout);
147146
},
148147
PixelFormat::Rgba8 => generate_smpte_colorbars_rgba8(width, height, &mut template),
149148
}
@@ -231,10 +230,10 @@ impl ProcessorNode for ColorBarsNode {
231230
pooled.as_mut_slice()[..total_bytes].copy_from_slice(&template);
232231
match pixel_format {
233232
PixelFormat::I420 => {
234-
draw_sweep_bar_i420(pooled.as_mut_slice(), width, height, &layout, seq)
233+
draw_sweep_bar_i420(pooled.as_mut_slice(), width, height, &layout, seq);
235234
},
236235
PixelFormat::Rgba8 => {
237-
draw_sweep_bar_rgba8(pooled.as_mut_slice(), width, height, seq)
236+
draw_sweep_bar_rgba8(pooled.as_mut_slice(), width, height, seq);
238237
},
239238
}
240239
streamkit_core::types::VideoFrame::from_pooled(
@@ -248,7 +247,7 @@ impl ProcessorNode for ColorBarsNode {
248247
let mut data = template.clone();
249248
match pixel_format {
250249
PixelFormat::I420 => {
251-
draw_sweep_bar_i420(&mut data, width, height, &layout, seq)
250+
draw_sweep_bar_i420(&mut data, width, height, &layout, seq);
252251
},
253252
PixelFormat::Rgba8 => draw_sweep_bar_rgba8(&mut data, width, height, seq),
254253
}
@@ -338,7 +337,7 @@ fn draw_sweep_bar_i420(
338337
let chroma_w = u_plane.width as usize;
339338
let chroma_h = u_plane.height as usize;
340339
let chroma_bar_x = bar_x / 2;
341-
let chroma_bar_w = (bar_width + 1) / 2; // round up
340+
let chroma_bar_w = bar_width.div_ceil(2); // round up
342341
for row in 0..chroma_h {
343342
for dx in 0..chroma_bar_w {
344343
let col = (chroma_bar_x + dx) % chroma_w;

crates/nodes/src/video/compositor/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ pub(crate) fn parse_pixel_format(s: &str) -> Result<PixelFormat, StreamKitError>
133133
"rgba8" | "rgba" => Ok(PixelFormat::Rgba8),
134134
"i420" => Ok(PixelFormat::I420),
135135
other => Err(StreamKitError::Configuration(format!(
136-
"Unsupported output pixel format '{}'. Use 'rgba8' or 'i420'.",
137-
other
136+
"Unsupported output pixel format '{other}'. Use 'rgba8' or 'i420'."
138137
))),
139138
}
140139
}

crates/nodes/src/video/compositor/kernel.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::pixel_ops::{blit_overlay, i420_to_rgba8_buf, scale_blit_rgba};
1818
// ── Compositing kernel (runs on a persistent blocking thread) ────────────────
1919

2020
/// Snapshot of one input layer's data for the blocking compositor thread.
21-
pub(crate) struct LayerSnapshot {
21+
pub struct LayerSnapshot {
2222
pub data: Arc<streamkit_core::frame_pool::PooledVideoData>,
2323
pub width: u32,
2424
pub height: u32,
@@ -28,7 +28,7 @@ pub(crate) struct LayerSnapshot {
2828
}
2929

3030
/// Work item sent from the async loop to the persistent compositing thread.
31-
pub(crate) struct CompositeWorkItem {
31+
pub struct CompositeWorkItem {
3232
pub canvas_w: u32,
3333
pub canvas_h: u32,
3434
pub layers: Vec<Option<LayerSnapshot>>,
@@ -39,7 +39,7 @@ pub(crate) struct CompositeWorkItem {
3939
}
4040

4141
/// Result sent back from the compositing thread to the async loop.
42-
pub(crate) struct CompositeResult {
42+
pub struct CompositeResult {
4343
pub output_format: PixelFormat,
4444
pub rgba_data: Option<streamkit_core::frame_pool::PooledVideoData>,
4545
pub i420_data: Option<streamkit_core::frame_pool::PooledVideoData>,
@@ -50,7 +50,7 @@ pub(crate) struct CompositeResult {
5050
///
5151
/// `i420_scratch` is a reusable buffer for I420→RGBA8 conversion, avoiding
5252
/// per-frame allocation.
53-
pub(crate) fn composite_frame(
53+
pub fn composite_frame(
5454
canvas_w: u32,
5555
canvas_h: u32,
5656
layers: &[Option<LayerSnapshot>],
@@ -123,7 +123,7 @@ pub(crate) fn composite_frame(
123123
/// - There are no image or text overlays
124124
///
125125
/// Returns the index of the pass-through layer, or `None` if compositing is needed.
126-
pub(crate) fn try_i420_passthrough(
126+
pub fn try_i420_passthrough(
127127
canvas_w: u32,
128128
canvas_h: u32,
129129
layers: &[Option<LayerSnapshot>],

crates/nodes/src/video/compositor/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ impl ProcessorNode for CompositorNode {
322322
// (no intermediate scratch — avoids a full extra memcpy).
323323
let w = work.canvas_w as usize;
324324
let h = work.canvas_h as usize;
325-
let chroma_w = (w + 1) / 2;
326-
let chroma_h = (h + 1) / 2;
325+
let chroma_w = w.div_ceil(2);
326+
let chroma_h = h.div_ceil(2);
327327
let i420_size = w * h + 2 * chroma_w * chroma_h;
328328
let mut i420_pooled = if let Some(ref pool) = work.video_pool {
329329
pool.get(i420_size)
@@ -560,13 +560,12 @@ impl ProcessorNode for CompositorNode {
560560
break;
561561
}
562562

563-
let composite_result = match result_rx.recv().await {
564-
Some(r) => r,
565-
None => {
566-
tracing::debug!("Compositing result channel closed");
567-
stop_reason = "compositor_thread_gone";
568-
break;
569-
},
563+
let composite_result = if let Some(r) = result_rx.recv().await {
564+
r
565+
} else {
566+
tracing::debug!("Compositing result channel closed");
567+
stop_reason = "compositor_thread_gone";
568+
break;
570569
};
571570

572571
// Build metadata from the first available input frame.

crates/nodes/src/video/compositor/overlay.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use streamkit_core::StreamKitError;
1111

1212
/// A pre-decoded RGBA bitmap overlay ready for per-frame blitting.
1313
#[derive(Clone)]
14-
pub(crate) struct DecodedOverlay {
14+
pub struct DecodedOverlay {
1515
pub rgba_data: Vec<u8>,
1616
pub width: u32,
1717
pub height: u32,
@@ -20,9 +20,7 @@ pub(crate) struct DecodedOverlay {
2020
}
2121

2222
/// Decode a base64-encoded image (PNG/JPEG) into an RGBA8 bitmap.
23-
pub(crate) fn decode_image_overlay(
24-
config: &ImageOverlayConfig,
25-
) -> Result<DecodedOverlay, StreamKitError> {
23+
pub fn decode_image_overlay(config: &ImageOverlayConfig) -> Result<DecodedOverlay, StreamKitError> {
2624
use image::GenericImageView;
2725

2826
use base64::Engine;
@@ -48,7 +46,7 @@ pub(crate) fn decode_image_overlay(
4846
}
4947

5048
/// Rasterize a text overlay into an RGBA8 bitmap using `tiny-skia`.
51-
pub(crate) fn rasterize_text_overlay(config: &TextOverlayConfig) -> DecodedOverlay {
49+
pub fn rasterize_text_overlay(config: &TextOverlayConfig) -> DecodedOverlay {
5250
let w = config.rect.width.max(1);
5351
let h = config.rect.height.max(1);
5452

crates/nodes/src/video/compositor/pixel_ops.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::overlay::DecodedOverlay;
2121
/// Rows are processed in parallel via `rayon` when the blit region is large
2222
/// enough to benefit from multi-core dispatch.
2323
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::too_many_arguments)]
24-
pub(crate) fn scale_blit_rgba(
24+
pub fn scale_blit_rgba(
2525
dst: &mut [u8],
2626
dst_width: u32,
2727
dst_height: u32,
@@ -165,12 +165,12 @@ fn blit_row_opaque(
165165
row_slice[dst_idx + 2] = sb;
166166
row_slice[dst_idx + 3] = 255;
167167
} else if sa > 0 {
168-
let a16 = sa as u16;
168+
let a16 = u16::from(sa);
169169
row_slice[dst_idx] = blend_u8(sr, row_slice[dst_idx], a16);
170170
row_slice[dst_idx + 1] = blend_u8(sg, row_slice[dst_idx + 1], a16);
171171
row_slice[dst_idx + 2] = blend_u8(sb, row_slice[dst_idx + 2], a16);
172172
// Composite alpha: a_out = a_src + a_dst * (1 - a_src)
173-
let da = row_slice[dst_idx + 3] as u16;
173+
let da = u16::from(row_slice[dst_idx + 3]);
174174
row_slice[dst_idx + 3] = (a16 + ((da * (255 - a16) + 128) >> 8)).min(255) as u8;
175175
}
176176
}
@@ -221,7 +221,7 @@ fn blit_row_alpha(
221221
}
222222

223223
// Effective alpha: (sa * opacity) / 255, done in integer.
224-
let sa_eff = ((sa as u16 * opacity_u16 + 128) >> 8).min(255) as u16;
224+
let sa_eff = ((u16::from(sa) * opacity_u16 + 128) >> 8).min(255);
225225
if sa_eff == 255 {
226226
row_slice[dst_idx] = sr;
227227
row_slice[dst_idx + 1] = sg;
@@ -231,20 +231,15 @@ fn blit_row_alpha(
231231
row_slice[dst_idx] = blend_u8(sr, row_slice[dst_idx], sa_eff);
232232
row_slice[dst_idx + 1] = blend_u8(sg, row_slice[dst_idx + 1], sa_eff);
233233
row_slice[dst_idx + 2] = blend_u8(sb, row_slice[dst_idx + 2], sa_eff);
234-
let da = row_slice[dst_idx + 3] as u16;
234+
let da = u16::from(row_slice[dst_idx + 3]);
235235
row_slice[dst_idx + 3] = (sa_eff + ((da * (255 - sa_eff) + 128) >> 8)).min(255) as u8;
236236
}
237237
}
238238
}
239239

240240
/// Blit a pre-decoded overlay onto the canvas (full alpha blend at the
241241
/// overlay's configured opacity).
242-
pub(crate) fn blit_overlay(
243-
canvas: &mut [u8],
244-
canvas_w: u32,
245-
canvas_h: u32,
246-
overlay: &DecodedOverlay,
247-
) {
242+
pub fn blit_overlay(canvas: &mut [u8], canvas_w: u32, canvas_h: u32, overlay: &DecodedOverlay) {
248243
scale_blit_rgba(
249244
canvas,
250245
canvas_w,
@@ -264,14 +259,14 @@ pub(crate) fn blit_overlay(
264259
/// The caller must ensure `out` has length >= `width * height * 4`.
265260
/// Rows are processed in parallel via `rayon`.
266261
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
267-
pub(crate) fn i420_to_rgba8_buf(data: &[u8], width: u32, height: u32, out: &mut [u8]) {
262+
pub fn i420_to_rgba8_buf(data: &[u8], width: u32, height: u32, out: &mut [u8]) {
268263
use rayon::prelude::*;
269264

270265
let w = width as usize;
271266
let h = height as usize;
272267
let y_stride = w;
273-
let chroma_w = (w + 1) / 2;
274-
let chroma_h = (h + 1) / 2;
268+
let chroma_w = w.div_ceil(2);
269+
let chroma_h = h.div_ceil(2);
275270
let u_offset = y_stride * h;
276271
let v_offset = u_offset + chroma_w * chroma_h;
277272
let rgba_row_stride = w * 4;
@@ -287,9 +282,9 @@ pub(crate) fn i420_to_rgba8_buf(data: &[u8], width: u32, height: u32, out: &mut
287282
let v_base = v_offset + chroma_row * chroma_w;
288283

289284
for col in 0..w {
290-
let y_val = data[y_base + col] as i32;
291-
let u_val = data[u_base + col / 2] as i32;
292-
let v_val = data[v_base + col / 2] as i32;
285+
let y_val = i32::from(data[y_base + col]);
286+
let u_val = i32::from(data[u_base + col / 2]);
287+
let v_val = i32::from(data[v_base + col / 2]);
293288

294289
let c = y_val - 16;
295290
let d = u_val - 128;
@@ -309,7 +304,7 @@ pub(crate) fn i420_to_rgba8_buf(data: &[u8], width: u32, height: u32, out: &mut
309304
///
310305
/// Prefer [`i420_to_rgba8_buf`] with a pooled buffer to avoid per-frame allocation.
311306
#[allow(dead_code, clippy::cast_possible_truncation, clippy::cast_sign_loss)]
312-
pub(crate) fn i420_to_rgba8(data: &[u8], width: u32, height: u32) -> Vec<u8> {
307+
pub fn i420_to_rgba8(data: &[u8], width: u32, height: u32) -> Vec<u8> {
313308
let mut rgba = vec![0u8; width as usize * height as usize * 4];
314309
i420_to_rgba8_buf(data, width, height, &mut rgba);
315310
rgba
@@ -320,14 +315,14 @@ pub(crate) fn i420_to_rgba8(data: &[u8], width: u32, height: u32) -> Vec<u8> {
320315
/// The caller must ensure `out` has length >= `w * h + 2 * ((w+1)/2) * ((h+1)/2)`.
321316
/// Y, U and V planes are processed in parallel via `rayon`.
322317
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
323-
pub(crate) fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut [u8]) {
318+
pub fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut [u8]) {
324319
use rayon::prelude::*;
325320

326321
let w = width as usize;
327322
let h = height as usize;
328323
let y_stride = w;
329-
let chroma_w = (w + 1) / 2;
330-
let chroma_h = (h + 1) / 2;
324+
let chroma_w = w.div_ceil(2);
325+
let chroma_h = h.div_ceil(2);
331326
let y_size = y_stride * h;
332327
let chroma_size = chroma_w * chroma_h;
333328

@@ -341,9 +336,9 @@ pub(crate) fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut
341336

342337
for col in 0..w {
343338
let off = rgba_base + col * 4;
344-
let r = data[off] as i32;
345-
let g = data[off + 1] as i32;
346-
let b = data[off + 2] as i32;
339+
let r = i32::from(data[off]);
340+
let g = i32::from(data[off + 1]);
341+
let b = i32::from(data[off + 2]);
347342
let y = ((66 * r + 129 * g + 25 * b + 128) >> 8) + 16;
348343
y_row[col] = y.clamp(0, 255) as u8;
349344
}
@@ -370,9 +365,9 @@ pub(crate) fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut
370365
let cc = c0 + dc;
371366
if cc < w {
372367
let off = (rr * w + cc) * 4;
373-
sr += data[off] as i32;
374-
sg += data[off + 1] as i32;
375-
sb += data[off + 2] as i32;
368+
sr += i32::from(data[off]);
369+
sg += i32::from(data[off + 1]);
370+
sb += i32::from(data[off + 2]);
376371
count += 1;
377372
}
378373
}
@@ -392,11 +387,11 @@ pub(crate) fn rgba8_to_i420_buf(data: &[u8], width: u32, height: u32, out: &mut
392387
///
393388
/// Prefer [`rgba8_to_i420_buf`] with a pooled buffer to avoid per-frame allocation.
394389
#[allow(dead_code, clippy::cast_possible_truncation, clippy::cast_sign_loss)]
395-
pub(crate) fn rgba8_to_i420(data: &[u8], width: u32, height: u32) -> Vec<u8> {
390+
pub fn rgba8_to_i420(data: &[u8], width: u32, height: u32) -> Vec<u8> {
396391
let w = width as usize;
397392
let h = height as usize;
398-
let chroma_w = (w + 1) / 2;
399-
let chroma_h = (h + 1) / 2;
393+
let chroma_w = w.div_ceil(2);
394+
let chroma_h = h.div_ceil(2);
400395
let total = w * h + 2 * chroma_w * chroma_h;
401396
let mut out = vec![0u8; total];
402397
rgba8_to_i420_buf(data, width, height, &mut out);

crates/nodes/src/video/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub mod vp9;
1717

1818
/// Registers all available video nodes with the engine's registry.
1919
#[allow(clippy::missing_const_for_fn)]
20-
pub fn register_video_nodes(_registry: &mut NodeRegistry) {
20+
pub fn register_video_nodes(registry: &mut NodeRegistry) {
2121
#[cfg(feature = "colorbars")]
22-
colorbars::register_colorbars_nodes(_registry);
22+
colorbars::register_colorbars_nodes(registry);
2323

2424
#[cfg(feature = "compositor")]
25-
compositor::register_compositor_nodes(_registry);
25+
compositor::register_compositor_nodes(registry);
2626

2727
#[cfg(feature = "vp9")]
28-
vp9::register_vp9_nodes(_registry);
28+
vp9::register_vp9_nodes(registry);
2929
}

0 commit comments

Comments
 (0)