diff mbox series

[FFmpeg-devel,3/5] avcodec/h2645_sei: use the RefStruct API for film_grain_characteristics

Message ID 20241025022613.3921-3-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/h2645_sei.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index 33390d389d..9ed2fc5596 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -42,6 +42,7 @@ 
 #include "golomb.h"
 #include "h2645_sei.h"
 #include "itut35.h"
+#include "refstruct.h"
 
 #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI)
 #define IS_HEVC(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI)
@@ -495,11 +496,10 @@  int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type,
     case SEI_TYPE_DISPLAY_ORIENTATION:
         return decode_display_orientation(&h->display_orientation, gb);
     case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
-        if (!h->film_grain_characteristics) {
-            h->film_grain_characteristics = av_mallocz(sizeof(*h->film_grain_characteristics));
-            if (!h->film_grain_characteristics)
-                return AVERROR(ENOMEM);
-        }
+        ff_refstruct_unref(&h->film_grain_characteristics);
+        h->film_grain_characteristics = ff_refstruct_allocz(sizeof(*h->film_grain_characteristics));
+        if (!h->film_grain_characteristics)
+            return AVERROR(ENOMEM);
         return decode_film_grain_characteristics(h->film_grain_characteristics, codec_id, gb);
     case SEI_TYPE_FRAME_PACKING_ARRANGEMENT:
         return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id);
@@ -556,6 +556,9 @@  int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
     }
     dst->aom_film_grain.enable = src->aom_film_grain.enable;
 
+    ff_refstruct_replace(&dst->film_grain_characteristics,
+                          src->film_grain_characteristics);
+
     return 0;
 }
 
@@ -930,5 +933,5 @@  void ff_h2645_sei_reset(H2645SEI *s)
 
     ff_aom_film_grain_uninit_params(&s->aom_film_grain);
 
-    av_freep(&s->film_grain_characteristics);
+    ff_refstruct_unref(&s->film_grain_characteristics);
 }