Skip to content

Commit

Permalink
Rav1dFrameContext_lf::lr_line_buf: Make into AlignedVec64
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Mar 11, 2024
1 parent 929ca31 commit b441c58
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
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
{
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,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

0 comments on commit b441c58

Please sign in to comment.