From dae2cc1560d42a5d49985759a9c6a7edb05cd4e9 Mon Sep 17 00:00:00 2001 From: Nicole LeGare Date: Tue, 27 Feb 2024 16:35:48 -0800 Subject: [PATCH] `Rav1dFrameContext_lf::cdef_line_buf`: Make into `AlignedVec32` --- src/align.rs | 1 + src/decode.rs | 13 +++++-------- src/internal.rs | 2 +- src/lib.rs | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/align.rs b/src/align.rs index 0320e25da..0e26aaf72 100644 --- a/src/align.rs +++ b/src/align.rs @@ -206,3 +206,4 @@ impl Default for AlignedVec { } pub type AlignedVec64 = AlignedVec>; +pub type AlignedVec32 = AlignedVec>; diff --git a/src/decode.rs b/src/decode.rs index d1043d67b..39c801e4b 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -4392,17 +4392,14 @@ pub(crate) unsafe fn rav1d_decode_frame_init( || need_cdef_lpf_copy != f.lf.need_cdef_lpf_copy || f.sbh != f.lf.cdef_buf_sbh { - rav1d_free_aligned(f.lf.cdef_line_buf as *mut c_void); let mut alloc_sz: usize = 64; alloc_sz += (y_stride.unsigned_abs() * 4 * f.sbh as usize) << need_cdef_lpf_copy; alloc_sz += (uv_stride.unsigned_abs() * 8 * f.sbh as usize) << need_cdef_lpf_copy; - f.lf.cdef_line_buf = rav1d_alloc_aligned(alloc_sz, 32) as *mut u8; - let mut ptr = f.lf.cdef_line_buf; - if ptr.is_null() { - f.lf.cdef_buf_plane_sz[1] = 0; - f.lf.cdef_buf_plane_sz[0] = f.lf.cdef_buf_plane_sz[1]; - return Err(ENOMEM); - } + // TODO: Fallbile allocation. We need to do the following on allocation + // failure: + // f.lf.cdef_buf_plane_sz = [0, 0]; + f.lf.cdef_line_buf.resize(alloc_sz, 0); + let mut ptr = f.lf.cdef_line_buf.as_mut_ptr(); ptr = ptr.offset(32); if y_stride < 0 { diff --git a/src/internal.rs b/src/internal.rs index 5a5e7b0eb..5d5764e51 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -435,7 +435,7 @@ pub struct Rav1dFrameContext_lf { pub last_sharpness: c_int, pub lvl: [[[[u8; 2]; 8]; 4]; 8], /* [8 seg_id][4 dir][8 ref][2 is_gmv] */ pub tx_lpf_right_edge: Vec, /* len = h*2 */ - pub cdef_line_buf: *mut u8, + pub cdef_line_buf: AlignedVec32, /* AlignedVec32 */ pub lr_line_buf: *mut u8, pub cdef_line: [[*mut DynPixel; 3]; 2], /* [2 pre/post][3 plane] */ pub cdef_lpf_line: [*mut DynPixel; 3], /* plane */ diff --git a/src/lib.rs b/src/lib.rs index df7f840a1..4382e8e96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -903,7 +903,7 @@ impl Drop for Rav1dContext { let _ = mem::take(&mut f.lf.tx_lpf_right_edge); // TODO: remove when context is owned free(f.lf.start_of_tile_row as *mut c_void); rav1d_refmvs_clear(&mut f.rf); - rav1d_free_aligned(f.lf.cdef_line_buf as *mut c_void); + 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); n_1 = n_1.wrapping_add(1); }