shithub: dav1d

Download patch

ref: 2c3eaffd2a32c63330b5afb1bf90847a0e0b0472
parent: a1e945ca3020ee758a81e78a213c3af41cd4ffcc
author: Boyuan Xiao <boyuan.xiao@argondesign.com>
date: Tue Nov 13 12:06:40 EST 2018

Correct the condition for freeing references in dav1d_parse_obus

A new coded video sequence (see page 193; section 7.5 of the spec)
begins when we see a sequence header that isn't bit identical to
previous ones. This is the point at which we can throw away previous
frames etc.

--- a/src/obu.c
+++ b/src/obu.c
@@ -1090,7 +1090,10 @@
             return res;
         if (check_for_overrun(&gb, init_bit_pos, len))
             return -EINVAL;
-        if (!c->have_frame_hdr || memcmp(&hdr, &c->seq_hdr, sizeof(hdr))) {
+        // If we have read a sequence header which is different from
+        // the old one, this is a new video sequence and can't use any
+        // previous state. Free that state.
+        if (c->have_seq_hdr && memcmp(&hdr, &c->seq_hdr, sizeof(hdr))) {
             for (int i = 0; i < 8; i++) {
                 if (c->refs[i].p.p.data[0])
                     dav1d_thread_picture_unref(&c->refs[i].p);
@@ -1099,8 +1102,7 @@
                 if (c->cdf[i].cdf)
                     dav1d_cdf_thread_unref(&c->cdf[i]);
             }
-            if (c->have_seq_hdr)
-                c->seq_hdr = hdr;
+            c->seq_hdr = hdr;
         }
         c->have_seq_hdr = 1;
         break;