diff mbox series

[FFmpeg-devel,5/5] avcodec/hevc/hevcdec: use the RefStruct API for h264db

Message ID 20241025022613.3921-5-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/5] Partially revert "avcodec/h2645: allocate film grain metadata dynamically" | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer Oct. 25, 2024, 2:26 a.m. UTC
And ensure the buffer is synced between threads.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/hevc/hevcdec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index f2bdf6134e..357d7d0f1d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3416,7 +3416,7 @@  static int hevc_frame_end(HEVCContext *s, HEVCLayerContext *l)
             return AVERROR_BUG;
         case AV_FILM_GRAIN_PARAMS_H274:
             if (!s->h274db) {
-                s->h274db = av_mallocz(sizeof(*s->h274db));
+                s->h274db = ff_refstruct_allocz(sizeof(*s->h274db));
                 if (!s->h274db)
                     return AVERROR(ENOMEM);
             }
@@ -3849,7 +3849,7 @@  static av_cold int hevc_decode_free(AVCodecContext *avctx)
     av_buffer_unref(&s->rpu_buf);
 
     av_freep(&s->md5_ctx);
-    av_freep(&s->h274db);
+    ff_refstruct_unref(&s->h274db);
 
     ff_container_fifo_free(&s->output_fifo);
 
@@ -3985,6 +3985,8 @@  static int hevc_update_thread_context(AVCodecContext *dst,
         }
     }
 
+    ff_refstruct_replace(&s->h274db, s0->h274db);
+
     ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common);
     if (ret < 0)
         return ret;