diff mbox series

[FFmpeg-devel] avocdec/hevcdec: set SEI derived AVCodecContext fields as soon as they are parsed

Message ID 20200917003609.2305-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avocdec/hevcdec: set SEI derived AVCodecContext fields as soon as they are parsed | expand

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, 12:36 a.m. UTC
export_stream_params() may not be called in some scenarios, for example leaving
both the AVCodecContext and subsequent output frames with the color_trc value
taken from the VUI instead of the Alternative Transfer Characteristics SEI.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/hevcdec.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

Comments

James Almer Sept. 17, 2020, 1:29 p.m. UTC | #1
On 9/16/2020 9:36 PM, James Almer wrote:
> export_stream_params() may not be called in some scenarios, for example leaving
> both the AVCodecContext and subsequent output frames with the color_trc value
> taken from the VUI instead of the Alternative Transfer Characteristics SEI.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/hevcdec.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)

Ignore this patch. Will send a better version that syncs the fields
across threads.
diff mbox series

Patch

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index c1de75abe1..2f1e469c94 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -369,12 +369,6 @@  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);
-
-    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;
-    }
 }
 
 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
@@ -2806,8 +2800,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++) {
@@ -2853,6 +2845,22 @@  static int set_side_data(HEVCContext *s)
     return 0;
 }
 
+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 int hevc_frame_start(HEVCContext *s)
 {
     HEVCLocalContext *lc = s->HEVClc;
@@ -2974,6 +2982,9 @@  static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
                 goto fail;
         }
         ret = ff_hevc_decode_nal_sei(gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
+        if (ret < 0)
+            goto fail;
+        ret = export_stream_params_from_sei(s);
         if (ret < 0)
             goto fail;
         break;