Commit a72f2679 authored by Ronald S. Bultje's avatar Ronald S. Bultje

Add flush function

parent 916dc654
......@@ -84,4 +84,9 @@ DAV1D_API int dav1d_decode(Dav1dContext *c, Dav1dData *in, Dav1dPicture *out);
*/
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__ */
......@@ -2688,7 +2688,7 @@ int submit_frame(Dav1dContext *const c) {
&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);
}
......
......@@ -178,7 +178,7 @@ int dav1d_decode(Dav1dContext *const c,
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);
......@@ -215,6 +215,13 @@ int dav1d_decode(Dav1dContext *const c,
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) {
validate_input(c_out != NULL);
......
......@@ -1088,13 +1088,14 @@ int parse_obus(Dav1dContext *const c, Dav1dData *const in) {
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);
}
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;
......
......@@ -102,6 +102,7 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p,
(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 @@ void dav1d_thread_picture_ref(Dav1dThreadPicture *dst,
dst->t = src->t;
dst->visible = src->visible;
dst->progress = src->progress;
dst->flushed = src->flushed;
}
void dav1d_picture_unref(Dav1dPicture *const p) {
......
......@@ -44,7 +44,7 @@ enum PlaneType {
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment