Skip to content

Commit

Permalink
struct {D,R}av1dPicture::r#ref: Make an Option<NonNull<_>>.
Browse files Browse the repository at this point in the history
While not strictly needed since it will soon be replaced,
doing this now simplifies and breaks up future changes.
  • Loading branch information
kkysen committed Jan 25, 2024
1 parent 0004471 commit 4965f4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
6 changes: 3 additions & 3 deletions include/dav1d/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub struct Dav1dPicture {
pub mastering_display_ref: Option<RawArc<Rav1dMasteringDisplay>>, // opaque, so we can change this
pub itut_t35_ref: Option<RawArc<DRav1d<Rav1dITUTT35, Dav1dITUTT35>>>, // opaque, so we can change this
pub reserved_ref: [uintptr_t; 4],
pub r#ref: *mut Dav1dRef,
pub r#ref: Option<NonNull<Dav1dRef>>,
pub allocator_data: Option<NonNull<c_void>>,
}

Expand Down Expand Up @@ -121,7 +121,7 @@ pub(crate) struct Rav1dPicture {
pub content_light: Option<Arc<Rav1dContentLightLevel>>,
pub mastering_display: Option<Arc<Rav1dMasteringDisplay>>,
pub itut_t35: Option<Arc<DRav1d<Rav1dITUTT35, Dav1dITUTT35>>>,
pub r#ref: *mut Rav1dRef,
pub r#ref: Option<NonNull<Rav1dRef>>,
}

impl From<Dav1dPicture> for Rav1dPicture {
Expand Down Expand Up @@ -233,7 +233,7 @@ impl Default for Rav1dPicture {
content_light: None,
mastering_display: None,
itut_t35: None,
r#ref: ptr::null_mut(),
r#ref: None,
}
}
}
Expand Down
26 changes: 11 additions & 15 deletions src/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ unsafe fn picture_alloc_with_edges(
allocator: p_allocator.clone(),
pic: p.clone(),
});
p.r#ref = rav1d_ref_wrap(
p.r#ref = NonNull::new(rav1d_ref_wrap(
p.data.data[0] as *const u8,
Some(free_buffer),
pic_ctx as *mut c_void,
);
if p.r#ref.is_null() {
));
if p.r#ref.is_none() {
p_allocator.release_picture(p);
free(pic_ctx as *mut c_void);
writeln!(
Expand Down Expand Up @@ -282,7 +282,8 @@ pub(crate) unsafe fn rav1d_picture_alloc_copy(
w: c_int,
src: &Rav1dPicture,
) -> Rav1dResult {
let pic_ctx: *mut pic_ctx_context = (*(*src).r#ref).user_data as *mut pic_ctx_context;
let pic_ctx: *mut pic_ctx_context =
(*src).r#ref.unwrap().as_mut().user_data as *mut pic_ctx_context;
picture_alloc_with_edges(
&c.logger,
dst,
Expand All @@ -303,11 +304,11 @@ pub(crate) unsafe fn rav1d_picture_ref(dst: &mut Rav1dPicture, src: &Rav1dPictur
if validate_input!(dst.data.data[0].is_null()).is_err() {
return;
}
if !src.r#ref.is_null() {
if let Some(r#ref) = src.r#ref {
if validate_input!(!src.data.data[0].is_null()).is_err() {
return;
}
rav1d_ref_inc(src.r#ref);
rav1d_ref_inc(r#ref.as_ptr());
}
*dst = src.clone();
}
Expand All @@ -316,7 +317,7 @@ pub(crate) unsafe fn rav1d_picture_move_ref(dst: &mut Rav1dPicture, src: &mut Ra
if validate_input!(dst.data.data[0].is_null()).is_err() {
return;
}
if !src.r#ref.is_null() {
if src.r#ref.is_some() {
if validate_input!(!src.data.data[0].is_null()).is_err() {
return;
}
Expand All @@ -343,17 +344,12 @@ pub(crate) unsafe fn rav1d_thread_picture_move_ref(
}

pub(crate) unsafe fn rav1d_picture_unref_internal(p: &mut Rav1dPicture) {
let Rav1dPicture {
m: _,
data,
mut r#ref,
..
} = mem::take(p);
if !r#ref.is_null() {
let Rav1dPicture { data, r#ref, .. } = mem::take(p);
if let Some(r#ref) = r#ref {
if validate_input!(!data.data[0].is_null()).is_err() {
return;
}
rav1d_ref_dec(&mut r#ref);
rav1d_ref_dec(&mut r#ref.as_ptr());
}
}

Expand Down
5 changes: 2 additions & 3 deletions tests/seek_stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use rav1d::include::dav1d::common::Dav1dUserData;
use rav1d::include::dav1d::data::Dav1dData;
use rav1d::include::dav1d::dav1d::Dav1dContext;
use rav1d::include::dav1d::dav1d::Dav1dLogger;
use rav1d::include::dav1d::dav1d::Dav1dRef;
use rav1d::include::dav1d::dav1d::Dav1dSettings;
use rav1d::include::dav1d::dav1d::DAV1D_DECODEFRAMETYPE_ALL;
use rav1d::include::dav1d::dav1d::DAV1D_INLOOPFILTER_NONE;
Expand Down Expand Up @@ -175,7 +174,7 @@ unsafe fn decode_rand(
mastering_display_ref: None,
itut_t35_ref: None,
reserved_ref: [0; 4],
r#ref: 0 as *mut Dav1dRef,
r#ref: None,
allocator_data: None,
};
let num_frames: c_int = xor128_rand() % (fps * 5 as c_double) as c_int;
Expand Down Expand Up @@ -230,7 +229,7 @@ unsafe fn decode_all(
mastering_display_ref: None,
itut_t35_ref: None,
reserved_ref: [0; 4],
r#ref: 0 as *mut Dav1dRef,
r#ref: None,
allocator_data: None,
};
loop {
Expand Down
3 changes: 1 addition & 2 deletions tools/dav1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ use rav1d::include::dav1d::common::Dav1dUserData;
use rav1d::include::dav1d::data::Dav1dData;
use rav1d::include::dav1d::dav1d::Dav1dContext;
use rav1d::include::dav1d::dav1d::Dav1dLogger;
use rav1d::include::dav1d::dav1d::Dav1dRef;
use rav1d::include::dav1d::dav1d::Dav1dSettings;
use rav1d::include::dav1d::dav1d::DAV1D_DECODEFRAMETYPE_ALL;
use rav1d::include::dav1d::dav1d::DAV1D_INLOOPFILTER_NONE;
Expand Down Expand Up @@ -341,7 +340,7 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int {
mastering_display_ref: None,
itut_t35_ref: None,
reserved_ref: [0; 4],
r#ref: 0 as *mut Dav1dRef,
r#ref: None,
allocator_data: None,
};
let mut c: *mut Dav1dContext = 0 as *mut Dav1dContext;
Expand Down

0 comments on commit 4965f4f

Please sign in to comment.