Skip to content

Commit

Permalink
struct {D,R}av1dITUTT35: Skip .update_rav1d()ing it as we never r…
Browse files Browse the repository at this point in the history
…ead it.

This also lets us remove the `{D => R}av1dITUTT35` conversion, which contains `unsafe`.
  • Loading branch information
kkysen committed Dec 22, 2023
1 parent 2e6cbd5 commit 02e5316
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 28 deletions.
19 changes: 0 additions & 19 deletions include/dav1d/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::src::enum_map::EnumKey;
use std::ffi::c_int;
use std::ffi::c_uint;
use std::ops::BitAnd;
use std::slice;
use strum::EnumCount;
use strum::FromRepr;

Expand Down Expand Up @@ -509,24 +508,6 @@ pub(crate) struct Rav1dITUTT35 {
pub payload: Box<[u8]>,
}

impl From<Dav1dITUTT35> for Rav1dITUTT35 {
fn from(value: Dav1dITUTT35) -> Self {
let Dav1dITUTT35 {
country_code,
country_code_extension_byte,
payload_size,
payload,
} = value;
let payload = unsafe { slice::from_raw_parts_mut(payload, payload_size) };
let payload = unsafe { Box::from_raw(payload) };
Self {
country_code,
country_code_extension_byte,
payload,
}
}
}

impl From<Rav1dITUTT35> for Dav1dITUTT35 {
fn from(value: Rav1dITUTT35) -> Self {
let Rav1dITUTT35 {
Expand Down
2 changes: 1 addition & 1 deletion include/dav1d/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl From<Dav1dPicture> for Rav1dPicture {
content_light: content_light_ref.map(|raw| unsafe { Arc::from_raw(raw.as_ptr()) }),
mastering_display: mastering_display_ref
.map(|raw| unsafe { Arc::from_raw(raw.as_ptr()) }),
// `.update_rav1d()` happens in `#[no_mangle] extern "C"`/`DAV1D_API` calls
// We don't `.update_rav1d` [`Rav1dITUTT35`] because never read it.
itut_t35: if itut_t35.is_null() {
ptr::null_mut()
} else {
Expand Down
9 changes: 1 addition & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::include::dav1d::dav1d::RAV1D_DECODEFRAMETYPE_KEY;
use crate::include::dav1d::dav1d::RAV1D_INLOOPFILTER_ALL;
use crate::include::dav1d::headers::DRav1d;
use crate::include::dav1d::headers::Dav1dFrameHeader;
use crate::include::dav1d::headers::Dav1dITUTT35;
use crate::include::dav1d::headers::Dav1dSequenceHeader;
use crate::include::dav1d::headers::Rav1dFilmGrainData;
use crate::include::dav1d::headers::Rav1dFrameHeader;
Expand Down Expand Up @@ -845,13 +844,7 @@ pub unsafe extern "C" fn dav1d_apply_grain(
.cast::<DRav1d<Rav1dFrameHeader, Dav1dFrameHeader>>())
.update_rav1d();
}
if let Some(mut itut_t35_ref) = NonNull::new(in_0.itut_t35_ref) {
(*itut_t35_ref
.as_mut()
.data
.cast::<DRav1d<Rav1dITUTT35, Dav1dITUTT35>>())
.update_rav1d();
}
// Don't `.update_rav1d` [`Rav1dITUTT35`] because we never read it.
let mut out_rust = MaybeUninit::zeroed().assume_init(); // TODO(kkysen) Temporary until we return it directly.
let in_rust = in_0.into();
let result = rav1d_apply_grain(c, &mut out_rust, &in_rust);
Expand Down

0 comments on commit 02e5316

Please sign in to comment.