From patchwork Tue Aug 27 15:04:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51194 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c944:0:b0:48e:c0f8:d0de with SMTP id k4csp474357vqt; Tue, 27 Aug 2024 13:00:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUd+n+PW4GfHITlQVyONVX1xRbKPCbbbxKbRGJ/tewHiz7mGok4dEMjav/EHB4KuzCAq7TnuKaIZeZicHqHPaJL@gmail.com X-Google-Smtp-Source: AGHT+IFXjpxkFc2XJDxYqtOjGkUVx1pr04YxaGgLia/Mnqgkr/SLmvFqD+X3NG5vBfvssEN97iZf X-Received: by 2002:a05:6402:518b:b0:5a1:4f76:1a25 with SMTP id 4fb4d7f45d1cf-5c2118ef5c4mr361735a12.17.1724788814196; Tue, 27 Aug 2024 13:00:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724788814; cv=none; d=google.com; s=arc-20240605; b=a3uDwbB4/Q0FnN85OYnFOS0o0m4tlx9QTMhYFtIuddcCjq634Xi6VwGtf1lVdIKzQR CJdMh5EXBpsTCh6gVCgKcEv6Ctgqtw8oDXyAe12xvs5WnGtBSPPh0mB7d7FtgmgKH62B XY8azx/u8fHRuba7V+K7YxgfmNiY2iBF8TDBawALM27mxJKLlqOQoH8jTQJ296TnRfDt zUeQmamsb9DVo+wp1g12UWguQdgBsrSYJCkKmUZQVtDIOrfkisXxLJpZa6d+BtFSc+OT p0dDUXPHClECFgVmv9b2+3wyWtdyZreSgCSTmKP6CVt1A3Av0a53fRhwQ+a91Tnk1VYF 3gxQ== 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=+1qrzAbBa3qezjb1k7tfwjVxN1PziO95X6q33zx3Ghs=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=IGA/xUlJFO9PyU8Y9WbzBBQl1VGjboSy9K0umWglXde+jSSru7Ovx+6Sr5Rp38DwDc N0W5OF6b8xVgqJHXYTZjLzW9U8zyBMEsROsNz+IZzqVxx1zMp09HOUVpZvTrZMb5u75H ltExQT5enmaLxQB+o4nhllLEFwx7lK3qlbeY4mT7zYF2dDqKeEvvMXxVT8hsNwCcFW6c 3cKHdB1PcO+KodPu6/zMTqiecmtQHthp2Bi3N4KGe77OL4bFSlkNlDbOCw/UiI7F13Dc Ufu+r9gxCeiBjlRrwwQmmoaqI6mdDkjSKRGsMo7qwIdGirFBrBNJ6vzH3iYVbEqObvoN qGGQ==; 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=T4gW8D1k; 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 4fb4d7f45d1cf-5c0bb1c4f28si1818662a12.91.2024.08.27.13.00.13; Tue, 27 Aug 2024 13:00: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=@khirnov.net header.s=mail header.b=T4gW8D1k; 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 805C668D716; Tue, 27 Aug 2024 18:43:09 +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 8DF3C68DD93 for ; Tue, 27 Aug 2024 18:42:58 +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=T4gW8D1k; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 63DDB4E13 for ; Tue, 27 Aug 2024 17:42:55 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id eanplWJyMs29 for ; Tue, 27 Aug 2024 17:42:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1724773368; bh=Kj4EIQJ4LPYWpspr1bYzqnfxQthlF5yCcr5OML9fPHk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=T4gW8D1k06/g2HHV8p/uey32pth/lI1N8NACS+fMxqeasPoctxOMImvcym9pseAI4 gwaH1u51iknLESg2LK/n+TyJRlhvlI9YJMna3nI6/hQP3XP17a2aIkvZ6feNIxGTIc 5mKCt81n2c8xcHs9CHVvP48/V+7rilzYgwJDKVNruxs/ZxL6+sgWuBaTs13Mc2pBfJ IFMaA1ddiEOO1EKGp3XXk7o8WHWrjdGLJX2qPU4ehj/WZBBEo1fPLwMThweUHXpraq w6j1Lm3PIgE6Q3skVUoihhutBZpTFG3rY+tFY6+xl7JJsgv10TGCG1fyih2XeH3NpG Fsqey0OzzyjNg== 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 CFB8D4E04 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 185793A2B40 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:49 +0200 Message-ID: <20240827154041.13846-11-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 09/42] lavc/hevcdec: move HEVCContext.bs_{width, height} 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: 2yX1t8vn0zbP --- libavcodec/hevc/filter.c | 43 ++++++++++++----------- libavcodec/hevc/hevcdec.c | 73 ++++++++++++++++++++++----------------- libavcodec/hevc/hevcdec.h | 14 +++++--- 3 files changed, 73 insertions(+), 57 deletions(-) diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c index 56e354b486..18c73dc2fa 100644 --- a/libavcodec/hevc/filter.c +++ b/libavcodec/hevc/filter.c @@ -495,7 +495,7 @@ static int get_pcm(const HEVCSPS *sps, const uint8_t *is_pcm, int x, int y) (tc_offset & -2), \ 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)] -static void deblocking_filter_CTB(const HEVCContext *s, +static void deblocking_filter_CTB(const HEVCContext *s, const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0) { @@ -546,8 +546,8 @@ static void deblocking_filter_CTB(const HEVCContext *s, for (y = y0; y < y_end; y += 8) { // vertical filtering luma for (x = x0 ? x0 : 8; x < x_end; x += 8) { - const int bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2]; - const int bs1 = s->vertical_bs[(x + (y + 4) * s->bs_width) >> 2]; + const int bs0 = s->vertical_bs[(x + y * l->bs_width) >> 2]; + const int bs1 = s->vertical_bs[(x + (y + 4) * l->bs_width) >> 2]; if (bs0 || bs1) { const int qp = (get_qPy(sps, s->qp_y_tab, x - 1, y) + get_qPy(sps, s->qp_y_tab, x, y) + 1) >> 1; @@ -575,8 +575,8 @@ static void deblocking_filter_CTB(const HEVCContext *s, // horizontal filtering luma for (x = x0 ? x0 - 8 : 0; x < x_end2; x += 8) { - const int bs0 = s->horizontal_bs[( x + y * s->bs_width) >> 2]; - const int bs1 = s->horizontal_bs[((x + 4) + y * s->bs_width) >> 2]; + const int bs0 = s->horizontal_bs[( x + y * l->bs_width) >> 2]; + const int bs1 = s->horizontal_bs[((x + 4) + y * l->bs_width) >> 2]; if (bs0 || bs1) { const int qp = (get_qPy(sps, s->qp_y_tab, x, y - 1) + get_qPy(sps, s->qp_y_tab, x, y) + 1) >> 1; @@ -610,8 +610,8 @@ static void deblocking_filter_CTB(const HEVCContext *s, // vertical filtering chroma for (y = y0; y < y_end; y += (8 * v)) { for (x = x0 ? x0 : 8 * h; x < x_end; x += (8 * h)) { - const int bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2]; - const int bs1 = s->vertical_bs[(x + (y + (4 * v)) * s->bs_width) >> 2]; + const int bs0 = s->vertical_bs[(x + y * l->bs_width) >> 2]; + const int bs1 = s->vertical_bs[(x + (y + (4 * v)) * l->bs_width) >> 2]; if ((bs0 == 2) || (bs1 == 2)) { const int qp0 = (get_qPy(sps, s->qp_y_tab, x - 1, y) + @@ -644,8 +644,8 @@ static void deblocking_filter_CTB(const HEVCContext *s, if (x_end != sps->width) x_end2 = x_end - 8 * h; for (x = x0 ? x0 - 8 * h : 0; x < x_end2; x += (8 * h)) { - const int bs0 = s->horizontal_bs[( x + y * s->bs_width) >> 2]; - const int bs1 = s->horizontal_bs[((x + 4 * h) + y * s->bs_width) >> 2]; + const int bs0 = s->horizontal_bs[( x + y * l->bs_width) >> 2]; + const int bs1 = s->horizontal_bs[((x + 4 * h) + y * l->bs_width) >> 2]; if ((bs0 == 2) || (bs1 == 2)) { const int qp0 = bs0 == 2 ? (get_qPy(sps, s->qp_y_tab, x, y - 1) + get_qPy(sps, s->qp_y_tab, x, y) + 1) >> 1 : 0; @@ -736,7 +736,8 @@ static int boundary_strength(const HEVCContext *s, const MvField *curr, const Mv return 1; } -void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS *pps, +void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCPPS *pps, int x0, int y0, int log2_trafo_size) { const HEVCSPS *const sps = pps->sps; @@ -784,7 +785,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS * bs = 1; else bs = boundary_strength(s, curr, top, rpl_top); - s->horizontal_bs[((x0 + i) + y0 * s->bs_width) >> 2] = bs; + s->horizontal_bs[((x0 + i) + y0 * l->bs_width) >> 2] = bs; } } @@ -822,7 +823,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS * bs = 1; else bs = boundary_strength(s, curr, left, rpl_left); - s->vertical_bs[(x0 + (y0 + i) * s->bs_width) >> 2] = bs; + s->vertical_bs[(x0 + (y0 + i) * l->bs_width) >> 2] = bs; } } @@ -840,7 +841,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS * const MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; bs = boundary_strength(s, curr, top, rpl); - s->horizontal_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs; + s->horizontal_bs[((x0 + i) + (y0 + j) * l->bs_width) >> 2] = bs; } } @@ -855,7 +856,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS * const MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; bs = boundary_strength(s, curr, left, rpl); - s->vertical_bs[((x0 + i) + (y0 + j) * s->bs_width) >> 2] = bs; + s->vertical_bs[((x0 + i) + (y0 + j) * l->bs_width) >> 2] = bs; } } } @@ -865,7 +866,8 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS * #undef CB #undef CR -void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCPPS *pps, +void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCPPS *pps, int x, int y, int ctb_size) { const HEVCSPS *const sps = pps->sps; @@ -883,7 +885,7 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCPPS *pps, skip = 1; if (!skip) - deblocking_filter_CTB(s, pps, sps, x, y); + deblocking_filter_CTB(s, l, pps, sps, x, y); if (sps->sao_enabled && !skip) { int y_end = y >= sps->height - ctb_size; if (y && x) @@ -904,15 +906,16 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCPPS *pps, ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size - 4); } -void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCPPS *pps, +void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCPPS *pps, int x_ctb, int y_ctb, int ctb_size) { int x_end = x_ctb >= pps->sps->width - ctb_size; int y_end = y_ctb >= pps->sps->height - ctb_size; if (y_ctb && x_ctb) - ff_hevc_hls_filter(lc, pps, x_ctb - ctb_size, y_ctb - ctb_size, ctb_size); + ff_hevc_hls_filter(lc, l, pps, x_ctb - ctb_size, y_ctb - ctb_size, ctb_size); if (y_ctb && x_end) - ff_hevc_hls_filter(lc, pps, x_ctb, y_ctb - ctb_size, ctb_size); + ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb - ctb_size, ctb_size); if (x_ctb && y_end) - ff_hevc_hls_filter(lc, pps, x_ctb - ctb_size, y_ctb, ctb_size); + ff_hevc_hls_filter(lc, l, pps, x_ctb - ctb_size, y_ctb, ctb_size); } diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index b44bc93507..4978aa745c 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -90,7 +90,7 @@ static void pic_arrays_free(HEVCContext *s) } /* allocate arrays that depend on frame dimensions */ -static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) +static int pic_arrays_init(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) { int log2_min_cb_size = sps->log2_min_cb_size; int width = sps->width; @@ -100,8 +100,8 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) int ctb_count = sps->ctb_width * sps->ctb_height; int min_pu_size = sps->min_pu_width * sps->min_pu_height; - s->bs_width = (width >> 2) + 1; - s->bs_height = (height >> 2) + 1; + l->bs_width = (width >> 2) + 1; + l->bs_height = (height >> 2) + 1; s->sao = av_calloc(ctb_count, sizeof(*s->sao)); s->deblock = av_calloc(ctb_count, sizeof(*s->deblock)); @@ -127,8 +127,8 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address) goto fail; - s->horizontal_bs = av_calloc(s->bs_width, s->bs_height); - s->vertical_bs = av_calloc(s->bs_width, s->bs_height); + s->horizontal_bs = av_calloc(l->bs_width, l->bs_height); + s->vertical_bs = av_calloc(l->bs_width, l->bs_height); if (!s->horizontal_bs || !s->vertical_bs) goto fail; @@ -527,7 +527,7 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) return ff_get_format(s->avctx, pix_fmts); } -static int set_sps(HEVCContext *s, const HEVCSPS *sps) +static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) { int ret, i; @@ -538,7 +538,7 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps) if (!sps) return 0; - ret = pic_arrays_init(s, sps); + ret = pic_arrays_init(s, l, sps); if (ret < 0) goto fail; @@ -1317,6 +1317,7 @@ static void set_deblocking_bypass(const HEVCContext *s, const HEVCSPS *sps, } static int hls_transform_tree(HEVCLocalContext *lc, + const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int xBase, int yBase, int cb_xBase, int cb_yBase, @@ -1391,7 +1392,7 @@ static int hls_transform_tree(HEVCLocalContext *lc, #define SUBDIVIDE(x, y, idx) \ do { \ - ret = hls_transform_tree(lc, pps, sps, \ + ret = hls_transform_tree(lc, l, pps, sps, \ x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \ log2_trafo_size - 1, trafo_depth + 1, idx, \ cbf_cb, cbf_cr); \ @@ -1434,7 +1435,7 @@ do { } } if (!s->sh.disable_deblocking_filter_flag) { - ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_trafo_size); + ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_trafo_size); if (pps->transquant_bypass_enable_flag && lc->cu.cu_transquant_bypass_flag) set_deblocking_bypass(s, sps, x0, y0, log2_trafo_size); @@ -1443,8 +1444,8 @@ do { return 0; } -static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCPPS *pps, - int x0, int y0, int log2_cb_size) +static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCPPS *pps, int x0, int y0, int log2_cb_size) { const HEVCContext *const s = lc->parent; const HEVCSPS *const sps = pps->sps; @@ -1465,7 +1466,7 @@ static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCPPS *pps, int ret; if (!s->sh.disable_deblocking_filter_flag) - ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_cb_size); + ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); ret = init_get_bits(&gb, pcm, length); if (ret < 0) @@ -2200,6 +2201,7 @@ static void intra_prediction_unit_default_value(HEVCLocalContext *lc, } static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, + const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int log2_cb_size) { @@ -2255,7 +2257,7 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, intra_prediction_unit_default_value(lc, sps, x0, y0, log2_cb_size); if (!s->sh.disable_deblocking_filter_flag) - ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_cb_size); + ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); } else { int pcm_flag = 0; @@ -2276,7 +2278,7 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, } if (pcm_flag) { intra_prediction_unit_default_value(lc, sps, x0, y0, log2_cb_size); - ret = hls_pcm_sample(lc, pps, x0, y0, log2_cb_size); + ret = hls_pcm_sample(lc, l, pps, x0, y0, log2_cb_size); if (sps->pcm_loop_filter_disabled) set_deblocking_bypass(s, sps, x0, y0, log2_cb_size); @@ -2353,14 +2355,14 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ? sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag : sps->max_transform_hierarchy_depth_inter; - ret = hls_transform_tree(lc, pps, sps, x0, y0, x0, y0, x0, y0, + ret = hls_transform_tree(lc, l, pps, sps, x0, y0, x0, y0, x0, y0, log2_cb_size, log2_cb_size, 0, 0, cbf, cbf); if (ret < 0) return ret; } else { if (!s->sh.disable_deblocking_filter_flag) - ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_cb_size); + ff_hevc_deblocking_boundary_strengths(lc, l, pps, x0, y0, log2_cb_size); } } } @@ -2385,6 +2387,7 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, } static int hls_coding_quadtree(HEVCLocalContext *lc, + const HEVCLayerContext *l, const HEVCPPS *pps, const HEVCSPS *sps, int x0, int y0, int log2_cb_size, int cb_depth) @@ -2421,23 +2424,27 @@ static int hls_coding_quadtree(HEVCLocalContext *lc, int more_data = 0; - more_data = hls_coding_quadtree(lc, pps, sps, x0, y0, log2_cb_size - 1, cb_depth + 1); + more_data = hls_coding_quadtree(lc, l, pps, sps, + x0, y0, log2_cb_size - 1, cb_depth + 1); if (more_data < 0) return more_data; if (more_data && x1 < sps->width) { - more_data = hls_coding_quadtree(lc, pps, sps, x1, y0, log2_cb_size - 1, cb_depth + 1); + more_data = hls_coding_quadtree(lc, l, pps, sps, + x1, y0, log2_cb_size - 1, cb_depth + 1); if (more_data < 0) return more_data; } if (more_data && y1 < sps->height) { - more_data = hls_coding_quadtree(lc, pps, sps, x0, y1, log2_cb_size - 1, cb_depth + 1); + more_data = hls_coding_quadtree(lc, l, pps, sps, + x0, y1, log2_cb_size - 1, cb_depth + 1); if (more_data < 0) return more_data; } if (more_data && x1 < sps->width && y1 < sps->height) { - more_data = hls_coding_quadtree(lc, pps, sps, x1, y1, log2_cb_size - 1, cb_depth + 1); + more_data = hls_coding_quadtree(lc, l, pps, sps, + x1, y1, log2_cb_size - 1, cb_depth + 1); if (more_data < 0) return more_data; } @@ -2452,7 +2459,7 @@ static int hls_coding_quadtree(HEVCLocalContext *lc, else return 0; } else { - ret = hls_coding_unit(lc, s, pps, sps, x0, y0, log2_cb_size); + ret = hls_coding_unit(lc, s, l, pps, sps, x0, y0, log2_cb_size); if (ret < 0) return ret; if ((!((x0 + cb_size) % @@ -2524,6 +2531,7 @@ static void hls_decode_neighbour(HEVCLocalContext *lc, static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) { HEVCLocalContext *const lc = &s->local_ctx[0]; + const HEVCLayerContext *const l = &s->layers[s->cur_layer]; const HEVCPPS *const pps = s->pps; const HEVCSPS *const sps = pps->sps; const uint8_t *slice_data = gb->buffer + s->sh.data_offset; @@ -2555,7 +2563,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset; s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag; - more_data = hls_coding_quadtree(lc, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); + more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); if (more_data < 0) { s->tab_slice_address[ctb_addr_rs] = -1; return more_data; @@ -2564,12 +2572,12 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) ctb_addr_ts++; ff_hevc_save_states(lc, pps, ctb_addr_ts); - ff_hevc_hls_filters(lc, pps, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); } if (x_ctb + ctb_size >= sps->width && y_ctb + ctb_size >= sps->height) - ff_hevc_hls_filter(lc, pps, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); return ctb_addr_ts; } @@ -2579,6 +2587,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, { HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[self_id]; const HEVCContext *const s = lc->parent; + const HEVCLayerContext *const l = &s->layers[s->cur_layer]; const HEVCPPS *const pps = s->pps; const HEVCSPS *const sps = pps->sps; int ctb_size = 1 << sps->log2_ctb_size; @@ -2617,7 +2626,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, goto error; hls_sao_param(lc, pps, sps, x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size); - more_data = hls_coding_quadtree(lc, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); + more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0); if (more_data < 0) { ret = more_data; @@ -2628,7 +2637,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, ff_hevc_save_states(lc, pps, ctb_addr_ts); ff_thread_report_progress2(s->avctx, ctb_row, thread, 1); - ff_hevc_hls_filters(lc, pps, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filters(lc, l, pps, x_ctb, y_ctb, ctb_size); if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) { /* Casting const away here is safe, because it is an atomic operation. */ @@ -2638,7 +2647,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, } if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) { - ff_hevc_hls_filter(lc, pps, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filter(lc, l, pps, x_ctb, y_ctb, ctb_size); ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP); return ctb_addr_ts; } @@ -2913,7 +2922,7 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l) if (sps->vps != s->vps && l != &s->layers[0]) { av_log(s->avctx, AV_LOG_ERROR, "VPS changed in a non-base layer\n"); - set_sps(s, NULL, AV_PIX_FMT_NONE); + set_sps(s, l, NULL); return AVERROR_INVALIDDATA; } @@ -2923,7 +2932,7 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l) ff_hevc_clear_refs(l); - ret = set_sps(s, sps); + ret = set_sps(s, l, sps); if (ret < 0) return ret; @@ -2937,8 +2946,8 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l) new_sequence = 1; } - memset(s->horizontal_bs, 0, s->bs_width * s->bs_height); - memset(s->vertical_bs, 0, s->bs_width * s->bs_height); + memset(s->horizontal_bs, 0, l->bs_width * l->bs_height); + memset(s->vertical_bs, 0, l->bs_width * l->bs_height); memset(s->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height); memset(s->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1)); memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address)); @@ -3627,7 +3636,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, ff_refstruct_unref(&s->pps); if (s->ps.sps != s0->ps.sps) - if ((ret = set_sps(s, s0->ps.sps)) < 0) + if ((ret = set_sps(s, &s->layers[0], s0->ps.sps)) < 0) return ret; s->poc_tid0 = s0->poc_tid0; diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index be5d76c183..18b15e7dc1 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -440,6 +440,9 @@ typedef struct HEVCLocalContext { typedef struct HEVCLayerContext { HEVCFrame DPB[32]; + + int bs_width; + int bs_height; } HEVCLayerContext; typedef struct HEVCContext { @@ -484,8 +487,6 @@ typedef struct HEVCContext { int slice_idx; ///< number of the slice being currently decoded int eos; ///< current packet contains an EOS/EOB NAL int last_eos; ///< last packet contains an EOS/EOB NAL - int bs_width; - int bs_height; // NoRaslOutputFlag associated with the last IRAP frame int no_rasl_output_flag; @@ -649,13 +650,16 @@ void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, const HEVCPPS *pps, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv, int mvp_lx_flag, int LX); -void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCPPS *pps, +void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCPPS *pps, int x, int y, int ctb_size); -void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCPPS *pps, +void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCPPS *pps, int x_ctb, int y_ctb, int ctb_size); void ff_hevc_set_qPy(HEVCLocalContext *lc, const HEVCPPS *pps, int xBase, int yBase, int log2_cb_size); -void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS *pps, +void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCLayerContext *l, + const HEVCPPS *pps, int x0, int y0, int log2_trafo_size); int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc); int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc);