ref: a72f2679927158d7a00f846b5dede0f049c4668e
parent: 916dc654384848883cd0537314e73bd9b8ae1d90
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Thu Sep 27 05:18:22 EDT 2018
Add flush function
--- a/include/dav1d/dav1d.h
+++ b/include/dav1d/dav1d.h
@@ -84,4 +84,9 @@
*/
DAV1D_API void dav1d_close(Dav1dContext **c_out);
+/**
+ * Flush all delayed frames in decoder, to be used when seeking.
+ */
+DAV1D_API void dav1d_flush(Dav1dContext *c);
+
#endif /* __DAV1D_H__ */
--- a/src/decode.c
+++ b/src/decode.c
@@ -2688,7 +2688,7 @@
&f->frame_thread.td.lock);
out_delayed = &c->frame_thread.out_delayed[next];
if (out_delayed->p.data[0]) {
- if (out_delayed->visible)
+ if (out_delayed->visible && !out_delayed->flushed)
dav1d_picture_ref(&c->out, &out_delayed->p);
dav1d_thread_picture_unref(out_delayed);
}
--- a/src/lib.c
+++ b/src/lib.c
@@ -178,7 +178,7 @@
if (++c->frame_thread.next == c->n_fc)
c->frame_thread.next = 0;
if (out_delayed->p.data[0]) {
- if (out_delayed->visible) {
+ if (out_delayed->visible && !out_delayed->flushed) {
dav1d_picture_ref(out, &out_delayed->p);
}
dav1d_thread_picture_unref(out_delayed);
@@ -213,6 +213,13 @@
}
return -EAGAIN;
+}
+
+void dav1d_flush(Dav1dContext *const c) {
+ if (c->n_fc == 1) return;
+
+ for (int n = 0; n < c->n_fc; n++)
+ c->frame_thread.out_delayed[n].flushed = 1;
}
void dav1d_close(Dav1dContext **const c_out) {
--- a/src/obu.c
+++ b/src/obu.c
@@ -1088,7 +1088,7 @@
Dav1dThreadPicture *const out_delayed =
&c->frame_thread.out_delayed[next];
if (out_delayed->p.data[0]) {
- if (out_delayed->visible)
+ if (out_delayed->visible && !out_delayed->flushed)
dav1d_picture_ref(&c->out, &out_delayed->p);
dav1d_thread_picture_unref(out_delayed);
}
@@ -1095,6 +1095,7 @@
dav1d_thread_picture_ref(out_delayed,
&c->refs[c->frame_hdr.existing_frame_idx].p);
out_delayed->visible = 1;
+ out_delayed->flushed = 0;
pthread_mutex_unlock(&f->frame_thread.td.lock);
}
c->have_frame_hdr = 0;
--- a/src/picture.c
+++ b/src/picture.c
@@ -102,6 +102,7 @@
(void **) &p->progress);
p->visible = visible;
+ p->flushed = 0;
if (t) {
atomic_init(&p->progress[0], 0);
atomic_init(&p->progress[1], 0);
@@ -128,6 +129,7 @@
dst->t = src->t;
dst->visible = src->visible;
dst->progress = src->progress;
+ dst->flushed = src->flushed;
}
void dav1d_picture_unref(Dav1dPicture *const p) {
--- a/src/picture.h
+++ b/src/picture.h
@@ -44,7 +44,7 @@
typedef struct Dav1dThreadPicture {
Dav1dPicture p;
- int visible;
+ int visible, flushed;
struct thread_data *t;
// [0] block data (including segmentation map and motion vectors)
// [1] pixel data