From patchwork Sat Sep 14 10:45:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51590 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9fc3:0:b0:48e:c0f8:d0de with SMTP id k3csp307035vqy; Sat, 14 Sep 2024 04:29:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV8kL6lumHgQhLzKB3G0IR0MmpystZVLahIYAR/NwfK6DU7IgGdHPuT8anUBhNUz39oqP1lvcWw1W6R8vtr82eU@gmail.com X-Google-Smtp-Source: AGHT+IEDfv0TxI3YdG+BpxI2m04F3bC/LDNiqhr1cTLkmc0kcfzzFp0Q4jlCJxe94MxMErwwbjci X-Received: by 2002:a17:907:d3c5:b0:a8d:64af:dc2a with SMTP id a640c23a62f3a-a902947b903mr900817366b.25.1726313356960; Sat, 14 Sep 2024 04:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726313356; cv=none; d=google.com; s=arc-20240605; b=NjCjI6+AUHw7/i9XVc8n9zdKn5d02usl80cCqZX4G/DJpQrxfQgq99UzmcCvUTrJcH LQlTe09Y2wGl6d5pMhN41ORvlgCCT66Wr5WvXzyMfplPmfXeQzj+J/gIoZZuy+WovBCt BkLPZ43i0jTTMbNw2u8kKl8lW1PUHUUw0VT7WAXePw4f4zdzTRFDlnl+rqYUgUalI75c pubPE78KQD5/19Ih1GmNZnT2V4u/BVQ0mOEsevSdq7QTxjxK+aIgVoME/WYrQegc1DfF UYaUebVCHDyh5spGTJr/xLPuon/jzYWLp9zIGTBB2OlbdHbj2zjWKmn/n4ujZKUhUE4V BYrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=SihbBhRGoFEexzQUyorNWwizfgyCOGVVJcyqe6d6sE4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=iubU9wadtxJ8gmmOnA6BFbTMY+5jTAExGMy8QAkGVaPqsvJnxSfiSi3TlThFSqRWIm hr7LcsTj6K85MFsessKRj4AXiZCZmlthtgvwkDekHmgmyEJOMDpVLq9AKhVHGy+xvyfF T5+MZpNFZdMzwUvvkC3QycmiJBhyaKTE1iQsoL+JeZJRxiD4b+jmmxfrJVRCKlI1zyqQ QY1B3SowZkQNXlHB4xTBpEwtFjiyS8eTwz6ihdg9oOkA0/sq4FzG+N/ZgQz/To8mXW8t nmT6GiTgO3HI3zmpdMM7V+HtZ/D0qTt9clx7mfG0+uKhT+njxe6yfoQxdWCI+7Auk6aH oy0g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=oa7m8Eqc; 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 a640c23a62f3a-a906109a18dsi87235766b.121.2024.09.14.04.29.16; Sat, 14 Sep 2024 04:29:16 -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=@khirnov.net header.s=mail header.b=oa7m8Eqc; 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 06A9568DE61; Sat, 14 Sep 2024 14:11:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C86168DDC8 for ; Sat, 14 Sep 2024 14:10:54 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=oa7m8Eqc; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 0BD324E07 for ; Sat, 14 Sep 2024 13:10:50 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id PHu-fRNF0iSr for ; Sat, 14 Sep 2024 13:10:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1726312246; bh=QPf9PMiO1Bs/9HCjYtPvI5c/ORcxha5cw44GDm7NqUI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oa7m8Eqc/fBSpxASLXzR89byf0BLEVHyqtErLoybTkHby3tvJugsuC5wfc4bHvuMi q2utZuWS4tod+HRQ4yNlDKtbRG1k3sjC+opveu7NXLeCNcPjXBcjDuxfspwEnt67GD PClG8KpmrQ1vSd2EBWaz1wq/rDNFdYx+H6m7NmpXewNd+Xqgz94UKqgXhFlzilKDiu w9amsvZwYbsfunzK6wS1kEr0nFV2PomlXODMn9Wt5guN6YFtybMKc6lwUMxAbIrenC LhdFwTgwOLUjChbVt3zr7KWkZY87ifx1LFlnKSuy9k54892ycA5NF+6peCvoHtTMZy dIPKnHmuJvCQQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 769E94E12 for ; Sat, 14 Sep 2024 13:10:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 664F33A1B33 for ; Sat, 14 Sep 2024 13:10:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 14 Sep 2024 12:45:37 +0200 Message-ID: <20240914111036.17164-13-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240914111036.17164-1-anton@khirnov.net> References: <20240914111036.17164-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/23] lavc/hevcdec: implement slice header parsing for nuh_layer_id>0 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: vqwQJKnyFKMm Cf. F.7.3.6.1 "General slice segment header syntax" --- libavcodec/hevc/hevcdec.c | 36 ++++++++++++++++++++++++++++++++---- libavcodec/hevc/hevcdec.h | 1 + 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index ebe2f5ad11..d3a47b65f4 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -584,7 +584,8 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext { const HEVCPPS *pps; const HEVCSPS *sps; - unsigned pps_id; + const HEVCVPS *vps; + unsigned pps_id, layer_idx; int i, ret; // Coded parameters @@ -607,6 +608,8 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext pps = s->ps.pps_list[pps_id]; sps = pps->sps; + vps = sps->vps; + layer_idx = vps->layer_idx[s->nuh_layer_id]; if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) sh->no_output_of_prior_pics_flag = 1; @@ -652,7 +655,8 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext return AVERROR_INVALIDDATA; } if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I && - !pps->pps_curr_pic_ref_enabled_flag) { + !pps->pps_curr_pic_ref_enabled_flag && + s->nuh_layer_id == 0) { av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); return AVERROR_INVALIDDATA; } @@ -665,8 +669,10 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext if (sps->separate_colour_plane) sh->colour_plane_id = get_bits(gb, 2); - if (!IS_IDR(s)) { - int poc, pos; + if (!IS_IDR(s) || + (s->nuh_layer_id > 0 && + !(vps->poc_lsb_not_present & (1 << layer_idx)))) { + int poc; sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb); poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type); @@ -678,6 +684,10 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext poc = sh->poc; } sh->poc = poc; + } + + if (!IS_IDR(s)) { + int pos; sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); pos = get_bits_left(gb); @@ -724,6 +734,23 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext sh->slice_temporal_mvp_enabled_flag = 0; } + sh->inter_layer_pred = 0; + if (s->nuh_layer_id > 0) { + int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx]; + + if (vps->default_ref_layers_active) + sh->inter_layer_pred = !!num_direct_ref_layers; + else if (num_direct_ref_layers) { + sh->inter_layer_pred = get_bits1(gb); + + if (sh->inter_layer_pred && num_direct_ref_layers > 1) { + av_log(s->avctx, AV_LOG_ERROR, + "NumDirectRefLayers>1 not supported\n"); + return AVERROR_PATCHWELCOME; + } + } + } + if (sps->sao_enabled) { sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); if (sps->chroma_format_idc) { @@ -3238,6 +3265,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) int ret; s->nal_unit_type = nal->type; + s->nuh_layer_id = nal->nuh_layer_id; s->temporal_id = nal->temporal_id; if (FF_HW_HAS_CB(s->avctx, decode_params) && diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index e3194fd87e..16b1d1ce92 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -215,6 +215,7 @@ typedef struct SliceHeader { uint8_t dependent_slice_segment_flag; uint8_t pic_output_flag; uint8_t colour_plane_id; + uint8_t inter_layer_pred; ///< RPS coded in the slice header itself is stored here int short_term_ref_pic_set_sps_flag;