From patchwork Sun Mar 10 14:01:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 46932 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp735217pzb; Sun, 10 Mar 2024 07:02:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUjmt32HZBMuUunZGYCSIAzLQ3xVWv3fBF0ztyYx8QOL2voNeZw2zlv6CA6EHvFlo0xH/EVpUb2UElnfWD4mRIMnxMA7BM6NH/TSA== X-Google-Smtp-Source: AGHT+IHyBaV7Md2clF4aEGFeooydIiHuQlHBKqIBCXMofMaMd06KyKIJlg86HGxmRGfoKTU5lJ0A X-Received: by 2002:a05:6512:4005:b0:513:444c:8a7e with SMTP id br5-20020a056512400500b00513444c8a7emr3769123lfb.56.1710079375076; Sun, 10 Mar 2024 07:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710079375; cv=none; d=google.com; s=arc-20160816; b=VcEZejRh1b7r1BuPwGxcDo8s45uZOljnmyTtR1BoecqNTFCNKiw3LaNhaQStuFxg/n jVt3KHegWMQs85PNSiMNjxMIBI+zRNHhUn7Ak650BtGEMyUSTxu3bAnZIuYUGJMlVRM7 sShBtSIFdn1i+cMV5R5UOn6nUayEEJJViTLEjzpEkbifNPugvL2nhT0zL4tJzkxvZ9hQ y+qTwDgCcIApiE+oLPKJ79U+jIBBhIxGeVDPhOT5lFdVJehdbGFc8CAxGpjSgEbbJd2M Ly4p677fvkGCxPoLals4RgBjTtyfuLydHreXd1bSHuhF1Op2l6FBv+9NVqirM1qrlxn5 SPMQ== 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=hK0cyphOZKNOml3JhLvtsJiEGuCZGau4Gkb10Os4UwA=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=HzLrcK+Y9SdpTmrIaOCIPK0D45ZjROBm11uWwtn3IdUQVkoBufLn1qSwehEKlsxxwf 29hmdbrVxUljrDfcSfkyRu3qaHh0AvSP7xgBt9NLQctz88AoMEA+O+55C+BiiHkeKwvh Cw7NfV4RJc2NdK9C9gZUBeERT1JZcvjE7SIQXB2gtQ/+naDSDvqNhHG6dRJtKWjOcJtg GlHTOcPiQZtsQd67sS1bZ2O28v1FEMJWi41en/ycnYCfquRhrod6PGIfLb236ZVs8GXk CdpFu5bvQB3+sC1BQ1nM7EaA1RdnOS0DsWxFY/WLkEIL4MY2lQjVTRLChJB5QBuAi2zU KSOQ==; 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=EojCEbYi; 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 dn10-20020a17090794ca00b00a43fe0538ecsi1771583ejc.516.2024.03.10.07.02.50; Sun, 10 Mar 2024 07:02:55 -0700 (PDT) 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=EojCEbYi; 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 A6D0A68CE4C; Sun, 10 Mar 2024 16:02:32 +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 B010F68C484 for ; Sun, 10 Mar 2024 16:02:23 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1710079343; bh=X4pBMeVyHlHn+yHCVvrAaQwCxgsK3D3AZDM8GrHajuc=; h=From:To:Cc:Subject:Date:From; b=EojCEbYiPGmr/HoSK6YicfbffuWrk1lT6Os5sesXBpvxeSEOWhOl9whUzm9b9+QJB ntzb/XdnrK+aRwZHVi7IQqRQWH2hxGajjOqYwYtMW3CziovBKsousvIQyNkPmz9pf4 HPsGcnpqrvWhcQpBLsaehIwsOfCzPh/8+Bg/6Z6I= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 06A01424EF; Sun, 10 Mar 2024 15:02:23 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Mar 2024 15:01:11 +0100 Message-ID: <20240310140112.41366-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: LwnDDQSNBZ3j From: Niklas Haas Changes since v1: - Greatly simplified EMDF implementation, after gaining insight to the specification (which states that the emdf header must used certain hard-coded values) - Tested and validated on official samples --- Instead of the nal_prefix, this profile inside wraps the RPU inside an EMDF container, as specified in ETSI TS 102 366. However, this DV-specific EMDF container is restricted (by the specification) to a fixed set of hard-coded parameters, which we can effecitvely treat as a magic byte sequence. Validated and tested using official Dolby sample files, which I unfortunately cannot share. However, there are public sample files available at the merge request link 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://gitlab.com/mbunkus/mkvtoolnix/-/merge_requests/2254 --- libavcodec/dovi_rpu.c | 45 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c index a6b23f4dd11..529062be30a 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,36 @@ 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 an EMDF container skeleton, but with fixed + * values - so we can effectively treat this as a magic byte sequence. + * + * The exact fields are, as follows: + * emdf_version : f(2) = 0 + * key_id : f(3) = 6 + * emdf_payload_id : f(5) = 31 + * emdf_payload_id_ext : var(5) = 225 + * smploffste : f(1) = 0 + * duratione : f(1) = 0 + * groupide : f(1) = 0 + * codecdatae : f(1) = 0 + * discard_unknown_payload : f(1) = 1 + */ + const unsigned header_magic = 0x01be6841u; + unsigned header, emdf_payload_size; + header = get_bits_long(gb, 27); + VALIDATE(header, header_magic, header_magic); + emdf_payload_size = get_variable_bits(gb, 8); + VALIDATE(emdf_payload_size, 6, 512); + 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 Mar 10 14:01:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 46930 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp734974pzb; Sun, 10 Mar 2024 07:02:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVt1R1a4qLF9ENBbOPVOo2qCrDrgFRPNB4I7tnrb9Gqf1JI7fv2rosEYUMLPwKP6x1UZ2tMiRoM1HuNcTLgYpqXWSgsGn0BUrU4aA== X-Google-Smtp-Source: AGHT+IEUYxLkYQNppc3BuJYtxjNaNrutHeuSlfWu3zLtJEaD5IgZmHi6L8GR40t9fSsuepyZOSPO X-Received: by 2002:a17:907:2d11:b0:a45:abec:cff4 with SMTP id gs17-20020a1709072d1100b00a45abeccff4mr3110683ejc.32.1710079355006; Sun, 10 Mar 2024 07:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710079354; cv=none; d=google.com; s=arc-20160816; b=H4NZ584MruFeb2nMNUbHNIZjCcUY1Eirru1T7C7iByCu8WUVmMPidHiLmrSxnqD1uE bLqHTDyOMLpnPsd0H+mhNNJ0qQElsAYWebVBCf1rAJIpRxTijHAgdbtp9Arnwd/+qSVP /X08sSnkZK5fEwIHyQqrC4gxyZFyFpEYyjfEmkwQrJLpxjkpL0JEkQR2sNEcYp4j/LpN ChZ/K2nEMMG5fddaGInTo1Y+/9m5ocI6O/ev9eRkbKn0ZAusTckhMMJi6TqQXkqjC8Kj v7ZVTPCGHN1eAQb5F+Jd6D0iNgM0ul1iaVhovZhWOjrnU76gRJXpffyzI87cLOcJ5FjF TxKA== 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=AhxeUdFC2sQ7R68lDsMjnQ61V39RLdL+T4qncdlI+SM=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=n5wxONdZjP7RAilHBgwHk0VOZ4kVXrKVoa1YqOzC22eKlSPvyCZ2+djiFRCtkxWWZr nZscuH4MNdyj0hr4h5YzMF64i/FWl9A6BtQR+gVnJBRYHuNXwmYWeUmD64KgOU35TuDI mSiMmRThHZW362jYREqiiQXtzOwU8eM4I3eGXWNp+KjwdPQyPrUEkS3gVFWtf1HAutZH kCr0tFtcM4c3jaAx7FYpgtlKigKnS1YYiE+pAhGMVdFQB0BvomKDmrncN54oNol7xh8f 5OYqNhegIMv1cKXyvHQJoXoEHvj37jj1kBXDEgiOdlIPjqhXX9P8mQI9JIj8qu7qosay lGYw==; 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=ciq3d8wq; 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 d9-20020a170906370900b00a442ebff480si1612095ejc.443.2024.03.10.07.02.33; Sun, 10 Mar 2024 07:02:34 -0700 (PDT) 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=ciq3d8wq; 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 AF2EE68CDF4; Sun, 10 Mar 2024 16:02:30 +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 B2F3568CAF7 for ; Sun, 10 Mar 2024 16:02:23 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1710079343; bh=qgT2EKjFPIFUvsJhUFc9II45bStsbbsb9P6LKwmDY/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ciq3d8wq3Xh89xFLLM3nbNZYRODrGKyEp0or5y4fxs/j8eyDlGk9PCvAOuw22IQef tFZRJ5y87BMuvInljh45hKYheXTd+aAVjrltx2ZATAxUB1gg4m4ILW8OSweKg4mgUA uDxM2wMNNpHKVyp0uIC+GHqy4k9xKTt/3aOAEI+w= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 3DED342558; Sun, 10 Mar 2024 15:02:23 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Mar 2024 15:01:12 +0100 Message-ID: <20240310140112.41366-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240310140112.41366-2-ffmpeg@haasn.xyz> References: <20240310140112.41366-2-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: tZWMpgZcu2+g 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 5c4c643696f..1aa2d1f3436 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; } @@ -579,6 +587,22 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) 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; } @@ -638,6 +662,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 Mar 10 14:01:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 46931 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp735158pzb; Sun, 10 Mar 2024 07:02:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXYI6vxtjVXvrnOckJ0kzqpfKC+ytso1VgxL+XOaik53kZyuM52/K4DCTs4BhQuTNe1NPz0vxhjeuiK9kCI4NKZb/AJlSVf/ZIGaA== X-Google-Smtp-Source: AGHT+IGqorzpaSD6MXvoptm2R53aT6UJ/9Dm6Byiq/m5ospXBzrE/h8WZc3w/ssMgUZmEEEKPtja X-Received: by 2002:a05:6512:39ce:b0:513:a833:cda2 with SMTP id k14-20020a05651239ce00b00513a833cda2mr681226lfu.53.1710079370262; Sun, 10 Mar 2024 07:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710079370; cv=none; d=google.com; s=arc-20160816; b=YbxPiDAwK1Ls5Bo7OtpUHCBZeOxWCTuYkCRnT6Cx8ElJqKLdM8axo4imSzR8bpr43s Dq9cFld2vjcMdxSKPKd3VOoVn2U4v50qjAL6QPi1R/SxlWXPrJy1lsNESMrhYsD1N4dY JIH/3J967Br238ua2HzNr2jz02/TFVHFXz23PN2YZ625KLs/J81l2VDSo+63PkRIn4kf IW1Q685DEY32pQchJDAssjQCoYdn81Jcg9HPzBS1F+tPERynpFcd0hkbhzyOuGfgZFPP aC83xI8d4QWwcIMqB6310d8wpFFu+3uSFtQ7QT3HqXZwybwqLv3CBfV8GLvPBKk24Pon iTnQ== 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=ziG+WCse+swgjumds+N6InP4dM/a50+32y7ZzDwTQ/I=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=Xhh0gnFDm6FtgLK81K9iYcUwhVhU7CCPtMJ2vmIOtoRRufddINX+TNNVkOlcTYYEkn OtW4teNZhukfqyO4wLad7xSh/mi2yCKNw7YrM08d5QAlPHsdpDdjcWLbXCBcOQ95VK4H WpqyScQVWePHqeQEXkF5uVOW/SQYaI9jwTAFu/Xab7QqhezdtEoCTWwwNxc6R8/JNPdV trqYj+BWsvCTDjh+/IXFS0nyU/qc7n5E3tg9AaQ70k3CZqz/KTa8TGCO7a3p7M606spz LLHXZIvqhEWahslPMcXgBRSFQuAMceeEB+Z74XEraNA2q6T2Z1JEE3LnXaDNAs0/enkb CbsA==; 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=LYjfsqmP; 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 l25-20020a056402345900b005671d4c0714si1623255edc.161.2024.03.10.07.02.42; Sun, 10 Mar 2024 07:02:50 -0700 (PDT) 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=LYjfsqmP; 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 B23B768CE21; Sun, 10 Mar 2024 16:02:31 +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 ACD7B68BCA7 for ; Sun, 10 Mar 2024 16:02:23 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1710079343; bh=Ae5obRiYVyvJDY8GY8IVJ7CViKvP0JVX0ow1cBDJWcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LYjfsqmPAmlbpFnoM4441vWY61YT99kg7NJ+MUz609ThsQFCgpYyZViTzYFYEtPZs uLG/8irc/h5l4LgoPteDdWtHGMhkAUNpjKYvTGsjBSg3W7sOTDYOU0NWKLf/ezhF/J uL8wJdM3S7OJjgYMxK1ED5zG/7PAPpwRKLc0/zTM= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 70BCF4255D; Sun, 10 Mar 2024 15:02:23 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Mar 2024 15:01:13 +0100 Message-ID: <20240310140112.41366-4-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240310140112.41366-2-ffmpeg@haasn.xyz> References: <20240310140112.41366-2-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: Vmdij5sAoL6X 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 bbb5634773f..e6346b51dbe 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -734,6 +734,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; } @@ -828,6 +829,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; @@ -883,6 +885,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; } @@ -936,6 +944,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); @@ -985,6 +994,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 a6ad80c12ab..336eb613597 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -31,6 +31,7 @@ #include "packet.h" #include "cbs.h" #include "cbs_av1.h" +#include "dovi_rpu.h" typedef struct AV1Frame { AVFrame *f; @@ -81,6 +82,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;