Skip to content

Commit

Permalink
fn parse_*: Initialize and return directly for fn parse_frame_hdr
Browse files Browse the repository at this point in the history
…'s sub-parsers (#628)

For all of the sub-parser `fn`s under `fn parse_frame_hdr`, this
converts them all to initialize and return their types directly, as well
as break up the `&Rav1dFrameHeader` into the actual data dependencies so
that they can be called from `fn parse_frame_hdr` before the
`Rav1dFrameHeader` has been initialized.
  • Loading branch information
kkysen authored Jan 4, 2024
2 parents 57d9d4a + 0ef607c commit b8022a3
Show file tree
Hide file tree
Showing 3 changed files with 720 additions and 470 deletions.
35 changes: 23 additions & 12 deletions include/dav1d/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ pub struct Dav1dSegmentationData {
pub globalmv: c_int,
}

#[derive(Clone)]
#[derive(Clone, Default)]
#[repr(C)]
pub(crate) struct Rav1dSegmentationData {
pub delta_q: c_int,
Expand Down Expand Up @@ -1206,7 +1206,7 @@ pub struct Dav1dSegmentationDataSet {
pub last_active_segid: c_int,
}

#[derive(Clone)]
#[derive(Clone, Default)]
#[repr(C)]
pub(crate) struct Rav1dSegmentationDataSet {
pub d: [Rav1dSegmentationData; RAV1D_MAX_SEGMENTS as usize],
Expand Down Expand Up @@ -1284,7 +1284,7 @@ impl From<Rav1dLoopfilterModeRefDeltas> for Dav1dLoopfilterModeRefDeltas {
}
}

#[derive(Clone)]
#[derive(Clone, Default)]
pub struct Rav1dFilmGrainData {
pub seed: c_uint,
pub num_y_points: c_int,
Expand Down Expand Up @@ -2159,6 +2159,14 @@ pub(crate) struct Rav1dFrameSize {
pub have_render_size: c_int,
}

#[derive(Clone)]
#[repr(C)]
pub(crate) struct Rav1dFrameSkipMode {
pub allowed: c_int,
pub enabled: c_int,
pub refs: [c_int; 2],
}

#[derive(Clone)]
#[repr(C)]
pub(crate) struct Rav1dFrameHeader {
Expand Down Expand Up @@ -2201,9 +2209,7 @@ pub(crate) struct Rav1dFrameHeader {
pub restoration: Rav1dFrameHeader_restoration,
pub txfm_mode: Rav1dTxfmMode,
pub switchable_comp_refs: c_int,
pub skip_mode_allowed: c_int,
pub skip_mode_enabled: c_int,
pub skip_mode_refs: [c_int; 2],
pub skip_mode: Rav1dFrameSkipMode,
pub warp_motion: c_int,
pub reduced_txtp_set: c_int,
pub gmv: [Rav1dWarpedMotionParams; RAV1D_REFS_PER_FRAME],
Expand Down Expand Up @@ -2310,9 +2316,11 @@ impl From<Dav1dFrameHeader> for Rav1dFrameHeader {
restoration: restoration.into(),
txfm_mode,
switchable_comp_refs,
skip_mode_allowed,
skip_mode_enabled,
skip_mode_refs,
skip_mode: Rav1dFrameSkipMode {
allowed: skip_mode_allowed,
enabled: skip_mode_enabled,
refs: skip_mode_refs,
},
warp_motion,
reduced_txtp_set,
gmv: gmv.map(|c| c.into()),
Expand Down Expand Up @@ -2370,9 +2378,12 @@ impl From<Rav1dFrameHeader> for Dav1dFrameHeader {
restoration,
txfm_mode,
switchable_comp_refs,
skip_mode_allowed,
skip_mode_enabled,
skip_mode_refs,
skip_mode:
Rav1dFrameSkipMode {
allowed: skip_mode_allowed,
enabled: skip_mode_enabled,
refs: skip_mode_refs,
},
warp_motion,
reduced_txtp_set,
gmv,
Expand Down
6 changes: 3 additions & 3 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ unsafe fn decode_b(
if seg
.map(|seg| seg.globalmv == 0 && seg.r#ref == -1 && seg.skip == 0)
.unwrap_or(true)
&& (*f.frame_hdr).skip_mode_enabled != 0
&& (*f.frame_hdr).skip_mode.enabled != 0
&& cmp::min(bw4, bh4) > 1
{
let smctx = (*t.a).skip_mode.0[bx4 as usize] + t.l.skip_mode.0[by4 as usize];
Expand Down Expand Up @@ -2438,8 +2438,8 @@ unsafe fn decode_b(

if b.skip_mode != 0 {
*b.ref_mut() = [
frame_hdr.skip_mode_refs[0] as i8,
frame_hdr.skip_mode_refs[1] as i8,
frame_hdr.skip_mode.refs[0] as i8,
frame_hdr.skip_mode.refs[1] as i8,
];
*b.comp_type_mut() = COMP_INTER_AVG;
*b.inter_mode_mut() = NEARESTMV_NEARESTMV;
Expand Down
Loading

0 comments on commit b8022a3

Please sign in to comment.