From patchwork Mon Mar 4 13:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46769 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a919:b0:19e:cdac:8cce with SMTP id cd25csp2790785pzb; Mon, 4 Mar 2024 05:10:58 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXMHG5gHpglV8MnfGnS1Vs0M+Bl+wojxpJ9Vp3ylrc6Lj9UstNvuzIeKIS3rvJGNP+9Nk+7XBarO5IoznanwQCjDBHHPrS+qRuzFg== X-Google-Smtp-Source: AGHT+IHozJs/v1RKcgxDG3YdmM2sM6Du/h3Z4MVRQ5PRDWvBoWqD0y3pUomBpzQ98akZK34IzBc9 X-Received: by 2002:a17:906:f355:b0:a3f:da1c:ae4c with SMTP id hg21-20020a170906f35500b00a3fda1cae4cmr6873382ejb.54.1709557858251; Mon, 04 Mar 2024 05:10:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709557858; cv=none; d=google.com; s=arc-20160816; b=ZW3UsrDHesOKxqDvBTd7Jayq8YoN8f7k0ekJ/7QlKqgXPxgX/WjKsZne+HX5rIGzvy Ir200smXweo3NUdUAjUzc3W/bEHse4eSvRENQWai7MyLV177UAUj5vjRu6zJcfnS1uVp BuPFAngsHCIru8I7osRtzFf16uTPT6atwMX/qOOI3FWh8qZ4v9AXBB5ovIWuMm9Vhl4P VIRzBx6673BeyeYD3tuACwvooHF2U86x91D7p2HOVLxzQiR3RanEYM6bZrrcz8BbW9BU 2Sx3NoUmIE40gPP7HfF6ZfomoauIDNWp/ZJEpzVvwj5NiwRW74iFsWeIbtRdZpaOQgJA 3eNw== 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=csr3ZQpR7hgAQAQmdD4dLwzwTVLyTgRE8emRGyCpGTQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=d99/DHjcYdDUKdjGwqNDKkduLf8H60HHbVV+CmTGOnNY8d3MdlcsABWr2ttB2tH5XO axM0GbhqjIRYGYij+DIEubRa7J9CPdx3Hd3aCDyzGiVd4zz1bTgZkXFpvl8n+SdOny19 DITbvv7FYAzGJ2PrA7Saf+8iOuuutGtKVyh48W3jXG5yrUEFYWkF8qh4pWHum5CRNb5S KAVh3LEZoRq1oKGw8d1CobLOJKrCCr6Ak0L5KiLBNwHFzqj9k8HKqB6AJygbdQGymtYA uePGcAV9B5+nbM8uXqcGnk6Ov2HVs6mjpJeRf8aZCzYCOil4tDToXBp73NiwOGoMa7Jp 0IDA==; 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=dVXc4SW5; 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 s8-20020a170906354800b00a441a40c035si3887170eja.279.2024.03.04.05.10.57; Mon, 04 Mar 2024 05:10:58 -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=dVXc4SW5; 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 914D868D4B9; Mon, 4 Mar 2024 15:07:36 +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 87AB068D449 for ; Mon, 4 Mar 2024 15:07:14 +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=dVXc4SW5; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C891A4D6E for ; Mon, 4 Mar 2024 14:07:11 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id UOiBAQGySvR9 for ; Mon, 4 Mar 2024 14:07:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709557626; bh=RVrzhR7gskFiiLWNGQIW6b8OMsCx2UapVHvL/6tJaoo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dVXc4SW5DtWeYwEzACygijW7tNlNaGBkM0S8KetbCcymH6o4QItd33uBOh2n8Cv1l RDYqGih5KdEgjfklfQMuX4ZpZkuA1NutzFfgA0E6GDTOZhHThp4v/qtfhAJiVnjg/l NyU2Lpeeb3+Pbvk4HYfPfCM+Bk49Qg+PBAZA+9uJGbNiO9NLZg1doW4jLePhE8MYVn SjdO4qvc8t1AMW43DwMdOyTpNlGgN6hkJ0cDmnVdlD+l7oEkqsGddYOiFtBafQiDq+ XxVNmHKe1LTXsNCScIqxPYOPIcwlj6NzDKttoTDsXffwS+EL1LhGfbu+tJiGkeBU1o GUj0aEMu3Y/og== 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 BCF8B4D72 for ; Mon, 4 Mar 2024 14:07:06 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 308A33A186B for ; Mon, 4 Mar 2024 14:07:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 14:06:43 +0100 Message-ID: <20240304130657.30631-28-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304130657.30631-1-anton@khirnov.net> References: <20240304130657.30631-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/29] 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: FK/5SBE/i4on --- 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 af80ee0b17..bbb5634773 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -999,31 +999,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 56539608cd..a9d17cc9fd 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) && @@ -710,56 +711,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 3714137ed0..42d3ef00de 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;