Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4449,18 +4449,14 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
if y_stride * num_lines as isize != f.lf.lr_buf_plane_sz[0] as isize
|| uv_stride * num_lines as isize * 2 != f.lf.lr_buf_plane_sz[1] as isize
{
Comment on lines 4449 to 4451
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based @fbossen's comment here, #793 (comment), it seems this if should be removed, right?

I think we can also get rid of lr_buf_plane_sz and just calculate it from f.sr_cur.p.stride, f.sbh, seq_hdr.sb128, and c.tc.len() the one time we need it later on.

rav1d_free_aligned(f.lf.lr_line_buf as *mut c_void);
// lr simd may overread the input, so slightly over-allocate the lpf buffer
let mut alloc_sz: usize = 128;
alloc_sz += y_stride.unsigned_abs() * num_lines as usize;
alloc_sz += uv_stride.unsigned_abs() * num_lines as usize * 2;
f.lf.lr_line_buf = rav1d_alloc_aligned(alloc_sz, 64) as *mut u8;
let mut ptr = f.lf.lr_line_buf;
if ptr.is_null() {
f.lf.lr_buf_plane_sz[1] = 0;
f.lf.lr_buf_plane_sz[0] = f.lf.lr_buf_plane_sz[1];
return Err(ENOMEM);
}
// TODO: Fallible allocation
// On allocation failure set `f.lf.lr_buf_plane_sz` to 0.
f.lf.lr_line_buf.resize(alloc_sz, 0);
let mut ptr = f.lf.lr_line_buf.as_mut_ptr();

ptr = ptr.offset(64);
if y_stride < 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub struct Rav1dFrameContext_lf {
pub lvl: [[[[u8; 2]; 8]; 4]; 8], /* [8 seg_id][4 dir][8 ref][2 is_gmv] */
pub tx_lpf_right_edge: TxLpfRightEdge,
pub cdef_line_buf: AlignedVec32<u8>, /* AlignedVec32<DynPixel> */
pub lr_line_buf: *mut u8,
pub lr_line_buf: AlignedVec64<u8>,
pub cdef_line: [[usize; 3]; 2], /* [2 pre/post][3 plane] */
pub cdef_lpf_line: [usize; 3], /* plane */
pub lr_lpf_line: [*mut DynPixel; 3], /* plane */
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *mut Rav1dContext, s: &Rav1dSettings
addr_of_mut!(f.lf.lr_mask).write(Default::default());
addr_of_mut!(f.lf.tx_lpf_right_edge).write(Default::default());
addr_of_mut!(f.lf.cdef_line_buf).write(Default::default());
addr_of_mut!(f.lf.lr_line_buf).write(Default::default());
f.lf.last_sharpness = -(1 as c_int);
rav1d_refmvs_init(&mut f.rf);
n = n.wrapping_add(1);
Expand Down Expand Up @@ -928,7 +929,7 @@ impl Drop for Rav1dContext {
free(f.lf.start_of_tile_row as *mut c_void);
rav1d_refmvs_clear(&mut f.rf);
let _ = mem::take(&mut f.lf.cdef_line_buf); // TODO: remove when context is owned
rav1d_free_aligned(f.lf.lr_line_buf as *mut c_void);
let _ = mem::take(&mut f.lf.lr_line_buf); // TODO: remove when context is owned
n_1 = n_1.wrapping_add(1);
}
rav1d_free_aligned(self.fc as *mut c_void);
Expand Down