From patchwork Sun Feb 25 11:44:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 46518 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51b:b0:19e:cdac:8cce with SMTP id gm27csp835835pzb; Sun, 25 Feb 2024 03:45:17 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXYRcKCDLg1A/1uva8Wuhu9O4+LaZdTX3+RkDHbUYIe/NRamPlDOec1oPYXCNtSkCYD06VniAEwBvFG5mo8wWrbiC2A1aZC+zBPqg== X-Google-Smtp-Source: AGHT+IFBxq8t4nMMeCwBln7AKkOe3EkNQk8CqDhA1+3SRsG5S6xazUueXREh6fsuu4yde1QPAypE X-Received: by 2002:a50:d492:0:b0:565:a4dc:b288 with SMTP id s18-20020a50d492000000b00565a4dcb288mr2002162edi.4.1708861516801; Sun, 25 Feb 2024 03:45:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708861516; cv=none; d=google.com; s=arc-20160816; b=S9wbQa1YgqQgtK/+RZMLCNEQXZLbAK9hPlzSbLYYtfxcyemktenXnHLkSh6nelHHZF z6m9TX+quu7cQYoRyMVHndfUkES+lgJSazcey2rtHxunmfsFV+74pO9HvhWXmjt/ykF6 IxkVrt63xlY3n/o96bg9AR+nOn1zn4I4MxJ5Vdl9fKo0xGZywR10Dc9h0HtOUGLSyhW0 pRJGUmzjTBbOTKSjjcc9xL6xhy6pVc7CvpoEahXsYwHHaLmDQ0kDfUkx6HrBoLmbE1bN Pyb2FruT7e+5sbrhPLNirV/JLJ7hPnyYyWJFFTDU+BZh3pX2AzVCCqnUxjgt6S6IMQRj wfNg== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=h2v7LFofIInDDU3oBKfdw8gTs/KK14+/KUopDujYTLw=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=njFZfKZch3YHtFHt1nTb7iFJrf4G08nUYN59MFsqXBqekW/0fEPeaDTjtkuDuulxkb UGSfAOqjHEBJuX/NMnl9XZ30XO2bha3uUxZlHzbLd8mNaXSVeAJu6ZCmvPxl6oBsXUDy z1dq7UpTDcakuqtZFhDXup5fvPYRGnYVbi4eH/d7wsb1DMom/2hXlOadMg7543UYDZvt U44To7PJwieMkoskdJZP7v3UHeDQLqR1wy+N/VWLhGibZXsRoxsltXfJaen9IDccuHrh rteMFJR9ny5htNBU6Su3EoaQNMWDczofdkzQrTYkDoo8donjlgCcTrbnhoe0WhVfmqpM u9yg==; 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="AG/iHUYr"; 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 a19-20020a05640213d300b00565aec519f8si1058165edx.191.2024.02.25.03.45.16; Sun, 25 Feb 2024 03:45:16 -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="AG/iHUYr"; 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 9AD7268C6D3; Sun, 25 Feb 2024 13:45:04 +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 E479E68C69F for ; Sun, 25 Feb 2024 13:44:56 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1708861495; bh=iLkfkvfB5KD1Yy/5WOkrxf1LtXtVoqpKduf/4gCs87w=; h=From:To:Cc:Subject:Date:From; b=AG/iHUYrQchsYfdmTXQJSjRq+MJu8gF5MUNl1IZHbtrdKf/EVNG7+XzgUzj+UFN2S a19QU9TM1MiSzb5d9np/1LATQTPBvHET5sEbM/QGfWzUhekFjHqGfAkULSZmsYJnj4 PWAswJXbduPdBnJtaiPYVf4tF+J9ddv1YTdPaKq4= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 240B540E23; Sun, 25 Feb 2024 12:44:55 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Feb 2024 12:44:49 +0100 Message-ID: <20240225114451.27645-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/dovi_rpu: implement support for profile 10 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: LzLdaFyMxHV5 From: Niklas Haas Instead of the nal_prefix, this profile inside wraps the RPU inside an EMDF header, as specified in ETSI TS 102 366. This particular usage is supposedly specified in ETSI TS 103 572, at least according to European Patent EP 3 588 964 A1, but I could not find any references to DV RPUs in the former. It's worth pointing out that the EMDF container is not byte-aligned, meaning that payloads are delivered at arbitrary byte boundaries. Hence the reason for doing it inside ff_dovi_rpu_parse, which already uses a bitstream reader, rather than splitting off the container in a separate stage. (Plus, we hard-code the DV-specific payload ID) Magic values were taken from a combination of the sources below, all of which agree about what the specific EMDF header should look like. In fact, they all hard-code a very *specific* header sequence, but I wanted to go the extra mile and at least properly skip the variable fields - even though the non-existent Dolby Vision specification probably specifies that they all must be 0. This is probably overkill. Validated and tested using sample files from the merge request linked below. Relevant links: - https://www.etsi.org/deliver/etsi_ts/102300_102399/102366/01.04.01_60/ts_102366v010401p.pdf - https://patentimages.storage.googleapis.com/8a/0b/da/28294acaed2182/EP3588964A1.pdf - https://www.etsi.org/deliver/etsi_ts/103500_103599/103572/01.03.01_60/ts_103572v010301p.pdf - https://github.com/rockchip-linux/mpp/blob/fdeb8c378b79d4b4ef80457e4431815de89dc417/mpp/codec/dec/av1/av1d_cbs.c#L2378 - https://github.com/elginsk8r/android_kernel_amlogic_linux-4.9/blob/23a4c38bf06ef34821e476a8edddbf9213712c8a/drivers/amlogic/media/enhancement/amdolby_vision/amdolby_vision.c#L5638 - https://gitlab.com/mbunkus/mkvtoolnix/-/merge_requests/2254 --- libavcodec/dovi_rpu.c | 68 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c index a6b23f4dd11..c7cdd65a2f2 100644 --- a/libavcodec/dovi_rpu.c +++ b/libavcodec/dovi_rpu.c @@ -174,6 +174,18 @@ static inline int64_t get_se_coef(GetBitContext *gb, const AVDOVIRpuDataHeader * return 0; /* unreachable */ } +static inline unsigned get_variable_bits(GetBitContext *gb, int n) +{ + unsigned int value = get_bits(gb, n); + int read_more = get_bits1(gb); + while (read_more) { + value = (value + 1) << n; + value += get_bits(gb, n); + read_more = get_bits1(gb); + }; + return value; +} + #define VALIDATE(VAR, MIN, MAX) \ do { \ if (VAR < MIN || VAR > MAX) { \ @@ -200,9 +212,59 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0) return ret; - /* RPU header, common values */ - nal_prefix = get_bits(gb, 8); - VALIDATE(nal_prefix, 25, 25); + /* Container header */ + if (s->dv_profile == 10 /* dav1.10 */) { + /* DV inside AV1 re-uses EMDF container, parse header */ + int emdf_version, key_id, emdf_payload_id, emdf_payload_size, smploffste; + emdf_version = get_bits(gb, 2); + if (emdf_version == 3) + emdf_version += get_variable_bits(gb, 2); + key_id = get_bits(gb, 3); + if (key_id == 7) + key_id += get_variable_bits(gb, 3); + emdf_payload_id = get_bits(gb, 5); + if (emdf_payload_id == 0x1F) + emdf_payload_id += get_variable_bits(gb, 5); + + /* Magic values taken from amlogic and rockchip drivers, and also + * match values found in practice (and validated in hardware) */ + VALIDATE(key_id, 6, 6); + VALIDATE(emdf_payload_id, 256, 256); + + /* Note: In theory, there could be multiple payloads, and we should + * skip over the unused payloads until we find the one we're interested + * in. But this capability does not seem to be used in practice, so + * the DV-specific usage of EMDF probably requires only one payload + * per T.35 OBU */ + + /* Skip emdf_payload_config() */ + if ((smploffste = get_bits1(gb))) + skip_bits(gb, 11 + 1); + if (get_bits1(gb)) /* duratione */ + get_variable_bits(gb, 11); + if (get_bits1(gb)) /* groupide */ + get_variable_bits(gb, 2); + if (get_bits1(gb)) /* codecdatae */ + skip_bits(gb, 8); + if (!get_bits1(gb)) { /* discard_unknown_payload */ + int payload_frame_aligned; + if (!smploffste) { + if ((payload_frame_aligned = get_bits1(gb))) + skip_bits(gb, 1 + 1); + } + if (smploffste || payload_frame_aligned) + skip_bits(gb, 5 + 2); + } + + emdf_payload_size = get_variable_bits(gb, 8); + if (emdf_payload_size * 8 > get_bits_left(gb)) + return AVERROR_INVALIDDATA; + } else { + nal_prefix = get_bits(gb, 8); + VALIDATE(nal_prefix, 25, 25); + } + + /* RPU header */ rpu_type = get_bits(gb, 6); if (rpu_type != 2) { av_log(s->logctx, AV_LOG_WARNING, "Unrecognized RPU type " From patchwork Sun Feb 25 11:44:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 46517 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51b:b0:19e:cdac:8cce with SMTP id gm27csp835787pzb; Sun, 25 Feb 2024 03:45:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXVjY6hwWXmjYG12ED1pNarNutrphNEmPwSSS1PQDvArjmvhChOwkFHJ2SnWQAQKhWoAsQ52r6RPtEIBQkOhhY/AuDjpbE63a7FIw== X-Google-Smtp-Source: AGHT+IGQnTkdW8YVtWs1AszfaOh/wDr+2wio3a+iNgB5DgOMeVOaMMyRjChuhosm8O+vQyU6YZxX X-Received: by 2002:a17:907:1701:b0:a3f:365:2276 with SMTP id le1-20020a170907170100b00a3f03652276mr3696074ejc.34.1708861507417; Sun, 25 Feb 2024 03:45:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708861507; cv=none; d=google.com; s=arc-20160816; b=TRYVA5nJ30Gzq4uq6D0kIXm/TRnVlgZqazKOKN9AhCTWsA1+XKj4xY1Yj6jmvUkxDI 7dkP2A1ZNadFn7YVqcyjBPcy37EGQDrwAKKt3o8JOQWeMabH96ToYPngIhFV4grxdhjJ uItEF6XFp1vV2W6stPOahqei2zps1pAay3lybdkeHEabqXys2QXdanBNO8AC6MbAoVW0 M0AyPxHp8jXqdmTKaPfQceil+ycxfEHZItL5OV9uZlzLp2UN359V1dikvjXWF+U3FFUP QSTkZ8Z8kpunOLtErC54e1vuxIm09uUJcVRt3E5SflgP6MAgDQ8AiOrr8BZNZyR9+Pzs gAOw== 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=TOS7he7Bh4tIu8HkZlY12QyCWzoGE21RL7nSydhHXBU=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=MGfLczX3fXuvXLo5xoim3xfsh/p0AjAn83MA5CUrTxnabk/1pP7owPv2HES4rbzz8N tAtpqSc+jOJ+lwSVpA8sS4rxDRErc1UFH11gdd0KyyJnXyGmma61hyBfXEa/eYxR9pRd 03NwdV1+pyOhjQbG+mn0RX/VZDba+DXRdECjSzoHnw1jbiSm4v2QByay4iJWMNenbZjP HZLdh+UMhI8UR1SpfhDCEoosfnf7cPoNtJ5RklaXK82DQvQ9xAxXRoyBS+1v1rB7yMgv /eENpIjL4LaLdFlvNclh//OOdRTLzn5pIn1YCzfx77RK2vHac7oUH2GX6lnh1yRac+dN E71A==; 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=nmFUJqUL; 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 z22-20020a1709060ad600b00a3e8fc2e91asi1164110ejf.978.2024.02.25.03.45.06; Sun, 25 Feb 2024 03:45:07 -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=nmFUJqUL; 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 756DB68C74E; Sun, 25 Feb 2024 13:45:03 +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 E2A8568C2DC for ; Sun, 25 Feb 2024 13:44:56 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1708861496; bh=l1VGPviuvUL/aBke3Gb4iBwxubotMhVySKnZMxE9QaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nmFUJqULiHF6YBJYwPrfgPqeyVfGG9c5oucjd1Lw2UPRr6LEC7syi7CF2Wswn2Jy+ lTdTZnfNdtVhSyCR6gk/1+dq7hPkJA7P58wND0wcxqjD7NlydB+M8AHWI/3cj0+0VC C+Wc/CfApMjh2rUujQMTs1I7kD/xGlcjDD8IBmf8= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 719C34299C; Sun, 25 Feb 2024 12:44:56 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Feb 2024 12:44:50 +0100 Message-ID: <20240225114451.27645-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240225114451.27645-1-ffmpeg@haasn.xyz> References: <20240225114451.27645-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/libdav1d: parse DV profile 10 T.35 OBU 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: HAOvych5l45B From: Niklas Haas This is thankfully passed through verbatim by libdav1d, so we can parse it in our own code. In theory, taking the DV profile from the packet-level configuration struct is redundant since there is currently only one possible DV level for AV1 (and all others would fail parsing), but this marginally future-proofs it against possible new AV1-specific profiles being added in the future. --- libavcodec/libdav1d.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 78a5c63bf42..9bac4a9eb27 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -35,6 +35,7 @@ #include "bytestream.h" #include "codec_internal.h" #include "decode.h" +#include "dovi_rpu.h" #include "internal.h" #define FF_DAV1D_VERSION_AT_LEAST(x,y) \ @@ -44,6 +45,7 @@ typedef struct Libdav1dContext { AVClass *class; Dav1dContext *c; AVBufferPool *pool; + DOVIContext dovi; int pool_size; Dav1dData data; @@ -213,6 +215,7 @@ static av_cold int libdav1d_init(AVCodecContext *c) #else int threads = (c->thread_count ? c->thread_count : av_cpu_count()) * 3 / 2; #endif + const AVPacketSideData *sd; int res; av_log(c, AV_LOG_VERBOSE, "libdav1d %s\n", dav1d_version()); @@ -285,6 +288,11 @@ static av_cold int libdav1d_init(AVCodecContext *c) c->delay = res > 1 ? res : 0; #endif + dav1d->dovi.logctx = c; + dav1d->dovi.dv_profile = 10; // default for AV1 + sd = ff_get_coded_side_data(c, AV_PKT_DATA_DOVI_CONF); + if (sd && sd->size > 0) + ff_dovi_update_cfg(&dav1d->dovi, (AVDOVIDecoderConfigurationRecord *) sd->data); return 0; } @@ -593,6 +601,22 @@ FF_ENABLE_DEPRECATION_WARNINGS goto fail; break; } + case 0x3B: { // dolby_provider_code + int provider_oriented_code = bytestream2_get_be32(&gb); + if (itut_t35->country_code != 0xB5 || provider_oriented_code != 0x800) + break; + + res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer); + if (res < 0) { + av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n"); + break; // ignore + } + + res = ff_dovi_attach_side_data(&dav1d->dovi, frame); + if (res < 0) + goto fail; + break; + } default: // ignore unsupported provider codes break; } @@ -652,6 +676,7 @@ static av_cold int libdav1d_close(AVCodecContext *c) Libdav1dContext *dav1d = c->priv_data; av_buffer_pool_uninit(&dav1d->pool); + ff_dovi_ctx_unref(&dav1d->dovi); dav1d_data_unref(&dav1d->data); dav1d_close(&dav1d->c); From patchwork Sun Feb 25 11:44:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 46519 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51b:b0:19e:cdac:8cce with SMTP id gm27csp835860pzb; Sun, 25 Feb 2024 03:45:25 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUq0/V77k7cb7WbJWbWEv8VyHtg7o4Omqo6DFegzGJLxtC+OxeZrBxQ+q/YPDO6HK8IJ8puN+7T+/q4+PD00MJ4lVPCu+1tMRT2Jg== X-Google-Smtp-Source: AGHT+IF9gOL465N9x7JDf7MHivZAkU4UqlW12yqI4LhCmW6XHtUXl/ZzK7JLLj3EXVH2mOOcRQ+5 X-Received: by 2002:a17:906:6954:b0:a3f:c49e:54d with SMTP id c20-20020a170906695400b00a3fc49e054dmr3118302ejs.63.1708861525389; Sun, 25 Feb 2024 03:45:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708861525; cv=none; d=google.com; s=arc-20160816; b=CG8d9uYKL4DidnnTJvuf9aeVK+X2hbcDmBjVYlMSr/WtNTtWE2DCEtXgPcawAZHz9Y jawWU+BxV1kk+W16LU2hpm/hybiQ5j2auXAadtFgFArkRzJ+85fhitI1gB+3zu5Fiqt3 jvXZgtC3OO9bi49fvJ48jzF55CYCrfEb7koaQtq78htFzFk/9mIl3ToX97TfwVQ2tsEi 0JFBx4t14S4OozmuAzywpzp0Z2gbbTSLGmf1oJ50Ds6ggEnl9M9zEv2ueeEEdvtSY3m9 D82P3mjmMVuw4abgKl/GOtAC+UxiHr9b6dp49HiOmW0pVqTNqJON5Z19xUrnynvvv1+U k0iQ== 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=Wpp05FRL8CytLa1eDwoJsy+yzotmZ84Zaxmlc+Zn1K4=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=j8vzjJiRrFVW6sb4iyRXKWjiLIhyeFmYS3tfhxwcFtGnqxpztYo/QOmscoah9OonE1 uYiYyP6X/6zXqKWIChx+ZwTAcdEh7sXJxWTDw06xdb+Vmh0ZmPcCGfv1A/722XHf6w3Y wbOlGpRz3sBk1F4531kbkvQMR5dc06tq4q0GaiBov8YyOU8iN+znzlvmapSj2PgkOZKo B2g9os0kMXvBb0c6hlEkRw5xFvWtADz89CJSBDkNFVm0n9IKPRz1xDvd0ubT08Eu2BUK gjgI8H2DrMZWYy+LxWdBB3cmwDqcXVVsyG4Cz7jAD9WtlG7G8ExPfSLRwT55OTV7MEfd vgtw==; 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=HkQ5dvQf; 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 gt20-20020a170906f21400b00a3f11d50d9bsi1247335ejb.914.2024.02.25.03.45.25; Sun, 25 Feb 2024 03:45:25 -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=HkQ5dvQf; 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 111EA68AA09; Sun, 25 Feb 2024 13:45:06 +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 996A168C69F for ; Sun, 25 Feb 2024 13:44:57 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1708861497; bh=2tjRJyihc7W5JF/OzPOzcu0ZWz6cvY8nWNo6yY5f3aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HkQ5dvQfJJ3k3ALMmaFMJZG/1RXQgMn+JxX1uOvYiGuelmOI9gFRIX8SyKgIioMW4 zhEvJms8jIH1uonEq465y5utvijZsWAe9A6hIxYCIjlVmJr4GWkgwkjJ8U6n9EQFXZ olj9Svj7KpI11EKa6n4mBl3NhD/PNXop77djf9r0= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 52E7942A98; Sun, 25 Feb 2024 12:44:57 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Feb 2024 12:44:51 +0100 Message-ID: <20240225114451.27645-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240225114451.27645-1-ffmpeg@haasn.xyz> References: <20240225114451.27645-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/av1dec: parse DV profile 10 T.35 OBU 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: RXuH5Ag1sjUd From: Niklas Haas See previous commit. --- libavcodec/av1dec.c | 25 +++++++++++++++++++++++++ libavcodec/av1dec.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 7debc4dedaa..f42dc77148f 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -727,6 +727,7 @@ static av_cold int av1_decode_free(AVCodecContext *avctx) ff_cbs_fragment_free(&s->current_obu); ff_cbs_close(&s->cbc); + ff_dovi_ctx_unref(&s->dovi); return 0; } @@ -818,6 +819,7 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) { AV1DecContext *s = avctx->priv_data; AV1RawSequenceHeader *seq; + const AVPacketSideData *sd; int ret; s->avctx = avctx; @@ -875,6 +877,12 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) ff_cbs_fragment_reset(&s->current_obu); } + s->dovi.logctx = avctx; + s->dovi.dv_profile = 10; // default for AV1 + sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); + if (sd && sd->size > 0) + ff_dovi_update_cfg(&s->dovi, (AVDOVIDecoderConfigurationRecord *) sd->data); + return ret; } @@ -928,6 +936,7 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame, const AV1RawMetadataITUTT35 *itut_t35) { GetByteContext gb; + AV1DecContext *s = avctx->priv_data; int ret, provider_code; bytestream2_init(&gb, itut_t35->payload, itut_t35->payload_size); @@ -976,6 +985,22 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame, return ret; break; } + case 0x3B: { // dolby_provider_code + int provider_oriented_code = bytestream2_get_be32(&gb); + if (itut_t35->itu_t_t35_country_code != 0xB5 || provider_oriented_code != 0x800) + break; + + ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, gb.buffer_end - gb.buffer); + if (ret < 0) { + av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n"); + break; // ignore + } + + ret = ff_dovi_attach_side_data(&s->dovi, frame); + if (ret < 0) + return ret; + break; + } default: // ignore unsupported provider codes break; } diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index b6a0c08e488..f1d57b39f9a 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -30,6 +30,7 @@ #include "packet.h" #include "cbs.h" #include "cbs_av1.h" +#include "dovi_rpu.h" typedef struct AV1Frame { AVFrame *f; @@ -79,6 +80,7 @@ typedef struct AV1DecContext { AV1RawMetadataHDRCLL *cll; AV1RawOBU *mdcv_ref; ///< RefStruct reference backing mdcv AV1RawMetadataHDRMDCV *mdcv; + DOVIContext dovi; AVFifo *itut_t35_fifo; uint16_t tile_num;