ref: 6af37afa94abac4f002c80bb1bdb794f21cf21ff
parent: f8e1a621f9b68ac60115773874b0ce646e79c02d
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Thu Nov 22 03:51:08 EST 2018
Add API to match input images to specific output pictures Fixes #59.
--- a/include/dav1d/common.h
+++ b/include/dav1d/common.h
@@ -28,6 +28,9 @@
#ifndef __DAV1D_COMMON_H__
#define __DAV1D_COMMON_H__
+#include <stddef.h>
+#include <stdint.h>
+
#ifndef DAV1D_API
#if defined _WIN32
#define DAV1D_API __declspec(dllexport)
@@ -39,5 +42,20 @@
#endif
#endif
#endif
+
+/**
+ * Input packet metadata which are copied from the input data used to
+ * decode each image into the matching structure of the output image
+ * returned back to the user. Since these are metadata fields, they
+ * can be used for other purposes than the documented ones, they will
+ * still be passed from input data to output picture without being
+ * used internally.
+ */
+typedef struct Dav1dDataProps {
+ uint64_t timestamp; ///< container timestamp of input data, default -1
+ uint64_t duration; ///< container duration of input data, default -1
+ uint64_t offset; ///< stream offset of input data, default -1
+ size_t size; ///< packet size, default Dav1dData.sz
+} Dav1dDataProps;
#endif // __DAV1D_COMMON_H__
--- a/include/dav1d/data.h
+++ b/include/dav1d/data.h
@@ -37,6 +37,7 @@
const uint8_t *data; ///< data pointer
size_t sz; ///< data size
struct Dav1dRef *ref; ///< allocation origin
+ Dav1dDataProps m;
} Dav1dData;
/**
--- a/include/dav1d/picture.h
+++ b/include/dav1d/picture.h
@@ -165,6 +165,7 @@
ptrdiff_t stride[2];
Dav1dPictureParameters p;
+ Dav1dDataProps m;
void *allocator_data; ///< pointer managed by the allocator
} Dav1dPicture;
--- a/src/data.c
+++ b/src/data.c
@@ -44,7 +44,8 @@
buf->ref = dav1d_ref_create(sz);
if (!buf->ref) return NULL;
buf->data = buf->ref->const_data;
- buf->sz = sz;
+ buf->sz = buf->m.size = sz;
+ buf->m.timestamp = buf->m.duration = buf->m.offset = ~0ULL;
return buf->ref->data;
}
@@ -60,7 +61,8 @@
buf->ref = dav1d_ref_wrap(ptr, free_callback, user_data);
if (!buf->ref) return -ENOMEM;
buf->data = ptr;
- buf->sz = sz;
+ buf->sz = buf->m.size = sz;
+ buf->m.timestamp = buf->m.duration = buf->m.offset = ~0ULL;
return 0;
}
--- a/src/decode.c
+++ b/src/decode.c
@@ -3110,6 +3110,7 @@
f->sr_cur.p.p.mtrx = f->seq_hdr.mtrx;
f->sr_cur.p.p.chr = f->seq_hdr.chr;
f->sr_cur.p.p.fullrange = f->seq_hdr.color_range;
+ f->sr_cur.p.m = f->tile[0].data.m;
if (f->frame_hdr.super_res.enabled) {
res = dav1d_picture_alloc_copy(&f->cur, f->frame_hdr.width[0], &f->sr_cur.p);
@@ -3186,7 +3187,6 @@
// segmap
if (f->frame_hdr.segmentation.enabled) {
-
// By default, the previous segmentation map is not initialised.
f->prev_segmap_ref = NULL;
f->prev_segmap = NULL;
--- a/src/obu.c
+++ b/src/obu.c
@@ -1260,6 +1260,7 @@
assert(pkt_bytelen >= (bit_pos >> 3));
dav1d_ref_inc(in->ref);
c->tile[c->n_tile_data].data.ref = in->ref;
+ c->tile[c->n_tile_data].data.m = in->m;
c->tile[c->n_tile_data].data.data = in->data + (bit_pos >> 3);
c->tile[c->n_tile_data].data.sz = pkt_bytelen - (bit_pos >> 3);
// ensure tile groups are in order and sane, see 6.10.1
@@ -1303,6 +1304,7 @@
if (c->n_fc == 1) {
dav1d_picture_ref(&c->out,
&c->refs[c->frame_hdr.existing_frame_idx].p.p);
+ c->out.m = in->m;
} else {
// need to append this to the frame output queue
const unsigned next = c->frame_thread.next++;
@@ -1330,6 +1332,7 @@
&c->refs[c->frame_hdr.existing_frame_idx].p);
out_delayed->visible = 1;
out_delayed->flushed = 0;
+ out_delayed->p.m = in->m;
pthread_mutex_unlock(&f->frame_thread.td.lock);
}
c->have_frame_hdr = 0;
--- a/src/picture.c
+++ b/src/picture.c
@@ -120,6 +120,7 @@
p->p.trc = DAV1D_TRC_UNKNOWN;
p->p.mtrx = DAV1D_MC_UNKNOWN;
p->p.chr = DAV1D_CHR_UNKNOWN;
+ p->m.timestamp = p->m.duration = p->m.offset = ~0ULL;
p->p.layout = layout;
p->p.bpc = bpc;
p->p.film_grain = (Dav1dFilmGrainData) { 0 };
@@ -178,6 +179,7 @@
if (!res) {
dst->poc = src->poc;
dst->p = src->p;
+ dst->m = src->m;
dst->p.w = w;
}