Skip to content

Commit

Permalink
FrameTileThreadData::lowest_pixel_mem: Make into Vec
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
randomPoison committed Mar 20, 2024
1 parent f7c4664 commit ef0fcf1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
17 changes: 5 additions & 12 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,6 @@ pub(crate) struct Rav1dFrameContext_task_thread {
pub pending_tasks: Mutex<Rav1dFrameContext_task_thread_pending_tasks>,
}

// 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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef0fcf1

Please sign in to comment.