diff --git a/src/api.rs b/src/api.rs index 8828a767ecafd58d30dcbbb393ffffc753bd4092..5d4ca9f0f0bacf79220868157f203d7bf6c749de 100644 --- a/src/api.rs +++ b/src/api.rs @@ -28,26 +28,44 @@ impl Ratio { } } -/// Here we store all the information we might receive from the cli +#[derive(Copy, Clone, Debug)] +pub struct EncoderConfig { + pub quantizer: usize, + pub speed: usize, + pub tune: Tune +} + +impl Default for EncoderConfig { + fn default() -> Self { + EncoderConfig { quantizer: 100, speed: 0, tune: Tune::Psnr } + } +} + +/// Frame-specific information #[derive(Clone, Copy, Debug)] -pub struct Config { +pub struct FrameInfo { pub width: usize, pub height: usize, pub bit_depth: usize, - pub chroma_sampling: ChromaSampling, + pub chroma_sampling: ChromaSampling +} + +/// Contain all the encoder configuration +#[derive(Clone, Copy, Debug)] +pub struct Config { + pub frame_info: FrameInfo, pub timebase: Ratio, pub enc: EncoderConfig } impl Config { pub fn new_context(&self) -> Context { - let fi = FrameInvariants::new(self.width, self.height, self.enc.clone()); - let seq = Sequence::new( - self.width, - self.height, - self.bit_depth, - self.chroma_sampling + let fi = FrameInvariants::new( + self.frame_info.width, + self.frame_info.height, + self.enc.clone() ); + let seq = Sequence::new(&self.frame_info); unsafe { av1_rtcd(); diff --git a/src/bin/rav1e.rs b/src/bin/rav1e.rs index 5d4f14987d47252b666a04c7361fc736fa8f82b8..f499468769b1f14274e0d173d1e5b51a8afa26d4 100644 --- a/src/bin/rav1e.rs +++ b/src/bin/rav1e.rs @@ -54,10 +54,7 @@ fn main() { let bit_depth = color_space.get_bit_depth(); let cfg = Config { - width, - height, - bit_depth, - chroma_sampling, + frame_info: FrameInfo { width, height, bit_depth, chroma_sampling }, timebase: Ratio::new(framerate.den, framerate.num), enc }; diff --git a/src/bin/rav1repl.rs b/src/bin/rav1repl.rs index fb2f7fb3a7606533c0e3ab4b61e6ad71cdb80bed..1c63daea89eabee527f584d14d58812c49fbc096 100644 --- a/src/bin/rav1repl.rs +++ b/src/bin/rav1repl.rs @@ -60,10 +60,7 @@ fn main() { let bit_depth = color_space.get_bit_depth(); let cfg = Config { - width, - height, - bit_depth, - chroma_sampling, + frame_info: FrameInfo { width, height, bit_depth, chroma_sampling }, timebase: Ratio::new(framerate.den, framerate.num), enc }; diff --git a/src/encoder.rs b/src/encoder.rs index 0e2734ec84cef43eb794ff78af24a710e4c13638..26f830592ff0763b6e262b6e0db379d404129a5d 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -7,6 +7,7 @@ // Media Patent License 1.0 was not distributed with this source code in the // PATENTS file, you can obtain it at www.aomedia.org/license/patent. +use api::*; use cdef::*; use context::*; use deblock::*; @@ -178,15 +179,15 @@ pub struct Sequence { } impl Sequence { - pub fn new(width: usize, height: usize, bit_depth: usize, chroma_sampling: ChromaSampling) -> Sequence { - let width_bits = 32 - (width as u32).leading_zeros(); - let height_bits = 32 - (height as u32).leading_zeros(); + pub fn new(info: &FrameInfo) -> Sequence { + let width_bits = 32 - (info.width as u32).leading_zeros(); + let height_bits = 32 - (info.height as u32).leading_zeros(); assert!(width_bits <= 16); assert!(height_bits <= 16); - let profile = if bit_depth == 12 { + let profile = if info.bit_depth == 12 { 2 - } else if chroma_sampling == ChromaSampling::Cs444 { + } else if info.chroma_sampling == ChromaSampling::Cs444 { 1 } else { 0 @@ -207,10 +208,10 @@ impl Sequence { profile: profile, num_bits_width: width_bits, num_bits_height: height_bits, - bit_depth: bit_depth, - chroma_sampling: chroma_sampling, - max_frame_width: width as u32, - max_frame_height: height as u32, + bit_depth: info.bit_depth, + chroma_sampling: info.chroma_sampling, + max_frame_width: info.width as u32, + max_frame_height: info.height as u32, frame_id_numbers_present_flag: false, frame_id_length: 0, delta_frame_id_length: 0, @@ -475,23 +476,6 @@ impl fmt::Display for FrameType{ } } -#[derive(Copy, Clone, Debug)] -pub struct EncoderConfig { - pub quantizer: usize, - pub speed: usize, - pub tune: Tune -} - -impl Default for EncoderConfig { - fn default() -> Self { - EncoderConfig { - quantizer: 100, - speed: 0, - tune: Tune::Psnr, - } - } -} - pub fn write_ivf_header(output_file: &mut dyn io::Write, width: usize, height: usize, num: usize, den: usize) { let mut bw = BitWriter::<LE>::new(output_file); bw.write_bytes(b"DKIF").unwrap(); diff --git a/src/test_encode_decode.rs b/src/test_encode_decode.rs index 30bc3911413596161375390e5ad899731118b9e7..0de64f97a2e9acbe183eeb9cc982633e0014fd7d 100644 --- a/src/test_encode_decode.rs +++ b/src/test_encode_decode.rs @@ -82,10 +82,7 @@ fn setup_encoder( let enc = EncoderConfig { quantizer, speed, ..Default::default() }; let cfg = Config { - width: w, - height: h, - bit_depth, - chroma_sampling, + frame_info: FrameInfo { width: w, height: h, bit_depth, chroma_sampling }, timebase: Ratio::new(1, 1000), enc };