@@ -596,10 +596,13 @@ static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f)
f->coded_lossless = 0;
}
-static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
+static int av1_frame_replace(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
{
int ret;
+ if (!src->f->buf[0])
+ av1_frame_unref(avctx, dst);
+
ret = av_buffer_replace(&dst->header_ref, src->header_ref);
if (ret < 0)
return ret;
@@ -609,13 +612,13 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s
if (!src->f->buf[0])
return 0;
- ret = av_frame_ref(dst->f, src->f);
+ ret = av_frame_replace(dst->f, src->f);
if (ret < 0)
goto fail;
if (src->hwaccel_picture_private) {
- dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
- if (!dst->hwaccel_priv_buf)
+ ret = av_buffer_replace(&dst->hwaccel_priv_buf, src->hwaccel_priv_buf);
+ if (ret < 0)
goto fail;
dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data;
}
@@ -1092,8 +1095,7 @@ static int update_reference_list(AVCodecContext *avctx)
for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
if (header->refresh_frame_flags & (1 << i)) {
- av1_frame_unref(avctx, &s->ref[i]);
- if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) {
+ if ((ret = av1_frame_replace(avctx, &s->ref[i], &s->cur_frame)) < 0) {
av_log(avctx, AV_LOG_ERROR,
"Failed to update frame %d in reference list\n", i);
return ret;
@@ -1236,10 +1238,8 @@ static int av1_decode_frame(AVCodecContext *avctx, AVFrame *frame,
s->raw_frame_header = &obu->obu.frame_header;
if (s->raw_frame_header->show_existing_frame) {
- av1_frame_unref(avctx, &s->cur_frame);
-
- ret = av1_frame_ref(avctx, &s->cur_frame,
- &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
+ ret = av1_frame_replace(avctx, &s->cur_frame,
+ &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to get reference frame.\n");
goto end;
Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/av1dec.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)