Commit 4f75e3a0 authored by Vladimir Kazakov's avatar Vladimir Kazakov Committed by Luca Barbato
parent bda810b6
......@@ -61,4 +61,4 @@ jobs:
- cargo doc --verbose
- rustup component add clippy
- cargo clippy --version
- cargo clippy -- -D warnings -A clippy::cast_lossless -A clippy::cast_ptr_alignment -A clippy::collapsible_if -A clippy::cyclomatic_complexity -A clippy::needless_range_loop -A clippy::too_many_arguments -A clippy::type_complexity -A clippy::verbose_bit_mask --verbose
- cargo clippy -- -D warnings -A clippy::cast_lossless -A clippy::cast_ptr_alignment -A clippy::cyclomatic_complexity -A clippy::needless_range_loop -A clippy::too_many_arguments -A clippy::type_complexity -A clippy::verbose_bit_mask --verbose
......@@ -813,49 +813,47 @@ impl<T: Pixel> ContextInner<T> {
let rec = if fi.show_frame { Some(fs.rec) } else { None };
let fi = fi.clone();
self.finalize_packet(rec, &fi)
} else {
if let Some(f) = self.frame_q.get(&fi.number) {
self.idx += 1;
if let Some(frame) = f.clone() {
let fti = fi.get_frame_subtype();
let qps =
self.rc_state.select_qi(self, fti, self.maybe_prev_log_base_q);
let fi = self.frame_invariants.get_mut(&idx).unwrap();
fi.set_quantizers(&qps);
let mut fs = FrameState::new_with_frame(fi, frame.clone());
// TODO: Trial encoding for first frame of each type.
let data = self.pool.install(||encode_frame(fi, &mut fs));
self.maybe_prev_log_base_q = Some(qps.log_base_q);
// TODO: Add support for dropping frames.
self.rc_state.update_state(
(data.len() * 8) as i64,
fti,
qps.log_target_q,
false
);
self.packet_data.extend(data);
fs.rec.pad(fi.width, fi.height);
// TODO avoid the clone by having rec Arc.
let rec = if fi.show_frame { Some(fs.rec.clone()) } else { None };
update_rec_buffer(fi, fs);
if fi.show_frame {
let fi = fi.clone();
self.finalize_packet(rec, &fi)
} else {
Err(EncoderStatus::NeedMoreData)
}
} else if let Some(f) = self.frame_q.get(&fi.number) {
self.idx += 1;
if let Some(frame) = f.clone() {
let fti = fi.get_frame_subtype();
let qps =
self.rc_state.select_qi(self, fti, self.maybe_prev_log_base_q);
let fi = self.frame_invariants.get_mut(&idx).unwrap();
fi.set_quantizers(&qps);
let mut fs = FrameState::new_with_frame(fi, frame.clone());
// TODO: Trial encoding for first frame of each type.
let data = self.pool.install(||encode_frame(fi, &mut fs));
self.maybe_prev_log_base_q = Some(qps.log_base_q);
// TODO: Add support for dropping frames.
self.rc_state.update_state(
(data.len() * 8) as i64,
fti,
qps.log_target_q,
false
);
self.packet_data.extend(data);
fs.rec.pad(fi.width, fi.height);
// TODO avoid the clone by having rec Arc.
let rec = if fi.show_frame { Some(fs.rec.clone()) } else { None };
update_rec_buffer(fi, fs);
if fi.show_frame {
let fi = fi.clone();
self.finalize_packet(rec, &fi)
} else {
Err(EncoderStatus::NeedMoreData)
}
} else {
Err(EncoderStatus::NeedMoreData)
}
} else {
Err(EncoderStatus::NeedMoreData)
}
};
......
......@@ -571,31 +571,37 @@ pub fn get_tx_set(
let tx_size_sqr = tx_size.sqr();
if tx_size.width() >= 64 || tx_size.height() >= 64 {
TxSet::TX_SET_DCTONLY
} else if tx_size_sqr_up == TxSize::TX_32X32 {
if is_inter {
return TxSet::TX_SET_DCTONLY;
}
if tx_size_sqr_up == TxSize::TX_32X32 {
return if is_inter {
TxSet::TX_SET_DCT_IDTX
} else {
TxSet::TX_SET_DCTONLY
}
} else if use_reduced_set {
if is_inter {
};
}
if use_reduced_set {
return if is_inter {
TxSet::TX_SET_DCT_IDTX
} else {
TxSet::TX_SET_DTT4_IDTX
}
} else if is_inter {
if tx_size_sqr == TxSize::TX_16X16 {
};
}
if is_inter {
return if tx_size_sqr == TxSize::TX_16X16 {
TxSet::TX_SET_DTT9_IDTX_1DDCT
} else {
TxSet::TX_SET_ALL16
}
};
}
if tx_size_sqr == TxSize::TX_16X16 {
TxSet::TX_SET_DTT4_IDTX
} else {
if tx_size_sqr == TxSize::TX_16X16 {
TxSet::TX_SET_DTT4_IDTX
} else {
TxSet::TX_SET_DTT4_IDTX_1DDCT
}
TxSet::TX_SET_DTT4_IDTX_1DDCT
}
}
......@@ -2889,22 +2895,20 @@ impl<'a> ContextWriter<'a> {
let left_uni_comp = left_comp_inter && is_samedir_ref_pair(left0, left1);
if avail_up && !above_intra && avail_left && !left_intra {
let samedir = is_samedir_ref_pair(above0, left0);
let samedir = is_samedir_ref_pair(above0, left0) as usize;
if !above_comp_inter && !left_comp_inter {
1 + 2 * samedir as usize
1 + 2 * samedir
} else if !above_comp_inter {
if !left_uni_comp { 1 } else { 3 + samedir as usize }
if !left_uni_comp { 1 } else { 3 + samedir }
} else if !left_comp_inter {
if !above_uni_comp { 1 } else { 3 + samedir as usize }
if !above_uni_comp { 1 } else { 3 + samedir }
} else if !above_uni_comp && !left_uni_comp {
0
} else if !above_uni_comp || !left_uni_comp {
2
} else {
if !above_uni_comp && !left_uni_comp {
0
} else if !above_uni_comp || !left_uni_comp {
2
} else {
3 + ((above0 == BWDREF_FRAME) == (left0 == BWDREF_FRAME)) as usize
}
3 + ((above0 == BWDREF_FRAME) == (left0 == BWDREF_FRAME)) as usize
}
} else if avail_up && avail_left {
if above_comp_inter {
......@@ -3855,10 +3859,10 @@ const MV_LOW: i32 = (-(1 << MV_IN_USE_BITS));
#[inline(always)]
pub fn av1_get_mv_joint(mv: MotionVector) -> MvJointType {
if mv.row == 0 {
if mv.col == 0 { MvJointType::MV_JOINT_ZERO } else { MvJointType::MV_JOINT_HNZVZ }
} else {
if mv.col == 0 { MvJointType::MV_JOINT_HZVNZ } else { MvJointType::MV_JOINT_HNZVNZ }
return if mv.col == 0 { MvJointType::MV_JOINT_ZERO } else { MvJointType::MV_JOINT_HNZVZ };
}
if mv.col == 0 { MvJointType::MV_JOINT_HZVNZ } else { MvJointType::MV_JOINT_HNZVNZ }
}
#[inline(always)]
pub fn mv_joint_vertical(joint_type: MvJointType) -> bool {
......
......@@ -333,51 +333,54 @@ impl Sequence {
pub fn get_skip_mode_allowed<T: Pixel>(&self, fi: &FrameInvariants<T>, reference_select: bool) -> bool {
if fi.intra_only || !reference_select || !self.enable_order_hint {
return false;
}
let mut forward_idx: isize = -1;
let mut backward_idx: isize = -1;
let mut forward_hint = 0;
let mut backward_hint = 0;
for i in 0..INTER_REFS_PER_FRAME {
if let Some(ref rec) = fi.rec_buffer.frames[fi.ref_frames[i] as usize] {
let ref_hint = rec.order_hint;
if self.get_relative_dist(ref_hint, fi.order_hint) < 0 {
if forward_idx < 0 || self.get_relative_dist(ref_hint, forward_hint) > 0 {
forward_idx = i as isize;
forward_hint = ref_hint;
}
} else if self.get_relative_dist(ref_hint, fi.order_hint) > 0 &&
(backward_idx < 0 || self.get_relative_dist(ref_hint, backward_hint) > 0) {
backward_idx = i as isize;
backward_hint = ref_hint;
}
}
}
if forward_idx < 0 {
false
} else if backward_idx >= 0 {
// set skip_mode_frame
true
} else {
let mut forward_idx: isize = -1;
let mut backward_idx: isize = -1;
let mut forward_hint = 0;
let mut backward_hint = 0;
let mut second_forward_idx: isize = -1;
let mut second_forward_hint = 0;
for i in 0..INTER_REFS_PER_FRAME {
if let Some(ref rec) = fi.rec_buffer.frames[fi.ref_frames[i] as usize] {
let ref_hint = rec.order_hint;
if self.get_relative_dist(ref_hint, fi.order_hint) < 0 {
if forward_idx < 0 || self.get_relative_dist(ref_hint, forward_hint) > 0 {
forward_idx = i as isize;
forward_hint = ref_hint;
}
} else if self.get_relative_dist(ref_hint, fi.order_hint) > 0 {
if backward_idx < 0 || self.get_relative_dist(ref_hint, backward_hint) > 0 {
backward_idx = i as isize;
backward_hint = ref_hint;
}
if self.get_relative_dist(ref_hint, forward_hint) < 0 &&
(second_forward_idx < 0 || self.get_relative_dist(ref_hint, second_forward_hint) > 0) {
second_forward_idx = i as isize;
second_forward_hint = ref_hint;
}
}
}
if forward_idx < 0 {
false
} else if backward_idx >= 0 {
// set skip_mode_frame
true
} else {
let mut second_forward_idx: isize = -1;
let mut second_forward_hint = 0;
for i in 0..INTER_REFS_PER_FRAME {
if let Some(ref rec) = fi.rec_buffer.frames[fi.ref_frames[i] as usize] {
let ref_hint = rec.order_hint;
if self.get_relative_dist(ref_hint, forward_hint) < 0 {
if second_forward_idx < 0 || self.get_relative_dist(ref_hint, second_forward_hint) > 0 {
second_forward_idx = i as isize;
second_forward_hint = ref_hint;
}
}
}
}
// TODO: Set skip_mode_frame, when second_forward_idx is not less than 0.
second_forward_idx >= 0
}
// TODO: Set skip_mode_frame, when second_forward_idx is not less than 0.
second_forward_idx >= 0
}
}
}
......@@ -653,8 +656,8 @@ impl<T: Pixel> FrameInvariants<T> {
fi.tx_mode_select = fi.config.speed_settings.rdo_tx_decision;
// FIXME: tx partition for intra not supported for chroma 422
if fi.tx_mode_select {
if fi.sequence.chroma_sampling == ChromaSampling::Cs422 { fi.tx_mode_select = false; }
if fi.tx_mode_select && fi.sequence.chroma_sampling == ChromaSampling::Cs422 {
fi.tx_mode_select = false;
}
fi
......@@ -759,29 +762,27 @@ impl<T: Pixel> FrameInvariants<T> {
} else {
(slot_idx + 4 - 1) as u8 % 4
}
} else if i == second_ref_frame.to_index() {
let oh = fi.order_hint + (inter_cfg.group_src_len as u32 >> lvl);
let lvl2 = pos_to_lvl(oh as u64, inter_cfg.pyramid_depth);
if lvl2 == 0 {
((oh >> inter_cfg.pyramid_depth) % 4) as u8
} else {
3 + lvl2 as u8
}
} else if i == ref_in_previous_group.to_index() {
if lvl == 0 {
(slot_idx + 4 - 1) as u8 % 4
} else {
slot_idx as u8
}
} else {
if i == second_ref_frame.to_index() {
let oh = fi.order_hint + (inter_cfg.group_src_len as u32 >> lvl);
let lvl2 = pos_to_lvl(oh as u64, inter_cfg.pyramid_depth);
if lvl2 == 0 {
((oh >> inter_cfg.pyramid_depth) % 4) as u8
} else {
3 + lvl2 as u8
}
} else if i == ref_in_previous_group.to_index() {
if lvl == 0 {
(slot_idx + 4 - 1) as u8 % 4
} else {
slot_idx as u8
}
let oh = fi.order_hint - (inter_cfg.group_src_len as u32 >> lvl);
let lvl1 = pos_to_lvl(oh as u64, inter_cfg.pyramid_depth);
if lvl1 == 0 {
((oh >> inter_cfg.pyramid_depth) % 4) as u8
} else {
let oh = fi.order_hint - (inter_cfg.group_src_len as u32 >> lvl);
let lvl1 = pos_to_lvl(oh as u64, inter_cfg.pyramid_depth);
if lvl1 == 0 {
((oh >> inter_cfg.pyramid_depth) % 4) as u8
} else {
3 + lvl1 as u8
}
3 + lvl1 as u8
}
}
}
......@@ -1704,11 +1705,8 @@ fn encode_partition_bottomup<T: Pixel>(
assert!(cost != std::f64::MAX);
early_exit = true;
break;
}
else {
if partition != PartitionType::PARTITION_SPLIT {
child_modes.push(child_rdo_output.part_modes[0].clone());
}
} else if partition != PartitionType::PARTITION_SPLIT {
child_modes.push(child_rdo_output.part_modes[0].clone());
}
}
};
......
......@@ -383,16 +383,14 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
assert!(seq.chroma_sampling == ChromaSampling::Cs420);
} else if seq.profile == 1 {
assert!(seq.chroma_sampling == ChromaSampling::Cs444);
} else {
if seq.bit_depth == 12 {
self.write_bit(subsampling_x)?;
} else if seq.bit_depth == 12 {
self.write_bit(subsampling_x)?;
if subsampling_x {
self.write_bit(subsampling_y)?;
}
} else {
assert!(seq.chroma_sampling == ChromaSampling::Cs422);
if subsampling_x {
self.write_bit(subsampling_y)?;
}
} else {
assert!(seq.chroma_sampling == ChromaSampling::Cs422);
}
if seq.chroma_sampling == ChromaSampling::Cs420 {
......@@ -450,10 +448,8 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
if fi.frame_type == FrameType::SWITCH {
assert!(fi.error_resilient);
} else {
if !(fi.frame_type == FrameType::KEY && fi.show_frame) {
self.write_bit(fi.error_resilient)?; // error resilient
}
} else if !(fi.frame_type == FrameType::KEY && fi.show_frame) {
self.write_bit(fi.error_resilient)?; // error resilient
}
}
......@@ -559,49 +555,47 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
}
let frame_refs_short_signaling = false;
if fi.frame_type == FrameType::KEY {
if fi.frame_type == FrameType::KEY || fi.intra_only {
// Done by above
} else {
if fi.intra_only {
// Done by above
} else {
if fi.sequence.enable_order_hint {
self.write_bit(frame_refs_short_signaling)?;
if frame_refs_short_signaling {
unimplemented!();
}
if fi.sequence.enable_order_hint {
self.write_bit(frame_refs_short_signaling)?;
if frame_refs_short_signaling {
unimplemented!();
}
}
for i in 0..INTER_REFS_PER_FRAME {
if !frame_refs_short_signaling {
self.write(REF_FRAMES_LOG2 as u32, fi.ref_frames[i] as u8)?;
}
if fi.sequence.frame_id_numbers_present_flag {
unimplemented!();
}
for i in 0..INTER_REFS_PER_FRAME {
if !frame_refs_short_signaling {
self.write(REF_FRAMES_LOG2 as u32, fi.ref_frames[i] as u8)?;
}
if fi.error_resilient && frame_size_override_flag {
if fi.sequence.frame_id_numbers_present_flag {
unimplemented!();
} else {
if frame_size_override_flag {
unimplemented!();
}
if fi.sequence.enable_superres {
unimplemented!();
}
self.write_bit(false)?; // render_and_frame_size_different
}
if fi.force_integer_mv != 0 {
} else {
self.write_bit(fi.allow_high_precision_mv);
}
if fi.error_resilient && frame_size_override_flag {
unimplemented!();
} else {
if frame_size_override_flag {
unimplemented!();
}
self.write_bit(fi.is_filter_switchable)?;
self.write_bit(fi.is_motion_mode_switchable)?;
self.write(2, 0)?; // EIGHTTAP_REGULAR
if fi.error_resilient || !fi.sequence.enable_ref_frame_mvs {
} else {
self.write_bit(fi.use_ref_frame_mvs)?;
if fi.sequence.enable_superres {
unimplemented!();
}
self.write_bit(false)?; // render_and_frame_size_different
}
if fi.force_integer_mv == 0 {
self.write_bit(fi.allow_high_precision_mv);
}
self.write_bit(fi.is_filter_switchable)?;
self.write_bit(fi.is_motion_mode_switchable)?;
self.write(2, 0)?; // EIGHTTAP_REGULAR
if (!fi.error_resilient && fi.sequence.enable_ref_frame_mvs) {
self.write_bit(fi.use_ref_frame_mvs)?;
}
}
......@@ -862,21 +856,16 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
if !fi.sequence.use_128x128_superblock {
self.write(1, if rs.planes[0].unit_size > 64 { 1 } else { 0 })?;
}
if rs.planes[0].unit_size > 64 {
self.write(1, if rs.planes[0].unit_size > 128 { 1 } else { 0 })?;
}
if use_chroma_lrf {
if fi.sequence.chroma_sampling == ChromaSampling::Cs420 {
self.write(
1,
if rs.planes[0].unit_size > rs.planes[1].unit_size {
1
} else {
0
}
)?;
}
if use_chroma_lrf && fi.sequence.chroma_sampling == ChromaSampling::Cs420 {
self.write(
1,
if rs.planes[0].unit_size > rs.planes[1].unit_size { 1 } else { 0 }
)?;
}
}
}
......
......@@ -1074,23 +1074,26 @@ pub fn get_sub_partitions_with_border_check<T: Pixel>(
if partition == PARTITION_NONE {
return partitions;
}
let hbsw = subsize.width_mi(); // Half the block size width in blocks
let hbsh = subsize.height_mi(); // Half the block size height in blocks
if partition == PARTITION_VERT || partition == PARTITION_SPLIT {
if four_partitions[1].x + hbsw as usize <= fi.w_in_b &&
four_partitions[1].y + hbsh as usize <= fi.h_in_b {
partitions.push(four_partitions[1]); }
if (partition == PARTITION_VERT || partition == PARTITION_SPLIT) &&
four_partitions[1].x + hbsw <= fi.w_in_b &&
four_partitions[1].y + hbsh <= fi.h_in_b {
partitions.push(four_partitions[1]);
};
if partition == PARTITION_HORZ || partition == PARTITION_SPLIT {
if four_partitions[2].x + hbsw as usize <= fi.w_in_b &&
four_partitions[2].y + hbsh as usize <= fi.h_in_b {
partitions.push(four_partitions[2]); }
if (partition == PARTITION_HORZ || partition == PARTITION_SPLIT) &&
four_partitions[2].x + hbsw <= fi.w_in_b &&
four_partitions[2].y + hbsh <= fi.h_in_b {
partitions.push(four_partitions[2]);
};
if partition == PARTITION_SPLIT {
if four_partitions[3].x + hbsw as usize <= fi.w_in_b &&
four_partitions[3].y + hbsh as usize <= fi.h_in_b {
partitions.push(four_partitions[3]); }
if partition == PARTITION_SPLIT &&
four_partitions[3].x + hbsw <= fi.w_in_b &&
four_partitions[3].y + hbsh <= fi.h_in_b {
partitions.push(four_partitions[3]);
};
partitions
......
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