From patchwork Tue Aug 27 15:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51193 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c944:0:b0:48e:c0f8:d0de with SMTP id k4csp474352vqt; Tue, 27 Aug 2024 13:00:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUdHnCPZMUClxjUUobL10VV6jhk/7YJCdD9YrUl1NnFq3ueOOxZPUJUpY8eIpRZ1zdjJ8zCD+mzS5y6yemONNa2@gmail.com X-Google-Smtp-Source: AGHT+IHpwP+FdyDuL2c9HzKOSjwZDZLs/uZfl5F/Id+BB7Am6+e06SNxzqijHQQ1qMU6OurhoL7B X-Received: by 2002:a17:907:7d91:b0:a80:f63e:159b with SMTP id a640c23a62f3a-a86a4eb416fmr557583466b.0.1724788813877; Tue, 27 Aug 2024 13:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724788813; cv=none; d=google.com; s=arc-20240605; b=Ouo4MQEBeEscS39yaXaozWNhCkCOqLhwNn826MRwSZ91pH1hmmY+vfG5cphSaGzM0W HvLkOTc+Mxa8aou6VpS3hExmuHZmzKm9V8nQ/YgX9AXBE7/0AUkTHuNuO6GjSz70QWIg fJlKerBZzdoP/GidoRXUzcLqhvdXO8p4pUs2PosQBDRNpRGGwkGW/7jiDv6w1AmnWhrW n21/0ifrltCnCMnNslb6ik6iudkGb+yym7PV2AjhHkC/9i2g0Rmdhjf+b7vHlsCBy74t xd1QEMEoOuSTTOVhOFD4YbxjBXRl3b4mkxTKVZHnEhRoZA135J4SRC1bVgdZJoJWex5E JFpw== 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=xRu79baEeAOVyNhElmJWy5IY8RuTeR/ic2f8UbzR59M=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=PqyvwZoVgfUvEeKupsqj/YXliCB2rIkkKgzfq7K9/iTrhnlesH5CpU6qLgb6JTmtqN StF9nfkO+mlFvNSac00WJ9oPmHxF7CWYIBJsq8L2VtZYNlE64t3OqGgX6JHIuN80gmBX 1HvG6h5h58s3lM8XfMGx7JI5ICOScmcF8B2DH5+NXHh/Y1mYYtPF9M6ob81qdJWUELtu Htm5N0W79OjzfuxAuKAdHSZaoq10R8YsSxIJuSfQPuL5k7fYGLoibPh71A8VqiE21EtU OXgyWRd9JE1gOHqlHgY8Y2x27jXqecvsni0QKXQZAxhcqOcdvzmhfsJWPFg58Kplaxe/ 8COw==; 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=m2OdDbx2; 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-a86e588c398si191558866b.614.2024.08.27.13.00.12; Tue, 27 Aug 2024 13:00:13 -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=m2OdDbx2; 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 8868268DE55; Tue, 27 Aug 2024 18:43:23 +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 5427068DDA1 for ; Tue, 27 Aug 2024 18:42:59 +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=m2OdDbx2; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3D29F4E04 for ; Tue, 27 Aug 2024 17:42:59 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 4-rM9Dps6fgD for ; Tue, 27 Aug 2024 17:42:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1724773371; bh=7uPhvNYP2/QhobpFoznYktyENrHEJHHBo2LivxpFPBo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=m2OdDbx2Q4QA4XaFkkcV2Iki06XMeWxIZnImfwTlfykDAbr7RlYCG89BhOkJXkpjn YMkzq1njvfq1RIn13ADUI6rPf2MYYizdGk4xx6dIkd21OxWKmrRAwruNdZ3S7FrxtY unM+FS7JgFRls0q85QVSB05EY+u2Q8F+LVnSyZWZ3YE5hlJK67zwQd8geheBog/Mo/ Oo8HtBY6h6uhvzQaZoBK+1nhMyHvE197y3HACO/vk0m6wrb4bRDc1VLOURTMDirJyB 27+yKpmfxTA6ksRcC5DrFnd8JmXXpMC0aqCPHQfxXh/YML//Z5EH1rRJzS5fqcbS8p ATKUjXkKVrSiw== 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 5B33A4E2E for ; Tue, 27 Aug 2024 17:42:49 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BC2C53A2F2B for ; Tue, 27 Aug 2024 17:42:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Aug 2024 17:05:03 +0200 Message-ID: <20240827154041.13846-25-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240827154041.13846-2-anton@khirnov.net> References: <20240827154041.13846-2-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/42] lavc/hevcdec: make a HEVCFrame hold a reference to its PPS 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: J7ApfidhZMcT ff_hevc_get_ref_list() needs the PPS of a previously decoded frame, which may be different from the currently active one. --- libavcodec/hevc/filter.c | 4 ++-- libavcodec/hevc/hevcdec.c | 1 + libavcodec/hevc/hevcdec.h | 4 ++-- libavcodec/hevc/mvs.c | 2 +- libavcodec/hevc/refs.c | 15 +++++++++------ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c index 298f1792b2..68ae0e9ef6 100644 --- a/libavcodec/hevc/filter.c +++ b/libavcodec/hevc/filter.c @@ -767,7 +767,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCLayer if (boundary_upper) { const RefPicList *rpl_top = (lc->boundary_flags & BOUNDARY_UPPER_SLICE) ? - ff_hevc_get_ref_list(s, s->cur_frame, x0, y0 - 1) : + ff_hevc_get_ref_list(s->cur_frame, x0, y0 - 1) : s->cur_frame->refPicList; int yp_pu = (y0 - 1) >> log2_min_pu_size; int yq_pu = y0 >> log2_min_pu_size; @@ -805,7 +805,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCLayer if (boundary_left) { const RefPicList *rpl_left = (lc->boundary_flags & BOUNDARY_LEFT_SLICE) ? - ff_hevc_get_ref_list(s, s->cur_frame, x0 - 1, y0) : + ff_hevc_get_ref_list(s->cur_frame, x0 - 1, y0) : s->cur_frame->refPicList; int xp_pu = (x0 - 1) >> log2_min_pu_size; int xq_pu = x0 >> log2_min_pu_size; diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index e02d5bba72..eb41f9a5d6 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3503,6 +3503,7 @@ static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) dst->needs_fg = 1; } + dst->pps = ff_refstruct_ref_c(src->pps); dst->tab_mvf = ff_refstruct_ref(src->tab_mvf); dst->rpl_tab = ff_refstruct_ref(src->rpl_tab); dst->rpl = ff_refstruct_ref(src->rpl); diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index 0b5d87b18f..a534aee60f 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -366,6 +366,7 @@ typedef struct HEVCFrame { int ctb_count; int poc; + const HEVCPPS *pps; ///< RefStruct reference RefPicListTab *rpl; ///< RefStruct reference int nb_rpl_elems; @@ -556,8 +557,7 @@ void ff_hevc_clear_refs(HEVCLayerContext *l); */ void ff_hevc_flush_dpb(HEVCContext *s); -const RefPicList *ff_hevc_get_ref_list(const HEVCContext *s, const HEVCFrame *frame, - int x0, int y0); +const RefPicList *ff_hevc_get_ref_list(const HEVCFrame *frame, int x0, int y0); /** * Construct the reference picture sets for the current frame. diff --git a/libavcodec/hevc/mvs.c b/libavcodec/hevc/mvs.c index 96d8d58f39..55f115ad0c 100644 --- a/libavcodec/hevc/mvs.c +++ b/libavcodec/hevc/mvs.c @@ -211,7 +211,7 @@ static int derive_temporal_colocated_mvs(const HEVCContext *s, MvField temp_col, #define DERIVE_TEMPORAL_COLOCATED_MVS \ derive_temporal_colocated_mvs(s, temp_col, \ refIdxLx, mvLXCol, X, colPic, \ - ff_hevc_get_ref_list(s, ref, x, y)) + ff_hevc_get_ref_list(ref, x, y)) /* * 8.5.3.1.7 temporal luma motion vector prediction diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c index 7b8dff4f55..58edc15a6f 100644 --- a/libavcodec/hevc/refs.c +++ b/libavcodec/hevc/refs.c @@ -38,6 +38,7 @@ void ff_hevc_unref_frame(HEVCFrame *frame, int flags) av_frame_unref(frame->frame_grain); frame->needs_fg = 0; + ff_refstruct_unref(&frame->pps); ff_refstruct_unref(&frame->tab_mvf); ff_refstruct_unref(&frame->rpl); @@ -49,13 +50,13 @@ void ff_hevc_unref_frame(HEVCFrame *frame, int flags) } } -const RefPicList *ff_hevc_get_ref_list(const HEVCContext *s, - const HEVCFrame *ref, int x0, int y0) +const RefPicList *ff_hevc_get_ref_list(const HEVCFrame *ref, int x0, int y0) { - int x_cb = x0 >> s->ps.sps->log2_ctb_size; - int y_cb = y0 >> s->ps.sps->log2_ctb_size; - int pic_width_cb = s->ps.sps->ctb_width; - int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb]; + const HEVCSPS *sps = ref->pps->sps; + int x_cb = x0 >> sps->log2_ctb_size; + int y_cb = y0 >> sps->log2_ctb_size; + int pic_width_cb = sps->ctb_width; + int ctb_addr_ts = ref->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb]; return &ref->rpl_tab[ctb_addr_ts]->refPicList[0]; } @@ -116,6 +117,8 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l) if (ret < 0) goto fail; + frame->pps = ff_refstruct_ref_c(s->pps); + return frame; fail: ff_hevc_unref_frame(frame, ~0);