Skip to content

Commit

Permalink
Port C code to Rust
Browse files Browse the repository at this point in the history
Co-authored-by: Khyber Sen <[email protected]>
  • Loading branch information
Frank Bossen and kkysen committed Dec 4, 2023
1 parent e526428 commit a6c4e58
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
29 changes: 27 additions & 2 deletions src/obu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ use crate::src::levels::OBU_META_ITUT_T35;
use crate::src::levels::OBU_META_SCALABILITY;
use crate::src::levels::OBU_META_TIMECODE;
use crate::src::log::rav1d_log;
use crate::src::picture::rav1d_picture_copy_props;
use crate::src::picture::rav1d_picture_get_event_flags;
use crate::src::picture::rav1d_thread_picture_ref;
use crate::src::picture::rav1d_thread_picture_unref;
Expand Down Expand Up @@ -2012,7 +2013,19 @@ pub(crate) unsafe fn rav1d_parse_obus(
&mut c.out,
&mut c.refs[(*c.frame_hdr).existing_frame_idx as usize].p,
);
rav1d_data_props_copy(&mut c.out.p.m, &mut r#in.m);
rav1d_picture_copy_props(
&mut (*c).out.p,
c.content_light,
c.content_light_ref,
c.mastering_display,
c.mastering_display_ref,
c.itut_t35,
c.itut_t35_ref,
&mut r#in.m,
);
// Must be removed from the context after being attached to the frame
rav1d_ref_dec(&mut c.itut_t35_ref);
c.itut_t35 = 0 as *mut Rav1dITUTT35;
c.event_flags |= rav1d_picture_get_event_flags(
&mut c.refs[(*c.frame_hdr).existing_frame_idx as usize].p,
);
Expand Down Expand Up @@ -2076,7 +2089,19 @@ pub(crate) unsafe fn rav1d_parse_obus(
&mut c.refs[(*c.frame_hdr).existing_frame_idx as usize].p,
);
(*out_delayed).visible = true;
rav1d_data_props_copy(&mut (*out_delayed).p.m, &mut r#in.m);
rav1d_picture_copy_props(
&mut (*out_delayed).p,
c.content_light,
c.content_light_ref,
c.mastering_display,
c.mastering_display_ref,
c.itut_t35,
c.itut_t35_ref,
&mut r#in.m,
);
// Must be removed from the context after being attached to the frame
rav1d_ref_dec(&mut c.itut_t35_ref);
c.itut_t35 = 0 as *mut Rav1dITUTT35;
pthread_mutex_unlock(&mut c.task_thread.lock);
}
if (*c.refs[(*c.frame_hdr).existing_frame_idx as usize]
Expand Down
42 changes: 36 additions & 6 deletions src/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,11 @@ unsafe fn picture_alloc_with_edges(
(*p).p.h = h;
(*p).seq_hdr = seq_hdr;
(*p).frame_hdr = frame_hdr;
(*p).content_light = content_light;
(*p).mastering_display = mastering_display;
(*p).itut_t35 = itut_t35;
(*p).p.layout = (*seq_hdr).layout;
(*p).p.bpc = bpc;
rav1d_data_props_set_defaults(&mut (*p).m);
(*p).seq_hdr_ref = seq_hdr_ref;
(*p).frame_hdr_ref = frame_hdr_ref;
(*p).itut_t35_ref = itut_t35_ref;
let res = (*p_allocator).alloc_picture(p);
if res.is_err() {
free(pic_ctx as *mut c_void);
Expand Down Expand Up @@ -223,22 +219,56 @@ unsafe fn picture_alloc_with_edges(
if !frame_hdr_ref.is_null() {
rav1d_ref_inc(frame_hdr_ref);
}
rav1d_data_props_copy(&mut (*p).m, props);
rav1d_picture_copy_props(
p,
content_light,
content_light_ref,
mastering_display,
mastering_display_ref,
itut_t35,
itut_t35_ref,
props,
);

if extra != 0 && !extra_ptr.is_null() {
*extra_ptr = &mut (*pic_ctx).extra_ptr as *mut *mut c_void as *mut c_void;
}

Ok(())
}

pub unsafe fn rav1d_picture_copy_props(
p: *mut Rav1dPicture,
content_light: *mut Rav1dContentLightLevel,
content_light_ref: *mut Rav1dRef,
mastering_display: *mut Rav1dMasteringDisplay,
mastering_display_ref: *mut Rav1dRef,
itut_t35: *mut Rav1dITUTT35,
itut_t35_ref: *mut Rav1dRef,
props: *const Rav1dDataProps,
) {
rav1d_data_props_copy(&mut (*p).m, props);

rav1d_ref_dec(&mut (*p).content_light_ref);
(*p).content_light_ref = content_light_ref;
(*p).content_light = content_light;
if !content_light_ref.is_null() {
rav1d_ref_inc(content_light_ref);
}

rav1d_ref_dec(&mut (*p).mastering_display_ref);
(*p).mastering_display_ref = mastering_display_ref;
(*p).mastering_display = mastering_display;
if !mastering_display_ref.is_null() {
rav1d_ref_inc(mastering_display_ref);
}

rav1d_ref_dec(&mut (*p).itut_t35_ref);
(*p).itut_t35_ref = itut_t35_ref;
(*p).itut_t35 = itut_t35;
if !itut_t35_ref.is_null() {
rav1d_ref_inc(itut_t35_ref);
}
Ok(())
}

pub(crate) unsafe fn rav1d_thread_picture_alloc(
Expand Down

0 comments on commit a6c4e58

Please sign in to comment.