diff --git a/src/decode.rs b/src/decode.rs index 0f6b8a0c8..622c33770 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -125,11 +125,7 @@ use crate::src::msac::rav1d_msac_decode_symbol_adapt8; use crate::src::msac::rav1d_msac_decode_uniform; use crate::src::msac::rav1d_msac_init; use crate::src::picture::rav1d_picture_alloc_copy; -use crate::src::picture::rav1d_picture_ref; -use crate::src::picture::rav1d_picture_unref_internal; use crate::src::picture::rav1d_thread_picture_alloc; -use crate::src::picture::rav1d_thread_picture_ref; -use crate::src::picture::rav1d_thread_picture_unref; use crate::src::picture::Rav1dThreadPicture; use crate::src::qm::dav1d_qm_tbl; use crate::src::recon::debug_block_info; @@ -4574,12 +4570,12 @@ pub(crate) unsafe fn rav1d_decode_frame_exit( // TODO(kkysen) use array::zip when stable for i in 0..7 { if f.refp[i].p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut f.refp[i]); + let _ = mem::take(&mut f.refp[i]); } let _ = mem::take(&mut f.ref_mvs[i]); } - rav1d_picture_unref_internal(&mut f.cur); - rav1d_thread_picture_unref(&mut f.sr_cur); + let _ = mem::take(&mut f.cur); + let _ = mem::take(&mut f.sr_cur); let _ = mem::take(&mut f.in_cdf); if let Some(frame_hdr) = &f.frame_hdr { if frame_hdr.refresh_context != 0 { @@ -4693,14 +4689,14 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult { if error.is_err() { c.cached_error = mem::replace(&mut error, Ok(())); *c.cached_error_props.get_mut().unwrap() = out_delayed.p.m.clone(); - rav1d_thread_picture_unref(out_delayed); + let _ = mem::take(out_delayed); } else if out_delayed.p.data.is_some() { let progress = out_delayed.progress.as_ref().unwrap()[1].load(Ordering::Relaxed); if (out_delayed.visible || c.output_invisible_frames) && progress != FRAME_ERROR { - rav1d_thread_picture_ref(&mut c.out, out_delayed); + c.out = out_delayed.clone(); c.event_flags |= out_delayed.flags.into(); } - rav1d_thread_picture_unref(out_delayed); + let _ = mem::take(out_delayed); } } (f, out_delayed as *mut _, Some(task_thread_lock)) @@ -4720,13 +4716,13 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult { } for i in 0..7 { if f.refp[i].p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut f.refp[i]); + let _ = mem::take(&mut f.refp[i]); } let _ = mem::take(&mut f.ref_mvs[i]); } - rav1d_thread_picture_unref(out); - rav1d_picture_unref_internal(&mut f.cur); - rav1d_thread_picture_unref(&mut f.sr_cur); + let _ = mem::take(&mut *out); + let _ = mem::take(&mut f.cur); + let _ = mem::take(&mut f.sr_cur); let _ = mem::take(&mut f.mvs); let _ = mem::take(&mut f.seq_hdr); let _ = mem::take(&mut f.frame_hdr); @@ -4771,12 +4767,12 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult { || bpc != c.refs[refidx].p.p.p.bpc { for j in 0..i { - rav1d_thread_picture_unref(&mut f.refp[j]); + let _ = mem::take(&mut f.refp[j]); } on_error(f, c, out); return Err(EINVAL); } - rav1d_thread_picture_ref(&mut f.refp[i], &mut c.refs[refidx].p); + f.refp[i] = c.refs[refidx].p.clone(); ref_coded_width[i] = c.refs[refidx].p.p.frame_hdr.as_ref().unwrap().size.width[0]; if frame_hdr.size.width[0] != c.refs[refidx].p.p.p.w || frame_hdr.size.height != c.refs[refidx].p.p.p.h @@ -4839,7 +4835,7 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult { return res; } } else { - rav1d_picture_ref(&mut f.cur, &mut f.sr_cur.p); + f.cur = f.sr_cur.p.clone(); } if frame_hdr.size.width[0] != frame_hdr.size.width[1] { f.resize_step[0] = scale_fac(f.cur.p.w, f.sr_cur.p.p.w); @@ -4854,11 +4850,11 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult { // move f->cur into output queue if c.n_fc == 1 { if frame_hdr.show_frame != 0 || c.output_invisible_frames { - rav1d_thread_picture_ref(&mut c.out, &mut f.sr_cur); + c.out = f.sr_cur.clone(); c.event_flags |= f.sr_cur.flags.into(); } } else { - rav1d_thread_picture_ref(out, &mut f.sr_cur); + *out = f.sr_cur.clone(); } f.w4 = frame_hdr.size.width[0] + 3 >> 2; @@ -4966,9 +4962,9 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult { for i in 0..8 { if refresh_frame_flags & (1 << i) != 0 { if c.refs[i].p.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut c.refs[i].p); + let _ = mem::take(&mut c.refs[i].p); } - rav1d_thread_picture_ref(&mut c.refs[i].p, &mut f.sr_cur); + c.refs[i].p = f.sr_cur.clone(); if frame_hdr.refresh_context != 0 { c.cdf[i] = f.out_cdf.clone(); @@ -4988,11 +4984,11 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult { if c.n_fc == 1 { let res = rav1d_decode_frame(c, f); if res.is_err() { - rav1d_thread_picture_unref(&mut c.out); + let _ = mem::take(&mut c.out); for i in 0..8 { if refresh_frame_flags & (1 << i) != 0 { if c.refs[i].p.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut c.refs[i].p); + let _ = mem::take(&mut c.refs[i].p); } let _ = mem::take(&mut c.cdf[i]); let _ = mem::take(&mut c.refs[i].segmap); diff --git a/src/lib.rs b/src/lib.rs index 4253da7fa..796fcf8b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,12 +44,6 @@ use crate::src::obu::rav1d_parse_sequence_header; use crate::src::picture::dav1d_default_picture_alloc; use crate::src::picture::dav1d_default_picture_release; use crate::src::picture::rav1d_picture_alloc_copy; -use crate::src::picture::rav1d_picture_move_ref; -use crate::src::picture::rav1d_picture_ref; -use crate::src::picture::rav1d_picture_unref_internal; -use crate::src::picture::rav1d_thread_picture_move_ref; -use crate::src::picture::rav1d_thread_picture_ref; -use crate::src::picture::rav1d_thread_picture_unref; use crate::src::picture::PictureFlags; use crate::src::picture::Rav1dThreadPicture; use crate::src::refmvs::rav1d_refmvs_clear; @@ -393,14 +387,14 @@ unsafe fn output_image(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRes &mut c.cache }; if !c.apply_grain || !(*r#in).p.has_grain() { - rav1d_picture_move_ref(out, &mut (*r#in).p); + *out = mem::take(&mut (*r#in).p); } else { res = rav1d_apply_grain(c, out, &(*r#in).p); } - rav1d_thread_picture_unref(&mut *r#in); + let _ = mem::take(&mut *r#in); if !c.all_layers && c.max_spatial_id && c.out.p.data.is_some() { - rav1d_thread_picture_move_ref(r#in, &mut c.out); + *r#in = mem::take(&mut c.out); } res } @@ -416,15 +410,15 @@ unsafe fn output_picture_ready(c: &mut Rav1dContext, drain: bool) -> bool { { return true; } - rav1d_thread_picture_unref(&mut c.cache); - rav1d_thread_picture_move_ref(&mut c.cache, &mut c.out); + let _ = mem::take(&mut c.cache); + c.cache = mem::take(&mut c.out); return false; } else { if c.cache.p.data.is_some() && drain { return true; } else { if c.out.p.data.is_some() { - rav1d_thread_picture_move_ref(&mut c.cache, &mut c.out); + c.cache = mem::take(&mut c.out); return false; } } @@ -474,16 +468,16 @@ unsafe fn drain_picture(c: &mut Rav1dContext, out: &mut Rav1dPicture) -> Rav1dRe let error = mem::replace(&mut *f.task_thread.retval.try_lock().unwrap(), Ok(())); if error.is_err() { *c.cached_error_props.get_mut().unwrap() = out_delayed.p.m.clone(); - rav1d_thread_picture_unref(out_delayed); + let _ = mem::take(out_delayed); return error; } if out_delayed.p.data.is_some() { let progress = out_delayed.progress.as_ref().unwrap()[1].load(Ordering::Relaxed); if (out_delayed.visible || c.output_invisible_frames) && progress != FRAME_ERROR { - rav1d_thread_picture_ref(&mut c.out, out_delayed); + c.out = out_delayed.clone(); c.event_flags |= out_delayed.flags.into(); } - rav1d_thread_picture_unref(out_delayed); + let _ = mem::take(out_delayed); if output_picture_ready(c, false) { return output_image(c, out); } @@ -602,12 +596,12 @@ pub(crate) unsafe fn rav1d_apply_grain( in_0: &Rav1dPicture, ) -> Rav1dResult { if !in_0.has_grain() { - rav1d_picture_ref(out, in_0); + *out = in_0.clone(); return Ok(()); } let res = rav1d_picture_alloc_copy(c, out, in_0.p.w, in_0); if res.is_err() { - rav1d_picture_unref_internal(out); + let _ = mem::take(out); return res; } else { if c.tc.len() > 1 { @@ -666,17 +660,17 @@ pub unsafe extern "C" fn dav1d_apply_grain( pub(crate) unsafe fn rav1d_flush(c: *mut Rav1dContext) { let _ = mem::take(&mut (*c).in_0); if (*c).out.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut (*c).out); + let _ = mem::take(&mut (*c).out); } if (*c).cache.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut (*c).cache); + let _ = mem::take(&mut (*c).cache); } (*c).drain = 0 as c_int; (*c).cached_error = Ok(()); let mut i = 0; while i < 8 { if (*c).refs[i as usize].p.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut (*((*c).refs).as_mut_ptr().offset(i as isize)).p); + let _ = mem::take(&mut (*((*c).refs).as_mut_ptr().offset(i as isize)).p); } let _ = mem::take(&mut (*c).refs[i as usize].segmap); let _ = mem::take(&mut (*c).refs[i as usize].refmvs); @@ -735,7 +729,7 @@ pub(crate) unsafe fn rav1d_flush(c: *mut Rav1dContext) { *f.task_thread.retval.try_lock().unwrap() = Ok(()); let out_delayed = &mut (*c).frame_thread.out_delayed[next as usize]; if out_delayed.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(out_delayed); + let _ = mem::take(out_delayed); } n = n.wrapping_add(1); next = next.wrapping_add(1); @@ -834,9 +828,7 @@ impl Drop for Rav1dContext { .frame_hdr .is_some() { - rav1d_thread_picture_unref( - &mut self.frame_thread.out_delayed[n_2 as usize], - ); + let _ = mem::take(&mut self.frame_thread.out_delayed[n_2 as usize]); } n_2 = n_2.wrapping_add(1); } @@ -846,9 +838,7 @@ impl Drop for Rav1dContext { let mut n_4 = 0; while n_4 < 8 { if self.refs[n_4 as usize].p.p.frame_hdr.is_some() { - rav1d_thread_picture_unref( - &mut (*(self.refs).as_mut_ptr().offset(n_4 as isize)).p, - ); + let _ = mem::take(&mut (*(self.refs).as_mut_ptr().offset(n_4 as isize)).p); } let _ = mem::take(&mut self.refs[n_4 as usize].refmvs); let _ = mem::take(&mut self.refs[n_4 as usize].segmap); @@ -893,7 +883,7 @@ pub unsafe extern "C" fn dav1d_get_decode_error_data_props( } pub(crate) unsafe fn rav1d_picture_unref(p: &mut Rav1dPicture) { - rav1d_picture_unref_internal(p); + let _ = mem::take(p); } #[no_mangle] diff --git a/src/obu.rs b/src/obu.rs index 8e22c5462..3516ee7bc 100644 --- a/src/obu.rs +++ b/src/obu.rs @@ -64,8 +64,6 @@ use crate::src::internal::Rav1dTileGroupHeader; use crate::src::levels::ObuMetaType; use crate::src::log::Rav1dLog as _; use crate::src::picture::rav1d_picture_copy_props; -use crate::src::picture::rav1d_thread_picture_ref; -use crate::src::picture::rav1d_thread_picture_unref; use crate::src::picture::PictureFlags; use crate::src::thread_task::FRAME_ERROR; use std::array; @@ -2137,7 +2135,7 @@ unsafe fn parse_obus( // update refs with only the headers in case we skip the frame for i in 0..8 { if c.frame_hdr.as_ref().unwrap().refresh_frame_flags & (1 << i) != 0 { - rav1d_thread_picture_unref(&mut c.refs[i as usize].p); + let _ = mem::take(&mut c.refs[i as usize].p); c.refs[i as usize].p.p.frame_hdr = c.frame_hdr.clone(); c.refs[i as usize].p.p.seq_hdr = c.seq_hdr.clone(); } @@ -2292,7 +2290,7 @@ unsafe fn parse_obus( let _ = mem::take(&mut c.mastering_display); for i in 0..8 { if c.refs[i as usize].p.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut c.refs[i as usize].p); + let _ = mem::take(&mut c.refs[i as usize].p); } let _ = mem::take(&mut c.refs[i as usize].segmap); let _ = mem::take(&mut c.refs[i as usize].refmvs); @@ -2525,10 +2523,7 @@ unsafe fn parse_obus( return Err(EINVAL); } if c.n_fc == 1 { - rav1d_thread_picture_ref( - &mut c.out, - &mut c.refs[frame_hdr.existing_frame_idx as usize].p, - ); + c.out = c.refs[frame_hdr.existing_frame_idx as usize].p.clone(); rav1d_picture_copy_props( &mut (*c).out.p, c.content_light.clone(), @@ -2575,21 +2570,18 @@ unsafe fn parse_obus( if error.is_err() { c.cached_error = mem::replace(&mut *error, Ok(())); *c.cached_error_props.get_mut().unwrap() = out_delayed.p.m.clone(); - rav1d_thread_picture_unref(out_delayed); + let _ = mem::take(out_delayed); } else if out_delayed.p.data.is_some() { let progress = out_delayed.progress.as_ref().unwrap()[1].load(Ordering::Relaxed); if (out_delayed.visible || c.output_invisible_frames) && progress != FRAME_ERROR { - rav1d_thread_picture_ref(&mut c.out, out_delayed); + c.out = out_delayed.clone(); c.event_flags |= out_delayed.flags.into(); } - rav1d_thread_picture_unref(out_delayed); + let _ = mem::take(out_delayed); } - rav1d_thread_picture_ref( - out_delayed, - &mut c.refs[frame_hdr.existing_frame_idx as usize].p, - ); + *out_delayed = c.refs[frame_hdr.existing_frame_idx as usize].p.clone(); out_delayed.visible = true; rav1d_picture_copy_props( &mut out_delayed.p, @@ -2617,9 +2609,9 @@ unsafe fn parse_obus( } if c.refs[i as usize].p.p.frame_hdr.is_some() { - rav1d_thread_picture_unref(&mut c.refs[i as usize].p); + let _ = mem::take(&mut c.refs[i as usize].p); } - rav1d_thread_picture_ref(&mut c.refs[i as usize].p, &mut c.refs[r as usize].p); + c.refs[i as usize].p = c.refs[r as usize].p.clone(); c.cdf[i as usize] = c.cdf[r as usize].clone(); diff --git a/src/picture.rs b/src/picture.rs index 3a0dd944d..172121239 100644 --- a/src/picture.rs +++ b/src/picture.rs @@ -64,7 +64,7 @@ impl From for Rav1dEventFlags { } } -#[derive(Default)] +#[derive(Clone, Default)] #[repr(C)] pub(crate) struct Rav1dThreadPicture { pub p: Rav1dPicture, @@ -310,38 +310,3 @@ pub(crate) unsafe fn rav1d_picture_alloc_copy( ); Ok(()) } - -pub(crate) unsafe fn rav1d_picture_ref(dst: &mut Rav1dPicture, src: &Rav1dPicture) { - *dst = src.clone(); -} - -pub(crate) unsafe fn rav1d_picture_move_ref(dst: &mut Rav1dPicture, src: &mut Rav1dPicture) { - *dst = mem::take(src); -} - -pub(crate) unsafe fn rav1d_thread_picture_ref( - dst: *mut Rav1dThreadPicture, - src: *const Rav1dThreadPicture, -) { - rav1d_picture_ref(&mut (*dst).p, &(*src).p); - (*dst).visible = (*src).visible; - (*dst).showable = (*src).showable; - (*dst).progress = (*src).progress.clone(); - (*dst).flags = (*src).flags; -} - -pub(crate) unsafe fn rav1d_thread_picture_move_ref( - dst: *mut Rav1dThreadPicture, - src: *mut Rav1dThreadPicture, -) { - *dst = mem::take(&mut *src); -} - -pub(crate) unsafe fn rav1d_picture_unref_internal(p: &mut Rav1dPicture) { - let _ = mem::take(p); -} - -pub(crate) unsafe fn rav1d_thread_picture_unref(p: *mut Rav1dThreadPicture) { - rav1d_picture_unref_internal(&mut (*p).p); - let _ = mem::take(&mut (*p).progress); -}