diff mbox series

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

Message ID 20200917133408.1113-1-jamrial@gmail.com
State Accepted
Commit bd4ef145c0c1a1f699fd4d9939dba4d7a338a2cf
Headers show
Series [FFmpeg-devel,1/2] avcodec/hevcdec: sync SEI derived AVCodecContext fields across threads
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

James Almer Sept. 17, 2020, 1:34 p.m. UTC
Fixes ticket #8610.

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

Comments

James Almer Sept. 21, 2020, 2:05 p.m. UTC | #1
On 9/17/2020 10:34 AM, James Almer wrote:
> Fixes ticket #8610.
> 
> Found-by: Pavel Koshevoy <pkoshevoy@gmail.com>
> Signed-off-by: James Almer <jamrial@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

Will apply the set soon if there are no objections.
diff mbox series

Patch

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