From ef0fcf1c2ba31ba39d21e57a97fb415fa5ca2db0 Mon Sep 17 00:00:00 2001 From: Nicole LeGare Date: Wed, 20 Mar 2024 16:54:15 -0700 Subject: [PATCH] `FrameTileThreadData::lowest_pixel_mem`: Make into Vec Also remove `FrameTileThreadData` because it only had a single field and was only used in one place. `lowest_pixel_mem` is now a field of `Rav1dFrameData`. --- src/decode.rs | 17 +++++------------ src/internal.rs | 9 +-------- src/lib.rs | 5 +---- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index d042cb75b..eceba9c76 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -4325,18 +4325,11 @@ pub(crate) unsafe fn rav1d_decode_frame_init( } let lowest_pixel_mem_sz = frame_hdr.tiling.cols * f.sbh; - if lowest_pixel_mem_sz != f.tile_thread.lowest_pixel_mem_sz { - free(f.tile_thread.lowest_pixel_mem as *mut c_void); - f.tile_thread.lowest_pixel_mem = - malloc(lowest_pixel_mem_sz as usize * ::core::mem::size_of::<[[c_int; 2]; 7]>()) - as *mut [[c_int; 2]; 7]; - if f.tile_thread.lowest_pixel_mem.is_null() { - f.tile_thread.lowest_pixel_mem_sz = 0; - return Err(ENOMEM); - } - f.tile_thread.lowest_pixel_mem_sz = lowest_pixel_mem_sz; - } - let mut lowest_pixel_ptr = f.tile_thread.lowest_pixel_mem; + // TODO: Fallible allocation + f.lowest_pixel_mem + .resize(lowest_pixel_mem_sz as usize, Default::default()); + + let mut lowest_pixel_ptr = f.lowest_pixel_mem.as_mut_ptr(); for tile_row in 0..frame_hdr.tiling.rows { let tile_row_base = tile_row * frame_hdr.tiling.cols; let tile_row_sb_h = frame_hdr.tiling.row_start_sb[(tile_row + 1) as usize] as c_int diff --git a/src/internal.rs b/src/internal.rs index 40dcbd7e5..0048bb462 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -517,13 +517,6 @@ pub(crate) struct Rav1dFrameContext_task_thread { pub pending_tasks: Mutex, } -// threading (refer to tc[] for per-thread things) -#[repr(C)] -pub struct FrameTileThreadData { - pub lowest_pixel_mem: *mut [[c_int; 2]; 7], - pub lowest_pixel_mem_sz: c_int, -} - pub(crate) struct Rav1dFrameContext_frame_thread_progress { pub entropy: AtomicI32, pub deblock: AtomicI32, // in sby units @@ -592,7 +585,7 @@ pub(crate) struct Rav1dFrameData { pub frame_thread_progress: Rav1dFrameContext_frame_thread_progress, pub lf: Rav1dFrameContext_lf, pub task_thread: Rav1dFrameContext_task_thread, - pub tile_thread: FrameTileThreadData, + pub lowest_pixel_mem: Vec<[[c_int; 2]; 7]>, } impl Rav1dFrameData { diff --git a/src/lib.rs b/src/lib.rs index 30d7408de..94784a63a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -902,10 +902,7 @@ impl Drop for Rav1dContext { while !(self.fc).is_null() && n_1 < self.n_fc { let f: &mut Rav1dFrameData = &mut *(self.fc).offset(n_1 as isize); if self.n_fc > 1 as c_uint { - freep( - &mut f.tile_thread.lowest_pixel_mem as *mut *mut [[c_int; 2]; 7] - as *mut c_void, - ); + let _ = mem::take(&mut f.lowest_pixel_mem); // TODO: remove when context is owned } if self.tc.len() > 1 { let _ = mem::take(&mut f.task_thread.pending_tasks); // TODO: remove when context is owned