From patchwork Fri Feb 23 13:58:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46489 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:26a3:b0:19e:cdac:8cce with SMTP id h35csp994896pze; Fri, 23 Feb 2024 06:36:21 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWcHo2yW+KKplDfOPt2BHAEyMnH+k/QqNYUnfcChh0aUSvqV5050LG6mRIzVm2uhOmniAvTULcC9AfltO7ZC2PLieS/LtiQcVTcBA== X-Google-Smtp-Source: AGHT+IHUDIcBeCvamWulIou8w8EoTOLkcnS3Gc04b82OQfYqjPPbnY1LFDzV3nINE5K0QnHMW2FB X-Received: by 2002:a05:6512:2349:b0:512:e8ee:1753 with SMTP id p9-20020a056512234900b00512e8ee1753mr1389050lfu.56.1708698981140; Fri, 23 Feb 2024 06:36:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708698981; cv=none; d=google.com; s=arc-20160816; b=tuxhtcQSvkXkEVQKZT5L8LVLVkFF4qKp5eUNdD6UtZQfrhZMmaEA0IgnRIaB8fIFRU RwKmpW5os/AWlNM464Ezsj32dLyCNqeEpwDk82s9L6bbJk5PAZqgM7DLwfsMc46aaoKG STiR3pR7ELvnxreZ1SqQD6DrLTjGSBQv4oTvSO9nSGKG8QGRJn8hSlbd8yIfSf3KAfkH a5/9vA1gKri2E7u5S962L5zBWcEg7ObvJmeYw86ifseidJVcmCN1RoTkja763FD2b5AK ryiIBuBhKJp48rMPV73yUdL+A6bnRpLneMtOUREisvcqiRxjdJ23eaviKHzNsURIKpM5 MYZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=MUxoQaqxA477baRfs9WqvZ1yNuWpe1xqNvOx5gCx1s8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=cFSpfSbea4+Mkznn/3uULIaEPt6HBDdUIspoaHm73Edpn1/SYpcqRrPJSKBIvhVwSj B958zLu3VCkDv9lnjtK1ATVvsobDWz9uStp2BQetBoG7F4HhdBeW58EnqBM1Ezu0SR6T 3TLB/w7HkVh3oFUZbQ0MaN8kR6//B12IRG8p0f4uRMtuYHvgiKM8UOCdA4ti6kYthIGb OFVoF26YZUNc67EnJX4LxUgMhAd9JkVCFLe1l+3HrT0vCqpxXfIgQPBUBETyZgF2Okcr IRCSZjKbO0vFZ89Rqb9cRxVGCBXrRNNUBEedR8co+Lz5XbynXOPqdU/8kZI+o6kcDmo3 DIRQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=WoH1J8XZ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a13-20020a50e70d000000b005640d58d562si6216512edn.534.2024.02.23.06.36.20; Fri, 23 Feb 2024 06:36:21 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=WoH1J8XZ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 35B5968CC83; Fri, 23 Feb 2024 16:32:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B83C68C65D for ; Fri, 23 Feb 2024 16:31:36 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=WoH1J8XZ; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 9713B4492 for ; Fri, 23 Feb 2024 15:31:35 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 1yeBEU58KE8p for ; Fri, 23 Feb 2024 15:31:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1708698688; bh=6DEebR0jC1id8uZaGunwqDr65EbnBbxlITvUEVx3PqU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WoH1J8XZlWSHtKV0yqMIIGH2CKXJYSgsV0hijMZPFSJ4k9KqQekTk/GmXyCcCMKwV 9fdu5S6UDsYL2THVtzbfAt+6KPB/Zo1+4cgzkKIRJFuCNKtL6l4Wf6a3X9mTvY3Deh DvN13c2SDyPXgAWd/f8wZbybO0kH2hnDLYuRrcXaQtVzNW/UHp2iOPZ+f17gYdghqL 9IkVV+KaueBcDhgsKYV8p21LPkGY4QebR0i1MUq06aQ7q0yKJKmTvy8pBqR3B/mSEA mFgHihKZmLKnU8JMVGDJNtC6Sy+pO3qFlTMEx8IWE2HnplgVREsUStlixphWNQbsCl pSbyxc3qzCaVA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 490104D69 for ; Fri, 23 Feb 2024 15:31:28 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8F4D63A2761 for ; Fri, 23 Feb 2024 15:31:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Feb 2024 14:58:59 +0100 Message-ID: <20240223143115.16521-38-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240223143115.16521-1-anton@khirnov.net> References: <20240223143115.16521-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 37/38] lavc/*dec: use side data preference for mastering display/content light metadata X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: D1QGRjPvm8Ad --- libavcodec/av1dec.c | 46 +++++++++++--------- libavcodec/h2645_sei.c | 96 +++++++++++++++++++++++------------------- libavcodec/libdav1d.c | 47 ++++++++++++--------- libavcodec/pngdec.c | 54 ++++++++++++++---------- libavcodec/qsvdec.c | 50 +++++++++++++--------- 5 files changed, 165 insertions(+), 128 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 4fcfed3c7b..177c25f394 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -990,31 +990,39 @@ static int export_metadata(AVCodecContext *avctx, AVFrame *frame) int ret = 0; if (s->mdcv) { - AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame); - if (!mastering) - return AVERROR(ENOMEM); + AVMasteringDisplayMetadata *mastering; - for (int i = 0; i < 3; i++) { - mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16); - mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16); + ret = ff_decode_mastering_display_new(avctx, frame, &mastering); + if (ret < 0) + return ret; + + if (mastering) { + for (int i = 0; i < 3; i++) { + mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16); + mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16); + } + mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16); + mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16); + + mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8); + mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14); + + mastering->has_primaries = 1; + mastering->has_luminance = 1; } - mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16); - mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16); - - mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8); - mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14); - - mastering->has_primaries = 1; - mastering->has_luminance = 1; } if (s->cll) { - AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame); - if (!light) - return AVERROR(ENOMEM); + AVContentLightMetadata *light; - light->MaxCLL = s->cll->max_cll; - light->MaxFALL = s->cll->max_fall; + ret = ff_decode_content_light_new(avctx, frame, &light); + if (ret < 0) + return ret; + + if (light) { + light->MaxCLL = s->cll->max_cll; + light->MaxFALL = s->cll->max_fall; + } } while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) { diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index f3497d5568..86a4c21820 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -516,6 +516,7 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, int seed) { H2645SEIFramePacking *fp = &sei->frame_packing; + int ret; if (fp->present && is_frame_packing_type_valid(fp->arrangement_type, codec_id) && @@ -711,56 +712,63 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, const int chroma_den = 50000; const int luma_den = 10000; int i; - AVMasteringDisplayMetadata *metadata = - av_mastering_display_metadata_create_side_data(frame); - if (!metadata) - return AVERROR(ENOMEM); + AVMasteringDisplayMetadata *metadata; - for (i = 0; i < 3; i++) { - const int j = mapping[i]; - metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0]; - metadata->display_primaries[i][0].den = chroma_den; - metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1]; - metadata->display_primaries[i][1].den = chroma_den; + ret = ff_decode_mastering_display_new(avctx, frame, &metadata); + if (ret < 0) + return ret; + + if (metadata) { + for (i = 0; i < 3; i++) { + const int j = mapping[i]; + metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0]; + metadata->display_primaries[i][0].den = chroma_den; + metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1]; + metadata->display_primaries[i][1].den = chroma_den; + } + metadata->white_point[0].num = sei->mastering_display.white_point[0]; + metadata->white_point[0].den = chroma_den; + metadata->white_point[1].num = sei->mastering_display.white_point[1]; + metadata->white_point[1].den = chroma_den; + + metadata->max_luminance.num = sei->mastering_display.max_luminance; + metadata->max_luminance.den = luma_den; + metadata->min_luminance.num = sei->mastering_display.min_luminance; + metadata->min_luminance.den = luma_den; + metadata->has_luminance = 1; + metadata->has_primaries = 1; + + av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); + av_log(avctx, AV_LOG_DEBUG, + "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n", + av_q2d(metadata->display_primaries[0][0]), + av_q2d(metadata->display_primaries[0][1]), + av_q2d(metadata->display_primaries[1][0]), + av_q2d(metadata->display_primaries[1][1]), + av_q2d(metadata->display_primaries[2][0]), + av_q2d(metadata->display_primaries[2][1]), + av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); + av_log(avctx, AV_LOG_DEBUG, + "min_luminance=%f, max_luminance=%f\n", + av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); } - metadata->white_point[0].num = sei->mastering_display.white_point[0]; - metadata->white_point[0].den = chroma_den; - metadata->white_point[1].num = sei->mastering_display.white_point[1]; - metadata->white_point[1].den = chroma_den; - - metadata->max_luminance.num = sei->mastering_display.max_luminance; - metadata->max_luminance.den = luma_den; - metadata->min_luminance.num = sei->mastering_display.min_luminance; - metadata->min_luminance.den = luma_den; - metadata->has_luminance = 1; - metadata->has_primaries = 1; - - av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); - av_log(avctx, AV_LOG_DEBUG, - "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n", - av_q2d(metadata->display_primaries[0][0]), - av_q2d(metadata->display_primaries[0][1]), - av_q2d(metadata->display_primaries[1][0]), - av_q2d(metadata->display_primaries[1][1]), - av_q2d(metadata->display_primaries[2][0]), - av_q2d(metadata->display_primaries[2][1]), - av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); - av_log(avctx, AV_LOG_DEBUG, - "min_luminance=%f, max_luminance=%f\n", - av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); } if (sei->content_light.present) { - AVContentLightMetadata *metadata = - av_content_light_metadata_create_side_data(frame); - if (!metadata) - return AVERROR(ENOMEM); - metadata->MaxCLL = sei->content_light.max_content_light_level; - metadata->MaxFALL = sei->content_light.max_pic_average_light_level; + AVContentLightMetadata *metadata; - av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); - av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", - metadata->MaxCLL, metadata->MaxFALL); + ret = ff_decode_content_light_new(avctx, frame, &metadata); + if (ret < 0) + return ret; + + if (metadata) { + metadata->MaxCLL = sei->content_light.max_content_light_level; + metadata->MaxFALL = sei->content_light.max_pic_average_light_level; + + av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); + av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", + metadata->MaxCLL, metadata->MaxFALL); + } } return 0; diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index f002c994c1..f9a92d10d3 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -507,33 +507,38 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (p->mastering_display) { - AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame); - if (!mastering) { - res = AVERROR(ENOMEM); + AVMasteringDisplayMetadata *mastering; + + res = ff_decode_mastering_display_new(c, frame, &mastering); + if (res < 0) goto fail; + + if (mastering) { + for (int i = 0; i < 3; i++) { + mastering->display_primaries[i][0] = av_make_q(p->mastering_display->primaries[i][0], 1 << 16); + mastering->display_primaries[i][1] = av_make_q(p->mastering_display->primaries[i][1], 1 << 16); + } + mastering->white_point[0] = av_make_q(p->mastering_display->white_point[0], 1 << 16); + mastering->white_point[1] = av_make_q(p->mastering_display->white_point[1], 1 << 16); + + mastering->max_luminance = av_make_q(p->mastering_display->max_luminance, 1 << 8); + mastering->min_luminance = av_make_q(p->mastering_display->min_luminance, 1 << 14); + + mastering->has_primaries = 1; + mastering->has_luminance = 1; } - - for (int i = 0; i < 3; i++) { - mastering->display_primaries[i][0] = av_make_q(p->mastering_display->primaries[i][0], 1 << 16); - mastering->display_primaries[i][1] = av_make_q(p->mastering_display->primaries[i][1], 1 << 16); - } - mastering->white_point[0] = av_make_q(p->mastering_display->white_point[0], 1 << 16); - mastering->white_point[1] = av_make_q(p->mastering_display->white_point[1], 1 << 16); - - mastering->max_luminance = av_make_q(p->mastering_display->max_luminance, 1 << 8); - mastering->min_luminance = av_make_q(p->mastering_display->min_luminance, 1 << 14); - - mastering->has_primaries = 1; - mastering->has_luminance = 1; } if (p->content_light) { - AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame); - if (!light) { - res = AVERROR(ENOMEM); + AVContentLightMetadata *light; + + res = ff_decode_content_light_new(c, frame, &light); + if (res < 0) goto fail; + + if (light) { + light->MaxCLL = p->content_light->max_content_light_level; + light->MaxFALL = p->content_light->max_frame_average_light_level; } - light->MaxCLL = p->content_light->max_content_light_level; - light->MaxFALL = p->content_light->max_frame_average_light_level; } if (p->itut_t35) { #if FF_DAV1D_VERSION_AT_LEAST(6,9) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 8f409c74b8..de50e6a5b6 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -746,33 +746,41 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame) avctx->bits_per_raw_sample = s->significant_bits; if (s->have_clli) { - AVContentLightMetadata *clli = - av_content_light_metadata_create_side_data(frame); - if (!clli) - return AVERROR(ENOMEM); - /* - * 0.0001 divisor value - * see: https://www.w3.org/TR/png-3/#cLLi-chunk - */ - clli->MaxCLL = s->clli_max / 10000; - clli->MaxFALL = s->clli_avg / 10000; + AVContentLightMetadata *clli; + + ret = ff_decode_content_light_new(avctx, frame, &clli); + if (ret < 0) + return ret; + + if (clli) { + /* + * 0.0001 divisor value + * see: https://www.w3.org/TR/png-3/#cLLi-chunk + */ + clli->MaxCLL = s->clli_max / 10000; + clli->MaxFALL = s->clli_avg / 10000; + } } if (s->have_mdvc) { - AVMasteringDisplayMetadata *mdvc = - av_mastering_display_metadata_create_side_data(frame); - if (!mdvc) - return AVERROR(ENOMEM); - mdvc->has_primaries = 1; - for (int i = 0; i < 3; i++) { - mdvc->display_primaries[i][0] = av_make_q(s->mdvc_primaries[i][0], 50000); - mdvc->display_primaries[i][1] = av_make_q(s->mdvc_primaries[i][1], 50000); + AVMasteringDisplayMetadata *mdvc; + + ret = ff_decode_mastering_display_new(avctx, frame, &mdvc); + if (ret < 0) + return ret; + + if (mdvc) { + mdvc->has_primaries = 1; + for (int i = 0; i < 3; i++) { + mdvc->display_primaries[i][0] = av_make_q(s->mdvc_primaries[i][0], 50000); + mdvc->display_primaries[i][1] = av_make_q(s->mdvc_primaries[i][1], 50000); + } + mdvc->white_point[0] = av_make_q(s->mdvc_white_point[0], 50000); + mdvc->white_point[1] = av_make_q(s->mdvc_white_point[1], 50000); + mdvc->has_luminance = 1; + mdvc->max_luminance = av_make_q(s->mdvc_max_lum, 10000); + mdvc->min_luminance = av_make_q(s->mdvc_min_lum, 10000); } - mdvc->white_point[0] = av_make_q(s->mdvc_white_point[0], 50000); - mdvc->white_point[1] = av_make_q(s->mdvc_white_point[1], 50000); - mdvc->has_luminance = 1; - mdvc->max_luminance = av_make_q(s->mdvc_max_lum, 10000); - mdvc->min_luminance = av_make_q(s->mdvc_min_lum, 10000); } return 0; diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index d688a17c41..4f39f6942a 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -651,42 +651,50 @@ static int qsv_export_film_grain(AVCodecContext *avctx, mfxExtAV1FilmGrainParam static int qsv_export_hdr_side_data(AVCodecContext *avctx, mfxExtMasteringDisplayColourVolume *mdcv, mfxExtContentLightLevelInfo *clli, AVFrame *frame) { + int ret; + // The SDK re-uses this flag for HDR SEI parsing if (mdcv->InsertPayloadToggle) { - AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame); + AVMasteringDisplayMetadata *mastering; const int mapping[3] = {2, 0, 1}; const int chroma_den = 50000; const int luma_den = 10000; int i; - if (!mastering) - return AVERROR(ENOMEM); + ret = ff_decode_mastering_display_new(avctx, frame, &mastering); + if (ret < 0) + return ret; - for (i = 0; i < 3; i++) { - const int j = mapping[i]; - mastering->display_primaries[i][0] = av_make_q(mdcv->DisplayPrimariesX[j], chroma_den); - mastering->display_primaries[i][1] = av_make_q(mdcv->DisplayPrimariesY[j], chroma_den); + if (mastering) { + for (i = 0; i < 3; i++) { + const int j = mapping[i]; + mastering->display_primaries[i][0] = av_make_q(mdcv->DisplayPrimariesX[j], chroma_den); + mastering->display_primaries[i][1] = av_make_q(mdcv->DisplayPrimariesY[j], chroma_den); + } + + mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den); + mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den); + + mastering->max_luminance = av_make_q(mdcv->MaxDisplayMasteringLuminance, luma_den); + mastering->min_luminance = av_make_q(mdcv->MinDisplayMasteringLuminance, luma_den); + + mastering->has_luminance = 1; + mastering->has_primaries = 1; } - - mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den); - mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den); - - mastering->max_luminance = av_make_q(mdcv->MaxDisplayMasteringLuminance, luma_den); - mastering->min_luminance = av_make_q(mdcv->MinDisplayMasteringLuminance, luma_den); - - mastering->has_luminance = 1; - mastering->has_primaries = 1; } // The SDK re-uses this flag for HDR SEI parsing if (clli->InsertPayloadToggle) { - AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame); + AVContentLightMetadata *light; - if (!light) - return AVERROR(ENOMEM); + ret = ff_decode_content_light_new(avctx, frame, &light); + if (ret < 0) + return ret; - light->MaxCLL = clli->MaxContentLightLevel; - light->MaxFALL = clli->MaxPicAverageLightLevel; + if (light) { + light->MaxCLL = clli->MaxContentLightLevel; + light->MaxFALL = clli->MaxPicAverageLightLevel; + } } return 0;