diff --git a/src/decode.rs b/src/decode.rs index ce47a5c6c..1099a39ab 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -48,12 +48,12 @@ use crate::include::common::intops::clip; use crate::include::common::intops::clip_u8; use crate::include::common::intops::iclip; use crate::include::dav1d::common::Rav1dDataProps; +use crate::include::dav1d::headers::Dav1dSequenceHeader; use crate::include::dav1d::headers::Rav1dFilterMode; use crate::include::dav1d::headers::Rav1dFrameHeader; use crate::include::dav1d::headers::Rav1dFrameHeaderTiling; use crate::include::dav1d::headers::Rav1dPixelLayout; use crate::include::dav1d::headers::Rav1dRestorationType; -use crate::include::dav1d::headers::Rav1dSequenceHeader; use crate::include::dav1d::headers::Rav1dTxfmMode; use crate::include::dav1d::headers::Rav1dWarpedMotionParams; use crate::include::dav1d::headers::Rav1dWarpedMotionType; @@ -178,7 +178,7 @@ use std::sync::atomic::Ordering; use strum::EnumCount; fn init_quant_tables( - seq_hdr: &Rav1dSequenceHeader, + seq_hdr: &Dav1dSequenceHeader, frame_hdr: &Rav1dFrameHeader, qidx: u8, dq: &[[[RelaxedAtomic; 2]; 3]; SegmentId::COUNT], @@ -1147,7 +1147,7 @@ fn decode_b( bp: BlockPartition, intra_edge_flags: EdgeFlags, ) -> Result<(), ()> { - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); use std::fmt; /// Helper struct for printing a number as a signed hexidecimal value. @@ -1788,7 +1788,7 @@ fn decode_b( let mut y_mode = y_mode; let mut y_angle = y_angle; - let seq_hdr = f.seq_hdr(); + let seq_hdr = f.seq_hdr.as_ref().unwrap(); if y_mode == DC_PRED && pal_sz[0] == 0 && cmp::max(b_dim[2], b_dim[3]) <= 3 @@ -3440,7 +3440,7 @@ fn decode_sb( let have_h_split = f.bw > t.b.x + hsz; let have_v_split = f.bh > t.b.y + hsz; - let sb128 = f.seq_hdr().sb128 != 0; + let sb128 = f.seq_hdr.as_ref().unwrap().sb128 != 0; let intra_edge = &IntraEdges::DEFAULT; if !have_h_split && !have_v_split { @@ -3847,7 +3847,7 @@ static SS_SIZE_MUL: enum_map_ty!(Rav1dPixelLayout, [u8; 2]) = enum_map!(Rav1dPix fn setup_tile( c: &Rav1dContext, ts: &mut Rav1dTileState, - seq_hdr: &Rav1dSequenceHeader, + seq_hdr: &Dav1dSequenceHeader, frame_hdr: &Rav1dFrameHeader, bitdepth_max: i32, sb_shift: i32, @@ -4100,7 +4100,7 @@ pub(crate) fn rav1d_decode_tile_sbrow( t: &mut Rav1dTaskContext, f: &Rav1dFrameData, ) -> Result<(), ()> { - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let root_bl = if seq_hdr.sb128 != 0 { BlockLevel::Bl128x128 } else { @@ -4157,7 +4157,7 @@ pub(crate) fn rav1d_decode_tile_sbrow( root_bl, EdgeIndex::root(), )?; - if t.b.x & 16 != 0 || f.seq_hdr().sb128 != 0 { + if t.b.x & 16 != 0 || f.seq_hdr.as_ref().unwrap().sb128 != 0 { t.a += 1; } } @@ -4272,13 +4272,13 @@ pub(crate) fn rav1d_decode_tile_sbrow( root_bl, EdgeIndex::root(), )?; - if t.b.x & 16 != 0 || f.seq_hdr().sb128 != 0 { + if t.b.x & 16 != 0 || f.seq_hdr.as_ref().unwrap().sb128 != 0 { t.a += 1; t.lf_mask = t.lf_mask.map(|i| i + 1); } } - if f.seq_hdr().ref_frame_mvs != 0 + if f.seq_hdr.as_ref().unwrap().ref_frame_mvs != 0 && c.tc.len() > 1 && f.frame_hdr().frame_type.is_inter_or_switch() { @@ -4366,7 +4366,7 @@ pub(crate) fn rav1d_decode_frame_init(c: &Rav1dContext, fc: &Rav1dFrameContext) let num_sb128 = f.sb128w * f.sb128h; let size_mul = &SS_SIZE_MUL[f.cur.p.layout]; - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let hbd = (seq_hdr.hbd != 0) as c_int; if c.fc.len() > 1 { let mut tile_idx = 0; @@ -4709,7 +4709,7 @@ pub(crate) fn rav1d_decode_frame_init_cdf( setup_tile( c, ts, - &***f.seq_hdr.as_ref().unwrap(), + &**f.seq_hdr.as_ref().unwrap(), frame_hdr, f.bitdepth_max, f.sb_shift, @@ -4786,7 +4786,7 @@ fn rav1d_decode_frame_main(c: &Rav1dContext, f: &mut Rav1dFrameData) -> Rav1dRes let sbh_end = cmp::min(sbh_end.into(), f.sbh); for sby in sbh_start.into()..sbh_end { - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let frame_hdr = &***f.frame_hdr.as_ref().unwrap(); t.b.y = sby << 4 + seq_hdr.sb128; let by_end = t.b.y + f.sb_step >> 1; diff --git a/src/fg_apply.rs b/src/fg_apply.rs index 7e42f6901..ef2b427f2 100644 --- a/src/fg_apply.rs +++ b/src/fg_apply.rs @@ -130,7 +130,7 @@ pub(crate) fn rav1d_apply_grain_row( ) { // Synthesize grain for the affected planes let GrainBD { grain_lut, scaling } = grain; - let seq_hdr = &***out.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**out.seq_hdr.as_ref().unwrap(); let frame_hdr = &***out.frame_hdr.as_ref().unwrap(); let data = &frame_hdr.film_grain.data; let in_data = &r#in.data.as_ref().unwrap().data; @@ -141,7 +141,7 @@ pub(crate) fn rav1d_apply_grain_row( let ss_y = (r#in.p.layout == Rav1dPixelLayout::I420) as usize; let ss_x = (r#in.p.layout != Rav1dPixelLayout::I444) as usize; let cpw = w + ss_x >> ss_x; - let is_id = seq_hdr.mtrx == Rav1dMatrixCoefficients::IDENTITY; + let is_id = seq_hdr.mtrx == Rav1dMatrixCoefficients::IDENTITY.into(); let bitdepth_max = (1 << out.p.bpc) - 1; let bd = BD::from_c(bitdepth_max); diff --git a/src/include/dav1d/headers.rs b/src/include/dav1d/headers.rs index 331d950a8..701483380 100644 --- a/src/include/dav1d/headers.rs +++ b/src/include/dav1d/headers.rs @@ -181,6 +181,7 @@ pub const DAV1D_ADAPTIVE: Dav1dAdaptiveBoolean = Rav1dAdaptiveBoolean::Adaptive as Dav1dAdaptiveBoolean; #[derive(Clone, Copy, PartialEq, Eq, FromRepr)] +#[repr(u32)] pub enum Rav1dAdaptiveBoolean { Off = 0, On = 1, @@ -206,7 +207,7 @@ impl TryFrom for Rav1dAdaptiveBoolean { type Error = (); fn try_from(value: Dav1dAdaptiveBoolean) -> Result { - Self::from_repr(value as usize).ok_or(()) + Self::from_repr(value).ok_or(()) } } @@ -383,6 +384,7 @@ impl From for Dav1dWarpedMotionParams { // TODO(kkysen) Eventually the [`impl Default`] might not be needed. #[derive(Clone, Copy, PartialEq, Eq, EnumCount, FromRepr, Default)] +#[repr(u32)] pub enum Rav1dPixelLayout { #[default] I400 = 0, @@ -401,7 +403,7 @@ impl Sub for Rav1dPixelLayout { type Output = Rav1dPixelLayout; fn sub(self, rhs: Self) -> Self::Output { - Self::from_repr((self as u8 - rhs as u8) as usize).unwrap() + Self::from_repr(self as u32 - rhs as u32).unwrap() } } @@ -421,7 +423,7 @@ impl TryFrom for Rav1dPixelLayout { type Error = (); fn try_from(value: Dav1dPixelLayout) -> Result { - Self::from_repr(value as usize).ok_or(()) + Self::from_repr(value).ok_or(()) } } @@ -731,6 +733,7 @@ pub const DAV1D_CHR_COLOCATED: Dav1dChromaSamplePosition = Rav1dChromaSamplePosition::Colocated as Dav1dChromaSamplePosition; #[derive(Clone, Copy, PartialEq, Eq, FromRepr)] +#[repr(u32)] pub enum Rav1dChromaSamplePosition { Unknown = 0, /// Horizontally co-located with (0, 0) luma sample, vertical position @@ -751,7 +754,7 @@ impl TryFrom for Rav1dChromaSamplePosition { type Error = (); fn try_from(value: Dav1dChromaSamplePosition) -> Result { - Self::from_repr(value as usize).ok_or(()) + Self::from_repr(value).ok_or(()) } } @@ -828,7 +831,7 @@ impl Rav1dITUTT35 { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq, Eq, Default)] #[repr(C)] pub struct Dav1dSequenceHeaderOperatingPoint { pub major_level: u8, @@ -898,7 +901,7 @@ impl From for Dav1dSequenceHeaderOperatingPoi } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Default, PartialEq, Eq)] #[repr(C)] pub struct Dav1dSequenceHeaderOperatingParameterInfo { pub decoder_buffer_delay: u32, @@ -950,11 +953,11 @@ pub struct Dav1dSequenceHeader { pub profile: u8, pub max_width: c_int, pub max_height: c_int, - pub layout: Dav1dPixelLayout, + pub layout: Rav1dPixelLayout, pub pri: Dav1dColorPrimaries, pub trc: Dav1dTransferCharacteristics, pub mtrx: Dav1dMatrixCoefficients, - pub chr: Dav1dChromaSamplePosition, + pub chr: Rav1dChromaSamplePosition, pub hbd: u8, pub color_range: u8, pub num_operating_points: u8, @@ -990,8 +993,8 @@ pub struct Dav1dSequenceHeader { pub order_hint: u8, pub jnt_comp: u8, pub ref_frame_mvs: u8, - pub screen_content_tools: Dav1dAdaptiveBoolean, - pub force_integer_mv: Dav1dAdaptiveBoolean, + pub screen_content_tools: Rav1dAdaptiveBoolean, + pub force_integer_mv: Rav1dAdaptiveBoolean, pub order_hint_n_bits: u8, pub super_res: u8, pub cdef: u8, @@ -1027,69 +1030,7 @@ impl TryFrom for Rav1dProfile { } } -#[derive(Clone)] -#[repr(C)] -pub struct Rav1dSequenceHeader { - pub profile: Rav1dProfile, - pub max_width: c_int, - pub max_height: c_int, - pub layout: Rav1dPixelLayout, - pub pri: Rav1dColorPrimaries, - pub trc: Rav1dTransferCharacteristics, - pub mtrx: Rav1dMatrixCoefficients, - pub chr: Rav1dChromaSamplePosition, - pub hbd: u8, - pub color_range: u8, - pub num_operating_points: u8, - pub operating_points: [Rav1dSequenceHeaderOperatingPoint; RAV1D_MAX_OPERATING_POINTS], - pub still_picture: u8, - pub reduced_still_picture_header: u8, - pub timing_info_present: u8, - /// > 0 if defined, 0 otherwise - pub num_units_in_tick: u32, - /// > 0 if defined, 0 otherwise - pub time_scale: u32, - pub equal_picture_interval: u8, - pub num_ticks_per_picture: u32, - pub decoder_model_info_present: u8, - pub encoder_decoder_buffer_delay_length: u8, - /// > 0 if defined, 0 otherwise - pub num_units_in_decoding_tick: u32, - pub buffer_removal_delay_length: u8, - pub frame_presentation_delay_length: u8, - pub display_model_info_present: u8, - pub width_n_bits: u8, - pub height_n_bits: u8, - pub frame_id_numbers_present: u8, - pub delta_frame_id_n_bits: u8, - pub frame_id_n_bits: u8, - pub sb128: u8, - pub filter_intra: u8, - pub intra_edge_filter: u8, - pub inter_intra: u8, - pub masked_compound: u8, - pub warped_motion: u8, - pub dual_filter: u8, - pub order_hint: u8, - pub jnt_comp: u8, - pub ref_frame_mvs: u8, - pub screen_content_tools: Rav1dAdaptiveBoolean, - pub force_integer_mv: Rav1dAdaptiveBoolean, - pub order_hint_n_bits: u8, - pub super_res: u8, - pub cdef: u8, - pub restoration: u8, - pub ss_hor: u8, - pub ss_ver: u8, - pub monochrome: u8, - pub color_description_present: u8, - pub separate_uv_delta_q: u8, - pub film_grain_present: u8, - pub operating_parameter_info: - [Rav1dSequenceHeaderOperatingParameterInfo; RAV1D_MAX_OPERATING_POINTS], -} - -impl Rav1dSequenceHeader { +impl Dav1dSequenceHeader { /// TODO(kkysen) We should split [`Rav1dSequenceHeader`] into an inner `struct` /// without the `operating_parameter_info` field /// so that we can just `#[derive(PartialEq, Eq)]` it. @@ -1206,236 +1147,6 @@ impl Rav1dSequenceHeader { } } -impl From for Rav1dSequenceHeader { - fn from(value: Dav1dSequenceHeader) -> Self { - let Dav1dSequenceHeader { - profile, - max_width, - max_height, - layout, - pri, - trc, - mtrx, - chr, - hbd, - color_range, - num_operating_points, - operating_points, - still_picture, - reduced_still_picture_header, - timing_info_present, - num_units_in_tick, - time_scale, - equal_picture_interval, - num_ticks_per_picture, - decoder_model_info_present, - encoder_decoder_buffer_delay_length, - num_units_in_decoding_tick, - buffer_removal_delay_length, - frame_presentation_delay_length, - display_model_info_present, - width_n_bits, - height_n_bits, - frame_id_numbers_present, - delta_frame_id_n_bits, - frame_id_n_bits, - sb128, - filter_intra, - intra_edge_filter, - inter_intra, - masked_compound, - warped_motion, - dual_filter, - order_hint, - jnt_comp, - ref_frame_mvs, - screen_content_tools, - force_integer_mv, - order_hint_n_bits, - super_res, - cdef, - restoration, - ss_hor, - ss_ver, - monochrome, - color_description_present, - separate_uv_delta_q, - film_grain_present, - operating_parameter_info, - } = value; - Self { - profile: profile.try_into().unwrap(), - max_width, - max_height, - layout: layout.try_into().unwrap(), - pri: pri.try_into().unwrap(), - trc: trc.try_into().unwrap(), - mtrx: mtrx.try_into().unwrap(), - chr: chr.try_into().unwrap(), - hbd, - color_range, - num_operating_points, - operating_points: operating_points.map(|c| c.into()), - still_picture, - reduced_still_picture_header, - timing_info_present, - num_units_in_tick, - time_scale, - equal_picture_interval, - num_ticks_per_picture, - decoder_model_info_present, - encoder_decoder_buffer_delay_length, - num_units_in_decoding_tick, - buffer_removal_delay_length, - frame_presentation_delay_length, - display_model_info_present, - width_n_bits, - height_n_bits, - frame_id_numbers_present, - delta_frame_id_n_bits, - frame_id_n_bits, - sb128, - filter_intra, - intra_edge_filter, - inter_intra, - masked_compound, - warped_motion, - dual_filter, - order_hint, - jnt_comp, - ref_frame_mvs, - screen_content_tools: screen_content_tools.try_into().unwrap(), - force_integer_mv: force_integer_mv.try_into().unwrap(), - order_hint_n_bits, - super_res, - cdef, - restoration, - ss_hor, - ss_ver, - monochrome, - color_description_present, - separate_uv_delta_q, - film_grain_present, - operating_parameter_info: operating_parameter_info.map(|c| c.into()), - } - } -} - -impl From for Dav1dSequenceHeader { - fn from(value: Rav1dSequenceHeader) -> Self { - let Rav1dSequenceHeader { - profile, - max_width, - max_height, - layout, - pri, - trc, - mtrx, - chr, - hbd, - color_range, - num_operating_points, - operating_points, - still_picture, - reduced_still_picture_header, - timing_info_present, - num_units_in_tick, - time_scale, - equal_picture_interval, - num_ticks_per_picture, - decoder_model_info_present, - encoder_decoder_buffer_delay_length, - num_units_in_decoding_tick, - buffer_removal_delay_length, - frame_presentation_delay_length, - display_model_info_present, - width_n_bits, - height_n_bits, - frame_id_numbers_present, - delta_frame_id_n_bits, - frame_id_n_bits, - sb128, - filter_intra, - intra_edge_filter, - inter_intra, - masked_compound, - warped_motion, - dual_filter, - order_hint, - jnt_comp, - ref_frame_mvs, - screen_content_tools, - force_integer_mv, - order_hint_n_bits, - super_res, - cdef, - restoration, - ss_hor, - ss_ver, - monochrome, - color_description_present, - separate_uv_delta_q, - film_grain_present, - operating_parameter_info, - } = value; - Self { - profile: profile.into(), - max_width, - max_height, - layout: layout.into(), - pri: pri.into(), - trc: trc.into(), - mtrx: mtrx.into(), - chr: chr.into(), - hbd, - color_range, - num_operating_points, - operating_points: operating_points.map(|rust| rust.into()), - still_picture, - reduced_still_picture_header, - timing_info_present, - num_units_in_tick, - time_scale, - equal_picture_interval, - num_ticks_per_picture, - decoder_model_info_present, - encoder_decoder_buffer_delay_length, - num_units_in_decoding_tick, - buffer_removal_delay_length, - frame_presentation_delay_length, - display_model_info_present, - width_n_bits, - height_n_bits, - frame_id_numbers_present, - delta_frame_id_n_bits, - frame_id_n_bits, - sb128, - filter_intra, - intra_edge_filter, - inter_intra, - masked_compound, - warped_motion, - dual_filter, - order_hint, - jnt_comp, - ref_frame_mvs, - screen_content_tools: screen_content_tools.into(), - force_integer_mv: force_integer_mv.into(), - order_hint_n_bits, - super_res, - cdef, - restoration, - ss_hor, - ss_ver, - monochrome, - color_description_present, - separate_uv_delta_q, - film_grain_present, - operating_parameter_info: operating_parameter_info.map(|rust| rust.into()), - } - } -} - #[derive(Clone)] #[repr(C)] pub struct Dav1dSegmentationData { diff --git a/src/include/dav1d/picture.rs b/src/include/dav1d/picture.rs index ac8af7050..81da81352 100644 --- a/src/include/dav1d/picture.rs +++ b/src/include/dav1d/picture.rs @@ -24,7 +24,6 @@ use crate::include::dav1d::headers::Rav1dFrameHeader; use crate::include::dav1d::headers::Rav1dITUTT35; use crate::include::dav1d::headers::Rav1dMasteringDisplay; use crate::include::dav1d::headers::Rav1dPixelLayout; -use crate::include::dav1d::headers::Rav1dSequenceHeader; use crate::pixels::Pixels; use crate::send_sync_non_null::SendSyncNonNull; use crate::strided::Strided; @@ -104,7 +103,7 @@ pub struct Dav1dPicture { pub n_itut_t35: usize, pub reserved: [uintptr_t; 4], pub frame_hdr_ref: Option>>, // opaque, so we can change this - pub seq_hdr_ref: Option>>, // opaque, so we can change this + pub seq_hdr_ref: Option>, // opaque, so we can change this pub content_light_ref: Option>, // opaque, so we can change this pub mastering_display_ref: Option>, // opaque, so we can change this pub itut_t35_ref: Option, Box<[Dav1dITUTT35]>>>>, // opaque, so we can change this @@ -414,7 +413,7 @@ impl Drop for Rav1dPictureData { #[derive(Clone, Default)] #[repr(C)] pub(crate) struct Rav1dPicture { - pub seq_hdr: Option>>, + pub seq_hdr: Option>, pub frame_hdr: Option>>, pub data: Option>, pub stride: [ptrdiff_t; 2], @@ -500,7 +499,7 @@ impl From for Dav1dPicture { } = value; Self { // [`DRav1d::from_rav1d`] is called right after [`parse_seq_hdr`]. - seq_hdr: seq_hdr.as_ref().map(|arc| (&arc.as_ref().dav1d).into()), + seq_hdr: seq_hdr.as_ref().map(|arc| (arc.as_ref()).into()), // [`DRav1d::from_rav1d`] is called in [`parse_frame_hdr`]. frame_hdr: frame_hdr.as_ref().map(|arc| (&arc.as_ref().dav1d).into()), data: data @@ -753,7 +752,7 @@ impl Rav1dPicAllocator { &self, w: c_int, h: c_int, - seq_hdr: Arc>, + seq_hdr: Arc, frame_hdr: Option>>, ) -> Rav1dResult { let pic = Rav1dPicture { diff --git a/src/internal.rs b/src/internal.rs index 855e4c78f..5a99b3d2c 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -31,7 +31,6 @@ use crate::include::dav1d::headers::Rav1dContentLightLevel; use crate::include::dav1d::headers::Rav1dFrameHeader; use crate::include::dav1d::headers::Rav1dITUTT35; use crate::include::dav1d::headers::Rav1dMasteringDisplay; -use crate::include::dav1d::headers::Rav1dSequenceHeader; use crate::include::dav1d::headers::Rav1dWarpedMotionParams; use crate::include::dav1d::picture::Rav1dPicAllocator; use crate::include::dav1d::picture::Rav1dPicture; @@ -379,7 +378,7 @@ pub struct Rav1dState { /// to a frame worker to be decoded. pub(crate) tiles: Vec, pub(crate) n_tiles: c_int, - pub(crate) seq_hdr: Option>>, // TODO(kkysen) Previously pooled. + pub(crate) seq_hdr: Option>, // TODO(kkysen) Previously pooled. pub(crate) frame_hdr: Option>>, // TODO(kkysen) Previously pooled. pub(crate) content_light: Option>, pub(crate) mastering_display: Option>, @@ -792,7 +791,7 @@ impl Rav1dFrameContext { #[derive(Default)] #[repr(C)] pub(crate) struct Rav1dFrameData { - pub seq_hdr: Option>>, + pub seq_hdr: Option>, pub frame_hdr: Option>>, pub refp: [Rav1dThreadPicture; 7], // during block coding / reconstruction @@ -856,10 +855,6 @@ impl Rav1dFrameData { pub fn frame_hdr(&self) -> &Rav1dFrameHeader { self.frame_hdr.as_ref().unwrap() } - - pub fn seq_hdr(&self) -> &Rav1dSequenceHeader { - self.seq_hdr.as_ref().unwrap() - } } #[derive(Default)] diff --git a/src/lf_apply.rs b/src/lf_apply.rs index 52b00fcfe..f8104a5e2 100644 --- a/src/lf_apply.rs +++ b/src/lf_apply.rs @@ -159,7 +159,7 @@ pub(crate) fn rav1d_copy_lpf( let frame_hdr = &***f.frame_hdr.as_ref().unwrap(); let resize = (frame_hdr.size.width[0] != frame_hdr.size.width[1]) as c_int; let offset_y = 8 * (sby != 0) as c_int; - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let tt_off = have_tt * sby * (4 << seq_hdr.sb128); let sr_cur_data = &f.sr_cur.p.data.as_ref().unwrap().data; let dst = array::from_fn::<_, 3, _>(|i| { @@ -523,7 +523,7 @@ pub(crate) fn rav1d_loopfilter_sbrow_cols( ) { let lflvl = &f.lf.mask[lflvl_offset..]; let mut have_left; // Don't filter outside the frame - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let is_sb64 = (seq_hdr.sb128 == 0) as c_int; let starty4 = ((sby & is_sb64) as u32) << 4; let sbsz = 32 >> is_sb64; @@ -675,7 +675,7 @@ pub(crate) fn rav1d_loopfilter_sbrow_rows( // Don't filter outside the frame let have_top = sby > 0; - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let is_sb64 = (seq_hdr.sb128 == 0) as c_int; let starty4 = (sby & is_sb64) << 4; let sbsz = 32 >> is_sb64; diff --git a/src/lib.rs b/src/lib.rs index c743bd84d..db6ee08fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -506,7 +506,7 @@ pub unsafe extern "C" fn dav1d_parse_sequence_header( validate_input!((sz > 0 && sz <= usize::MAX / 2, EINVAL))?; // SAFETY: `ptr` is the start of a `&[u8]` slice of length `sz`. let data = unsafe { slice::from_raw_parts(ptr.as_ptr(), sz) }; - let seq_hdr = rav1d_parse_sequence_header(data)?.dav1d; + let seq_hdr = rav1d_parse_sequence_header(data)?; // SAFETY: `out` is safe to write to. unsafe { out.as_ptr().write(seq_hdr) }; Ok(()) diff --git a/src/lr_apply.rs b/src/lr_apply.rs index ecb035a38..8eca3acd4 100644 --- a/src/lr_apply.rs +++ b/src/lr_apply.rs @@ -45,7 +45,7 @@ fn lr_stripe( ) { let bd = BD::from_c(f.bitdepth_max); - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let chroma = (plane != 0) as c_int; let ss_ver = chroma & (f.sr_cur.p.p.layout == Rav1dPixelLayout::I420) as c_int; let stride: ptrdiff_t = f.sr_cur.p.stride[chroma as usize]; @@ -254,7 +254,7 @@ pub(crate) fn rav1d_lr_sbrow( let offset_y = 8 * (sby != 0) as c_int; let restore_planes = f.lf.restore_planes; let not_last = ((sby + 1) < f.sbh) as c_int; - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); if restore_planes.contains(LrRestorePlanes::Y) { let h = f.sr_cur.p.p.h; let w = f.sr_cur.p.p.w; diff --git a/src/obu.rs b/src/obu.rs index 60d358041..9cd7f7790 100644 --- a/src/obu.rs +++ b/src/obu.rs @@ -15,6 +15,8 @@ use crate::include::dav1d::data::Rav1dData; use crate::include::dav1d::dav1d::Rav1dDecodeFrameType; use crate::include::dav1d::headers::DRav1d; use crate::include::dav1d::headers::Dav1dSequenceHeader; +use crate::include::dav1d::headers::Dav1dSequenceHeaderOperatingParameterInfo; +use crate::include::dav1d::headers::Dav1dSequenceHeaderOperatingPoint; use crate::include::dav1d::headers::Rav1dAdaptiveBoolean; use crate::include::dav1d::headers::Rav1dChromaSamplePosition; use crate::include::dav1d::headers::Rav1dColorPrimaries; @@ -47,13 +49,11 @@ use crate::include::dav1d::headers::Rav1dProfile; use crate::include::dav1d::headers::Rav1dRestorationType; use crate::include::dav1d::headers::Rav1dSegmentationData; use crate::include::dav1d::headers::Rav1dSegmentationDataSet; -use crate::include::dav1d::headers::Rav1dSequenceHeader; -use crate::include::dav1d::headers::Rav1dSequenceHeaderOperatingParameterInfo; -use crate::include::dav1d::headers::Rav1dSequenceHeaderOperatingPoint; use crate::include::dav1d::headers::Rav1dTransferCharacteristics; use crate::include::dav1d::headers::Rav1dTxfmMode; use crate::include::dav1d::headers::Rav1dWarpedMotionParams; use crate::include::dav1d::headers::Rav1dWarpedMotionType; +use crate::include::dav1d::headers::DAV1D_MAX_OPERATING_POINTS; use crate::include::dav1d::headers::RAV1D_MAX_CDEF_STRENGTHS; use crate::include::dav1d::headers::RAV1D_MAX_OPERATING_POINTS; use crate::include::dav1d::headers::RAV1D_MAX_TILE_COLS; @@ -152,7 +152,7 @@ fn check_trailing_bits(gb: &mut GetBits, strict_std_compliance: bool) -> Rav1dRe fn parse_seq_hdr( gb: &mut GetBits, strict_std_compliance: bool, -) -> Rav1dResult { +) -> Rav1dResult { let debug = Debug::new(false, "SEQHDR", gb); let profile = Rav1dProfile::from_repr(gb.get_bits(3) as usize).ok_or(EINVAL)?; @@ -167,7 +167,7 @@ fn parse_seq_hdr( let num_operating_points; let mut operating_points = - [Rav1dSequenceHeaderOperatingPoint::default(); RAV1D_MAX_OPERATING_POINTS]; + [Dav1dSequenceHeaderOperatingPoint::default(); DAV1D_MAX_OPERATING_POINTS]; let timing_info_present; let num_units_in_tick; let time_scale; @@ -180,7 +180,7 @@ fn parse_seq_hdr( let frame_presentation_delay_length; let display_model_info_present; let mut operating_parameter_info = - [Rav1dSequenceHeaderOperatingParameterInfo::default(); RAV1D_MAX_OPERATING_POINTS]; + [Dav1dSequenceHeaderOperatingParameterInfo::default(); RAV1D_MAX_OPERATING_POINTS]; if reduced_still_picture_header != 0 { num_operating_points = 1; operating_points[0].major_level = gb.get_bits(3) as u8; @@ -472,7 +472,7 @@ fn parse_seq_hdr( } } chr = if ss_hor & ss_ver != 0 { - Rav1dChromaSamplePosition::from_repr(gb.get_bits(2) as usize).unwrap() + Rav1dChromaSamplePosition::from_repr(gb.get_bits(2)).unwrap() } else { Rav1dChromaSamplePosition::Unknown }; @@ -500,19 +500,19 @@ fn parse_seq_hdr( // point in setting its position properly. check_trailing_bits(gb, strict_std_compliance)?; - Ok(Rav1dSequenceHeader { - profile, + Ok(Dav1dSequenceHeader { + profile: profile as u8, max_width, max_height, layout, - pri, - trc, - mtrx, + pri: pri.into(), + trc: trc.into(), + mtrx: mtrx.into(), chr, hbd, color_range, num_operating_points, - operating_points, + operating_points: operating_points.into(), still_picture, reduced_still_picture_header, timing_info_present, @@ -557,9 +557,7 @@ fn parse_seq_hdr( }) } -pub(crate) fn rav1d_parse_sequence_header( - mut data: &[u8], -) -> Rav1dResult> { +pub(crate) fn rav1d_parse_sequence_header(mut data: &[u8]) -> Rav1dResult { let mut res = Err(ENOENT); while !data.is_empty() { @@ -599,12 +597,12 @@ pub(crate) fn rav1d_parse_sequence_header( data = &data[obu_end..] } - res.map(DRav1d::from_rav1d) + res } fn parse_frame_size( state: &Rav1dState, - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, refidx: Option<&[i8; RAV1D_REFS_PER_FRAME]>, frame_size_override: bool, gb: &mut GetBits, @@ -705,7 +703,7 @@ static DEFAULT_MODE_REF_DELTAS: Rav1dLoopfilterModeRefDeltas = Rav1dLoopfilterMo fn parse_refidx( state: &Rav1dState, - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, frame_ref_short_signaling: u8, frame_offset: u8, frame_id: u32, @@ -838,7 +836,7 @@ fn parse_refidx( } fn parse_tiling( - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, size: &Rav1dFrameSize, debug: &Debug, gb: &mut GetBits, @@ -959,7 +957,7 @@ fn parse_tiling( } fn parse_quant( - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, debug: &Debug, gb: &mut GetBits, ) -> Rav1dFrameHeaderQuant { @@ -1246,7 +1244,7 @@ fn parse_delta( fn parse_loopfilter( state: &Rav1dState, - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, all_lossless: bool, allow_intrabc: bool, primary_ref_frame: u8, @@ -1328,7 +1326,7 @@ fn parse_loopfilter( } fn parse_cdef( - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, all_lossless: bool, allow_intrabc: bool, debug: &Debug, @@ -1365,7 +1363,7 @@ fn parse_cdef( } fn parse_restoration( - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, all_lossless: bool, super_res_enabled: bool, allow_intrabc: bool, @@ -1429,7 +1427,7 @@ fn parse_restoration( fn parse_skip_mode( state: &Rav1dState, - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, switchable_comp_refs: u8, frame_type: Rav1dFrameType, frame_offset: u8, @@ -1601,7 +1599,7 @@ fn parse_gmv( } fn parse_film_grain_data( - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, seed: c_uint, gb: &mut GetBits, ) -> Rav1dResult { @@ -1711,7 +1709,7 @@ fn parse_film_grain_data( fn parse_film_grain( state: &Rav1dState, - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, show_frame: u8, showable_frame: u8, frame_type: Rav1dFrameType, @@ -1770,7 +1768,7 @@ fn parse_film_grain( fn parse_frame_hdr( c: &Rav1dContext, state: &Rav1dState, - seqhdr: &Rav1dSequenceHeader, + seqhdr: &Dav1dSequenceHeader, temporal_id: u8, spatial_id: u8, gb: &mut GetBits, @@ -2304,7 +2302,7 @@ fn parse_obus( } _ => {} } - state.seq_hdr = Some(Arc::new(DRav1d::from_rav1d(seq_hdr))); // TODO(kkysen) fallible allocation + state.seq_hdr = Some(Arc::new(seq_hdr)); // TODO(kkysen) fallible allocation } Some(Rav1dObuType::RedundantFrameHdr) if state.frame_hdr.is_some() => {} Some(Rav1dObuType::RedundantFrameHdr | Rav1dObuType::Frame | Rav1dObuType::FrameHdr) => { diff --git a/src/picture.rs b/src/picture.rs index 10464d063..46da0f259 100644 --- a/src/picture.rs +++ b/src/picture.rs @@ -14,7 +14,6 @@ use crate::include::dav1d::headers::Rav1dFrameHeader; use crate::include::dav1d::headers::Rav1dITUTT35; use crate::include::dav1d::headers::Rav1dMasteringDisplay; use crate::include::dav1d::headers::Rav1dPixelLayout; -use crate::include::dav1d::headers::Rav1dSequenceHeader; use crate::include::dav1d::picture::Dav1dPicture; use crate::include::dav1d::picture::Rav1dPicAllocator; use crate::include::dav1d::picture::Rav1dPicture; @@ -219,7 +218,7 @@ fn picture_alloc_with_edges( p: &mut Rav1dPicture, w: c_int, h: c_int, - seq_hdr: Option>>, + seq_hdr: Option>, frame_hdr: Option>>, bpc: u8, p_allocator: &Rav1dPicAllocator, diff --git a/src/recon.rs b/src/recon.rs index 16cdfe588..bcdaa16c1 100644 --- a/src/recon.rs +++ b/src/recon.rs @@ -3687,7 +3687,7 @@ pub(crate) fn rav1d_filter_sbrow_deblock_cols( let y = sby * f.sb_step * 4; let p = f.cur.lf_offsets::(y); - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let mask_offset = (sby >> (seq_hdr.sb128 == 0) as c_int) * f.sb128w; rav1d_loopfilter_sbrow_cols::( f, @@ -3706,7 +3706,7 @@ pub(crate) fn rav1d_filter_sbrow_deblock_rows( ) { let y = sby * f.sb_step * 4; let p = f.cur.lf_offsets::(y); - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let sb128 = seq_hdr.sb128; let cdef = seq_hdr.cdef; let mask_offset = (sby >> (sb128 == 0) as c_int) * f.sb128w; @@ -3735,7 +3735,7 @@ pub(crate) fn rav1d_filter_sbrow_cdef( let sbsz = f.sb_step; let y = sby * sbsz * 4; let p = f.cur.lf_offsets::(y); - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let prev_mask = (sby - 1 >> (seq_hdr.sb128 == 0) as c_int) * f.sb128w; let mask_offset = (sby >> (seq_hdr.sb128 == 0) as c_int) * f.sb128w; let start = sby * sbsz; @@ -3816,7 +3816,7 @@ pub(crate) fn rav1d_filter_sbrow( ) { rav1d_filter_sbrow_deblock_cols::(c, f, t, sby); rav1d_filter_sbrow_deblock_rows::(c, f, t, sby); - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); if seq_hdr.cdef != 0 { rav1d_filter_sbrow_cdef::(c, f, t, sby); } diff --git a/src/refmvs.rs b/src/refmvs.rs index 87f77ba32..1721af086 100644 --- a/src/refmvs.rs +++ b/src/refmvs.rs @@ -14,8 +14,8 @@ use crate::error::Rav1dResult; use crate::ffi_safe::FFISafe; use crate::include::common::intops::apply_sign; use crate::include::common::intops::iclip; +use crate::include::dav1d::headers::Dav1dSequenceHeader; use crate::include::dav1d::headers::Rav1dFrameHeader; -use crate::include::dav1d::headers::Rav1dSequenceHeader; use crate::include::dav1d::headers::Rav1dWarpedMotionType; use crate::internal::Bxy; use crate::intra_edge::EdgeFlags; @@ -1600,7 +1600,7 @@ fn save_tmvs_rust( pub(crate) fn rav1d_refmvs_init_frame( rf: &mut RefMvsFrame, - seq_hdr: &Rav1dSequenceHeader, + seq_hdr: &Dav1dSequenceHeader, frm_hdr: &Rav1dFrameHeader, ref_poc: &[u32; 7], ref_ref_poc: &[[u32; 7]; 7], diff --git a/src/thread_task.rs b/src/thread_task.rs index f841b1b53..b443ab2dd 100644 --- a/src/thread_task.rs +++ b/src/thread_task.rs @@ -396,7 +396,7 @@ fn merge_pending(c: &Rav1dContext) -> c_int { fn create_filter_sbrow(fc: &Rav1dFrameContext, f: &Rav1dFrameData, pass: c_int) -> Rav1dResult { let frame_hdr = &***f.frame_hdr.as_ref().unwrap(); let has_deblock = (frame_hdr.loopfilter.level_y != [0; 2]) as c_int; - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let has_cdef = seq_hdr.cdef; let has_resize = (frame_hdr.size.width[0] != frame_hdr.size.width[1]) as c_int; let has_lr = !f.lf.restore_planes.is_empty(); @@ -1230,7 +1230,7 @@ pub fn rav1d_worker_task(task_thread: Arc) { (f.bd_fn().filter_sbrow_deblock_rows)(c, &f, &mut tc, sby); } // signal deblock progress - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); let frame_hdr = &***f.frame_hdr.as_ref().unwrap(); if frame_hdr.loopfilter.level_y != [0; 2] { drop(f); @@ -1272,7 +1272,7 @@ pub fn rav1d_worker_task(task_thread: Arc) { } TaskType::Cdef => { let f = fc.data.try_read().unwrap(); - let seq_hdr = &***f.seq_hdr.as_ref().unwrap(); + let seq_hdr = &**f.seq_hdr.as_ref().unwrap(); if seq_hdr.cdef != 0 { if fc.task_thread.error.load(Ordering::SeqCst) == 0 { (f.bd_fn().filter_sbrow_cdef)(c, &f, &mut tc, sby); diff --git a/tools/dav1d.rs b/tools/dav1d.rs index 6aeb59d09..5c0d6533c 100644 --- a/tools/dav1d.rs +++ b/tools/dav1d.rs @@ -67,9 +67,10 @@ use rav1d::include::dav1d::headers::Dav1dSequenceHeader; use rav1d::include::dav1d::headers::Dav1dSequenceHeaderOperatingParameterInfo; use rav1d::include::dav1d::headers::Dav1dSequenceHeaderOperatingPoint; use rav1d::include::dav1d::headers::Dav1dTransferCharacteristics; -use rav1d::include::dav1d::headers::DAV1D_CHR_UNKNOWN; +use rav1d::include::dav1d::headers::Rav1dAdaptiveBoolean; +use rav1d::include::dav1d::headers::Rav1dChromaSamplePosition; +use rav1d::include::dav1d::headers::Rav1dPixelLayout; use rav1d::include::dav1d::headers::DAV1D_MC_IDENTITY; -use rav1d::include::dav1d::headers::DAV1D_OFF; use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I400; use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I420; use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I444; @@ -400,11 +401,11 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int { profile: 0, max_width: 0, max_height: 0, - layout: DAV1D_PIXEL_LAYOUT_I400, + layout: Rav1dPixelLayout::I400, pri: 0 as Dav1dColorPrimaries, trc: 0 as Dav1dTransferCharacteristics, mtrx: DAV1D_MC_IDENTITY, - chr: DAV1D_CHR_UNKNOWN, + chr: Rav1dChromaSamplePosition::Unknown, hbd: 0, color_range: 0, num_operating_points: 0, @@ -445,8 +446,8 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int { order_hint: 0, jnt_comp: 0, ref_frame_mvs: 0, - screen_content_tools: DAV1D_OFF, - force_integer_mv: DAV1D_OFF, + screen_content_tools: Rav1dAdaptiveBoolean::Off, + force_integer_mv: Rav1dAdaptiveBoolean::Off, order_hint_n_bits: 0, super_res: 0, cdef: 0, diff --git a/tools/seek_stress.rs b/tools/seek_stress.rs index d2e093a5f..469fa7c54 100644 --- a/tools/seek_stress.rs +++ b/tools/seek_stress.rs @@ -47,10 +47,10 @@ use rav1d::include::dav1d::headers::Dav1dSequenceHeader; use rav1d::include::dav1d::headers::Dav1dSequenceHeaderOperatingParameterInfo; use rav1d::include::dav1d::headers::Dav1dSequenceHeaderOperatingPoint; use rav1d::include::dav1d::headers::Dav1dTransferCharacteristics; -use rav1d::include::dav1d::headers::DAV1D_CHR_UNKNOWN; +use rav1d::include::dav1d::headers::Rav1dAdaptiveBoolean; +use rav1d::include::dav1d::headers::Rav1dChromaSamplePosition; +use rav1d::include::dav1d::headers::Rav1dPixelLayout; use rav1d::include::dav1d::headers::DAV1D_MC_IDENTITY; -use rav1d::include::dav1d::headers::DAV1D_OFF; -use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I400; use rav1d::include::dav1d::picture::Dav1dPicAllocator; use rav1d::include::dav1d::picture::Dav1dPicture; use std::ffi::c_char; @@ -192,11 +192,11 @@ unsafe fn seek( profile: 0, max_width: 0, max_height: 0, - layout: DAV1D_PIXEL_LAYOUT_I400, + layout: Rav1dPixelLayout::I400, pri: 0 as Dav1dColorPrimaries, trc: 0 as Dav1dTransferCharacteristics, mtrx: DAV1D_MC_IDENTITY, - chr: DAV1D_CHR_UNKNOWN, + chr: Rav1dChromaSamplePosition::Unknown, hbd: 0, color_range: 0, num_operating_points: 0, @@ -237,8 +237,8 @@ unsafe fn seek( order_hint: 0, jnt_comp: 0, ref_frame_mvs: 0, - screen_content_tools: DAV1D_OFF, - force_integer_mv: DAV1D_OFF, + screen_content_tools: Rav1dAdaptiveBoolean::Off, + force_integer_mv: Rav1dAdaptiveBoolean::Off, order_hint_n_bits: 0, super_res: 0, cdef: 0,