From patchwork Fri Mar 8 13:21:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 46906 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c995:b0:1a1:738b:6bc0 with SMTP id gy21csp932924pzb; Fri, 8 Mar 2024 05:22:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXL1tRqxTWEcTl9wVmoVRYoyowaMYlCCKIlbnLGdooDY9jBEZIyQZlpdeqRcM75OXjUQl23VZjY6ePXsNygIhQzLznlRTxrLg75Yw== X-Google-Smtp-Source: AGHT+IE6NZMoltZalUYExQteiCf6fylFjZpxlSzlN3mf6axTs4Gosm6n3ZF1vkq0s2f6tpubyZV5 X-Received: by 2002:a17:906:a8c:b0:a43:f66a:17f7 with SMTP id y12-20020a1709060a8c00b00a43f66a17f7mr14447240ejf.19.1709904132035; Fri, 08 Mar 2024 05:22:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709904132; cv=none; d=google.com; s=arc-20160816; b=xKndgXFhSfGoKkZiK3Ne8vEo6bXVzrIqp2gjkTDJsXitihMZTpQmI6K64TB02IpTi2 xeEFnnqMZ5wAuh8SW640gslnmw6ThXxZa8PDfF9X1TU15/vFRTKtPgyKwSK/zLjYsjNQ n4xxiMUJxwWipI+sdkUCbf9esEcy8EtLwN0VVA6fhGHLL7LKYKDUSLFNoPkEUB+DKYvk pG3+QuaGf/K03oCPcOWJxeCcWfx3vwxp0EqhGGECY1LnxQcpan1nUh5WYXvLzZLjFCmN K7kKeaSIFjXqZi0USLxm4isj4vbWo6NoOvE9CB+wue8mnsst/Q83pvBLkL+VgLobzT5B 32+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=qxygCAuqb+SQB5uWTst6B7KCRWbhm0ihiGXbxquM4Bk=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=YpVqR1m8Q0TfDuPpbmBhbtX0+6TcCPCvaK+JfZJx43bkwn7Ppfhfu2JEI8M1Ufzo3n DFTepeql1GWP903iqUYgr6rwR+EGbVi5mB4S67ssONB/jJFmf99EyCdaij4VfHGtEx0H Y4/8VuZ7JDyJgdIBafzfiHUdcjRt6Q8DcqJwZlKSQGuPKEBoqkgxtBg3EwLItz5B7yA/ 10hZzCfxzZe2NVVMYDCVeCpZ9SrU12k5lyDeaJf7ItLJMHfRmAB8N9E7MRTXtmGvUNkw DKTA7cNu4jZBZ7rnrFLtXmBEwsYauTJhVZ4OCGKgQq9pNrz6UxuFWTeSkX2EGiTkZOtq 7K9Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Kfujc8mv; 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 hz3-20020a1709072ce300b00a45e221043bsi1030141ejc.239.2024.03.08.05.22.11; Fri, 08 Mar 2024 05:22:12 -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=@haasn.xyz header.s=mail header.b=Kfujc8mv; 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 5295068CFC8; Fri, 8 Mar 2024 15:22:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 01B5D68CF3F for ; Fri, 8 Mar 2024 15:22:02 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1709904122; bh=Py7NaqLtup8Xk0KHrwdWzKY/2vPLIU/lJkgLEe1P1sU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kfujc8mvu/iyiebqiOEdBX5wMbrrpwSRNuyB3+CHtmKAKgArblbDByBdIDn9hmoo6 WB3BmZWNk2XuHY0IPeeHtqP1GM18x/gPNctMA2qTGF9/HNprE18R8ghyb2UW37FH3/ VC1mHegFoa4PkhQHS7DhQxbbesnoCExV3LehtnPs= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id CC1744197E; Fri, 8 Mar 2024 14:22:02 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Mar 2024 14:21:08 +0100 Message-ID: <20240308132108.28337-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240308132108.28337-1-ffmpeg@haasn.xyz> References: <20240308132108.28337-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/4] avcodec/h2645_sei: decode AFGS1 T.35 SEI 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SlMGb1RNHPqM From: Niklas Haas Changes from v1: - fixed field size of provider_oriented_code (8 instead of 16 bits) --- I restricted this SEI to HEVC for now, until I see a H.264 sample. --- libavcodec/Makefile | 2 +- libavcodec/h2645_sei.c | 38 ++++++++++++++++++++++++++++++++++++++ libavcodec/h2645_sei.h | 3 +++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 5d99120aa91..68e5394d84e 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -105,7 +105,7 @@ OBJS-$(CONFIG_H264_SEI) += h264_sei.o h2645_sei.o OBJS-$(CONFIG_HEVCPARSE) += hevc_parse.o hevc_ps.o hevc_data.o \ h2645data.o h2645_parse.o h2645_vui.o OBJS-$(CONFIG_HEVC_SEI) += hevc_sei.o h2645_sei.o \ - dynamic_hdr_vivid.o + dynamic_hdr_vivid.o aom_film_grain.o OBJS-$(CONFIG_HPELDSP) += hpeldsp.o OBJS-$(CONFIG_HUFFMAN) += huffman.o OBJS-$(CONFIG_HUFFYUVDSP) += huffyuvdsp.o diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index e60606f43f9..d6452e8fbfa 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -209,6 +209,24 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, } break; } + case 0x5890: { // aom_provider_code + const uint16_t aom_grain_provider_oriented_code = 0x0001; + uint16_t provider_oriented_code; + + if (!IS_HEVC(codec_id)) + goto unsupported_provider_code; + + if (bytestream2_get_bytes_left(gb) < 2) + return AVERROR_INVALIDDATA; + + provider_oriented_code = bytestream2_get_byteu(gb); + if (provider_oriented_code == aom_grain_provider_oriented_code) { + return ff_aom_parse_film_grain_sets(&h->aom_film_grain, + gb->buffer, + bytestream2_get_bytes_left(gb)); + } + break; + } unsupported_provider_code: #endif default: @@ -692,6 +710,25 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; } +#if CONFIG_HEVC_SEI + if (sei->aom_film_grain.enable) { + const AVFilmGrainAOMParamSet *fgps; + fgps = ff_aom_select_film_grain_set(&sei->aom_film_grain, frame); + if (fgps && fgps->apply_grain) { + AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); + if (!fgp) + return AVERROR(ENOMEM); + + fgp->type = AV_FILM_GRAIN_PARAMS_AV1; + fgp->seed = fgps->grain_seed; + fgp->codec.aom = fgps->params; + + if (avctx) + avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; + } + } +#endif + if (sei->ambient_viewing_environment.present) { H2645SEIAmbientViewingEnvironment *env = &sei->ambient_viewing_environment; @@ -788,4 +825,5 @@ void ff_h2645_sei_reset(H2645SEI *s) s->ambient_viewing_environment.present = 0; s->mastering_display.present = 0; s->content_light.present = 0; + s->aom_film_grain.enable = 0; } diff --git a/libavcodec/h2645_sei.h b/libavcodec/h2645_sei.h index 0ebf48011af..e5fcfd4e0c2 100644 --- a/libavcodec/h2645_sei.h +++ b/libavcodec/h2645_sei.h @@ -23,7 +23,9 @@ #include "libavutil/buffer.h" #include "libavutil/frame.h" +#include "libavutil/film_grain_params.h" +#include "aom_film_grain.h" #include "avcodec.h" #include "bytestream.h" #include "codec_id.h" @@ -132,6 +134,7 @@ typedef struct H2645SEI { H2645SEIAmbientViewingEnvironment ambient_viewing_environment; H2645SEIMasteringDisplay mastering_display; H2645SEIContentLight content_light; + AVFilmGrainAOMParamSets aom_film_grain; } H2645SEI; enum {