diff mbox series

[FFmpeg-devel,30/42] avcodec/vp9: Switch to ProgressFrames

Message ID AS8P250MB0744827931E0DBBD1CB7E7768FFAA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State New
Headers show
Series New API for reference counting and ThreadFrames | expand

Commit Message

Andreas Rheinhardt Sept. 19, 2023, 7:57 p.m. UTC
This already fixes a race in the vp9-encparams test. In this test,
side data is added to the current frame after having been decoded
(and therefore after ff_thread_finish_setup() has been called).
Yet the update_thread_context callback called ff_thread_ref_frame()
and therefore av_frame_ref() with this frame as source frame and
the ensuing read was unsynchronised with adding the side data,
i.e. there was a data race.

By switching to the ProgressFrame API the implicit av_frame_ref()
is removed and the race fixed except if this frame is later reused by
a show-existing-frame which uses an explicit av_frame_ref().
The vp9-encparams test does not cover this, so this commit
already fixes all the races in this test.

This decoder kept multiple references to the same ThreadFrames
in the same context and therefore had lots of implicit av_frame_ref()
even when decoding single-threaded. This incurred lots of small
allocations: When decoding an ordinary 10s video in single-threaded
mode the number of allocations reported by Valgrind went down
from 57,814 to 20,908; for 10 threads it went down from 84,223 to
21,901.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
Compare this with Anton's earlier patch [1] 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220315104932.25496-2-anton@khirnov.net/

 libavcodec/dxva2_vp9.c       |   4 +-
 libavcodec/vp9.c             | 137 +++++++++++------------------------
 libavcodec/vp9_mc_template.c |   2 +-
 libavcodec/vp9block.c        |   5 +-
 libavcodec/vp9dec.h          |   4 +-
 libavcodec/vp9lpf.c          |   1 +
 libavcodec/vp9mvs.c          |   4 +-
 libavcodec/vp9recon.c        |  19 ++---
 libavcodec/vp9shared.h       |   6 +-
 9 files changed, 68 insertions(+), 114 deletions(-)

Comments

Anton Khirnov Oct. 21, 2023, 11:04 a.m. UTC | #1
Quoting Andreas Rheinhardt (2023-09-19 21:57:22)
> @@ -1605,7 +1590,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
>          f->flags &= ~AV_FRAME_FLAG_KEY;
>      f->pict_type = (s->s.h.keyframe || s->s.h.intraonly) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
>  
> -    if (s->s.frames[REF_FRAME_SEGMAP].tf.f->buf[0] &&
> +    // Inexistent frames have the implicit dimension 0x0 != CUR_FRAME

Is this a word? I think one would normally say "non-existent".

Otherwise looks ok.
diff mbox series

Patch

diff --git a/libavcodec/dxva2_vp9.c b/libavcodec/dxva2_vp9.c
index eba4df9031..1352b9b7db 100644
--- a/libavcodec/dxva2_vp9.c
+++ b/libavcodec/dxva2_vp9.c
@@ -80,7 +80,7 @@  static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c
     pp->Reserved8Bits = 0;
 
     for (i = 0; i < 8; i++) {
-        if (h->refs[i].f->buf[0]) {
+        if (h->refs[i].f) {
             fill_picture_entry(&pp->ref_frame_map[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[i].f), 0);
             pp->ref_frame_coded_width[i]  = h->refs[i].f->width;
             pp->ref_frame_coded_height[i] = h->refs[i].f->height;
@@ -90,7 +90,7 @@  static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c
 
     for (i = 0; i < 3; i++) {
         uint8_t refidx = h->h.refidx[i];
-        if (h->refs[refidx].f->buf[0])
+        if (h->refs[refidx].f)
             fill_picture_entry(&pp->frame_refs[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[refidx].f), 0);
         else
             pp->frame_refs[i].bPicEntry = 0xFF;
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index dac81fd712..c940206b94 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -30,9 +30,9 @@ 
 #include "hwaccel_internal.h"
 #include "hwconfig.h"
 #include "profiles.h"
+#include "progressframe.h"
 #include "refstruct.h"
 #include "thread.h"
-#include "threadframe.h"
 #include "pthread_internal.h"
 
 #include "videodsp.h"
@@ -99,7 +99,7 @@  static void vp9_tile_data_free(VP9TileData *td)
 
 static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f)
 {
-    ff_thread_release_ext_buffer(avctx, &f->tf);
+    ff_thread_progress_unref(avctx, &f->tf);
     ff_refstruct_unref(&f->extradata);
     ff_refstruct_unref(&f->hwaccel_picture_private);
     f->segmentation_map = NULL;
@@ -110,7 +110,7 @@  static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
     VP9Context *s = avctx->priv_data;
     int ret, sz;
 
-    ret = ff_thread_get_ext_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF);
+    ret = ff_thread_progress_get_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF);
     if (ret < 0)
         return ret;
 
@@ -146,13 +146,9 @@  fail:
     return ret;
 }
 
-static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src)
+static void vp9_frame_ref(VP9Frame *dst, const VP9Frame *src)
 {
-    int ret;
-
-    ret = ff_thread_ref_frame(&dst->tf, &src->tf);
-    if (ret < 0)
-        return ret;
+    ff_thread_progress_ref(&dst->tf, &src->tf);
 
     dst->extradata = ff_refstruct_ref(src->extradata);
 
@@ -162,8 +158,13 @@  static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src)
 
     ff_refstruct_replace(&dst->hwaccel_picture_private,
                           src->hwaccel_picture_private);
+}
 
-    return 0;
+static void vp9_frame_replace(AVCodecContext *avctx, VP9Frame *dst, const VP9Frame *src)
+{
+    vp9_frame_unref(avctx, dst);
+    if (src && src->tf.f)
+        vp9_frame_ref(dst, src);
 }
 
 static int update_size(AVCodecContext *avctx, int w, int h)
@@ -584,9 +585,9 @@  static int decode_frame_header(AVCodecContext *avctx,
             s->s.h.signbias[1]    = get_bits1(&s->gb) && !s->s.h.errorres;
             s->s.h.refidx[2]      = get_bits(&s->gb, 3);
             s->s.h.signbias[2]    = get_bits1(&s->gb) && !s->s.h.errorres;
-            if (!s->s.refs[s->s.h.refidx[0]].f->buf[0] ||
-                !s->s.refs[s->s.h.refidx[1]].f->buf[0] ||
-                !s->s.refs[s->s.h.refidx[2]].f->buf[0]) {
+            if (!s->s.refs[s->s.h.refidx[0]].f ||
+                !s->s.refs[s->s.h.refidx[1]].f ||
+                !s->s.refs[s->s.h.refidx[2]].f) {
                 av_log(avctx, AV_LOG_ERROR, "Not all references are available\n");
                 return AVERROR_INVALIDDATA;
             }
@@ -606,7 +607,8 @@  static int decode_frame_header(AVCodecContext *avctx,
             // Note that in this code, "CUR_FRAME" is actually before we
             // have formally allocated a frame, and thus actually represents
             // the _last_ frame
-            s->s.h.use_last_frame_mvs &= s->s.frames[CUR_FRAME].tf.f->width == w &&
+            s->s.h.use_last_frame_mvs &= s->s.frames[CUR_FRAME].tf.f &&
+                                         s->s.frames[CUR_FRAME].tf.f->width == w &&
                                        s->s.frames[CUR_FRAME].tf.f->height == h;
             if (get_bits1(&s->gb)) // display size
                 skip_bits(&s->gb, 32);
@@ -1235,16 +1237,12 @@  static av_cold int vp9_decode_free(AVCodecContext *avctx)
     VP9Context *s = avctx->priv_data;
     int i;
 
-    for (i = 0; i < 3; i++) {
+    for (int i = 0; i < 3; i++)
         vp9_frame_unref(avctx, &s->s.frames[i]);
-        av_frame_free(&s->s.frames[i].tf.f);
-    }
     ff_refstruct_pool_uninit(&s->frame_extradata_pool);
     for (i = 0; i < 8; i++) {
-        ff_thread_release_ext_buffer(avctx, &s->s.refs[i]);
-        av_frame_free(&s->s.refs[i].f);
-        ff_thread_release_ext_buffer(avctx, &s->next_refs[i]);
-        av_frame_free(&s->next_refs[i].f);
+        ff_thread_progress_unref(avctx, &s->s.refs[i]);
+        ff_thread_progress_unref(avctx, &s->next_refs[i]);
     }
 
     free_buffers(s);
@@ -1379,7 +1377,7 @@  static int decode_tiles(AVCodecContext *avctx,
             // FIXME maybe we can make this more finegrained by running the
             // loopfilter per-block instead of after each sbrow
             // In fact that would also make intra pred left preparation easier?
-            ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, row >> 3, 0);
+            ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, row >> 3);
         }
     }
     return 0;
@@ -1556,12 +1554,13 @@  static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     int ret, i, j, ref;
     int retain_segmap_ref = s->s.frames[REF_FRAME_SEGMAP].segmentation_map &&
                             (!s->s.h.segmentation.enabled || !s->s.h.segmentation.update_map);
+    const VP9Frame *src;
     AVFrame *f;
 
     if ((ret = decode_frame_header(avctx, data, size, &ref)) < 0) {
         return ret;
     } else if (ret == 0) {
-        if (!s->s.refs[ref].f->buf[0]) {
+        if (!s->s.refs[ref].f) {
             av_log(avctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref);
             return AVERROR_INVALIDDATA;
         }
@@ -1569,33 +1568,19 @@  static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             return ret;
         frame->pts     = pkt->pts;
         frame->pkt_dts = pkt->dts;
-        for (i = 0; i < 8; i++) {
-            if (s->next_refs[i].f->buf[0])
-                ff_thread_release_ext_buffer(avctx, &s->next_refs[i]);
-            if (s->s.refs[i].f->buf[0] &&
-                (ret = ff_thread_ref_frame(&s->next_refs[i], &s->s.refs[i])) < 0)
-                return ret;
-        }
+        for (int i = 0; i < 8; i++)
+            ff_thread_progress_replace(avctx, &s->next_refs[i], &s->s.refs[i]);
         *got_frame = 1;
         return pkt->size;
     }
     data += ret;
     size -= ret;
 
-    if (!retain_segmap_ref || s->s.h.keyframe || s->s.h.intraonly) {
-        if (s->s.frames[REF_FRAME_SEGMAP].tf.f->buf[0])
-            vp9_frame_unref(avctx, &s->s.frames[REF_FRAME_SEGMAP]);
-        if (!s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres && s->s.frames[CUR_FRAME].tf.f->buf[0] &&
-            (ret = vp9_frame_ref(avctx, &s->s.frames[REF_FRAME_SEGMAP], &s->s.frames[CUR_FRAME])) < 0)
-            return ret;
-    }
-    if (s->s.frames[REF_FRAME_MVPAIR].tf.f->buf[0])
-        vp9_frame_unref(avctx, &s->s.frames[REF_FRAME_MVPAIR]);
-    if (!s->s.h.intraonly && !s->s.h.keyframe && !s->s.h.errorres && s->s.frames[CUR_FRAME].tf.f->buf[0] &&
-        (ret = vp9_frame_ref(avctx, &s->s.frames[REF_FRAME_MVPAIR], &s->s.frames[CUR_FRAME])) < 0)
-        return ret;
-    if (s->s.frames[CUR_FRAME].tf.f->buf[0])
-        vp9_frame_unref(avctx, &s->s.frames[CUR_FRAME]);
+    src = !s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres ? &s->s.frames[CUR_FRAME] : NULL;
+    if (!retain_segmap_ref || s->s.h.keyframe || s->s.h.intraonly)
+        vp9_frame_replace(avctx, &s->s.frames[REF_FRAME_SEGMAP], src);
+    vp9_frame_replace(avctx, &s->s.frames[REF_FRAME_MVPAIR], src);
+    vp9_frame_unref(avctx, &s->s.frames[CUR_FRAME]);
     if ((ret = vp9_frame_alloc(avctx, &s->s.frames[CUR_FRAME])) < 0)
         return ret;
     f = s->s.frames[CUR_FRAME].tf.f;
@@ -1605,7 +1590,8 @@  static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         f->flags &= ~AV_FRAME_FLAG_KEY;
     f->pict_type = (s->s.h.keyframe || s->s.h.intraonly) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
-    if (s->s.frames[REF_FRAME_SEGMAP].tf.f->buf[0] &&
+    // Inexistent frames have the implicit dimension 0x0 != CUR_FRAME
+    if (!s->s.frames[REF_FRAME_MVPAIR].tf.f ||
         (s->s.frames[REF_FRAME_MVPAIR].tf.f->width  != s->s.frames[CUR_FRAME].tf.f->width ||
          s->s.frames[REF_FRAME_MVPAIR].tf.f->height != s->s.frames[CUR_FRAME].tf.f->height)) {
         vp9_frame_unref(avctx, &s->s.frames[REF_FRAME_SEGMAP]);
@@ -1613,15 +1599,9 @@  static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     // ref frame setup
     for (i = 0; i < 8; i++) {
-        if (s->next_refs[i].f->buf[0])
-            ff_thread_release_ext_buffer(avctx, &s->next_refs[i]);
-        if (s->s.h.refreshrefmask & (1 << i)) {
-            ret = ff_thread_ref_frame(&s->next_refs[i], &s->s.frames[CUR_FRAME].tf);
-        } else if (s->s.refs[i].f->buf[0]) {
-            ret = ff_thread_ref_frame(&s->next_refs[i], &s->s.refs[i]);
-        }
-        if (ret < 0)
-            return ret;
+        ff_thread_progress_replace(avctx, &s->next_refs[i],
+                                   s->s.h.refreshrefmask & (1 << i) ?
+                                       &s->s.frames[CUR_FRAME].tf : &s->s.refs[i]);
     }
 
     if (avctx->hwaccel) {
@@ -1731,7 +1711,7 @@  static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         {
             ret = decode_tiles(avctx, data, size);
             if (ret < 0) {
-                ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
+                ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
                 return ret;
             }
         }
@@ -1747,7 +1727,7 @@  static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             ff_thread_finish_setup(avctx);
         }
     } while (s->pass++ == 1);
-    ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
+    ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
 
     if (s->td->error_info < 0) {
         av_log(avctx, AV_LOG_ERROR, "Failed to decode tile data\n");
@@ -1762,13 +1742,8 @@  static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
 finish:
     // ref frame setup
-    for (i = 0; i < 8; i++) {
-        if (s->s.refs[i].f->buf[0])
-            ff_thread_release_ext_buffer(avctx, &s->s.refs[i]);
-        if (s->next_refs[i].f->buf[0] &&
-            (ret = ff_thread_ref_frame(&s->s.refs[i], &s->next_refs[i])) < 0)
-            return ret;
-    }
+    for (int i = 0; i < 8; i++)
+        ff_thread_progress_replace(avctx, &s->s.refs[i], &s->next_refs[i]);
 
     if (!s->s.h.invisible) {
         if ((ret = av_frame_ref(frame, s->s.frames[CUR_FRAME].tf.f)) < 0)
@@ -1787,7 +1762,7 @@  static void vp9_decode_flush(AVCodecContext *avctx)
     for (i = 0; i < 3; i++)
         vp9_frame_unref(avctx, &s->s.frames[i]);
     for (i = 0; i < 8; i++)
-        ff_thread_release_ext_buffer(avctx, &s->s.refs[i]);
+        ff_thread_progress_unref(avctx, &s->s.refs[i]);
 
     if (FF_HW_HAS_CB(avctx, flush))
         FF_HW_SIMPLE_CALL(avctx, flush);
@@ -1809,42 +1784,18 @@  static av_cold int vp9_decode_init(AVCodecContext *avctx)
     }
 #endif
 
-    for (int i = 0; i < 3; i++) {
-        s->s.frames[i].tf.f = av_frame_alloc();
-        if (!s->s.frames[i].tf.f)
-            return AVERROR(ENOMEM);
-    }
-    for (int i = 0; i < 8; i++) {
-        s->s.refs[i].f      = av_frame_alloc();
-        s->next_refs[i].f   = av_frame_alloc();
-        if (!s->s.refs[i].f || !s->next_refs[i].f)
-            return AVERROR(ENOMEM);
-    }
     return 0;
 }
 
 #if HAVE_THREADS
 static int vp9_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
 {
-    int i, ret;
     VP9Context *s = dst->priv_data, *ssrc = src->priv_data;
 
-    for (i = 0; i < 3; i++) {
-        if (s->s.frames[i].tf.f->buf[0])
-            vp9_frame_unref(dst, &s->s.frames[i]);
-        if (ssrc->s.frames[i].tf.f->buf[0]) {
-            if ((ret = vp9_frame_ref(dst, &s->s.frames[i], &ssrc->s.frames[i])) < 0)
-                return ret;
-        }
-    }
-    for (i = 0; i < 8; i++) {
-        if (s->s.refs[i].f->buf[0])
-            ff_thread_release_ext_buffer(dst, &s->s.refs[i]);
-        if (ssrc->next_refs[i].f->buf[0]) {
-            if ((ret = ff_thread_ref_frame(&s->s.refs[i], &ssrc->next_refs[i])) < 0)
-                return ret;
-        }
-    }
+    for (int i = 0; i < 3; i++)
+        vp9_frame_replace(dst, &s->s.frames[i], &ssrc->s.frames[i]);
+    for (int i = 0; i < 8; i++)
+        ff_thread_progress_replace(dst, &s->s.refs[i], &ssrc->next_refs[i]);
     ff_refstruct_replace(&s->frame_extradata_pool, ssrc->frame_extradata_pool);
     s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size;
 
@@ -1884,7 +1835,7 @@  const FFCodec ff_vp9_decoder = {
     .p.capabilities        = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
     .caps_internal         = FF_CODEC_CAP_INIT_CLEANUP |
                              FF_CODEC_CAP_SLICE_THREAD_HAS_MF |
-                             FF_CODEC_CAP_ALLOCATE_PROGRESS,
+                             FF_CODEC_CAP_USES_PROGRESSFRAMES,
     .flush                 = vp9_decode_flush,
     UPDATE_THREAD_CONTEXT(vp9_decode_update_thread_context),
     .p.profiles            = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
diff --git a/libavcodec/vp9_mc_template.c b/libavcodec/vp9_mc_template.c
index e654c0e5ed..81e4ed59c7 100644
--- a/libavcodec/vp9_mc_template.c
+++ b/libavcodec/vp9_mc_template.c
@@ -36,7 +36,7 @@  static void FN(inter_pred)(VP9TileData *td)
     const VP9Context *s = td->s;
     VP9Block *b = td->b;
     int row = td->row, col = td->col;
-    const ThreadFrame *tref1 = &s->s.refs[s->s.h.refidx[b->ref[0]]], *tref2;
+    const ProgressFrame *tref1 = &s->s.refs[s->s.h.refidx[b->ref[0]]], *tref2;
     const AVFrame *ref1 = tref1->f, *ref2;
     int w1 = ref1->width, h1 = ref1->height, w2, h2;
     ptrdiff_t ls_y = td->y_stride, ls_uv = td->uv_stride;
diff --git a/libavcodec/vp9block.c b/libavcodec/vp9block.c
index 5743f048cc..554b4caebb 100644
--- a/libavcodec/vp9block.c
+++ b/libavcodec/vp9block.c
@@ -22,8 +22,9 @@ 
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/frame.h"
 
-#include "threadframe.h"
+#include "progressframe.h"
 #include "vp89_rac.h"
 #include "vp9.h"
 #include "vp9data.h"
@@ -113,7 +114,7 @@  static void decode_mode(VP9TileData *td)
             uint8_t *refsegmap = s->s.frames[REF_FRAME_SEGMAP].segmentation_map;
 
             if (!s->s.frames[REF_FRAME_SEGMAP].uses_2pass)
-                ff_thread_await_progress(&s->s.frames[REF_FRAME_SEGMAP].tf, row >> 3, 0);
+                ff_thread_progress_await(&s->s.frames[REF_FRAME_SEGMAP].tf, row >> 3);
             for (y = 0; y < h4; y++) {
                 int idx_base = (y + row) * 8 * s->sb_cols + col;
                 for (x = 0; x < w4; x++)
diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h
index 013aac49eb..cbeb0b1bea 100644
--- a/libavcodec/vp9dec.h
+++ b/libavcodec/vp9dec.h
@@ -120,7 +120,7 @@  typedef struct VP9Context {
     int w, h;
     enum AVPixelFormat pix_fmt, last_fmt, gf_fmt;
     unsigned sb_cols, sb_rows, rows, cols;
-    ThreadFrame next_refs[8];
+    ProgressFrame next_refs[8];
 
     struct {
         uint8_t lim_lut[64];
@@ -245,7 +245,7 @@  void ff_vp9_decode_block(VP9TileData *td, int row, int col,
                          VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
                          enum BlockLevel bl, enum BlockPartition bp);
 
-void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl,
+void ff_vp9_loopfilter_sb(struct AVCodecContext *avctx, VP9Filter *lflvl,
                           int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff);
 
 void ff_vp9_intra_recon_8bpp(VP9TileData *td,
diff --git a/libavcodec/vp9lpf.c b/libavcodec/vp9lpf.c
index 414cede852..afeebebf59 100644
--- a/libavcodec/vp9lpf.c
+++ b/libavcodec/vp9lpf.c
@@ -21,6 +21,7 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "avcodec.h"
 #include "vp9dec.h"
 
 static av_always_inline void filter_plane_cols(VP9Context *s, int col, int ss_h, int ss_v,
diff --git a/libavcodec/vp9mvs.c b/libavcodec/vp9mvs.c
index b93d878d6f..d0016d85ca 100644
--- a/libavcodec/vp9mvs.c
+++ b/libavcodec/vp9mvs.c
@@ -21,7 +21,7 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "threadframe.h"
+#include "progressframe.h"
 #include "vp89_rac.h"
 #include "vp9data.h"
 #include "vp9dec.h"
@@ -175,7 +175,7 @@  static void find_ref_mvs(VP9TileData *td,
         VP9mvrefPair *mv = &s->s.frames[REF_FRAME_MVPAIR].mv[row * s->sb_cols * 8 + col];
 
         if (!s->s.frames[REF_FRAME_MVPAIR].uses_2pass)
-            ff_thread_await_progress(&s->s.frames[REF_FRAME_MVPAIR].tf, row >> 3, 0);
+            ff_thread_progress_await(&s->s.frames[REF_FRAME_MVPAIR].tf, row >> 3);
         if (mv->ref[0] == ref)
             RETURN_MV(mv->mv[0]);
         else if (mv->ref[1] == ref)
diff --git a/libavcodec/vp9recon.c b/libavcodec/vp9recon.c
index 073c04b47d..4af693608e 100644
--- a/libavcodec/vp9recon.c
+++ b/libavcodec/vp9recon.c
@@ -22,9 +22,10 @@ 
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/frame.h"
 #include "libavutil/mem_internal.h"
 
-#include "threadframe.h"
+#include "progressframe.h"
 #include "videodsp.h"
 #include "vp9data.h"
 #include "vp9dec.h"
@@ -298,7 +299,7 @@  void ff_vp9_intra_recon_16bpp(VP9TileData *td, ptrdiff_t y_off, ptrdiff_t uv_off
 static av_always_inline void mc_luma_unscaled(VP9TileData *td, const vp9_mc_func (*mc)[2],
                                               uint8_t *dst, ptrdiff_t dst_stride,
                                               const uint8_t *ref, ptrdiff_t ref_stride,
-                                              const ThreadFrame *ref_frame,
+                                              const ProgressFrame *ref_frame,
                                               ptrdiff_t y, ptrdiff_t x, const VP9mv *mv,
                                               int bw, int bh, int w, int h, int bytesperpixel)
 {
@@ -314,7 +315,7 @@  static av_always_inline void mc_luma_unscaled(VP9TileData *td, const vp9_mc_func
     // we use +7 because the last 7 pixels of each sbrow can be changed in
     // the longest loopfilter of the next sbrow
     th = (y + bh + 4 * !!my + 7) >> 6;
-    ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
+    ff_thread_progress_await(ref_frame, FFMAX(th, 0));
     // The arm/aarch64 _hv filters read one more row than what actually is
     // needed, so switch to emulated edge one pixel sooner vertically
     // (!!my * 5) than horizontally (!!mx * 4).
@@ -336,7 +337,7 @@  static av_always_inline void mc_chroma_unscaled(VP9TileData *td, const vp9_mc_fu
                                                 ptrdiff_t dst_stride,
                                                 const uint8_t *ref_u, ptrdiff_t src_stride_u,
                                                 const uint8_t *ref_v, ptrdiff_t src_stride_v,
-                                                const ThreadFrame *ref_frame,
+                                                const ProgressFrame *ref_frame,
                                                 ptrdiff_t y, ptrdiff_t x, const VP9mv *mv,
                                                 int bw, int bh, int w, int h, int bytesperpixel)
 {
@@ -353,7 +354,7 @@  static av_always_inline void mc_chroma_unscaled(VP9TileData *td, const vp9_mc_fu
     // we use +7 because the last 7 pixels of each sbrow can be changed in
     // the longest loopfilter of the next sbrow
     th = (y + bh + 4 * !!my + 7) >> (6 - s->ss_v);
-    ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
+    ff_thread_progress_await(ref_frame, FFMAX(th, 0));
     // The arm/aarch64 _hv filters read one more row than what actually is
     // needed, so switch to emulated edge one pixel sooner vertically
     // (!!my * 5) than horizontally (!!mx * 4).
@@ -407,7 +408,7 @@  static av_always_inline void mc_luma_scaled(VP9TileData *td, vp9_scaled_mc_func
                                             const vp9_mc_func (*mc)[2],
                                             uint8_t *dst, ptrdiff_t dst_stride,
                                             const uint8_t *ref, ptrdiff_t ref_stride,
-                                            const ThreadFrame *ref_frame,
+                                            const ProgressFrame *ref_frame,
                                             ptrdiff_t y, ptrdiff_t x, const VP9mv *in_mv,
                                             int px, int py, int pw, int ph,
                                             int bw, int bh, int w, int h, int bytesperpixel,
@@ -444,7 +445,7 @@  static av_always_inline void mc_luma_scaled(VP9TileData *td, vp9_scaled_mc_func
     // we use +7 because the last 7 pixels of each sbrow can be changed in
     // the longest loopfilter of the next sbrow
     th = (y + refbh_m1 + 4 + 7) >> 6;
-    ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
+    ff_thread_progress_await(ref_frame, FFMAX(th, 0));
     // The arm/aarch64 _hv filters read one more row than what actually is
     // needed, so switch to emulated edge one pixel sooner vertically
     // (y + 5 >= h - refbh_m1) than horizontally (x + 4 >= w - refbw_m1).
@@ -467,7 +468,7 @@  static av_always_inline void mc_chroma_scaled(VP9TileData *td, vp9_scaled_mc_fun
                                               ptrdiff_t dst_stride,
                                               const uint8_t *ref_u, ptrdiff_t src_stride_u,
                                               const uint8_t *ref_v, ptrdiff_t src_stride_v,
-                                              const ThreadFrame *ref_frame,
+                                              const ProgressFrame *ref_frame,
                                               ptrdiff_t y, ptrdiff_t x, const VP9mv *in_mv,
                                               int px, int py, int pw, int ph,
                                               int bw, int bh, int w, int h, int bytesperpixel,
@@ -514,7 +515,7 @@  static av_always_inline void mc_chroma_scaled(VP9TileData *td, vp9_scaled_mc_fun
     // we use +7 because the last 7 pixels of each sbrow can be changed in
     // the longest loopfilter of the next sbrow
     th = (y + refbh_m1 + 4 + 7) >> (6 - s->ss_v);
-    ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
+    ff_thread_progress_await(ref_frame, FFMAX(th, 0));
     // The arm/aarch64 _hv filters read one more row than what actually is
     // needed, so switch to emulated edge one pixel sooner vertically
     // (y + 5 >= h - refbh_m1) than horizontally (x + 4 >= w - refbw_m1).
diff --git a/libavcodec/vp9shared.h b/libavcodec/vp9shared.h
index b445a2a746..805668416f 100644
--- a/libavcodec/vp9shared.h
+++ b/libavcodec/vp9shared.h
@@ -29,8 +29,8 @@ 
 
 #include "libavutil/mem_internal.h"
 
+#include "progressframe.h"
 #include "vp9.h"
-#include "threadframe.h"
 
 enum BlockPartition {
     PARTITION_NONE,    // [ ] <-.
@@ -63,7 +63,7 @@  typedef struct VP9mvrefPair {
 } VP9mvrefPair;
 
 typedef struct VP9Frame {
-    ThreadFrame tf;
+    ProgressFrame tf;
     void *extradata;               ///< RefStruct reference
     uint8_t *segmentation_map;
     VP9mvrefPair *mv;
@@ -164,7 +164,7 @@  typedef struct VP9BitstreamHeader {
 typedef struct VP9SharedContext {
     VP9BitstreamHeader h;
 
-    ThreadFrame refs[8];
+    ProgressFrame refs[8];
 #define CUR_FRAME 0
 #define REF_FRAME_MVPAIR 1
 #define REF_FRAME_SEGMAP 2