[FFmpeg-devel] [PATCH 4/4] avcodec/vp9: use ff_thread_replace_frame()
James Almer
jamrial at gmail.com
Wed Aug 11 04:48:57 EEST 2021
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/vp9.c | 67 ++++++++++++++++++++++++++++++------------------
1 file changed, 42 insertions(+), 25 deletions(-)
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 874005a5ae..85f44b9d8c 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -186,6 +186,35 @@ fail:
return AVERROR(ENOMEM);
}
+static int vp9_frame_replace(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src)
+{
+ int ret;
+
+ ret = ff_thread_replace_frame(avctx, &dst->tf, &src->tf);
+ if (ret < 0)
+ return ret;
+
+ ret = av_buffer_replace(&dst->extradata, src->extradata);
+ if (ret < 0)
+ goto fail;
+
+ dst->segmentation_map = src->segmentation_map;
+ dst->mv = src->mv;
+ dst->uses_2pass = src->uses_2pass;
+
+ ret = av_buffer_replace(&dst->hwaccel_priv_buf, src->hwaccel_priv_buf);
+ if (ret < 0)
+ goto fail;
+
+ dst->hwaccel_picture_private = src->hwaccel_picture_private;
+
+ return 0;
+
+fail:
+ vp9_frame_unref(avctx, dst);
+ return ret;
+}
+
static int update_size(AVCodecContext *avctx, int w, int h)
{
#define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \
@@ -1574,10 +1603,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, void *frame,
((AVFrame *)frame)->pts = pkt->pts;
((AVFrame *)frame)->pkt_dts = pkt->dts;
for (i = 0; i < 8; i++) {
- if (s->next_refs[i].f->buf[0])
- ff_thread_release_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)
+ ret = ff_thread_replace_frame(avctx, &s->next_refs[i], &s->s.refs[i]);
+ if (ret < 0)
return ret;
}
*got_frame = 1;
@@ -1614,12 +1641,10 @@ static int vp9_decode_frame(AVCodecContext *avctx, void *frame,
// ref frame setup
for (i = 0; i < 8; i++) {
- if (s->next_refs[i].f->buf[0])
- ff_thread_release_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]);
+ ret = ff_thread_replace_frame(avctx, &s->next_refs[i], &s->s.frames[CUR_FRAME].tf);
+ } else {
+ ret = ff_thread_replace_frame(avctx, &s->next_refs[i], &s->s.refs[i]);
}
if (ret < 0)
return ret;
@@ -1763,10 +1788,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, void *frame,
finish:
// ref frame setup
for (i = 0; i < 8; i++) {
- if (s->s.refs[i].f->buf[0])
- ff_thread_release_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)
+ ret = ff_thread_replace_frame(avctx, &s->s.refs[i], &s->next_refs[i]);
+ if (ret < 0)
return ret;
}
@@ -1818,20 +1841,14 @@ static int vp9_decode_update_thread_context(AVCodecContext *dst, const AVCodecCo
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;
- }
+ ret = vp9_frame_replace(dst, &s->s.frames[i], &ssrc->s.frames[i]);
+ if (ret < 0)
+ return ret;
}
for (i = 0; i < 8; i++) {
- if (s->s.refs[i].f->buf[0])
- ff_thread_release_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;
- }
+ ret = ff_thread_replace_frame(dst, &s->s.refs[i], &ssrc->next_refs[i]);
+ if (ret < 0)
+ return ret;
}
s->s.h.invisible = ssrc->s.h.invisible;
--
2.32.0
More information about the ffmpeg-devel
mailing list