From patchwork Tue Aug 27 15:04:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51168 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c944:0:b0:48e:c0f8:d0de with SMTP id k4csp358611vqt; Tue, 27 Aug 2024 09:10:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVqhwtq3mnN+KLzTNSzM3+czbUgNcfyAB1cK/wQ4/HCl6xsvBhGGQqvpaEjqwVCRe7ovB310nKKNhqlJBwCVDsz@gmail.com X-Google-Smtp-Source: AGHT+IHy4rsDgs/hSm/MkP/mzQXNyMvKadkXdysSjVXvqChZfiZNxBUJgtb/r7lnfA1JbpQ/rCUi X-Received: by 2002:a05:651c:1601:b0:2f5:10c5:9111 with SMTP id 38308e7fff4ca-2f510c592c6mr22039161fa.8.1724775020771; Tue, 27 Aug 2024 09:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724775020; cv=none; d=google.com; s=arc-20240605; b=K+rl79wbkWexky0yhildHQ3s1QaPseJRRiswZ+lWqb7kGaGDmKrRdpvmNA12qVfHzR pfDEsimwD4w8HUoQVWAqoQAdVee+iP63nI/7L0sTkbsARVc70rBDAUxzMGmv86NIQJIE XdiXYIsjNgW5wthiEVDaqv/7ewbAXcxoVEohN3HUcH4HfC5FFjF+xgvDDI5jKG2R/UnK jB7xJ8Tizl2vaHNSf2RplnksPMN0xgCnU58tZMHWSCQzoLUX8NRW92wN1092XtH5avwP eYHqP5xiZS2R1MQoqAxjNNSHixCOgYRprZ6Kx07WPuqzwZofzE64nG0pH+f6NpiGJ8qo 7Dkw== 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=kimDh+hz+X6YtFmvMNltzoN5IuzhuCwVqDDaIE8+GYo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=CS1kCJ7jyzOs5rDeogPQAaJpD1C+Gd1fN5FQtPSV/yloK7hPGZVH93j8UYCJnkhqsH SZWwYdO2IOfjIGdaRZ6qCHuZNDJau3YxJKdcqNbwsEBzbnb7Ba5A4wLVy76VjwjQoqqG wC7U3qr7U8P2ilQL+XhYyI4b8BJlZ2xuKIXdurdTFzbEbfVr/wTF0ibTHrEHQF2gs4AW rhtP+mz8ht8/liwEFaZb1xeLIHybDjq4YrCizJoL1UnCDZdlC36ejULYi50RirbWfjBY UnsOXrkmCO3u1RQg0buVXp9AWdcPexj7J+fRoyl8yp4BloMaNcuWJMsBOwQqEidj+QLd FQVA==; 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=liRX6pd0; 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-2f5136d8b9dsi8939621fa.326.2024.08.27.09.10.20; Tue, 27 Aug 2024 09:10:20 -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=liRX6pd0; 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 7BE5C68DE8D; Tue, 27 Aug 2024 18:43:39 +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 D7BBD68DDD4 for ; Tue, 27 Aug 2024 18:42:57 +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=liRX6pd0; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 6E4894DFA for ; Tue, 27 Aug 2024 17:42:53 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id I88VRhT8nmWd for ; Tue, 27 Aug 2024 17:42:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1724773368; bh=tU8k/ZI0OhT70dhVvjjDqhP4EIDeO+q5Ekxo5TWnGrY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=liRX6pd0dsTdtlu2/bwKsnlHI+0OR+oy049XavcxDk5ejWzdoSgvzfOChOV+1t+hN LmPjkrSo8KubTJ+7Kp/roxxznxtOA4MWpcSgzskDWn/gXs86LuYTyLUtoRmFsbIk1F 7+Mw5vcGnh8UH1bhuozqdU2yDKwGoGsntRYYZn420py5fz19swWIOKwkeCVuR4pnoQ MMTEcg3wtLe43jyoCWpDNMGLXAE/9yRLOZ1uJKqY8gcW2pvnlugf1vgWmynR6F1uJb vKa78Ark/n5bVbtVE7UAdVYAU6DDakHA4i1sb8vofJvFR/o7171kboBOL/T7uSxtCp 1xaJMvWdHM2dA== 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 CFC124E05 for ; Tue, 27 Aug 2024 17:42:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 23E6F3A2B5B for ; Tue, 27 Aug 2024 17:42:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Aug 2024 17:04:50 +0200 Message-ID: <20240827154041.13846-12-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 10/42] lavc/hevcdec: move HEVCContext.sao 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: Zsue+pqkbkwa --- libavcodec/hevc/filter.c | 29 +++++++++++++++-------------- libavcodec/hevc/hevcdec.c | 29 +++++++++++++++-------------- libavcodec/hevc/hevcdec.h | 3 ++- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c index 18c73dc2fa..78f408f170 100644 --- a/libavcodec/hevc/filter.c +++ b/libavcodec/hevc/filter.c @@ -264,7 +264,8 @@ static void restore_tqb_pixels(const HEVCContext *s, #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)]) -static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, +static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCContext *s, const HEVCPPS *pps, const HEVCSPS *sps, int x, int y) { @@ -275,7 +276,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int y_ctb = y >> sps->log2_ctb_size; int ctb_addr_rs = y_ctb * sps->ctb_width + x_ctb; int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs]; - SAOParams *sao = &CTB(s->sao, x_ctb, y_ctb); + SAOParams *sao = &CTB(l->sao, x_ctb, y_ctb); // flags indicating unfilterable edges uint8_t vert_edge[] = { 0, 0 }; uint8_t horiz_edge[] = { 0, 0 }; @@ -385,17 +386,17 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, src1[1] = s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb - 1) * w + x0 - left) << sh); pos = 0; if (left) { - src_idx = (CTB(s->sao, x_ctb-1, y_ctb-1).type_idx[c_idx] == + src_idx = (CTB(l->sao, x_ctb-1, y_ctb-1).type_idx[c_idx] == SAO_APPLIED); copy_pixel(dst1, src1[src_idx], sh); pos += (1 << sh); } - src_idx = (CTB(s->sao, x_ctb, y_ctb-1).type_idx[c_idx] == + src_idx = (CTB(l->sao, x_ctb, y_ctb-1).type_idx[c_idx] == SAO_APPLIED); memcpy(dst1 + pos, src1[src_idx] + pos, width << sh); if (right) { pos += width << sh; - src_idx = (CTB(s->sao, x_ctb+1, y_ctb-1).type_idx[c_idx] == + src_idx = (CTB(l->sao, x_ctb+1, y_ctb-1).type_idx[c_idx] == SAO_APPLIED); copy_pixel(dst1 + pos, src1[src_idx] + pos, sh); } @@ -412,24 +413,24 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, src1[1] = s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb + 2) * w + x0 - left) << sh); pos = 0; if (left) { - src_idx = (CTB(s->sao, x_ctb-1, y_ctb+1).type_idx[c_idx] == + src_idx = (CTB(l->sao, x_ctb-1, y_ctb+1).type_idx[c_idx] == SAO_APPLIED); copy_pixel(dst1, src1[src_idx], sh); pos += (1 << sh); } - src_idx = (CTB(s->sao, x_ctb, y_ctb+1).type_idx[c_idx] == + src_idx = (CTB(l->sao, x_ctb, y_ctb+1).type_idx[c_idx] == SAO_APPLIED); memcpy(dst1 + pos, src1[src_idx] + pos, width << sh); if (right) { pos += width << sh; - src_idx = (CTB(s->sao, x_ctb+1, y_ctb+1).type_idx[c_idx] == + src_idx = (CTB(l->sao, x_ctb+1, y_ctb+1).type_idx[c_idx] == SAO_APPLIED); copy_pixel(dst1 + pos, src1[src_idx] + pos, sh); } } left_pixels = 0; if (!left_edge) { - if (CTB(s->sao, x_ctb-1, y_ctb).type_idx[c_idx] == SAO_APPLIED) { + 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), sh, height, stride_dst, 1 << sh); @@ -439,7 +440,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, } right_pixels = 0; if (!right_edge) { - if (CTB(s->sao, x_ctb+1, y_ctb).type_idx[c_idx] == SAO_APPLIED) { + 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), sh, height, stride_dst, 1 << sh); @@ -889,16 +890,16 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCLayerContext *l, if (sps->sao_enabled && !skip) { int y_end = y >= sps->height - ctb_size; if (y && x) - sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y - ctb_size); + sao_filter_CTB(lc, l, s, pps, sps, x - ctb_size, y - ctb_size); if (x && y_end) - sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y); + sao_filter_CTB(lc, l, s, pps, sps, x - ctb_size, y); if (y && x_end) { - sao_filter_CTB(lc, s, pps, sps, x, y - ctb_size); + sao_filter_CTB(lc, l, s, pps, sps, x, y - ctb_size); if (s->avctx->active_thread_type & FF_THREAD_FRAME ) ff_progress_frame_report(&s->cur_frame->tf, y); } if (x_end && y_end) { - sao_filter_CTB(lc, s, pps, sps, x , y); + sao_filter_CTB(lc, l, s, pps, sps, x , y); if (s->avctx->active_thread_type & FF_THREAD_FRAME ) ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size); } diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 4978aa745c..0bb4d43ed4 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -66,9 +66,9 @@ static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, */ /* free everything allocated by pic_arrays_init() */ -static void pic_arrays_free(HEVCContext *s) +static void pic_arrays_free(HEVCContext *s, HEVCLayerContext *l) { - av_freep(&s->sao); + av_freep(&l->sao); av_freep(&s->deblock); av_freep(&s->skip_flag); @@ -103,9 +103,9 @@ static int pic_arrays_init(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *s l->bs_width = (width >> 2) + 1; l->bs_height = (height >> 2) + 1; - s->sao = av_calloc(ctb_count, sizeof(*s->sao)); + l->sao = av_calloc(ctb_count, sizeof(*l->sao)); s->deblock = av_calloc(ctb_count, sizeof(*s->deblock)); - if (!s->sao || !s->deblock) + if (!l->sao || !s->deblock) goto fail; s->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width); @@ -140,7 +140,7 @@ static int pic_arrays_init(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *s return 0; fail: - pic_arrays_free(s); + pic_arrays_free(s, l); return AVERROR(ENOMEM); } @@ -531,7 +531,7 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) { int ret, i; - pic_arrays_free(s); + pic_arrays_free(s, l); s->ps.sps = NULL; ff_refstruct_unref(&s->vps); @@ -576,7 +576,7 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) return 0; fail: - pic_arrays_free(s); + pic_arrays_free(s, l); for (i = 0; i < 3; i++) { av_freep(&s->sao_pixel_buffer_h[i]); av_freep(&s->sao_pixel_buffer_v[i]); @@ -990,21 +990,21 @@ do { \ if (!sao_merge_up_flag && !sao_merge_left_flag) \ sao->elem = value; \ else if (sao_merge_left_flag) \ - sao->elem = CTB(s->sao, rx-1, ry).elem; \ + sao->elem = CTB(l->sao, rx-1, ry).elem; \ else if (sao_merge_up_flag) \ - sao->elem = CTB(s->sao, rx, ry-1).elem; \ + sao->elem = CTB(l->sao, rx, ry-1).elem; \ else \ sao->elem = 0; \ } while (0) -static void hls_sao_param(HEVCLocalContext *lc, +static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int rx, int ry) { const HEVCContext *const s = lc->parent; int sao_merge_left_flag = 0; int sao_merge_up_flag = 0; - SAOParams *sao = &CTB(s->sao, rx, ry); + SAOParams *sao = &CTB(l->sao, rx, ry); int c_idx, i; if (s->sh.slice_sample_adaptive_offset_flag[0] || @@ -2556,7 +2556,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) return ret; } - hls_sao_param(lc, pps, sps, + hls_sao_param(lc, l, pps, sps, x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset; @@ -2624,7 +2624,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1); if (ret < 0) goto error; - hls_sao_param(lc, pps, sps, + hls_sao_param(lc, l, pps, sps, x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); @@ -3518,7 +3518,8 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) HEVCContext *s = avctx->priv_data; int i; - pic_arrays_free(s); + for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) + pic_arrays_free(s, &s->layers[i]); ff_refstruct_unref(&s->vps); ff_refstruct_unref(&s->pps); diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index 18b15e7dc1..e0b026eef6 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -443,6 +443,8 @@ typedef struct HEVCLayerContext { int bs_width; int bs_height; + + SAOParams *sao; } HEVCLayerContext; typedef struct HEVCContext { @@ -476,7 +478,6 @@ typedef struct HEVCContext { const HEVCVPS *vps; ///< RefStruct reference const HEVCPPS *pps; ///< RefStruct reference SliceHeader sh; - SAOParams *sao; DBParams *deblock; enum HEVCNALUnitType nal_unit_type; int temporal_id; ///< temporal_id_plus1 - 1