@@ -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);
}
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(-)