Commit 3eb43b54 authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato

Refactor the encoder configuration

- Move the frame information in a separate struct
- Move the EncoderConfig in api.rs
parent 5c69ccaf
......@@ -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();
......
......@@ -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
};
......
......@@ -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
};
......
......@@ -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();
......
......@@ -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
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment