Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions crates/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,31 @@ pub struct VideoFrame {
}

impl VideoFrame {
/// Validate that `layout` is consistent with the given dimensions/format
/// and that `data_len` is large enough.
fn validate_layout(
width: u32,
height: u32,
pixel_format: PixelFormat,
layout: &VideoLayout,
data_len: usize,
) -> Result<(), StreamKitError> {
let expected_layout =
VideoLayout::aligned(width, height, pixel_format, layout.stride_align());
if *layout != expected_layout {
return Err(StreamKitError::Runtime(format!(
"VideoFrame layout mismatch: expected {expected_layout:?}, got {layout:?}"
)));
}
if data_len < layout.total_bytes() {
return Err(StreamKitError::Runtime(format!(
"VideoFrame data buffer too small: need {} bytes, have {data_len}",
layout.total_bytes(),
)));
}
Ok(())
}

pub fn from_pooled(
width: u32,
height: u32,
Expand All @@ -635,20 +660,7 @@ impl VideoFrame {
mut data: PooledVideoData,
metadata: Option<PacketMetadata>,
) -> Result<Self, StreamKitError> {
let expected_layout =
VideoLayout::aligned(width, height, pixel_format, layout.stride_align());
if layout != expected_layout {
return Err(StreamKitError::Runtime(format!(
"VideoFrame layout mismatch: expected {expected_layout:?}, got {layout:?}"
)));
}
if data.len() < layout.total_bytes() {
return Err(StreamKitError::Runtime(format!(
"VideoFrame data buffer too small: need {} bytes, have {}",
layout.total_bytes(),
data.len()
)));
}
Self::validate_layout(width, height, pixel_format, &layout, data.len())?;
data.truncate(layout.total_bytes());
Ok(Self { width, height, pixel_format, layout, data: Arc::new(data), metadata })
}
Expand Down Expand Up @@ -691,20 +703,7 @@ impl VideoFrame {
data: Arc<PooledVideoData>,
metadata: Option<PacketMetadata>,
) -> Result<Self, StreamKitError> {
let expected_layout =
VideoLayout::aligned(width, height, pixel_format, layout.stride_align());
if layout != expected_layout {
return Err(StreamKitError::Runtime(format!(
"VideoFrame layout mismatch: expected {expected_layout:?}, got {layout:?}"
)));
}
if data.len() < layout.total_bytes() {
return Err(StreamKitError::Runtime(format!(
"VideoFrame data buffer too small: need {} bytes, have {}",
layout.total_bytes(),
data.len()
)));
}
Self::validate_layout(width, height, pixel_format, &layout, data.len())?;
Ok(Self { width, height, pixel_format, layout, data, metadata })
}

Expand Down
2 changes: 1 addition & 1 deletion crates/engine/benches/compositor_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use streamkit_core::VideoFramePool;
use streamkit_nodes::video::compositor::config::Rect;
use streamkit_nodes::video::compositor::kernel::{composite_frame, ConversionCache, LayerSnapshot};
use streamkit_nodes::video::compositor::overlay::DecodedOverlay;
use streamkit_nodes::video::compositor::pixel_ops::{rgba8_to_i420_buf, rgba8_to_nv12_buf};
use streamkit_nodes::video::pixel_ops::{rgba8_to_i420_buf, rgba8_to_nv12_buf};

// ── Default benchmark parameters ────────────────────────────────────────────

Expand Down
2 changes: 1 addition & 1 deletion crates/engine/benches/pixel_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

use std::time::Instant;

use streamkit_nodes::video::compositor::pixel_ops::{
use streamkit_nodes::video::pixel_ops::{
i420_to_rgba8_buf, nv12_to_rgba8_buf, rgba8_to_i420_buf, rgba8_to_nv12_buf,
};

Expand Down
Loading