[FFmpeg-devel] [PATCH 1/2] avcodec/hevcdec: sync SEI derived AVCodecContext fields across threads

James Almer jamrial at gmail.com
Thu Sep 17 16:34:07 EEST 2020


Fixes ticket #8610.

Found-by: Pavel Koshevoy <pkoshevoy at gmail.com>
Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/hevcdec.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index c1de75abe1..1f3ea54d39 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -369,12 +369,22 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
     if (num != 0 && den != 0)
         av_reduce(&avctx->framerate.den, &avctx->framerate.num,
                   num, den, 1 << 30);
+}
+
+static int export_stream_params_from_sei(HEVCContext *s)
+{
+    AVCodecContext *avctx = s->avctx;
+
+    if (s->sei.a53_caption.buf_ref)
+        s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
 
     if (s->sei.alternative_transfer.present &&
         av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) &&
         s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
         avctx->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics;
     }
+
+    return 0;
 }
 
 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
@@ -582,6 +592,10 @@ static int hls_slice_header(HEVCContext *s)
         s->max_ra     = INT_MAX;
     }
 
+    ret = export_stream_params_from_sei(s);
+    if (ret < 0)
+        return ret;
+
     sh->dependent_slice_segment_flag = 0;
     if (!sh->first_slice_in_pic_flag) {
         int slice_address_length;
@@ -2806,8 +2820,6 @@ static int set_side_data(HEVCContext *s)
         if (!sd)
             av_buffer_unref(&a53->buf_ref);
         a53->buf_ref = NULL;
-
-        s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
     }
 
     for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) {
@@ -3250,6 +3262,11 @@ static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int f
         }
     }
 
+    /* export stream parameters from SEI */
+    ret = export_stream_params_from_sei(s);
+    if (ret < 0)
+        return ret;
+
     return 0;
 }
 
@@ -3537,6 +3554,10 @@ static int hevc_update_thread_context(AVCodecContext *dst,
     s->sei.content_light        = s0->sei.content_light;
     s->sei.alternative_transfer = s0->sei.alternative_transfer;
 
+    ret = export_stream_params_from_sei(s);
+    if (ret < 0)
+        return ret;
+
     return 0;
 }
 #endif
-- 
2.27.0



More information about the ffmpeg-devel mailing list