From patchwork Tue Aug 27 15:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51161 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c944:0:b0:48e:c0f8:d0de with SMTP id k4csp347799vqt; Tue, 27 Aug 2024 08:55:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUaY9NcPtIJOpIM4+VjiJel3WO06R9/6a3ROWYWYufGHx3z6ryjvBFTWCa6VtfU8DA43DAjWJXnoVjdyiv9/tDY@gmail.com X-Google-Smtp-Source: AGHT+IFHzWtOTRysZEob1+8e/3I9X5hYks79QGjPHBt/2jn5dGVs3a9FY4u5PrIXlxUYsTgcKfJb X-Received: by 2002:a2e:be04:0:b0:2ef:324f:c907 with SMTP id 38308e7fff4ca-2f4f571f6aemr149976301fa.5.1724774118022; Tue, 27 Aug 2024 08:55:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724774118; cv=none; d=google.com; s=arc-20240605; b=dZMm63eRMPz2kRjwRp6GjXHixgGiH34O1TSbio/QcDQP4d2ybL7JFbuYKFveOoNJsQ oAsB3fNL16FQuB1K64n9u/U9Y6YABjqdZbltFCeCemdxnaIt1Hq2gp708nbT80vibgj2 RNtQUkAdtdnT3nUDWe5Vgge4mUgI1JcCXY7F3LF5r+uh3Vg4KW7BciuYV2KkVjo3gqBU yM7zcJShf9kHKDLAgEdRQ96itvV1ZsLf8+MSE50OWPgPzsQYwTAFXflab/jWqJvlNVSW 4oAAZFdau5lhl7M1RVCh0YK+lmIuUUxe8W5FhCLUOg7X0eDRRxkiWmym6MFDizDs5cWa n9yQ== 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=PWfeguWytA7+aOT1iltk22KMUoRuTBJcTe2T3WM5IR8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=lyOM3A0Yw1yL9aXd9R6sYjOsclJBAy8aw1azYbBH3nnvxi3Xo1oSYVhjJNEUvW6Vzg HRItQo2YGkudjGnIV5nu4RbX+s7dS+mF1IIkFho4NT2xJKcdUufToZ8+Tf2/dRM3X3dT Gn4GtsxVQKofm7RoeCxt/RrRNfEa9SGtkxt3jVy70Pa6/V9CFglafTOpz39WcPUa9qWE mmAuwYrQSKxEgdqKIwE02BbWCRUxIkL0ej8Pva6pahESZNcX/8mFzMORivbdrO+O+v4E Odf0UwNOOQQufkO93UMZPfBjB1i80QaRTIkaGudl7ebwkoeQ8+m6LeImnx2UxMjfiCAj Mtpw==; 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=pOJpr43e; 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 38308e7fff4ca-2f4047aa0dcsi38293021fa.126.2024.08.27.08.55.17; Tue, 27 Aug 2024 08:55:18 -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=pOJpr43e; 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 532FA68DE7E; Tue, 27 Aug 2024 18:43:35 +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 6C1A368DDB9 for ; Tue, 27 Aug 2024 18:43:01 +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=pOJpr43e; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 5482C4DF3 for ; Tue, 27 Aug 2024 17:43:01 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 72yrRhoXHKLc for ; Tue, 27 Aug 2024 17:43:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1724773372; bh=vHhwW4dX5Y5Auw+Ax5ZuPIPTjE/YglHzIJ/QimZqUJ4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pOJpr43eA8LeSE4w6z/L5G6s5bqmQKwe/b+9wc5F6CiE/OG+6MkGdfoZwtq8dc/OS scK9BA9S2494PfPXF4Q8vU8Oa6otuPpbVnv7U6gFHKZfOrdvVV4/X1nL6emAMDMGI1 r6hY43hULNLDaxdz5C8eND5d9ovgy3Imkyq0fLBJO9GrxsZ/jPkCkpsTlLe/TirGp9 pAa5avkQrK6OVetK2liPrxPgnipQ7a3KOwMENB8E+M08JlMCMKDnSNKG/DnB0NPhX9 w2RUfXG1GXsG38XE63celHEoN6HmdLPU6RHpYRxwFglEjRGhWltDRwdrVk8ov8+C2I Lep3U0raolkEg== 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 D2B104E30 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 B074B3A2E98 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:02 +0200 Message-ID: <20240827154041.13846-24-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 22/42] lavc/hevcdec: move HEVCContext.sao_pixel_buffer_[vh] to HEVCLayerContext 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: 7YcqZ7oxWuoX Handle them together with other sps-dependent arrays. Note that current code only allocates these arrays when hwaccel is not set, but this is wrong as the relevant code runs BEFORE get_format() is called and hence before we know whether hwaccel is in use. --- libavcodec/hevc/filter.c | 22 +++++++-------- libavcodec/hevc/hevcdec.c | 59 ++++++++++++++++----------------------- libavcodec/hevc/hevcdec.h | 5 ++-- 3 files changed, 38 insertions(+), 48 deletions(-) diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c index db82f2319f..298f1792b2 100644 --- a/libavcodec/hevc/filter.c +++ b/libavcodec/hevc/filter.c @@ -204,7 +204,7 @@ static void copy_vert(uint8_t *dst, const uint8_t *src, } } -static void copy_CTB_to_hv(const HEVCContext *s, const HEVCSPS *sps, +static void copy_CTB_to_hv(const HEVCLayerContext *l, const HEVCSPS *sps, const uint8_t *src, ptrdiff_t stride_src, int x, int y, int width, int height, int c_idx, int x_ctb, int y_ctb) @@ -214,15 +214,15 @@ static void copy_CTB_to_hv(const HEVCContext *s, const HEVCSPS *sps, int h = sps->height >> sps->vshift[c_idx]; /* copy horizontal edges */ - memcpy(s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb) * w + x) << sh), + memcpy(l->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb) * w + x) << sh), src, width << sh); - memcpy(s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb + 1) * w + x) << sh), + memcpy(l->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb + 1) * w + x) << sh), src + stride_src * (height - 1), width << sh); /* copy vertical edges */ - copy_vert(s->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb) * h + y) << sh), src, sh, height, 1 << sh, stride_src); + copy_vert(l->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb) * h + y) << sh), src, sh, height, 1 << sh, stride_src); - copy_vert(s->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 1) * h + y) << sh), src + ((width - 1) << sh), sh, height, 1 << sh, stride_src); + copy_vert(l->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 1) * h + y) << sh), src + ((width - 1) << sh), sh, height, 1 << sh, stride_src); } static void restore_tqb_pixels(const HEVCLayerContext *l, @@ -343,7 +343,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l, switch (sao->type_idx[c_idx]) { case SAO_BAND: - copy_CTB_to_hv(s, sps, src, stride_src, x0, y0, width, height, c_idx, + copy_CTB_to_hv(l, sps, src, stride_src, x0, y0, width, height, c_idx, x_ctb, y_ctb); if (pps->transquant_bypass_enable_flag || (sps->pcm_loop_filter_disabled && sps->pcm_enabled)) { @@ -385,7 +385,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l, dst1 = dst - stride_dst - (left << sh); src1[0] = src - stride_src - (left << sh); - src1[1] = s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb - 1) * w + x0 - left) << sh); + src1[1] = l->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb - 1) * w + x0 - left) << sh); pos = 0; if (left) { src_idx = (CTB(l->sao, x_ctb-1, y_ctb-1).type_idx[c_idx] == @@ -412,7 +412,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l, dst1 = dst + height * stride_dst - (left << sh); src1[0] = src + height * stride_src - (left << sh); - src1[1] = s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb + 2) * w + x0 - left) << sh); + src1[1] = l->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb + 2) * w + x0 - left) << sh); pos = 0; if (left) { src_idx = (CTB(l->sao, x_ctb-1, y_ctb+1).type_idx[c_idx] == @@ -434,7 +434,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l, if (!left_edge) { if (CTB(l->sao, x_ctb-1, y_ctb).type_idx[c_idx] == SAO_APPLIED) { copy_vert(dst - (1 << sh), - s->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb - 1) * h + y0) << sh), + l->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb - 1) * h + y0) << sh), sh, height, stride_dst, 1 << sh); } else { left_pixels = 1; @@ -444,7 +444,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l, if (!right_edge) { if (CTB(l->sao, x_ctb+1, y_ctb).type_idx[c_idx] == SAO_APPLIED) { copy_vert(dst + (width << sh), - s->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 2) * h + y0) << sh), + l->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 2) * h + y0) << sh), sh, height, stride_dst, 1 << sh); } else { right_pixels = 1; @@ -456,7 +456,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l, (width + left_pixels + right_pixels) << sh, height, stride_dst, stride_src); - copy_CTB_to_hv(s, sps, src, stride_src, x0, y0, width, height, c_idx, + copy_CTB_to_hv(l, sps, src, stride_src, x0, y0, width, height, c_idx, x_ctb, y_ctb); s->hevcdsp.sao_edge_filter[tab](src, dst, stride_src, sao->offset_val[c_idx], sao->eo_class[c_idx], width, height); diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index c4e3debae1..e02d5bba72 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -85,6 +85,11 @@ static void pic_arrays_free(HEVCLayerContext *l) av_freep(&l->horizontal_bs); av_freep(&l->vertical_bs); + for (int i = 0; i < 3; i++) { + av_freep(&l->sao_pixel_buffer_h[i]); + av_freep(&l->sao_pixel_buffer_v[i]); + } + ff_refstruct_pool_uninit(&l->tab_mvf_pool); ff_refstruct_pool_uninit(&l->rpl_tab_pool); } @@ -137,6 +142,24 @@ static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps) if (!l->tab_mvf_pool || !l->rpl_tab_pool) goto fail; + if (sps->sao_enabled) { + int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; + + for (int c_idx = 0; c_idx < c_count; c_idx++) { + int w = sps->width >> sps->hshift[c_idx]; + int h = sps->height >> sps->vshift[c_idx]; + l->sao_pixel_buffer_h[c_idx] = + av_malloc((w * 2 * sps->ctb_height) << + sps->pixel_shift); + l->sao_pixel_buffer_v[c_idx] = + av_malloc((h * 2 * sps->ctb_width) << + sps->pixel_shift); + if (!l->sao_pixel_buffer_h[c_idx] || + !l->sao_pixel_buffer_v[c_idx]) + goto fail; + } + } + return 0; fail: @@ -529,7 +552,7 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) { - int ret, i; + int ret; pic_arrays_free(l); s->ps.sps = NULL; @@ -546,30 +569,6 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); ff_videodsp_init (&s->vdsp, sps->bit_depth); - for (i = 0; i < 3; i++) { - av_freep(&s->sao_pixel_buffer_h[i]); - av_freep(&s->sao_pixel_buffer_v[i]); - } - - if (sps->sao_enabled && !s->avctx->hwaccel) { - int c_count = (sps->chroma_format_idc != 0) ? 3 : 1; - int c_idx; - - for(c_idx = 0; c_idx < c_count; c_idx++) { - int w = sps->width >> sps->hshift[c_idx]; - int h = sps->height >> sps->vshift[c_idx]; - s->sao_pixel_buffer_h[c_idx] = - av_malloc((w * 2 * sps->ctb_height) << - sps->pixel_shift); - s->sao_pixel_buffer_v[c_idx] = - av_malloc((h * 2 * sps->ctb_width) << - sps->pixel_shift); - if (!s->sao_pixel_buffer_h[c_idx] || - !s->sao_pixel_buffer_v[c_idx]) - goto fail; - } - } - s->ps.sps = sps; s->vps = ff_refstruct_ref_c(sps->vps); @@ -577,10 +576,6 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) fail: pic_arrays_free(l); - for (i = 0; i < 3; i++) { - av_freep(&s->sao_pixel_buffer_h[i]); - av_freep(&s->sao_pixel_buffer_v[i]); - } s->ps.sps = NULL; return ret; } @@ -3526,7 +3521,6 @@ static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) static av_cold int hevc_decode_free(AVCodecContext *avctx) { HEVCContext *s = avctx->priv_data; - int i; for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) pic_arrays_free(&s->layers[i]); @@ -3539,11 +3533,6 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) av_freep(&s->md5_ctx); - for (i = 0; i < 3; i++) { - av_freep(&s->sao_pixel_buffer_h[i]); - av_freep(&s->sao_pixel_buffer_v[i]); - } - ff_container_fifo_free(&s->output_fifo); for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) { diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index 1a43c3662c..0b5d87b18f 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -466,6 +466,9 @@ typedef struct HEVCLayerContext { uint8_t *horizontal_bs; uint8_t *vertical_bs; + uint8_t *sao_pixel_buffer_h[3]; + uint8_t *sao_pixel_buffer_v[3]; + struct FFRefStructPool *tab_mvf_pool; struct FFRefStructPool *rpl_tab_pool; } HEVCLayerContext; @@ -485,8 +488,6 @@ typedef struct HEVCContext { uint8_t slice_initialized; struct ContainerFifo *output_fifo; - uint8_t *sao_pixel_buffer_h[3]; - uint8_t *sao_pixel_buffer_v[3]; HEVCParamSets ps; HEVCSEI sei;