Commit f3ad57bc authored by Vittorio Giovara's avatar Vittorio Giovara

Consistently use EncoderConfig instead of VideoDetails

VideoDetails is mainly used while decoding y4m, but it is carried
around in the configuration, initializing various internal structures.

Having all encoding-related fields in a single structure simplifies
setting up and configuring the encoder, as well as offering
an easier-to-use and possibly a more extensible API.

Fix #910.
parent 8342b32c
......@@ -45,12 +45,14 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
aom_dsp_rtcd();
}
let config = EncoderConfig {
width: 1024,
height: 1024,
quantizer: qindex,
speed_settings: SpeedSettings::from_preset(10),
..Default::default()
};
let sequence = Sequence::new(&Default::default());
let mut fi = FrameInvariants::new(1024, 1024, config, sequence);
let mut fi = FrameInvariants::new(config, sequence);
let mut w = ec::WriterEncoder::new();
let fc = CDFContext::new(fi.base_q_idx);
let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
......@@ -111,11 +113,16 @@ fn cdef_frame(c: &mut Criterion) {
c.bench_function(&n, move |b| cdef_frame_bench(b, w, h));
}
fn cdef_frame_bench(b: &mut Bencher, w: usize, h: usize) {
let config =
EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
fn cdef_frame_bench(b: &mut Bencher, width: usize, height: usize) {
let config = EncoderConfig {
width,
height,
quantizer: 100,
speed_settings: SpeedSettings::from_preset(10),
..Default::default()
};
let sequence = Sequence::new(&Default::default());
let fi = FrameInvariants::new(w, h, config, sequence);
let fi = FrameInvariants::new(config, sequence);
let mut bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fs = FrameState::new(&fi);
......@@ -135,10 +142,15 @@ fn cfl_rdo(c: &mut Criterion) {
}
fn cfl_rdo_bench(b: &mut Bencher, bsize: BlockSize) {
let config =
EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
let config = EncoderConfig {
width: 1024,
height: 1024,
quantizer: 100,
speed_settings: SpeedSettings::from_preset(10),
..Default::default()
};
let sequence = Sequence::new(&Default::default());
let fi = FrameInvariants::new(1024, 1024, config, sequence );
let fi = FrameInvariants::new(config, sequence );
let mut fs = FrameState::new(&fi);
let offset = BlockOffset { x: 1, y: 1 };
b.iter(|| rdo_cfl_alpha(&mut fs, &offset, bsize, fi.sequence.bit_depth, fi.sequence.chroma_sampling))
......
......@@ -68,6 +68,12 @@ pub struct Point {
#[derive(Copy, Clone, Debug)]
pub struct EncoderConfig {
pub width: usize,
pub height: usize,
pub bit_depth: usize,
pub chroma_sampling: ChromaSampling,
pub chroma_sample_position: ChromaSamplePosition,
pub time_base: Rational,
/// The *minimum* interval between two keyframes
pub min_key_frame_interval: u64,
/// The *maximum* interval between two keyframes
......@@ -93,6 +99,12 @@ impl Default for EncoderConfig {
impl EncoderConfig {
pub fn with_speed_preset(speed: usize) -> Self {
EncoderConfig {
width: 640,
height: 480,
bit_depth: 8,
chroma_sampling: ChromaSampling::Cs420,
chroma_sample_position: ChromaSamplePosition::Unknown,
time_base: Rational { num: 30, den: 1 },
min_key_frame_interval: 12,
max_key_frame_interval: 240,
low_latency: false,
......@@ -318,7 +330,6 @@ pub struct ContentLight {
/// Contain all the encoder configuration
#[derive(Clone, Copy, Debug)]
pub struct Config {
pub video_info: VideoDetails,
pub enc: EncoderConfig
}
......@@ -355,7 +366,7 @@ impl Config {
packet_data: Vec::new(),
segment_start_idx: 0,
segment_start_frame: 0,
keyframe_detector: SceneChangeDetector::new(self.video_info.bit_depth),
keyframe_detector: SceneChangeDetector::new(self.enc.bit_depth),
config: *self,
}
}
......@@ -418,9 +429,9 @@ impl fmt::Display for Packet {
impl Context {
pub fn new_frame(&self) -> Arc<Frame> {
Arc::new(Frame::new(
self.config.video_info.width.align_power_of_two(3),
self.config.video_info.height.align_power_of_two(3),
self.config.video_info.chroma_sampling
self.config.enc.width.align_power_of_two(3),
self.config.enc.height.align_power_of_two(3),
self.config.enc.chroma_sampling
))
}
......@@ -500,17 +511,11 @@ impl Context {
fn build_frame_properties(&mut self, idx: u64) -> (FrameInvariants, bool) {
if idx == 0 {
let mut seq = Sequence::new(&self.config.video_info);
seq.pixel_range = self.config.enc.pixel_range;
seq.color_description = self.config.enc.color_description;
seq.mastering_display = self.config.enc.mastering_display;
seq.content_light = self.config.enc.content_light;
let seq = Sequence::new(&self.config.enc);
// The first frame will always be a key frame
let fi = FrameInvariants::new_key_frame(
&FrameInvariants::new(
self.config.video_info.width,
self.config.video_info.height,
self.config.enc,
seq
),
......
......@@ -39,8 +39,13 @@ fn main() {
None => None
};
cli.enc.width = video_info.width;
cli.enc.height = video_info.height;
cli.enc.bit_depth = video_info.bit_depth;
cli.enc.chroma_sampling = video_info.chroma_sampling;
cli.enc.chroma_sample_position = video_info.chroma_sample_position;
cli.enc.time_base = video_info.time_base;
let cfg = Config {
video_info,
enc: cli.enc
};
......
......@@ -291,15 +291,15 @@ pub struct Sequence {
}
impl Sequence {
pub fn new(info: &VideoDetails) -> Sequence {
let width_bits = 32 - (info.width as u32).leading_zeros();
let height_bits = 32 - (info.height as u32).leading_zeros();
pub fn new(config: &EncoderConfig) -> Sequence {
let width_bits = 32 - (config.width as u32).leading_zeros();
let height_bits = 32 - (config.height as u32).leading_zeros();
assert!(width_bits <= 16);
assert!(height_bits <= 16);
let profile = if info.bit_depth == 12 {
let profile = if config.bit_depth == 12 {
2
} else if info.chroma_sampling == ChromaSampling::Cs444 {
} else if config.chroma_sampling == ChromaSampling::Cs444 {
1
} else {
0
......@@ -320,15 +320,15 @@ impl Sequence {
profile,
num_bits_width: width_bits,
num_bits_height: height_bits,
bit_depth: info.bit_depth,
chroma_sampling: info.chroma_sampling,
chroma_sample_position: info.chroma_sample_position,
pixel_range: PixelRange::Unspecified,
color_description: None,
mastering_display: None,
content_light: None,
max_frame_width: info.width as u32,
max_frame_height: info.height as u32,
bit_depth: config.bit_depth,
chroma_sampling: config.chroma_sampling,
chroma_sample_position: config.chroma_sample_position,
pixel_range: config.pixel_range,
color_description: config.color_description,
mastering_display: config.mastering_display,
content_light: config.content_light,
max_frame_width: config.width as u32,
max_frame_height: config.height as u32,
frame_id_numbers_present_flag: false,
frame_id_length: 0,
delta_frame_id_length: 0,
......@@ -579,8 +579,7 @@ pub struct FrameInvariants {
}
impl FrameInvariants {
pub fn new(width: usize, height: usize,
config: EncoderConfig, sequence: Sequence) -> FrameInvariants {
pub fn new(config: EncoderConfig, sequence: Sequence) -> FrameInvariants {
// Speed level decides the minimum partition size, i.e. higher speed --> larger min partition size,
// with exception that SBs on right or bottom frame borders split down to BLOCK_4X4.
// At speed = 0, RDO search is exhaustive.
......@@ -591,14 +590,14 @@ impl FrameInvariants {
FrameInvariants {
sequence,
width,
height,
padded_w: width.align_power_of_two(3),
padded_h: height.align_power_of_two(3),
sb_width: width.align_power_of_two_and_shift(6),
sb_height: height.align_power_of_two_and_shift(6),
w_in_b: 2 * width.align_power_of_two_and_shift(3), // MiCols, ((width+7)/8)<<3 >> MI_SIZE_LOG2
h_in_b: 2 * height.align_power_of_two_and_shift(3), // MiRows, ((height+7)/8)<<3 >> MI_SIZE_LOG2
width: config.width,
height: config.height,
padded_w: config.width.align_power_of_two(3),
padded_h: config.height.align_power_of_two(3),
sb_width: config.width.align_power_of_two_and_shift(6),
sb_height: config.height.align_power_of_two_and_shift(6),
w_in_b: 2 * config.width.align_power_of_two_and_shift(3), // MiCols, ((width+7)/8)<<3 >> MI_SIZE_LOG2
h_in_b: 2 * config.height.align_power_of_two_and_shift(3), // MiRows, ((height+7)/8)<<3 >> MI_SIZE_LOG2
number: 0,
order_hint: 0,
show_frame: true,
......
......@@ -97,15 +97,12 @@ fn setup_encoder(
enc.min_key_frame_interval = min_keyint;
enc.max_key_frame_interval = max_keyint;
enc.low_latency = low_latency;
enc.width = w;
enc.height = h;
enc.bit_depth = bit_depth;
enc.chroma_sampling = chroma_sampling;
let cfg = Config {
video_info: VideoDetails {
width: w,
height: h,
bit_depth,
chroma_sampling,
..Default::default()
},
enc
};
......
......@@ -77,15 +77,12 @@ fn setup_encoder(
enc.min_key_frame_interval = min_keyint;
enc.max_key_frame_interval = max_keyint;
enc.low_latency = low_latency;
enc.width = w;
enc.height = h;
enc.bit_depth = bit_depth;
enc.chroma_sampling = chroma_sampling;
let cfg = Config {
video_info: VideoDetails {
width: w,
height: h,
bit_depth,
chroma_sampling,
..Default::default()
},
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