Skip to content

Commit

Permalink
Remove rav1e::Frame::new()
Browse files Browse the repository at this point in the history
It is a big footgun (xiph#2461) and should be avoided.
  • Loading branch information
lu-zero committed Jul 28, 2020
1 parent b17d500 commit 116c9c7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/bin/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod y4m;
pub trait Decoder {
fn get_video_details(&self) -> VideoDetails;
fn read_frame<T: Pixel>(
&mut self, cfg: &VideoDetails,
&mut self, ctx: &Context<T>, cfg: &VideoDetails,
) -> Result<Frame<T>, DecodeError>;
}

Expand Down
5 changes: 2 additions & 3 deletions src/bin/decoder/y4m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ impl Decoder for y4m::Decoder<Box<dyn Read>> {
}

fn read_frame<T: Pixel>(
&mut self, cfg: &VideoDetails,
&mut self, ctx: &Context<T>, cfg: &VideoDetails,
) -> Result<Frame<T>, DecodeError> {
let bytes = self.get_bytes_per_sample();
self
.read_frame()
.map(|frame| {
let mut f: Frame<T> =
Frame::new(cfg.width, cfg.height, cfg.chroma_sampling);
let mut f = ctx.new_frame();

let (chroma_width, _) =
cfg.chroma_sampling.get_chroma_dimensions(cfg.width, cfg.height);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rav1e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<D: Decoder> Source<D> {
}
}

match self.input.read_frame(&video_info) {
match self.input.read_frame(ctx, &video_info) {
Ok(frame) => {
match video_info.bit_depth {
8 | 10 | 12 => {}
Expand Down
2 changes: 1 addition & 1 deletion src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct FrameParameters {
pub use v_frame::frame::Frame;

/// Public Trait Interface for Frame Allocation
pub trait FrameAlloc {
pub(crate) trait FrameAlloc {
/// Initialise new frame default type
fn new(width: usize, height: usize, chroma_sampling: ChromaSampling)
-> Self;
Expand Down
9 changes: 2 additions & 7 deletions src/fuzzing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,8 @@ pub fn fuzz_encode(data: &[u8]) {
let mut context: Context<u8> = res.unwrap();

let frame_count = g.g::<u8>() % 3 + 1;
let mut frame = context.new_frame();
let frames = (0..frame_count).map(|_| {
let mut frame = Frame::new(
config.enc.width,
config.enc.height,
config.enc.chroma_sampling,
);

for plane in &mut frame.planes {
let stride = plane.cfg.stride;
for row in plane.data_origin_mut().chunks_mut(stride) {
Expand All @@ -169,7 +164,7 @@ pub fn fuzz_encode(data: &[u8]) {
}
}

frame
frame.clone()
});

let _ = encode_frames(&mut context, frames);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub mod prelude {
pub use crate::api::*;
pub use crate::encoder::Tune;
pub use crate::frame::{
Frame, FrameAlloc, FrameParameters, FrameTypeOverride, Plane, PlaneConfig,
Frame, FrameParameters, FrameTypeOverride, Plane, PlaneConfig,
};
pub use crate::partition::BlockSize;
pub use crate::predict::PredictionMode;
Expand Down

0 comments on commit 116c9c7

Please sign in to comment.