[FFmpeg-devel] [PATCH 33/42] avcodec/vp9: Simplify replacing VP9Frame

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Sep 19 22:57:25 EEST 2023


ff_thread_progress_replace() can handle a blank ProgressFrame
as src (in which case it simply unreferences dst), but not
a NULL one. So add a blank frame to be used as source for
this case, so that we can use the replace functions
to simplify vp9_frame_replace().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/vp9.c       | 16 +++++-----------
 libavcodec/vp9shared.h |  3 ++-
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 87c507bb36..8eba56b720 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -146,11 +146,11 @@ fail:
     return ret;
 }
 
-static void vp9_frame_ref(VP9Frame *dst, const VP9Frame *src)
+static void vp9_frame_replace(AVCodecContext *avctx, VP9Frame *dst, const VP9Frame *src)
 {
-    ff_thread_progress_ref(&dst->tf, &src->tf);
+    ff_thread_progress_replace(avctx, &dst->tf, &src->tf);
 
-    dst->extradata = ff_refstruct_ref(src->extradata);
+    ff_refstruct_replace(&dst->extradata, src->extradata);
 
     dst->segmentation_map = src->segmentation_map;
     dst->mv = src->mv;
@@ -160,13 +160,6 @@ static void vp9_frame_ref(VP9Frame *dst, const VP9Frame *src)
                           src->hwaccel_picture_private);
 }
 
-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)
 {
 #define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \
@@ -1579,7 +1572,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     data += ret;
     size -= ret;
 
-    src = !s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres ? &s->s.frames[CUR_FRAME] : NULL;
+    src = !s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres ?
+              &s->s.frames[CUR_FRAME] : &s->s.frames[BLANK_FRAME];
     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);
diff --git a/libavcodec/vp9shared.h b/libavcodec/vp9shared.h
index 805668416f..8a450c26a6 100644
--- a/libavcodec/vp9shared.h
+++ b/libavcodec/vp9shared.h
@@ -168,7 +168,8 @@ typedef struct VP9SharedContext {
 #define CUR_FRAME 0
 #define REF_FRAME_MVPAIR 1
 #define REF_FRAME_SEGMAP 2
-    VP9Frame frames[3];
+#define BLANK_FRAME 3
+    VP9Frame frames[4];
 } VP9SharedContext;
 
 #endif /* AVCODEC_VP9SHARED_H */
-- 
2.34.1



More information about the ffmpeg-devel mailing list