Skip to content

Commit

Permalink
backport from dav1d 1.2.0: picture: fix attaching props to delayed …
Browse files Browse the repository at this point in the history
…output pictures (#599)

I couldn't figure out how to push a rebased version to #518, so this is
the same as #518 just rebased.
  • Loading branch information
kkysen authored Dec 7, 2023
2 parents 86edf43 + a6c4e58 commit 2ccdf9e
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 16 deletions.
19 changes: 17 additions & 2 deletions src/obu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,14 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, const int globa
if (c->n_fc == 1) {
dav1d_thread_picture_ref(&c->out,
&c->refs[c->frame_hdr->existing_frame_idx].p);
dav1d_data_props_copy(&c->out.p.m, &in->m);
dav1d_picture_copy_props(&c->out.p,
c->content_light, c->content_light_ref,
c->mastering_display, c->mastering_display_ref,
c->itut_t35, c->itut_t35_ref,
&in->m);
// Must be removed from the context after being attached to the frame
dav1d_ref_dec(&c->itut_t35_ref);
c->itut_t35 = NULL;
c->event_flags |= dav1d_picture_get_event_flags(&c->refs[c->frame_hdr->existing_frame_idx].p);
} else {
pthread_mutex_lock(&c->task_thread.lock);
Expand Down Expand Up @@ -1639,7 +1646,15 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, const int globa
dav1d_thread_picture_ref(out_delayed,
&c->refs[c->frame_hdr->existing_frame_idx].p);
out_delayed->visible = 1;
dav1d_data_props_copy(&out_delayed->p.m, &in->m);
dav1d_picture_copy_props(&out_delayed->p,
c->content_light, c->content_light_ref,
c->mastering_display, c->mastering_display_ref,
c->itut_t35, c->itut_t35_ref,
&in->m);
// Must be removed from the context after being attached to the frame
dav1d_ref_dec(&c->itut_t35_ref);
c->itut_t35 = NULL;

pthread_mutex_unlock(&c->task_thread.lock);
}
if (c->refs[c->frame_hdr->existing_frame_idx].p.p.frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY) {
Expand Down
29 changes: 27 additions & 2 deletions src/obu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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 @@ -2026,7 +2027,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 @@ -2090,7 +2103,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
26 changes: 20 additions & 6 deletions src/picture.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ static int picture_alloc_with_edges(Dav1dContext *const c,
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;
dav1d_data_props_set_defaults(&p->m);
Expand All @@ -155,21 +152,38 @@ static int picture_alloc_with_edges(Dav1dContext *const c,
p->frame_hdr_ref = frame_hdr_ref;
if (frame_hdr_ref) dav1d_ref_inc(frame_hdr_ref);

dav1d_data_props_copy(&p->m, props);
dav1d_picture_copy_props(p, content_light, content_light_ref,
mastering_display, mastering_display_ref,
itut_t35, itut_t35_ref, props);

if (extra && extra_ptr)
*extra_ptr = &pic_ctx->extra_ptr;

return 0;
}

void dav1d_picture_copy_props(Dav1dPicture *const p,
Dav1dContentLightLevel *const content_light, Dav1dRef *const content_light_ref,
Dav1dMasteringDisplay *const mastering_display, Dav1dRef *const mastering_display_ref,
Dav1dITUTT35 *const itut_t35, Dav1dRef *const itut_t35_ref,
const Dav1dDataProps *const props)
{
dav1d_data_props_copy(&p->m, props);

dav1d_ref_dec(&p->content_light_ref);
p->content_light_ref = content_light_ref;
p->content_light = content_light;
if (content_light_ref) dav1d_ref_inc(content_light_ref);

dav1d_ref_dec(&p->mastering_display_ref);
p->mastering_display_ref = mastering_display_ref;
p->mastering_display = mastering_display;
if (mastering_display_ref) dav1d_ref_inc(mastering_display_ref);

dav1d_ref_dec(&p->itut_t35_ref);
p->itut_t35_ref = itut_t35_ref;
p->itut_t35 = itut_t35;
if (itut_t35_ref) dav1d_ref_inc(itut_t35_ref);

return 0;
}

int dav1d_thread_picture_alloc(Dav1dContext *const c, Dav1dFrameContext *const f,
Expand Down
6 changes: 6 additions & 0 deletions src/picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ int dav1d_default_picture_alloc(Dav1dPicture *p, void *cookie);
void dav1d_default_picture_release(Dav1dPicture *p, void *cookie);
void dav1d_picture_unref_internal(Dav1dPicture *p);

void dav1d_picture_copy_props(Dav1dPicture *p,
Dav1dContentLightLevel *content_light, Dav1dRef *content_light_ref,
Dav1dMasteringDisplay *mastering_display, Dav1dRef *mastering_display_ref,
Dav1dITUTT35 *itut_t35, Dav1dRef *itut_t35_ref,
const Dav1dDataProps *props);

/**
* Get event flags from picture flags.
*/
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 2ccdf9e

Please sign in to comment.