From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9A1C148BEB for ; Sun, 10 Mar 2024 14:02:48 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7692568CE3D; Sun, 10 Mar 2024 16:02:32 +0200 (EET) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 " -- 2.44.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".