From patchwork Sat Jul 13 14:58:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50521 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2298:b0:482:c625:d099 with SMTP id fp24csp1405832vqb; Sat, 13 Jul 2024 07:59:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUc9XOpA8jdgZQQYImsxdSL9hJ50rA1eTi+wuvB9qaHIQTddiVQyIABiZiZE/QN5Ke6pxDIVL2rMsSnPmWYJ5qDgnGApvcnN9gMpQ== X-Google-Smtp-Source: AGHT+IElrV+jAI9FIfuFKKPP9dRR0kqPgExl/UCS/oaGPP71gcK4Tt1cJXtIza+cY0C2ZxgcRLB5 X-Received: by 2002:a05:6402:26c7:b0:59a:aa54:4e23 with SMTP id 4fb4d7f45d1cf-59aaa54586cmr2381474a12.3.1720882754451; Sat, 13 Jul 2024 07:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720882754; cv=none; d=google.com; s=arc-20160816; b=v1wqnEIJKBlFNhxbW9HCnvq09bFBI8zZchw8WEE7I/L8XUR5YK2FRCaz1b27PxVJ5a fiMVZ+dnhT+yW8Kuf1BNpa7JiD8QLC4nvc90tbcreMSunfig1xuNrdJXFDP7QKTaXpjM u0LA9d6k9EULTQpgCKQK/89tc+iFrBw4jJ8ICpxwun8Xe3j4SepraU5Uq3LkJgYsCZce lL2QZUGdOXEATkLcNUnpIxwg5yxF20M797q9n2mUfsMMuj8yArSpxhfZuPxaENvsIDqc pzrhz5LSAhT8S/rWhtjIkrIpDeoKZCUftvbUdel6md56LKlg6pHbEDL5eVBs7I2r9p7y oGvg== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=Ok8Zuv1hwOHZSW3oHKigMu74gxSJMwlGXXF1L2iTJi4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=PlNyQR3zSsmB9nz/OW0Z3xIW9hV+OlLMuapmpsYKEAcmUToNN6yPSVIWh/2kkDgLuH DFX/bdUdZOCiKRa0ZJLUMw8lojWn1o0SuXAUvSjUcmEMsVz23msKeD6QRu4KK7sJHGNH qVBbiLJ2R8Y1ZMJcUkeVP2t3F+sPVWsXvj8EptwBmaMIhswFGlmP54JAhnns7EQ21Hb7 dqAobu/pN63nBnaCUr9f2bCo3132lnp56KgJCTQpTLbvnuQ3JjZQtxo8ASwqPHjQTQQn oi1mE+EltEGU57mxJJ0BwKrHss0ELN2NG/lRYyiiOW3eyPxAwFzOV2mFwnocbQSp7QTh kTxA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=cuLTcPDt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-59b26f662c1si641474a12.383.2024.07.13.07.59.13; Sat, 13 Jul 2024 07:59:14 -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=@gmail.com header.s=20230601 header.b=cuLTcPDt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92A3068D82A; Sat, 13 Jul 2024 17:59:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C67868D82A for ; Sat, 13 Jul 2024 17:59:04 +0300 (EEST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1fbc0a1494dso19596995ad.3 for ; Sat, 13 Jul 2024 07:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720882741; x=1721487541; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=cx5J45Yk8dZ2xk+wpgrJ46fz6OriF+KJ1bwLdScVC1E=; b=cuLTcPDtcBHLFCBoGuKvxGHM3oxJj7ZjyJzRRS+4kEKtNNf+x9eKiGJNygDXnKGuG4 QgLlUvd4g9LcqdOHpwq8YPkMt44l9Efn60fGDgcayAnLJQmIuXx4l6QswZATnBICI2bD /4utsrPF0KzL8WeTuJTsqhj/Us26aVwfnzQV8XXr/WGgTFagUcBnh/z8b5cCAQ5Ga57Y kDR1m9H+xiHTSaxnaetufSJ+by4TRhV+2n77s7gxaiHsWwsWWwv4gIQDKaEt6aMqSaPH 4+atfbZ/hSBqVw3Ti3FQALLDn/49kKTWECHL747bVaJQ1vMY/kdt8c11sIukf0Xbm90Z qOHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720882741; x=1721487541; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cx5J45Yk8dZ2xk+wpgrJ46fz6OriF+KJ1bwLdScVC1E=; b=UQxWeoUq9fDyV27RL/FCg77dHSq2ndxQo74n4DEaYdEFgZpgGsEZ8sjIrIPiFcV8YT q2uCAx7hlPccVtHeQX6nZOjFQWDhvw11ZNuywMYeV73lqVfgzeRrnJxkVvm+d7VfWMuX FLDpgmlI/r7CzuYYauCsKGwpoMzfF8BbecROtQLTP1n13kIgd/mxUcZQ3y3r6LSUc0Ra 8jTMWNVMuhsBhZLvFNOttW61NclUal8Z51fdkkfKoFntTikPMCcs4p5EJgYiDKn4AInb ImwqQEv0I0uY/jjMQYvkb88loM80+OYnA2XVu87ITyrUymsz77UjjNHdIxhpRcvRP/zP Q7aQ== X-Gm-Message-State: AOJu0Ywul123J2X+akkZjFs3agruin4w30fczPw8OWXAMnpbW91eh76M U5xsDTmfo04JqCEnXINYjpBIeqF0NRSMni2YEppH0Jr6sDOZK04UKePteA== X-Received: by 2002:a17:903:11c3:b0:1fb:82f5:6641 with SMTP id d9443c01a7336-1fbb6d0b69emr113184185ad.23.1720882741321; Sat, 13 Jul 2024 07:59:01 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0eea3cfbsm9800275ad.115.2024.07.13.07.59.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 07:59:00 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Jul 2024 11:58:43 -0300 Message-ID: <20240713145846.1331-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h265: fix range of sps_max_sub_layers_minus1 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: f6t9yA6dWLVb The VPS referenced by the SPS must always be present as the max value for sps_max_sub_layers_minus1 is vps_max_sub_layers_minus1. This replaces a buggy custom range check for the aforementioned field. Also, add the missing conformance check for sps_temporal_id_nesting_flag while at it. Signed-off-by: James Almer --- libavcodec/cbs_h265_syntax_template.c | 37 +++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c index 86ca00a0c9..c6db439b3b 100644 --- a/libavcodec/cbs_h265_syntax_template.c +++ b/libavcodec/cbs_h265_syntax_template.c @@ -788,25 +788,28 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, ub(4, sps_video_parameter_set_id); h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id]; + if (!vps) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n", + current->sps_video_parameter_set_id); + return AVERROR_INVALIDDATA; + } - u(3, sps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1); + u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1); flag(sps_temporal_id_nesting_flag); - if (vps) { - if (vps->vps_max_sub_layers_minus1 > current->sps_max_sub_layers_minus1) { - av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " - "sps_max_sub_layers_minus1 (%d) must be less than or equal to " - "vps_max_sub_layers_minus1 (%d).\n", - vps->vps_max_sub_layers_minus1, - current->sps_max_sub_layers_minus1); - return AVERROR_INVALIDDATA; - } - if (vps->vps_temporal_id_nesting_flag && - !current->sps_temporal_id_nesting_flag) { - av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " - "sps_temporal_id_nesting_flag must be 1 if " - "vps_temporal_id_nesting_flag is 1.\n"); - return AVERROR_INVALIDDATA; - } + + if (vps->vps_temporal_id_nesting_flag && + !current->sps_temporal_id_nesting_flag) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " + "sps_temporal_id_nesting_flag must be 1 if " + "vps_temporal_id_nesting_flag is 1.\n"); + return AVERROR_INVALIDDATA; + } + if (current->sps_max_sub_layers_minus1 == 0 && + current->sps_temporal_id_nesting_flag != 1) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " + "sps_temporal_id_nesting_flag must be 1 if " + "sps_max_sub_layers_minus1 is 0.\n"); + return AVERROR_INVALIDDATA; } CHECK(FUNC(profile_tier_level)(ctx, rw, ¤t->profile_tier_level, From patchwork Sat Jul 13 14:58:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50527 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2298:b0:482:c625:d099 with SMTP id fp24csp1439587vqb; Sat, 13 Jul 2024 09:16:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXjF5Ks3a9uW9Zu1xobFBcf6C/mPPQzntznTjQIFjdMzCGUblXjFR2GRwGckn+XIBV3XB997gyOg5GvlenlTjde4sFAdkZFZm/2vA== X-Google-Smtp-Source: AGHT+IEnUPmG21Go+RAVwz9iFRKH4o5a15GCVuwtNsLA0ehJOgdmfor1H6fW1BU/LrdNPlHGeV52 X-Received: by 2002:a2e:95ce:0:b0:2ee:86c1:f743 with SMTP id 38308e7fff4ca-2eeb30e36a2mr89849931fa.15.1720887408169; Sat, 13 Jul 2024 09:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720887408; cv=none; d=google.com; s=arc-20160816; b=V4JUvHNM3wlT3JMClDhWJzeDBQzMkPaZyIwJcf44Wlk8/LrZM/lujj1OERl1kYDPx5 wkrs6mlilzcxEnJiFdae9NvCi0t9QDvOwVjRzYE0RYu8W9TW1KivX78sLqw+cEoNadaa cNCNacsEad2kAdfGc0QgCMJWDQs+8DHkFCZzmjdjxN38p/SltTsesvh3wS1PesDv1Yul jxTxmzG2eh1Aii2N1x9sCaI6sitYrtbTyuVlqy2deVEqntrL0V3Ar17DJhKy34+RzTsD ik09tuB2C5fTdLbLywZUAJygYv+QFv45N2tKYlcuCTkU5khCraiIAWOw0EV40JoFjZgB 07Qw== 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=Z+AHAIlH1VOSiuXC/D9rjjh7wDe60j+xLjFw3JGXffY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Y/gtqTeK+dHZ7Irdfz3SUmw5DML4rKfzc8Qq4yDWULspvclTpYC8aujEJkJLzS6G0p pGqbHwbaAio0oV7Rehx0JLoRFfMoD+gm1f444IKVUWhi9RyGSGTbyxFseQ7YGawHD5Ou 5o8+iPHaf5IKyV7jtKMhbNA++JHq71YJK6nkwwbQ1Wsxdzf3LMfRRNXsW1W69hRbbjoC GgE5ZteMS8TyeQTryQcH31mbPvEpfoeqxzFPJ1TbPz85U4TFOF99U2tSK/U/Sf1s4+AJ SglW0+yD0QIKGxbld2SAw80hpOcYZ4MYLZ49AItU9MKWdDnT8i1XGlIfx3UubcdLJk8o DHFw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=EWP0PMyj; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2eee192fe58si4346191fa.447.2024.07.13.09.16.47; Sat, 13 Jul 2024 09:16:48 -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=@gmail.com header.s=20230601 header.b=EWP0PMyj; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C477368DBCA; Sat, 13 Jul 2024 17:59:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2845668D82A for ; Sat, 13 Jul 2024 17:59:06 +0300 (EEST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1fb19ca5273so18227835ad.3 for ; Sat, 13 Jul 2024 07:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720882743; x=1721487543; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Gp6Mqpbsgv0lxXiThW7/4kMTO2ywv7q65SNKIHc7l4c=; b=EWP0PMyjWRNkKCNkNtW2aBBaWKy/vfxAzBsB/CIMZUPK34NQuHNcthHqoHQXYnpXnr ag3q7M62Xn3oEwiNbOCFqCrys0Vo8Wrsr3EXOjBhKR4VMoJYi4Pkfy8mvJrPYNJdZ/lP tfmNK4Q9JtKHp4e6Kd6ZhOwx6ZiqppemCLk7NeolmCOlphOPKIfzlztOxalhsZyAnAX4 ELO/HIok6ZHrTlk2xob6FXOvEcKP0K3pwSYr5cPTQ2pcXZwpqmkJ67UQ4vPVYE7EIdFc s1jZzo+qX+GxqwjNqMUoxvxfY9Jd6y82G3p05PWS1bcjhnx7W+5XaZesSQr/Tb9J6XGZ aRQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720882743; x=1721487543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gp6Mqpbsgv0lxXiThW7/4kMTO2ywv7q65SNKIHc7l4c=; b=JamFcSCvr2APWNzxerIGe27xEbO1MC1rxh72S68jwwsHrV+DzXFO3ZFZ6t9rSFE3tb 7FT77NrQ2XdkZ6SZUIDYjwHujhnTgrp5iJ5gpc887tQv6cxQ34PgLFdBMGhcUZoVXnFL YRPYL4hDm8dIBEAXgVGJePy4H1V7//X3rZ4CRHy4FJu5DGPzl/OO2g18iAhP3egbAsFk 1B+VIPMY1WG4Je7EjMshgn0B6w09BKGWXQHAIP33yS1hypcFG9Fvo3tbI845Bc0zSez0 M3jyUYmuw7KwhtjteqzTKIUmvUyrhgb9T+XMqcfvxwaHMe7MSbPxSKVCMGkFbvU5et5H h29Q== X-Gm-Message-State: AOJu0YzRg6CE2DJjKp626rpRmyduWl86GHXcPiUYCbEjr/uZjquR8wun phFoMlwpydRkOKt9eZ6KAx+wVuGcgQ39+6IyiE11sRw8nglID2DF216+xw== X-Received: by 2002:a17:902:ce8d:b0:1fb:83c5:cf8a with SMTP id d9443c01a7336-1fbb6d25184mr120695055ad.8.1720882743228; Sat, 13 Jul 2024 07:59:03 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0eea3cfbsm9800275ad.115.2024.07.13.07.59.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 07:59:02 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Jul 2024 11:58:44 -0300 Message-ID: <20240713145846.1331-2-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240713145846.1331-1-jamrial@gmail.com> References: <20240713145846.1331-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h265: add partial support for Multilayer extension fields in parameter set NALUs 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: CjUw0hGSs8V2 Signed-off-by: James Almer --- libavcodec/cbs_h2645.c | 3 +- libavcodec/cbs_h265.h | 44 ++++++++++ libavcodec/cbs_h265_syntax_template.c | 113 +++++++++++++++++++++++++- libavcodec/hevc/ps.h | 4 +- 4 files changed, 159 insertions(+), 5 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 5ec781ddab..828e56b8c0 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -499,7 +499,8 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, size_t size = nal->size; enum AVCodecID codec_id = ctx->codec->codec_id; - if (codec_id != AV_CODEC_ID_VVC && nal->nuh_layer_id > 0) + if (codec_id == AV_CODEC_ID_HEVC && nal->nuh_layer_id > 0 && + (nal->type < HEVC_NAL_VPS || nal->type > HEVC_NAL_PPS)) continue; // Remove trailing zeroes. diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index 91a5a55317..afb942ced5 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -248,12 +248,16 @@ typedef struct H265RawSPS { uint8_t sps_video_parameter_set_id; uint8_t sps_max_sub_layers_minus1; + uint8_t sps_ext_or_max_sub_layers_minus1; uint8_t sps_temporal_id_nesting_flag; H265RawProfileTierLevel profile_tier_level; uint8_t sps_seq_parameter_set_id; + uint8_t update_rep_format_flag; + uint8_t sps_rep_format_idx; + uint8_t chroma_format_idc; uint8_t separate_colour_plane_flag; @@ -284,6 +288,8 @@ typedef struct H265RawSPS { uint8_t max_transform_hierarchy_depth_intra; uint8_t scaling_list_enabled_flag; + uint8_t sps_infer_scaling_list_flag; + uint8_t sps_scaling_list_ref_layer_id; uint8_t sps_scaling_list_data_present_flag; H265RawScalingList scaling_list; @@ -342,6 +348,9 @@ typedef struct H265RawSPS { uint8_t motion_vector_resolution_control_idc; uint8_t intra_boundary_filtering_disable_flag; + + // Multilayer extension. + uint8_t inter_view_mv_vert_constraint_flag; } H265RawSPS; typedef struct H265RawPPS { @@ -433,6 +442,41 @@ typedef struct H265RawPPS { uint8_t luma_bit_depth_entry_minus8; uint8_t chroma_bit_depth_entry_minus8; uint16_t pps_palette_predictor_initializers[3][128]; + + // Multilayer extension. + uint8_t poc_reset_info_present_flag; + uint8_t pps_infer_scaling_list_flag; + uint8_t pps_scaling_list_ref_layer_id; + uint8_t num_ref_loc_offsets; + uint8_t ref_loc_offset_layer_id[64]; + uint8_t scaled_ref_layer_offset_present_flag[64]; + int16_t scaled_ref_layer_left_offset[64]; + int16_t scaled_ref_layer_top_offset[64]; + int16_t scaled_ref_layer_right_offset[64]; + int16_t scaled_ref_layer_bottom_offset[64]; + uint8_t ref_region_offset_present_flag[64]; + int16_t ref_region_left_offset[64]; + int16_t ref_region_top_offset[64]; + int16_t ref_region_right_offset[64]; + int16_t ref_region_bottom_offset[64]; + uint8_t resample_phase_set_present_flag[64]; + uint8_t phase_hor_luma[64]; + uint8_t phase_ver_luma[64]; + uint8_t phase_hor_chroma_plus8[64]; + uint8_t phase_ver_chroma_plus8[64]; + uint8_t colour_mapping_enabled_flag; + uint8_t num_cm_ref_layers; + uint8_t cm_ref_layer_id[62]; + uint8_t cm_octant_depth; + uint8_t cm_y_part_num_log2; + uint8_t luma_bit_depth_cm_input; + uint8_t chroma_bit_depth_cm_input; + uint8_t luma_bit_depth_cm_output; + uint8_t chroma_bit_depth_cm_output; + uint8_t cm_res_quant_bits; + uint8_t cm_delta_flc_bits; + int8_t cm_adapt_threshold_u_delta; + int8_t cm_adapt_threshold_v_delta; } H265RawPPS; typedef struct H265RawAUD { diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c index c6db439b3b..2f8ee0db10 100644 --- a/libavcodec/cbs_h265_syntax_template.c +++ b/libavcodec/cbs_h265_syntax_template.c @@ -747,6 +747,16 @@ static int FUNC(sps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +static int FUNC(sps_multilayer_extension)(CodedBitstreamContext *ctx, RWContext *rw, + H265RawSPS *current) +{ + int err; + + flag(inter_view_mv_vert_constraint_flag); + + return 0; +} + static int FUNC(vui_parameters_default)(CodedBitstreamContext *ctx, RWContext *rw, H265RawVUI *current, H265RawSPS *sps) @@ -781,6 +791,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, int err, i; unsigned int min_cb_log2_size_y, ctb_log2_size_y, min_cb_size_y, min_tb_log2_size_y; + unsigned int multi_layer_ext_sps_flag; HEADER("Sequence Parameter Set"); @@ -794,7 +805,17 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, return AVERROR_INVALIDDATA; } + if (current->nal_unit_header.nuh_layer_id == 0) u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1); + else { + u(3, sps_ext_or_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS); + infer(sps_max_sub_layers_minus1, current->sps_ext_or_max_sub_layers_minus1 == 7 + ? vps->vps_max_sub_layers_minus1 + : current->sps_ext_or_max_sub_layers_minus1); + } + multi_layer_ext_sps_flag = current->nal_unit_header.nuh_layer_id && + current->sps_ext_or_max_sub_layers_minus1 == 7; + if (!multi_layer_ext_sps_flag) { flag(sps_temporal_id_nesting_flag); if (vps->vps_temporal_id_nesting_flag && @@ -814,9 +835,20 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, CHECK(FUNC(profile_tier_level)(ctx, rw, ¤t->profile_tier_level, 1, current->sps_max_sub_layers_minus1)); + } else { + if (current->sps_max_sub_layers_minus1 > 0) + infer(sps_temporal_id_nesting_flag, vps->vps_temporal_id_nesting_flag); + else + infer(sps_temporal_id_nesting_flag, 1); + } ue(sps_seq_parameter_set_id, 0, 15); + if (multi_layer_ext_sps_flag) { + flag(update_rep_format_flag); + if (current->update_rep_format_flag) + ub(8, sps_rep_format_idx); + } else { ue(chroma_format_idc, 0, 3); if (current->chroma_format_idc == 3) flag(separate_colour_plane_flag); @@ -841,9 +873,11 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, ue(bit_depth_luma_minus8, 0, 8); ue(bit_depth_chroma_minus8, 0, 8); + } ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12); + if (!multi_layer_ext_sps_flag) { flag(sps_sub_layer_ordering_info_present_flag); for (i = (current->sps_sub_layer_ordering_info_present_flag ? 0 : current->sps_max_sub_layers_minus1); @@ -865,6 +899,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]); } } + } ue(log2_min_luma_coding_block_size_minus3, 0, 3); min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3; @@ -895,9 +930,17 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, flag(scaling_list_enabled_flag); if (current->scaling_list_enabled_flag) { + if (multi_layer_ext_sps_flag) + flag(sps_infer_scaling_list_flag); + else + infer(sps_infer_scaling_list_flag, 0); + if (current->sps_infer_scaling_list_flag) + ub(6, sps_scaling_list_ref_layer_id); + else { flag(sps_scaling_list_data_present_flag); if (current->sps_scaling_list_data_present_flag) CHECK(FUNC(scaling_list_data)(ctx, rw, ¤t->scaling_list)); + } } else { infer(sps_scaling_list_data_present_flag, 0); } @@ -955,7 +998,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, if (current->sps_range_extension_flag) CHECK(FUNC(sps_range_extension)(ctx, rw, current)); if (current->sps_multilayer_extension_flag) - return AVERROR_PATCHWELCOME; + CHECK(FUNC(sps_multilayer_extension)(ctx, rw, current)); if (current->sps_3d_extension_flag) return AVERROR_PATCHWELCOME; if (current->sps_scc_extension_flag) @@ -996,6 +1039,72 @@ static int FUNC(pps_range_extension)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +static int FUNC(pps_multilayer_extension)(CodedBitstreamContext *ctx, RWContext *rw, + H265RawPPS *current) +{ + CodedBitstreamH265Context *h265 = ctx->priv_data; + const H265RawVPS *vps = h265->active_vps; + int offset; + int err, i; + + flag(poc_reset_info_present_flag); + flag(pps_infer_scaling_list_flag); + if (current->pps_infer_scaling_list_flag) + ub(6, pps_scaling_list_ref_layer_id); + + if (!vps) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS missing for PPS Multilayer Extension.\n"); + return AVERROR_INVALIDDATA; + } + + ue(num_ref_loc_offsets, 0, vps->vps_max_layers_minus1); + for (i = 0; i < current->num_ref_loc_offsets; i++) { + ubs(6, ref_loc_offset_layer_id[i], 1, i); + offset = current->ref_loc_offset_layer_id[i]; + flags(scaled_ref_layer_offset_present_flag[i], 1, i); + if (current->scaled_ref_layer_offset_present_flag[i]) { + ses(scaled_ref_layer_left_offset[offset], -16384, 16383, 1, offset); + ses(scaled_ref_layer_top_offset[offset], -16384, 16383, 1, offset); + ses(scaled_ref_layer_right_offset[offset], -16384, 16383, 1, offset); + ses(scaled_ref_layer_bottom_offset[offset], -16384, 16383, 1, offset); + } else { + infer(scaled_ref_layer_left_offset[offset], 0); + infer(scaled_ref_layer_top_offset[offset], 0); + infer(scaled_ref_layer_right_offset[offset], 0); + infer(scaled_ref_layer_bottom_offset[offset], 0); + } + flags(ref_region_offset_present_flag[i], 1, i); + if (current->ref_region_offset_present_flag[i]) { + ses(ref_region_left_offset[offset], -16384, 16383, 1, offset); + ses(ref_region_top_offset[offset], -16384, 16383, 1, offset); + ses(ref_region_right_offset[offset], -16384, 16383, 1, offset); + ses(ref_region_bottom_offset[offset], -16384, 16383, 1, offset); + } else { + infer(ref_region_left_offset[offset], 0); + infer(ref_region_top_offset[offset], 0); + infer(ref_region_right_offset[offset], 0); + infer(ref_region_bottom_offset[offset], 0); + } + flags(resample_phase_set_present_flag[i], 1, i); + if (current->resample_phase_set_present_flag[i]) { + ues(phase_hor_luma[offset], 0, 31, 1, offset); + ues(phase_ver_luma[offset], 0, 31, 1, offset); + ues(phase_hor_chroma_plus8[offset], 0, 63, 1, offset); + ues(phase_ver_chroma_plus8[offset], 0, 63, 1, offset); + } else { + infer(phase_hor_luma[offset], 0); + infer(phase_ver_luma[offset], 0); + infer(phase_hor_chroma_plus8[offset], 8); + } + } + + flag(colour_mapping_enabled_flag); + if (current->colour_mapping_enabled_flag) + return AVERROR_PATCHWELCOME; + + return 0; +} + static int FUNC(pps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current) { @@ -1146,7 +1255,7 @@ static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw, if (current->pps_range_extension_flag) CHECK(FUNC(pps_range_extension)(ctx, rw, current)); if (current->pps_multilayer_extension_flag) - return AVERROR_PATCHWELCOME; + CHECK(FUNC(pps_multilayer_extension)(ctx, rw, current)); if (current->pps_3d_extension_flag) return AVERROR_PATCHWELCOME; if (current->pps_scc_extension_flag) diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h index 17395c5510..fab5a46273 100644 --- a/libavcodec/hevc/ps.h +++ b/libavcodec/hevc/ps.h @@ -390,8 +390,8 @@ typedef struct HEVCPPS { uint8_t resample_phase_set_present_flag[64]; uint8_t phase_hor_luma[64]; uint8_t phase_ver_luma[64]; - int8_t phase_hor_chroma[64]; - int8_t phase_ver_chroma[64]; + uint8_t phase_hor_chroma[64]; + uint8_t phase_ver_chroma[64]; uint8_t colour_mapping_enabled_flag; uint8_t num_cm_ref_layers; uint8_t cm_ref_layer_id[62]; From patchwork Sat Jul 13 14:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50524 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2298:b0:482:c625:d099 with SMTP id fp24csp1415355vqb; Sat, 13 Jul 2024 08:16:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX3P0Mp7GX91DWFA1bY8qEs3PQKE3uUcIQIgvWFulAsfpdEb1Y8yroVJ85zx8iOwaL5Dk0sGjGhLqnVla1oEJznlxvTv5/h4VGJrg== X-Google-Smtp-Source: AGHT+IEGG08sUDemTVX6mDi0onqovNrR9QHkJvc6PNqumeLES1Xj722FBTg6U9Mp3TyFkFKabt4R X-Received: by 2002:a2e:9482:0:b0:2ec:56b9:259f with SMTP id 38308e7fff4ca-2eeb319134dmr89987361fa.48.1720883807550; Sat, 13 Jul 2024 08:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720883807; cv=none; d=google.com; s=arc-20160816; b=Z/EN+JhSY+nvMHi8MfVE02zKee9U9w4qyYGSoBf8swOC9lNxlIvadsaYAutFrN8NWh xZBOqpG1hNO+2tybh6i3aAy+EIdWjldSKAXrBhbVSejBN+B8U5rgGhLXDQq/I3ihvIEh 86fOM727wEjP0Wthu0eCYHWEplwswSEOuyYy7DMVONAw8Lt+tm+Ht91JHd4HCsyNUxp5 RPEvd9ZHCOQbHqQ/1fXQQcGdLj5ATI2PMCKCLfLIstiKE07BnCaT4vh+2hF6GNR15w5G wQkHD49rBFcnm0lx5FE+hRBE8nFBlAW200mmfSX3TBIEZDldUvB8zVo5Gu8BAEpHmFxL COQg== 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=nWQRfDpudIhXUFPafOY+NyFU0UwEam5iOVKRBeEMUww=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=u4hCljG5bqfqmmcGmm/ngFw3UCg821ravd7cEGB9x2cbfExvbVcfjcGQelIFQuCucw TTUAoJ3ymugMTYIZ6kEa/viU8Q2F0KJrV5pORExRnhs4c+XBnprnVfjg3eKyI6ZSgleC 449vPco9XdPbOQcRfcr9E3veJtPNgn6uXc9GQtHgC23JkVPVZXC4oz1msmidIDgE9kC9 TBW4hZZwKb2IyHiveZU7hCJlsWZlr521ro45xTve2VAgji6PcxmmCvMCwe0cwo88G5WD lSb3PS9rk56ShW6FfWbNJlZDCSbxfPk5gEVpr7YeC5uWCqx7GS+eypFhe1wxvOI77AG9 Fqqg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=c++iPuXS; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2eee192b102si4124341fa.409.2024.07.13.08.16.47; Sat, 13 Jul 2024 08:16:47 -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=@gmail.com header.s=20230601 header.b=c++iPuXS; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 86D9368DC1F; Sat, 13 Jul 2024 17:59:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2944068DBE7 for ; Sat, 13 Jul 2024 17:59:08 +0300 (EEST) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fb72eb3143so20937305ad.1 for ; Sat, 13 Jul 2024 07:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720882745; x=1721487545; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+sOx6JUcFYH0ztM3qtw525t3MyAp0VRey9dd9lq6wR8=; b=c++iPuXSlBiY64aSHkUi8+qW0FR//C455YzvXNYtmck6ezPDYIJYC08ctpchP8/4Ic iuecwJDOSYmuSdrdgywbSr2P/EY/p0jmxO+oV813KhzMhZIm6WoAVV9N/59GLl5L6KCh VVvRhcK3PPzLRjL2xWkVcIPvgzq/j58sEDo/LNW00yNOT5pYIHjDZgzcXeNU5myp04Ko Fd92BI4x6P8B6h/ENCltmfhThe5hu1bDGllqLFcuhJiKEKfA9XvqQA3s55ELlS2sTOid duGwjB07HsX89CktCLn1dWJAbctBCCRlGL0ZPqPtByE9p7A9nKmUvf3//U49kXWvipDX C6Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720882745; x=1721487545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+sOx6JUcFYH0ztM3qtw525t3MyAp0VRey9dd9lq6wR8=; b=WFVMZmxLXPPvrI9E6v9ovOv5iKB+egjko8W0Pyf1oWATDY38yTVylVk8XbR0WC0CjC Mcuv+omtfBbmYde1lgwXg88SbSNFZQ7dWvCe27u8wSzbmdKZ8LRiWPkdqkk9XygfidBA 6OB8UiVHApbZtcWSxhGS+USjt36Fy3tmZAPaAEmLnBVsIEKx9RUR27jeGpJ6gFkn48JR FbRAMAQLf7v85fu1/QCQZ0D1BvoiCnxFYMmppaOi+tEIQOwInuJw5RrKrvFCSwiZKsFv 6EKE42ALqQvEgW7uF6IT+xJlS5hD2rV6vsDmp08GfCXrZpORpaDtvYCjH1GhPHWU+k8o iw9A== X-Gm-Message-State: AOJu0Yw9hri/ampTwVFKA/WN2jSurqFHzQdP1F3OtI0rath0n9jKzkr5 WH8nJOBDRvrIKm3QHqdSmlN6C8IFrS8+/AdsDr6aKQE0nnchn3eE7C5f+Q== X-Received: by 2002:a17:902:e843:b0:1fb:80a3:5826 with SMTP id d9443c01a7336-1fc0b4b4829mr28432385ad.4.1720882745473; Sat, 13 Jul 2024 07:59:05 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0eea3cfbsm9800275ad.115.2024.07.13.07.59.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 07:59:04 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Jul 2024 11:58:45 -0300 Message-ID: <20240713145846.1331-3-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240713145846.1331-1-jamrial@gmail.com> References: <20240713145846.1331-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h265: reindent after the previous commit 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: IWSIkIlqjPl0 Signed-off-by: James Almer --- libavcodec/cbs_h265_syntax_template.c | 124 +++++++++++++------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c index 2f8ee0db10..1826950e8e 100644 --- a/libavcodec/cbs_h265_syntax_template.c +++ b/libavcodec/cbs_h265_syntax_template.c @@ -806,7 +806,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, } if (current->nal_unit_header.nuh_layer_id == 0) - u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1); + u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1); else { u(3, sps_ext_or_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS); infer(sps_max_sub_layers_minus1, current->sps_ext_or_max_sub_layers_minus1 == 7 @@ -816,25 +816,25 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, multi_layer_ext_sps_flag = current->nal_unit_header.nuh_layer_id && current->sps_ext_or_max_sub_layers_minus1 == 7; if (!multi_layer_ext_sps_flag) { - flag(sps_temporal_id_nesting_flag); + flag(sps_temporal_id_nesting_flag); - if (vps->vps_temporal_id_nesting_flag && - !current->sps_temporal_id_nesting_flag) { - av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " - "sps_temporal_id_nesting_flag must be 1 if " - "vps_temporal_id_nesting_flag is 1.\n"); - return AVERROR_INVALIDDATA; - } - if (current->sps_max_sub_layers_minus1 == 0 && - current->sps_temporal_id_nesting_flag != 1) { - av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " - "sps_temporal_id_nesting_flag must be 1 if " - "sps_max_sub_layers_minus1 is 0.\n"); - return AVERROR_INVALIDDATA; - } + if (vps->vps_temporal_id_nesting_flag && + !current->sps_temporal_id_nesting_flag) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " + "sps_temporal_id_nesting_flag must be 1 if " + "vps_temporal_id_nesting_flag is 1.\n"); + return AVERROR_INVALIDDATA; + } + if (current->sps_max_sub_layers_minus1 == 0 && + current->sps_temporal_id_nesting_flag != 1) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " + "sps_temporal_id_nesting_flag must be 1 if " + "sps_max_sub_layers_minus1 is 0.\n"); + return AVERROR_INVALIDDATA; + } - CHECK(FUNC(profile_tier_level)(ctx, rw, ¤t->profile_tier_level, - 1, current->sps_max_sub_layers_minus1)); + CHECK(FUNC(profile_tier_level)(ctx, rw, ¤t->profile_tier_level, + 1, current->sps_max_sub_layers_minus1)); } else { if (current->sps_max_sub_layers_minus1 > 0) infer(sps_temporal_id_nesting_flag, vps->vps_temporal_id_nesting_flag); @@ -849,56 +849,56 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, if (current->update_rep_format_flag) ub(8, sps_rep_format_idx); } else { - ue(chroma_format_idc, 0, 3); - if (current->chroma_format_idc == 3) - flag(separate_colour_plane_flag); - else - infer(separate_colour_plane_flag, 0); + ue(chroma_format_idc, 0, 3); + if (current->chroma_format_idc == 3) + flag(separate_colour_plane_flag); + else + infer(separate_colour_plane_flag, 0); - ue(pic_width_in_luma_samples, 1, HEVC_MAX_WIDTH); - ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT); + ue(pic_width_in_luma_samples, 1, HEVC_MAX_WIDTH); + ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT); - flag(conformance_window_flag); - if (current->conformance_window_flag) { - ue(conf_win_left_offset, 0, current->pic_width_in_luma_samples); - ue(conf_win_right_offset, 0, current->pic_width_in_luma_samples); - ue(conf_win_top_offset, 0, current->pic_height_in_luma_samples); - ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples); - } else { - infer(conf_win_left_offset, 0); - infer(conf_win_right_offset, 0); - infer(conf_win_top_offset, 0); - infer(conf_win_bottom_offset, 0); - } + flag(conformance_window_flag); + if (current->conformance_window_flag) { + ue(conf_win_left_offset, 0, current->pic_width_in_luma_samples); + ue(conf_win_right_offset, 0, current->pic_width_in_luma_samples); + ue(conf_win_top_offset, 0, current->pic_height_in_luma_samples); + ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples); + } else { + infer(conf_win_left_offset, 0); + infer(conf_win_right_offset, 0); + infer(conf_win_top_offset, 0); + infer(conf_win_bottom_offset, 0); + } - ue(bit_depth_luma_minus8, 0, 8); - ue(bit_depth_chroma_minus8, 0, 8); + ue(bit_depth_luma_minus8, 0, 8); + ue(bit_depth_chroma_minus8, 0, 8); } ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12); if (!multi_layer_ext_sps_flag) { - flag(sps_sub_layer_ordering_info_present_flag); - for (i = (current->sps_sub_layer_ordering_info_present_flag ? - 0 : current->sps_max_sub_layers_minus1); - i <= current->sps_max_sub_layers_minus1; i++) { - ues(sps_max_dec_pic_buffering_minus1[i], - 0, HEVC_MAX_DPB_SIZE - 1, 1, i); - ues(sps_max_num_reorder_pics[i], - 0, current->sps_max_dec_pic_buffering_minus1[i], 1, i); - ues(sps_max_latency_increase_plus1[i], - 0, UINT32_MAX - 1, 1, i); - } - if (!current->sps_sub_layer_ordering_info_present_flag) { - for (i = 0; i < current->sps_max_sub_layers_minus1; i++) { - infer(sps_max_dec_pic_buffering_minus1[i], - current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]); - infer(sps_max_num_reorder_pics[i], - current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]); - infer(sps_max_latency_increase_plus1[i], - current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]); + flag(sps_sub_layer_ordering_info_present_flag); + for (i = (current->sps_sub_layer_ordering_info_present_flag ? + 0 : current->sps_max_sub_layers_minus1); + i <= current->sps_max_sub_layers_minus1; i++) { + ues(sps_max_dec_pic_buffering_minus1[i], + 0, HEVC_MAX_DPB_SIZE - 1, 1, i); + ues(sps_max_num_reorder_pics[i], + 0, current->sps_max_dec_pic_buffering_minus1[i], 1, i); + ues(sps_max_latency_increase_plus1[i], + 0, UINT32_MAX - 1, 1, i); + } + if (!current->sps_sub_layer_ordering_info_present_flag) { + for (i = 0; i < current->sps_max_sub_layers_minus1; i++) { + infer(sps_max_dec_pic_buffering_minus1[i], + current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]); + infer(sps_max_num_reorder_pics[i], + current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]); + infer(sps_max_latency_increase_plus1[i], + current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]); + } } - } } ue(log2_min_luma_coding_block_size_minus3, 0, 3); @@ -937,9 +937,9 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, if (current->sps_infer_scaling_list_flag) ub(6, sps_scaling_list_ref_layer_id); else { - flag(sps_scaling_list_data_present_flag); - if (current->sps_scaling_list_data_present_flag) - CHECK(FUNC(scaling_list_data)(ctx, rw, ¤t->scaling_list)); + flag(sps_scaling_list_data_present_flag); + if (current->sps_scaling_list_data_present_flag) + CHECK(FUNC(scaling_list_data)(ctx, rw, ¤t->scaling_list)); } } else { infer(sps_scaling_list_data_present_flag, 0); From patchwork Sat Jul 13 14:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50523 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2298:b0:482:c625:d099 with SMTP id fp24csp1415327vqb; Sat, 13 Jul 2024 08:16:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVud+Z/p2EcWSCKSOhTNnyF/X9G8kT4GcUPD8hNSLZypgInurYW8dYK8umjfLwKgppr6xkTG5gxmQ6CTmx03AUJeeXcoGYzZL8pxA== X-Google-Smtp-Source: AGHT+IF7hQJCyBhsn04hKjlizG9Cr49dGG7BkW58TSpkb8g9fhC/aKfbHZ8tUvsgDzONCD3Jen/n X-Received: by 2002:a17:906:730a:b0:a6f:2835:be95 with SMTP id a640c23a62f3a-a799d3a55b7mr379907966b.37.1720883806490; Sat, 13 Jul 2024 08:16:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720883806; cv=none; d=google.com; s=arc-20160816; b=P6b9g5GHqCoLXPffOTdeXwsaxpBHlbVlO2auT0Ls0K8qGL/bqe3lXDI67KAZliRpJ+ n9F6gEx1qHTEb35aujfWLHh7cav6ajn+p0eT8SNlv1ESUQl3hAoOwu+6VnlsslF15X1B y+tIq3OyTGofjjurq0j4QHNxcLZK9x+1lRZR/yEuQfHPyORXZTpECLAs87SFIwpDSuaL KUpVR+5PbZDUIwX13X/3FiQwpIue+XfVZOtOTNNwieA24ltYOBAra//vTCmvkhGZ+C0a I7GWmMT5SqctFAsiTdEWbOtkhE6S2Mikfb3PEJ0vNafvJNcfUmf3b3IpxQz6U8KbOfG1 9T1g== 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=4+j5vlgE1lTnWXdtK1/+WykZ3DzjEMfa8kGEzROcn4A=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=U1Hp1iLiwRsqJu5MBPUHlSBzUsuFFH+NaaoEfflRhsMXvVhUEDQzNa25cGJzQ0Tsqm YCK1/Dt0bsFVQMuFmt98astXFbFeSVHBqyt4wpj+ZFbgoJZvf574AAX9Jeor9XnU1Rym uyU/9O88NjBU4YCIwhoFl2qG5TPL5RF0suz7sTgaSN0K4OV/crz9x/0T7wAud4wHgBDW aCQJIMoMjvtlTHz/Ew6C5+WBmPca/xP7TUzewPNIA0wMR9b7T1nir8XtUctR2gIOdXaM /cAPB8ybV7fNUYodBO54WVF0jQBgQmnih4rx1js3RC0/BfUjOt8ySs1ufXLjTUDDX6JW SSGQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=Iy43aG7j; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a79bc5a8cb1si72247966b.238.2024.07.13.08.16.46; Sat, 13 Jul 2024 08:16:46 -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=@gmail.com header.s=20230601 header.b=Iy43aG7j; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D957168DC33; Sat, 13 Jul 2024 17:59:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5058968DC01 for ; Sat, 13 Jul 2024 17:59:09 +0300 (EEST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fafc9e07f8so21529015ad.0 for ; Sat, 13 Jul 2024 07:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720882747; x=1721487547; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=K8mrs7PrRVB7Og7yS37Y8mtOrgZZyglGY8Cq+imMgSE=; b=Iy43aG7j2vDAAtocYnlA4RPYg/A6V+yM8YFsprJw9gvbTkXZBPfsUdidQ5cmVoV7gs iPj+ncf56aojAQ2OjiymXaHOOwTbC9bR0e01sJ4dI3kVXzNcOZmcmW3csCHJpys+oRGb T6NPkVluudOdi7lGcrO6PA0X93v7i3k2UoxT3h5BNDh++clcLU744beG/kDWYFAPP+n9 K6XvpnpiHfd8l+DrV/V5GlBRvBznBgi92AeY1JcQ5Vj62rv7FEmNXrb0EPObsKMQPuC4 YsZfMWQ0A+8XQLhOWUNofQxJq8wv/Rxf07oYCmXaPodpv2GbZoXCrqJzNutkuKO4MXkf yZuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720882747; x=1721487547; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K8mrs7PrRVB7Og7yS37Y8mtOrgZZyglGY8Cq+imMgSE=; b=RzsquJExsPQb3aQDktbKJvvPCfy/2anNpJKAK/bXiJclGPgJb7eYXD6XOMjLaI1+VO 52cbRENwJnRxmuvMVqy8+f/dPkP6NnEkTR4w9/6LIRjDc8T7f02r+Q6qvublTAURVL7h Da/5iFosHRJl62uMID3UTj1V98RN3ilZ10Yf97i5c/6ibMuZl0rgBIP0ASONfDgdXVv4 gNe3zhBUrTyo691zMexcDR5oYO3ue9+3goKSGOYRLaSPsTyYMoESIm/MLBwekCDz0XYw aMiYrWbovN3zzM9WrhCpZ6wp6R8czBX7dBWUw3r/ZLZ86pEcFp5nvIvywAC4+Ka59kKt RSZg== X-Gm-Message-State: AOJu0YwK4ndDsWKheHwd7RW3ZxM1qmaRRBrbgmxbuyhFrI17YRpo+V5h PnUSAyuWIIftMe11wffXe7o3TC96VKRbLJtSiO+mAacaP9EnE0aIH8K/Dg== X-Received: by 2002:a17:902:db02:b0:1fa:643:f42f with SMTP id d9443c01a7336-1fbb6ef8fa3mr144493975ad.62.1720882747086; Sat, 13 Jul 2024 07:59:07 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0eea3cfbsm9800275ad.115.2024.07.13.07.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 07:59:06 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Jul 2024 11:58:46 -0300 Message-ID: <20240713145846.1331-4-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240713145846.1331-1-jamrial@gmail.com> References: <20240713145846.1331-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/cbs_h265: add support for 3D Reference Displays Information 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: CbediSYmLThN Signed-off-by: James Almer --- libavcodec/cbs_h2645.c | 6 ++++ libavcodec/cbs_h265.h | 16 ++++++++++ libavcodec/cbs_h265_syntax_template.c | 42 +++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 828e56b8c0..d73d77a985 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -2275,6 +2275,12 @@ static const SEIMessageTypeDescriptor cbs_sei_h265_types[] = { sizeof(H265RawSEIAlphaChannelInfo), SEI_MESSAGE_RW(h265, sei_alpha_channel_info), }, + { + SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO, + 1, 0, + sizeof(H265RawSEI3DReferenceDisplaysInfo), + SEI_MESSAGE_RW(h265, sei_3d_reference_displays_info), + }, SEI_MESSAGE_TYPE_END }; diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index afb942ced5..52631f9bfb 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -715,6 +715,22 @@ typedef struct H265RawSEIAlphaChannelInfo { uint8_t alpha_channel_clip_type_flag; } H265RawSEIAlphaChannelInfo; +typedef struct H265RawSEI3DReferenceDisplaysInfo { + uint8_t prec_ref_display_width; + uint8_t ref_viewing_distance_flag; + uint8_t prec_ref_viewing_dist; + uint8_t num_ref_displays_minus1; + uint8_t left_view_id[31]; + uint8_t right_view_id[31]; + uint8_t exponent_ref_display_width[31]; + uint8_t mantissa_ref_display_width[31]; + uint8_t exponent_ref_viewing_distance[31]; + uint8_t mantissa_ref_viewing_distance[31]; + uint8_t additional_shift_present_flag[31]; + uint16_t num_sample_shift_plus512[31]; + uint8_t three_dimensional_reference_displays_extension_flag; +} H265RawSEI3DReferenceDisplaysInfo; + typedef struct H265RawSEI { H265RawNALUnitHeader nal_unit_header; SEIRawMessageList message_list; diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c index 1826950e8e..ee01b5e0d0 100644 --- a/libavcodec/cbs_h265_syntax_template.c +++ b/libavcodec/cbs_h265_syntax_template.c @@ -2189,6 +2189,48 @@ SEI_FUNC(sei_alpha_channel_info, (CodedBitstreamContext *ctx, RWContext *rw, return 0; } +SEI_FUNC(sei_3d_reference_displays_info, (CodedBitstreamContext *ctx, RWContext *rw, + H265RawSEI3DReferenceDisplaysInfo *current, + SEIMessageState *sei)) +{ + int length; + int err, i; + + HEADER("Three Dimensional Reference Displays Information"); + + ue(prec_ref_display_width, 0, 31); + flag(ref_viewing_distance_flag); + if (current->ref_viewing_distance_flag) + ue(prec_ref_viewing_dist, 0, 31); + ue(num_ref_displays_minus1, 0, 31); + for (i = 0; i <= current->num_ref_displays_minus1; i++) { + ues(left_view_id[i], 0, UINT8_MAX, 1, i); + ues(right_view_id[i], 0, UINT8_MAX, 1, i); + us(6, exponent_ref_display_width[i], 0, 62, 1, i); + if (!current->exponent_ref_display_width[i]) + length = FFMAX(0, (int)current->prec_ref_display_width - 30); + else + length = FFMAX(0, (int)current->exponent_ref_display_width[i] + + (int)current->prec_ref_display_width - 31); + ubs(length, mantissa_ref_display_width[i], 1, i); + if (current->ref_viewing_distance_flag) { + us(6, exponent_ref_viewing_distance[i], 0, 62, 1, i); + if (!current->exponent_ref_viewing_distance[i]) + length = FFMAX(0, (int)current->prec_ref_viewing_dist - 30); + else + length = FFMAX(0, (int)current->exponent_ref_viewing_distance[i] + + (int)current->prec_ref_viewing_dist - 31); + ubs(length, mantissa_ref_viewing_distance[i], 1, i); + } + flags(additional_shift_present_flag[i], 1, i); + if (current->additional_shift_present_flag[i]) + us(10, num_sample_shift_plus512[i], 0, 1023, 1, i); + } + flag(three_dimensional_reference_displays_extension_flag); + + return 0; +} + static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEI *current, int prefix) {