shithub: dav1d

Download patch

ref: cd9a99f3f4c354e4d45bd55e80e5054985e8d9d0
parent: 1c749e6b4f5136014bfbe71fb5933f05510c61be
author: Ronald S. Bultje <[email protected]>
date: Sun Sep 23 00:45:55 EDT 2018

Fix flush if n_input_frames < n_frame_threads.

Fixes #11.

--- a/src/lib.c
+++ b/src/lib.c
@@ -153,34 +153,36 @@
     validate_input_or_ret(c != NULL, -EINVAL);
     validate_input_or_ret(out != NULL, -EINVAL);
 
-    while (!in) {
+    if (!in) {
         if (c->n_fc == 1) return -EAGAIN;
 
         // flush
-        const unsigned next = c->frame_thread.next;
-        Dav1dFrameContext *const f = &c->fc[next];
+        int flush_count = 0;
+        do {
+            const unsigned next = c->frame_thread.next;
+            Dav1dFrameContext *const f = &c->fc[next];
 
-        pthread_mutex_lock(&f->frame_thread.td.lock);
-        while (f->n_tile_data > 0)
-            pthread_cond_wait(&f->frame_thread.td.cond,
-                              &f->frame_thread.td.lock);
-        pthread_mutex_unlock(&f->frame_thread.td.lock);
-        Dav1dThreadPicture *const out_delayed =
-            &c->frame_thread.out_delayed[next];
-        if (out_delayed->p.data[0]) {
+            pthread_mutex_lock(&f->frame_thread.td.lock);
+            while (f->n_tile_data > 0)
+                pthread_cond_wait(&f->frame_thread.td.cond,
+                                  &f->frame_thread.td.lock);
+            pthread_mutex_unlock(&f->frame_thread.td.lock);
+            Dav1dThreadPicture *const out_delayed =
+                &c->frame_thread.out_delayed[next];
             if (++c->frame_thread.next == c->n_fc)
                 c->frame_thread.next = 0;
-            if (out_delayed->visible) {
-                dav1d_picture_ref(out, &out_delayed->p);
+            if (out_delayed->p.data[0]) {
+                if (out_delayed->visible) {
+                    dav1d_picture_ref(out, &out_delayed->p);
+                }
+                dav1d_thread_picture_unref(out_delayed);
+                if (out->data[0]) {
+                    return 0;
+                }
+                // else continue
             }
-            dav1d_thread_picture_unref(out_delayed);
-            if (out->data[0]) {
-                return 0;
-            }
-            // else continue
-        } else {
-            return -EAGAIN;
-        }
+        } while (++flush_count < c->n_fc);
+        return -EAGAIN;
     }
 
     while (in->sz > 0) {