OSUOSL/Nero are experiencing Internet connectivity problems. This affects us as we're hosted with OSUOSL. We apologize for the inconvenience.

Unverified Commit a639966d authored by Kyle Siefring's avatar Kyle Siefring Committed by GitHub

Format some very long lines of code (#866)

Format some very long lines of code
parent c13ff386
......@@ -44,8 +44,11 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
av1_rtcd();
aom_dsp_rtcd();
}
let config =
EncoderConfig { quantizer: qindex, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
let config = EncoderConfig {
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 w = ec::WriterEncoder::new();
......
......@@ -450,10 +450,18 @@ impl Context {
let idx_in_segment = idx - self.segment_start_idx;
if idx_in_segment > 0 {
let next_keyframe = self.next_keyframe();
let (fi, success) = FrameInvariants::new_inter_frame(&self.fi, self.segment_start_frame, idx_in_segment, next_keyframe);
let (fi, success) = FrameInvariants::new_inter_frame(
&self.fi,
self.segment_start_frame,
idx_in_segment,
next_keyframe
);
self.fi = fi;
if !success {
if !self.fi.inter_cfg.unwrap().reorder || ((idx_in_segment - 1) % self.fi.inter_cfg.unwrap().group_len == 0 && self.fi.number == (next_keyframe - 1)) {
if !self.fi.inter_cfg.unwrap().reorder
|| ((idx_in_segment - 1) % self.fi.inter_cfg.unwrap().group_len == 0
&& self.fi.number == (next_keyframe - 1))
{
self.segment_start_idx = idx;
self.segment_start_frame = next_keyframe;
self.fi.number = next_keyframe;
......@@ -477,7 +485,12 @@ impl Context {
self.fi = FrameInvariants::new_key_frame(&self.fi, self.segment_start_frame);
} else {
let next_keyframe = self.next_keyframe();
let (fi, success) = FrameInvariants::new_inter_frame(&self.fi, self.segment_start_frame, idx_in_segment, next_keyframe);
let (fi, success) = FrameInvariants::new_inter_frame(
&self.fi,
self.segment_start_frame,
idx_in_segment,
next_keyframe
);
self.fi = fi;
if !success {
return Err(());
......
......@@ -167,9 +167,18 @@ fn parse_config(matches: &ArgMatches) -> EncoderConfig {
panic!("Maximum keyframe interval must be greater than or equal to minimum keyframe interval");
}
let color_primaries = matches.value_of("COLOR_PRIMARIES").unwrap().parse().unwrap_or_default();
let transfer_characteristics = matches.value_of("TRANSFER_CHARACTERISTICS").unwrap().parse().unwrap_or_default();
let matrix_coefficients = matches.value_of("MATRIX_COEFFICIENTS").unwrap().parse().unwrap_or_default();
let color_primaries =
matches.value_of("COLOR_PRIMARIES").unwrap().parse().unwrap_or_default();
let transfer_characteristics = matches
.value_of("TRANSFER_CHARACTERISTICS")
.unwrap()
.parse()
.unwrap_or_default();
let matrix_coefficients = matches
.value_of("MATRIX_COEFFICIENTS")
.unwrap()
.parse()
.unwrap_or_default();
let mut cfg = EncoderConfig::with_speed_preset(speed);
cfg.max_key_frame_interval = min_interval;
......@@ -474,10 +483,22 @@ impl ProgressInfo {
}
pub fn print_stats(&self) -> String {
let (key, key_size) = (self.get_frame_type_count(FrameType::KEY), self.get_frame_type_size(FrameType::KEY));
let (inter, inter_size) = (self.get_frame_type_count(FrameType::INTER), self.get_frame_type_size(FrameType::INTER));
let (ionly, ionly_size) = (self.get_frame_type_count(FrameType::INTRA_ONLY), self.get_frame_type_size(FrameType::INTRA_ONLY));
let (switch, switch_size) = (self.get_frame_type_count(FrameType::SWITCH), self.get_frame_type_size(FrameType::SWITCH));
let (key, key_size) = (
self.get_frame_type_count(FrameType::KEY),
self.get_frame_type_size(FrameType::KEY)
);
let (inter, inter_size) = (
self.get_frame_type_count(FrameType::INTER),
self.get_frame_type_size(FrameType::INTER)
);
let (ionly, ionly_size) = (
self.get_frame_type_count(FrameType::INTRA_ONLY),
self.get_frame_type_size(FrameType::INTRA_ONLY)
);
let (switch, switch_size) = (
self.get_frame_type_count(FrameType::SWITCH),
self.get_frame_type_size(FrameType::SWITCH)
);
format!("\
Key Frames: {:>6} avg size: {:>7} B\n\
Inter: {:>6} avg size: {:>7} B\n\
......@@ -489,9 +510,15 @@ impl ProgressInfo {
ionly, ionly_size / key,
switch, switch_size / key,
if self.show_psnr {
let psnr_y = self.frame_info.iter().map(|fi| fi.psnr.unwrap().0).sum::<f64>() / self.frame_info.len() as f64;
let psnr_u = self.frame_info.iter().map(|fi| fi.psnr.unwrap().1).sum::<f64>() / self.frame_info.len() as f64;
let psnr_v = self.frame_info.iter().map(|fi| fi.psnr.unwrap().2).sum::<f64>() / self.frame_info.len() as f64;
let psnr_y =
self.frame_info.iter().map(|fi| fi.psnr.unwrap().0).sum::<f64>()
/ self.frame_info.len() as f64;
let psnr_u =
self.frame_info.iter().map(|fi| fi.psnr.unwrap().1).sum::<f64>()
/ self.frame_info.len() as f64;
let psnr_v =
self.frame_info.iter().map(|fi| fi.psnr.unwrap().2).sum::<f64>()
/ self.frame_info.len() as f64;
format!("\nMean PSNR: Y: {:.4} Cb: {:.4} Cr: {:.4} Avg: {:.4}",
psnr_y, psnr_u, psnr_v,
(psnr_y + psnr_u + psnr_v) / 3.0)
......
......@@ -41,7 +41,14 @@ fn main() {
let bit_depth = color_space.get_bit_depth();
let cfg = Config {
frame_info: FrameInfo { width, height, bit_depth, chroma_sampling, chroma_sample_position, ..Default::default() },
frame_info: FrameInfo {
width,
height,
bit_depth,
chroma_sampling,
chroma_sample_position,
..Default::default()
},
timebase: Rational::new(framerate.den as u64, framerate.num as u64),
enc: cli.enc
};
......
......@@ -45,7 +45,14 @@ fn main() {
let bit_depth = color_space.get_bit_depth();
let cfg = Config {
frame_info: FrameInfo { width, height, bit_depth, chroma_sampling, chroma_sample_position, ..Default::default() },
frame_info: FrameInfo {
width,
height,
bit_depth,
chroma_sampling,
chroma_sample_position,
..Default::default()
},
timebase: Rational::new(framerate.den as u64, framerate.num as u64),
enc
};
......
......@@ -690,7 +690,10 @@ impl FrameInvariants {
/// Returns the created FrameInvariants along with a bool indicating success.
/// This interface provides simpler usage, because we always need the produced
/// FrameInvariants regardless of success or failure.
pub fn new_inter_frame(previous_fi: &Self, segment_start_frame: u64, idx_in_segment: u64, next_keyframe: u64) -> (Self, bool) {
pub fn new_inter_frame(
previous_fi: &Self, segment_start_frame: u64, idx_in_segment: u64,
next_keyframe: u64
) -> (Self, bool) {
let mut fi = previous_fi.clone();
fi.frame_type = FrameType::INTER;
fi.intra_only = false;
......@@ -760,7 +763,11 @@ impl FrameInvariants {
let ref_in_previous_group = LAST3_FRAME;
// reuse probability estimates from previous frames only in top level frames
fi.primary_ref_frame = if lvl > 0 { PRIMARY_REF_NONE } else { (ref_in_previous_group - LAST_FRAME) as u32 };
fi.primary_ref_frame = if lvl > 0 {
PRIMARY_REF_NONE
} else {
(ref_in_previous_group - LAST_FRAME) as u32
};
for i in 0..INTER_REFS_PER_FRAME {
fi.ref_frames[i] = if lvl == 0 {
......@@ -857,7 +864,10 @@ impl fmt::Display for FrameType{
}
}
pub fn write_ivf_header(output_file: &mut dyn io::Write, width: usize, height: usize, num: usize, den: usize) {
pub fn write_ivf_header(
output_file: &mut dyn io::Write, width: usize, height: usize, num: usize,
den: usize
) {
let mut bw = BitWriter::endian(output_file, LittleEndian);
bw.write_bytes(b"DKIF").unwrap();
bw.write(16, 0).unwrap(); // version
......@@ -2221,10 +2231,11 @@ pub fn encode_block_with_modes(fi: &FrameInvariants, fs: &mut FrameState,
tx_size, tx_type, mode_context, &mv_stack, false);
}
fn encode_partition_bottomup(fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, w_pre_cdef: &mut dyn Writer, w_post_cdef: &mut dyn Writer,
bsize: BlockSize, bo: &BlockOffset, pmvs: &[[Option<MotionVector>; REF_FRAMES]; 5],
ref_rd_cost: f64
fn encode_partition_bottomup(
fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
w_pre_cdef: &mut dyn Writer, w_post_cdef: &mut dyn Writer, bsize: BlockSize,
bo: &BlockOffset, pmvs: &[[Option<MotionVector>; REF_FRAMES]; 5],
ref_rd_cost: f64
) -> (f64, Option<RDOPartitionOutput>) {
let mut rd_cost = std::f64::MAX;
let mut best_rd = std::f64::MAX;
......
......@@ -132,7 +132,9 @@ mod native {
}
}
fn get_mv_range(fi: &FrameInvariants, bo: &BlockOffset, blk_w: usize, blk_h: usize) -> (isize, isize, isize, isize) {
fn get_mv_range(
fi: &FrameInvariants, bo: &BlockOffset, blk_w: usize, blk_h: usize
) -> (isize, isize, isize, isize) {
let border_w = 128 + blk_w as isize * 8;
let border_h = 128 + blk_h as isize * 8;
let mvx_min = -(bo.x as isize) * (8 * MI_SIZE) as isize - border_w;
......
......@@ -738,7 +738,8 @@ pub struct MotionVector {
pub const NEWMV_MODE_CONTEXTS: usize = 7;
pub const GLOBALMV_MODE_CONTEXTS: usize = 2;
pub const REFMV_MODE_CONTEXTS: usize = 6;
pub const INTER_COMPOUND_MODES: usize = (1 + PredictionMode::NEW_NEWMV as usize - PredictionMode::NEAREST_NEARESTMV as usize);
pub const INTER_COMPOUND_MODES: usize = 1 + PredictionMode::NEW_NEWMV as usize
- PredictionMode::NEAREST_NEARESTMV as usize;
pub const REFMV_OFFSET: usize = 4;
pub const GLOBALMV_OFFSET: usize = 3;
......@@ -887,7 +888,11 @@ pub fn get_intra_edges<'a>(
BlockSize::from_width_and_height(2*tx_size.width(), 2*tx_size.height())
};
let num_avail = if y != 0 && has_tr(&bo, bsize) {
tx_size.height().min((if p == 0 { MI_SIZE } else { MI_SIZE / 2 }) * frame_w_in_b - x as usize - tx_size.width())
tx_size.height().min(
(if p == 0 { MI_SIZE } else { MI_SIZE / 2 }) * frame_w_in_b
- x as usize
- tx_size.width()
)
} else {
0
};
......@@ -916,7 +921,11 @@ pub fn get_intra_edges<'a>(
BlockSize::from_width_and_height(2*tx_size.width(), 2*tx_size.height())
};
let num_avail = if x != 0 && has_bl(&bo, bsize) {
tx_size.width().min((if p == 0 { MI_SIZE } else { MI_SIZE / 2 }) * frame_h_in_b - y as usize - tx_size.height())
tx_size.width().min(
(if p == 0 { MI_SIZE } else { MI_SIZE / 2 }) * frame_h_in_b
- y as usize
- tx_size.height()
)
} else {
0
};
......@@ -928,7 +937,10 @@ pub fn get_intra_edges<'a>(
}
if num_avail < tx_size.width() {
let val = left[2 * MAX_TX_SIZE - tx_size.height() - num_avail];
for v in left[(2 * MAX_TX_SIZE - tx_size.height() - tx_size.width())..(2 * MAX_TX_SIZE - tx_size.height() - num_avail)].iter_mut() {
for v in left[(2 * MAX_TX_SIZE - tx_size.height() - tx_size.width())
..(2 * MAX_TX_SIZE - tx_size.height() - num_avail)]
.iter_mut()
{
*v = val;
}
}
......
......@@ -13,7 +13,7 @@
use context::{INTRA_MODES, MAX_TX_SIZE};
use partition::*;
use util::Pixel;
use util::*;
#[cfg(all(target_arch = "x86_64", not(windows), feature = "nasm"))]
use libc;
......@@ -449,7 +449,8 @@ where
assert!((sm_weights_h[0] as u16) < scale);
assert!((scale - sm_weights_w[Self::W - 1] as u16) < scale);
assert!((scale - sm_weights_h[Self::H - 1] as u16) < scale);
assert!(log2_scale as usize + size_of_val(&output[0]) < 31); // ensures no overflow when calculating predictor
// ensures no overflow when calculating predictor
assert!(log2_scale as usize + size_of_val(&output[0]) < 31);
for r in 0..Self::H {
for c in 0..Self::W {
......@@ -510,7 +511,8 @@ where
// Weights sanity checks
assert!((sm_weights[0] as u16) < scale);
assert!((scale - sm_weights[Self::W - 1] as u16) < scale);
assert!(log2_scale as usize + size_of_val(&output[0]) < 31); // ensures no overflow when calculating predictor
// ensures no overflow when calculating predictor
assert!(log2_scale as usize + size_of_val(&output[0]) < 31);
for r in 0..Self::H {
for c in 0..Self::W {
......@@ -561,7 +563,8 @@ where
// Weights sanity checks
assert!((sm_weights[0] as u16) < scale);
assert!((scale - sm_weights[Self::H - 1] as u16) < scale);
assert!(log2_scale as usize + size_of_val(&output[0]) < 31); // ensures no overflow when calculating predictor
// ensures no overflow when calculating predictor
assert!(log2_scale as usize + size_of_val(&output[0]) < 31);
for r in 0..Self::H {
for c in 0..Self::W {
......@@ -841,7 +844,7 @@ where
output[i * stride + j] = if base < max_base_x {
let a: i32 = above[base].into();
let b: i32 = above[base + 1].into();
(a * (32 - shift) + b * shift + 16) >> 5
round_shift(a * (32 - shift) + b * shift, 5)
} else {
let c: i32 = above[max_base_x].into();
c
......@@ -855,16 +858,30 @@ where
let base = idx >> (6 - upsample_above);
if base >= -(1 << upsample_above) {
let shift = (((idx << upsample_above) >> 1) & 31) as i32;
let a: i32 = if base < 0 { top_left[0] } else { above[base as usize] }.into();
let a: i32 =
if base < 0 { top_left[0] } else { above[base as usize] }.into();
let b: i32 = above[(base + 1) as usize].into();
output[i * stride + j] = ((a * (32 - shift) + b * shift + 16) >> 5).max(0).min(sample_max).as_();
output[i * stride + j] =
round_shift(a * (32 - shift) + b * shift, 5)
.max(0)
.min(sample_max)
.as_();
} else {
let idx = (i << 6) as isize - ((j + 1) * dy) as isize;
let base = idx >> (6 - upsample_left);
let shift = (((idx << upsample_left) >> 1) & 31) as i32;
let a: i32 = if base < 0 { top_left[0] } else { left[Self::W + Self::H - 1 - base as usize] }.into();
let a: i32 = if base < 0 {
top_left[0]
} else {
left[Self::W + Self::H - 1 - base as usize]
}
.into();
let b: i32 = left[Self::W + Self::H - (2 + base) as usize].into();
output[i * stride + j] = ((a * (32 - shift) + b * shift + 16) >> 5).max(0).min(sample_max).as_();
output[i * stride + j] =
round_shift(a * (32 - shift) + b * shift, 5)
.max(0)
.min(sample_max)
.as_();
}
}
}
......@@ -876,7 +893,11 @@ where
let shift = (((idx << upsample_left) >> 1) & 31) as i32;
let a: i32 = left[Self::W + Self::H - 1 - base].into();
let b: i32 = left[Self::W + Self::H - 2 - base].into();
output[i * stride + j] = ((a * (32 - shift) + b * shift + 16) >> 5).max(0).min(sample_max).as_();
output[i * stride + j] =
round_shift(a * (32 - shift) + b * shift, 5)
.max(0)
.min(sample_max)
.as_();
}
}
}
......
......@@ -464,9 +464,16 @@ pub fn rdo_mode_decision(fi: &FrameInvariants, fs: &mut FrameState,
}
}
let luma_rdo = |luma_mode: PredictionMode, fs: &mut FrameState, cw: &mut ContextWriter, best: &mut EncodingSettings,
mvs: [MotionVector; 2], ref_frames: [usize; 2], mode_set_chroma: &[PredictionMode], luma_mode_is_intra: bool,
mode_context: usize, mv_stack: &Vec<CandidateMV>| {
let luma_rdo = |luma_mode: PredictionMode,
fs: &mut FrameState,
cw: &mut ContextWriter,
best: &mut EncodingSettings,
mvs: [MotionVector; 2],
ref_frames: [usize; 2],
mode_set_chroma: &[PredictionMode],
luma_mode_is_intra: bool,
mode_context: usize,
mv_stack: &Vec<CandidateMV>| {
let (tx_size, mut tx_type) = rdo_tx_size_type(
fi, fs, cw, bsize, bo, luma_mode, ref_frames, mvs, false,
);
......@@ -589,8 +596,11 @@ pub fn rdo_mode_decision(fi: &FrameInvariants, fs: &mut FrameState,
// Reduce number of prediction modes at higher speed levels
let num_modes_rdo = if (fi.frame_type == FrameType::KEY
&& fi.config.speed_settings.prediction_modes >= PredictionModesSetting::ComplexKeyframes)
|| (fi.frame_type == FrameType::INTER && fi.config.speed_settings.prediction_modes >= PredictionModesSetting::ComplexAll)
&& fi.config.speed_settings.prediction_modes
>= PredictionModesSetting::ComplexKeyframes)
|| (fi.frame_type == FrameType::INTER
&& fi.config.speed_settings.prediction_modes
>= PredictionModesSetting::ComplexAll)
{
7
} else {
......@@ -604,16 +614,35 @@ pub fn rdo_mode_decision(fi: &FrameInvariants, fs: &mut FrameState,
let po = bo.plane_offset(&rec.cfg);
get_intra_edges(&rec.slice(&po), tx_size, fi.sequence.bit_depth, 0, fi.w_in_b, fi.h_in_b, None)
};
intra_mode_set.iter().map(|&luma_mode| {
let rec = &mut fs.rec.planes[0];
let po = bo.plane_offset(&rec.cfg);
luma_mode.predict_intra(&mut rec.mut_slice(&po), tx_size, fi.sequence.bit_depth, &[0i16; 2], 0, &edge_buf);
let plane_org = fs.input.planes[0].slice(&po);
let plane_ref = rec.slice(&po);
intra_mode_set
.iter()
.map(|&luma_mode| {
let rec = &mut fs.rec.planes[0];
let po = bo.plane_offset(&rec.cfg);
luma_mode.predict_intra(
&mut rec.mut_slice(&po),
tx_size,
fi.sequence.bit_depth,
&[0i16; 2],
0,
&edge_buf
);
(luma_mode, get_sad(&plane_org, &plane_ref, tx_size.height(), tx_size.width(), fi.sequence.bit_depth))
}).collect::<Vec<_>>()
let plane_org = fs.input.planes[0].slice(&po);
let plane_ref = rec.slice(&po);
(
luma_mode,
get_sad(
&plane_org,
&plane_ref,
tx_size.height(),
tx_size.width(),
fi.sequence.bit_depth
)
)
})
.collect::<Vec<_>>()
};
sads.sort_by_key(|a| a.1);
......@@ -631,8 +660,15 @@ pub fn rdo_mode_decision(fi: &FrameInvariants, fs: &mut FrameState,
probs.sort_by_key(|a| !a.1);
let mut modes = Vec::new();
probs.iter().take(num_modes_rdo / 2).for_each(|&(luma_mode, _prob)| modes.push(luma_mode));
sads.iter().take(num_modes_rdo).for_each(|&(luma_mode, _sad)| if !modes.contains(&luma_mode) { modes.push(luma_mode) } );
probs
.iter()
.take(num_modes_rdo / 2)
.for_each(|&(luma_mode, _prob)| modes.push(luma_mode));
sads.iter().take(num_modes_rdo).for_each(|&(luma_mode, _sad)| {
if !modes.contains(&luma_mode) {
modes.push(luma_mode)
}
});
modes.iter().take(num_modes_rdo).for_each(|&luma_mode| {
let mvs = [MotionVector { row: 0, col: 0 }; 2];
......@@ -756,7 +792,15 @@ pub fn rdo_cfl_alpha(
let po = bo.plane_offset(&fs.input.planes[p].cfg);
(-16i16..17i16)
.min_by_key(|&alpha| {
let edge_buf = get_intra_edges(&rec.slice(&po), uv_tx_size, bit_depth, p, 0, 0, Some(PredictionMode::UV_CFL_PRED));
let edge_buf = get_intra_edges(
&rec.slice(&po),
uv_tx_size,
bit_depth,
p,
0,
0,
Some(PredictionMode::UV_CFL_PRED)
);
PredictionMode::UV_CFL_PRED.predict_intra(
&mut rec.mut_slice(&po),
uv_tx_size,
......@@ -784,8 +828,9 @@ pub fn rdo_cfl_alpha(
// RDO-based transform type decision
pub fn rdo_tx_type_decision(
fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
mode: PredictionMode, ref_frames: [usize; 2], mvs: [MotionVector; 2], bsize: BlockSize, bo: &BlockOffset, tx_size: TxSize,
tx_set: TxSet) -> TxType {
mode: PredictionMode, ref_frames: [usize; 2], mvs: [MotionVector; 2],
bsize: BlockSize, bo: &BlockOffset, tx_size: TxSize, tx_set: TxSet
) -> TxType {
let mut best_type = TxType::DCT_DCT;
let mut best_rd = std::f64::MAX;
......
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