From patchwork Thu Jun 30 22:29:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 36565 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp620813pzh; Thu, 30 Jun 2022 15:31:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vazS7+SfVHLavXBxc+4zu8XA4fSKnof9Umvh5e5HkCHjBHb/IRnf8JUoHIqqBGnLSsZ0/c X-Received: by 2002:a05:6402:18:b0:435:9a79:9a40 with SMTP id d24-20020a056402001800b004359a799a40mr14245527edu.328.1656628286250; Thu, 30 Jun 2022 15:31:26 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m7-20020aa7d347000000b00435c517de46si24166498edr.394.2022.06.30.15.31.25; Thu, 30 Jun 2022 15:31:26 -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=@outlook.com header.s=selector1 header.b=Spuvrpkl; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A2BA768B7E6; Fri, 1 Jul 2022 01:30:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2040.outbound.protection.outlook.com [40.92.91.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3213668B7C2 for ; Fri, 1 Jul 2022 01:30:43 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GVMW7xatd0g2F8QMrvNP52xAelzEkD8AITDcuNQnaEz+dQ9dl+KboHn1pwoqSUH6rKsuBGpIfQcg+Q3aPhp8pWB2d1rwtmiB9+3AyaK0A3PIVqHrgZqY2MF1neHdBUrQ3jspYhxj3nqtZQkMwEQ6k655mEduMo0wf+RXVCJguhig1lRh/PnFO+9m30BiSCQvpUITPC45Hum9/o7s7ugDIgmKDyjjiqWw9dMg5dUUkVBik2v5z2R5mIrw3eIuSQcF6yBm4M+ZVzxXGO/3d50NZJ+YkwSjpN4QWrE8Ip/YEiv7mFRTWMdykpnp+jZ/GG75nr6XJ3Fcf+AABUPH/EPJkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PpMnYAZCPGoDXAj5YjiqG3TIZYvrzEwKRvelH2iyZNM=; b=iEtwB7eKinDCI4m+p1s1dwtD5lMiw39DKyPmgm6EW9luH1jWNtqxikdmk+DHWlvDuL/Dj4VecpFUyLq4tMZsSHEdL8qETxP7hIqSo33QlfCpJ+XdPH6HRbyelm9njLTK8H+pYf2qpaHZCfqvmvwWUxZLi9HKgVz9XrMkqF/bdNgx3kyz6ib4+A4/g/r9X75yYrc1MLDUlig0Uk+PCQNRgc168tKOmQ2aMhFO1qBQD5zTmNC41MVJ+pbRNxyzW+PDw9m4XNXNKcUieLSXFbj/7GjihzYnfprPviZx8QR2LP2ELdpbe1k5GZXD/1Jf+/T4H75bhGHf5rUKgbNkQmReSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PpMnYAZCPGoDXAj5YjiqG3TIZYvrzEwKRvelH2iyZNM=; b=SpuvrpklB/NNyXP4uLtrlXKfF3GJYEf1BPO3zepYwChf78IFX0FsYHNvO1kvh4N16BwPNUReMJch0OhkuQgMGp11eGUgp7R2EGr81SMK5aTMPZI3T4zBeCY9g+IkYvBWCn6/pQdhTWKO/Ic/DrK9ujU/0Nytw0psztVre1k/acU0TgPpAvwr+7qye3I8cRg8ZpUNmuziGR1Ps0qLCGYOfyVF7Zo8VY1MA8L/88rZ/9l3DnuwkRDoWCnXBfUPRKytUxWt7qaHziXwxO84t/SOwlNhmrqEwZ4/PK0H7SINo70X3z5wxdf+XRxCPLT7HxSEufQ3TaG6+hegNRTH93zMdg== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by DB3PR0102MB3546.eurprd01.prod.exchangelabs.com (2603:10a6:8:d::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Thu, 30 Jun 2022 22:30:42 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c%10]) with mapi id 15.20.5373.018; Thu, 30 Jun 2022 22:30:42 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Jul 2022 00:29:39 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [qyF0k40jhzvIOMIHVlJ2DgDMQKLtEVzb] X-ClientProxiedBy: FR0P281CA0099.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::17) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220630222949.1758625-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42b7a39b-d322-4f23-e0ae-08da5ae82ad7 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEthM4Yqklomr1EC9yH/oOI+MBtpD1xQV13qLoSS3dA53v3Knrx61p0hut+SRxGu4jL5td1BiZ4C1N6uyguTsLmVbje//MBzyMAOi3HJI6Y12YTvIMfiJbS24rw9CLD2e5hlmoa1Dmfq5msDW/aMRPNhV0UnYd9XI3I/ErfoGQnjIXfAQPhX3mJ4TVBpz2WRRzmj9zrwzFFKnV6cbD/O8gxtPQMkibm0mQoZobZ0AOuIS+O+Knlz8mALNKN6RzfOgrY9wy12yZCuFrRNsjiQaMlYJ9ZqWynghCubFBCPDkBpR+8S6Ewt2IxN2or3IYTyZlBw3OZ9vl7r/A9KH2cvNScmOVSyScXKIcF3STuob7LVGOjFfpUGqFbLLOY8KEVYmB9zpY3aPilv+FT5MaXLx0/8Cdvmpun/lZd60SGY1aTUu2ff05ryDp/VhldbaF2eo5ikeT5Ypsr7csY0d+tQYy7AyFenRGA9hHZU+Ndoalphuvs7kR0zMJ9Tnmhc63j+juwgiXoWbBzpeC+ua9OnY3C2k+D8PfOSBhLIX/a2sqth34Ilu3gw+0giicS8lSavxb+lpRUQctMmEblVOR/cApXv6TyIowtvFuIH+GGkte4pjTCIafELvHoWIySc2Amt/JKCOjlCYGFmMwuRfJR4kr6rntLQ7N3Fx0HKToRElmrkv6TybFPnk2oa/pmo0YLi6hWee9pxBFZSNd4knmTJ6aDK9xHsfTvjEqadxaJCcZWQKNWJAh1q4DMvQg33upUqR685OCVZD85sPq7teyT0Pp7G X-MS-TrafficTypeDiagnostic: DB3PR0102MB3546:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WAtmK6Dx56/pOxYS4U23sr7rnroSlzDlEf+P/exuv4adwQ6MlSq5rSqRDes/32WO95wqpP30H+p0M52oIuCkoX375ZswviZslHFwy/9Y2NxTF0T5jmod68ORec5JCCBTgQjI3NTnCS2lQM0/+C1OUChPddS2lOG4NtkzMz6xmAFzpLrrO3VskOF30bxRihChn8Z8uuyVAvXPRXJDDcM0OBUKxpOiilDMkzHqu/liuSkEHWwuTpiALDOk+RYdHNmpU7rFPIZVvoZdfSfctjaMyThdmZowc3vh8q3NWLUx+g9bHXbC+2own1EN1e26dZZINQHnwzmUFL86k3zUkprkGHU67drQZxxssVashYZeb2KhdRhRR76mV8+1mj6ZzPAu9PE3jsMbUu1bGu1lBFn4sBIfv5yphMtZfCK3bwec9tLkzultF5hQuG6T0SVCYSSeGfN65PQxLn49+YgHnsnT7kXe5ssPUGLOxZ7KjySrDIwGxVF35kLSisE7nUK0GnL9TcsuJB/yEjGn6p12jK31u5ewobt9/gZxN4gvEptT1dkYmd97rQZfd4Bad8nhqGM07TS4W2B1rrsFyDlMJ6JhUmEXVDLxS+VTNItOKdZTn415H3EHJOTWDb+ZakVxu/vuIwYkBG6KbBGu3IZ/8CIG7NeXQpQ2vTmMhjiThwXkJdECzTWTQWtn+oEANoZWmofg X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WHdUNmjZGubsg1tdxmOj7siVNBXIr6K4jCCS+UBL3P7llSSbyZ/n4oJKgvWZpdtEBqANBoGoXOBG1D6QKZB7kI9r0MIlVTXjqKAxdDVIQXJaQiaAYqE4UXsoyd2pFA7GrHTiOdowme9fbV0GORNcNoUut/YSzFrutuTpKGL4i+OELqd7Ax1rdP4a47h9oJpWu7xEJKLuvB3BtmxXCvIRglJ41OKKPCwRx4K34jygFL0WOtKP4GSw28xVrV0Oh5c8tKNJm1g3Oj19w/5uel6v6+C4A2m+lqOz8mi0KmER3C++H7WmyGhABnjwXiBdlWtlyBbmuZNvzJq01GdpP0xAV6gFWi+qBbKSyi4qWVGczQpUIGX5sW0xrdQl7ufzEqDjbke/BfsTjwukaOvevewH95y1xwpGgXRHlMJ+vU5krNYnWBSQmlLgeVwkkishsCyoUx6kkIHbxsDu0QnG7+NErX8eAHfRTDWc66GcYRwkZ23Un2nZrQ+fg/T7BIHaqkjufGbIVVVbT4LpAlT2vD2FOpJPFlX0dTK4/d6e/NU4ka73v/2zcOsoi4jk6Z0NgFr2DD0ix3EZlw8dfdjsBWdTakZ06n7HxgA8A7XdNabj820aZFKsHx49Snvt+vcmsKyihAApuCEdgJCpGs7sdlw+Q4D4/OvrNmfI6jhsizIiVGFolBZsn/poEA88hsxzVI+GG7wHLeKMhQKDq6LHvHc0HOr+qBZUxNGpKKBGwVlBD4CU3R3xm+8iexKmmup4xJTRzXJZVZUhqccSfBYIicZ4XDxApWL6zGMV4/3vBN/Y5vSnTWtcBl5/+06i3ksBdWH9WWEBclChPK9jDsftCPEMK1QLE7qpRSCr9PF0+6D/22Dlsn7nobsgX6bQEQ0Ag0KLIC7uTUOhsP1CzNQ10QEwY1CkRz/oOMtsHkLt6GPDa7h+XmzgxtpRyLXOsZcsYUQ2dmiMq/c7MGEYKyjQEzYUJA+8HLvuOKYuWOAVUtsslrjNBPTvfrWQd7ET5VMF1KMpvRku7diypAueLipOk70bRbK7fMvI9v1YiO1LUXvQjUxkqvUun2L/rjk/pW8qWs0UcmS2V+4Y4LZUVM1KOmf4CHtqTgtb0OFpJ8/AJ32qkOE4/P5NEa85CnBDvrcK0mwAqz2MFwCzL8mC74d/g7f0wOgOe7YeaRVuWDkbWaNK//TavG4rWQxDmBEwmn/Fviz4IAXrfZSIHO8uSF/EzCMOSY+psAu9Pe5yQbO6LJmX1VUnohepmyW0QHqVU2r1Q5hj2xL5EFyn6ZgsPdREHcH+eI8rf5p/MCpZwAkDrsd/AiQ= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42b7a39b-d322-4f23-e0ae-08da5ae82ad7 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2022 22:30:42.6705 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0102MB3546 Subject: [FFmpeg-devel] [PATCH 08/18] avcodec/hevc_filter: Pass HEVCLocalContext when slice-threading 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jSSAT1MpaQ8n The HEVC decoder has both HEVCContext and HEVCLocalContext structures. The latter is supposed to be the structure containing the per-slicethread state. Yet that is not how it is handled in practice: Each HEVCLocalContext has a unique HEVCContext allocated for it and each of these coincides with the main HEVCContext except in exactly one field: The corresponding HEVCLocalContext. This makes it possible to pass the HEVCContext everywhere where logically a HEVCLocalContext should be used. This commit stops doing this for lavc/hevc_filter.c; it also constifies everything that is possible in order to ensure that no slice thread accidentally modifies the main HEVCContext state. There are places where this was not possible, namely with the SAOParams in sao_filter_CTB() or with sao_pixels_buffer_h in copy_CTB_to_hv(). Both of these instances lead to data races, see https://fate.ffmpeg.org/report.cgi?time=20220629145651&slot=x86_64-archlinux-gcc-tsan-slices Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_filter.c | 77 ++++++++++++++++++++-------------------- libavcodec/hevcdec.c | 21 +++++------ libavcodec/hevcdec.h | 8 ++--- 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index 7b53c66c3b..2fe05a2327 100644 --- a/libavcodec/hevc_filter.c +++ b/libavcodec/hevc_filter.c @@ -44,7 +44,7 @@ static const uint8_t betatable[52] = { 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 // QP 38...51 }; -static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset) +static int chroma_tc(const HEVCContext *s, int qp_y, int c_idx, int tc_offset) { static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 @@ -73,9 +73,9 @@ static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset) return tctable[idxt]; } -static int get_qPy_pred(HEVCContext *s, int xBase, int yBase, int log2_cb_size) +static int get_qPy_pred(HEVCLocalContext *lc, const HEVCContext *s, + int xBase, int yBase, int log2_cb_size) { - HEVCLocalContext *lc = s->HEVClc; int ctb_size_mask = (1 << s->ps.sps->log2_ctb_size) - 1; int MinCuQpDeltaSizeMask = (1 << (s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1; @@ -116,19 +116,20 @@ static int get_qPy_pred(HEVCContext *s, int xBase, int yBase, int log2_cb_size) return (qPy_a + qPy_b + 1) >> 1; } -void ff_hevc_set_qPy(HEVCContext *s, int xBase, int yBase, int log2_cb_size) +void ff_hevc_set_qPy(HEVCLocalContext *lc, int xBase, int yBase, int log2_cb_size) { - int qp_y = get_qPy_pred(s, xBase, yBase, log2_cb_size); + const HEVCContext *const s = lc->parent; + int qp_y = get_qPy_pred(lc, s, xBase, yBase, log2_cb_size); - if (s->HEVClc->tu.cu_qp_delta != 0) { + if (lc->tu.cu_qp_delta != 0) { int off = s->ps.sps->qp_bd_offset; - s->HEVClc->qp_y = FFUMOD(qp_y + s->HEVClc->tu.cu_qp_delta + 52 + 2 * off, + lc->qp_y = FFUMOD(qp_y + lc->tu.cu_qp_delta + 52 + 2 * off, 52 + off) - off; } else - s->HEVClc->qp_y = qp_y; + lc->qp_y = qp_y; } -static int get_qPy(HEVCContext *s, int xC, int yC) +static int get_qPy(const HEVCContext *s, int xC, int yC) { int log2_min_cb_size = s->ps.sps->log2_min_cb_size; int x = xC >> log2_min_cb_size; @@ -186,7 +187,7 @@ static void copy_vert(uint8_t *dst, const uint8_t *src, } } -static void copy_CTB_to_hv(HEVCContext *s, const uint8_t *src, +static void copy_CTB_to_hv(const HEVCContext *s, 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) { @@ -206,7 +207,7 @@ static void copy_CTB_to_hv(HEVCContext *s, const uint8_t *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); } -static void restore_tqb_pixels(HEVCContext *s, +static void restore_tqb_pixels(const HEVCContext *s, uint8_t *src1, const uint8_t *dst1, ptrdiff_t stride_src, ptrdiff_t stride_dst, int x0, int y0, int width, int height, int c_idx) @@ -241,10 +242,9 @@ static void restore_tqb_pixels(HEVCContext *s, #define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)]) -static void sao_filter_CTB(HEVCContext *s, int x, int y) +static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, int y) { static const uint8_t sao_tab[8] = { 0, 1, 2, 2, 3, 3, 4, 4 }; - HEVCLocalContext *lc = s->HEVClc; int c_idx; int edges[4]; // 0 left 1 top 2 right 3 bottom int x_ctb = x >> s->ps.sps->log2_ctb_size; @@ -450,7 +450,7 @@ static void sao_filter_CTB(HEVCContext *s, int x, int y) } } -static int get_pcm(HEVCContext *s, int x, int y) +static int get_pcm(const HEVCContext *s, int x, int y) { int log2_min_pu_size = s->ps.sps->log2_min_pu_size; int x_pu, y_pu; @@ -471,7 +471,7 @@ static int get_pcm(HEVCContext *s, int x, int y) (tc_offset & -2), \ 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)] -static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) +static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0) { uint8_t *src; int x, y; @@ -709,11 +709,11 @@ static int boundary_strength(const HEVCContext *s, const MvField *curr, const Mv return 1; } -void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, +void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0, int log2_trafo_size) { - HEVCLocalContext *lc = s->HEVClc; - MvField *tab_mvf = s->ref->tab_mvf; + const HEVCContext *s = lc->parent; + const MvField *tab_mvf = s->ref->tab_mvf; int log2_min_pu_size = s->ps.sps->log2_min_pu_size; int log2_min_tu_size = s->ps.sps->log2_min_tb_size; int min_pu_width = s->ps.sps->min_pu_width; @@ -745,8 +745,8 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, for (i = 0; i < (1 << log2_trafo_size); i += 4) { int x_pu = (x0 + i) >> log2_min_pu_size; int x_tu = (x0 + i) >> log2_min_tu_size; - MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; - MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; + const MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; + const MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; uint8_t top_cbf_luma = s->cbf_luma[yp_tu * min_tu_width + x_tu]; uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu]; @@ -783,8 +783,8 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, for (i = 0; i < (1 << log2_trafo_size); i += 4) { int y_pu = (y0 + i) >> log2_min_pu_size; int y_tu = (y0 + i) >> log2_min_tu_size; - MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; - MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; + const MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; + const MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu]; uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu]; @@ -799,7 +799,7 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, } if (log2_trafo_size > log2_min_pu_size && !is_intra) { - RefPicList *rpl = s->ref->refPicList; + const RefPicList *rpl = s->ref->refPicList; // bs for TU internal horizontal PU boundaries for (j = 8; j < (1 << log2_trafo_size); j += 8) { @@ -808,8 +808,8 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, for (i = 0; i < (1 << log2_trafo_size); i += 4) { int x_pu = (x0 + i) >> log2_min_pu_size; - MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; - MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu]; + const MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu]; + 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; @@ -823,8 +823,8 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, for (i = 8; i < (1 << log2_trafo_size); i += 8) { int xp_pu = (x0 + i - 1) >> log2_min_pu_size; int xq_pu = (x0 + i) >> log2_min_pu_size; - MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; - MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu]; + const MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu]; + 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; @@ -837,8 +837,9 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, #undef CB #undef CR -void ff_hevc_hls_filter(HEVCContext *s, int x, int y, int ctb_size) +void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size) { + const HEVCContext *const s = lc->parent; int x_end = x >= s->ps.sps->width - ctb_size; int skip = 0; if (s->avctx->skip_loop_filter >= AVDISCARD_ALL || @@ -856,16 +857,16 @@ void ff_hevc_hls_filter(HEVCContext *s, int x, int y, int ctb_size) if (s->ps.sps->sao_enabled && !skip) { int y_end = y >= s->ps.sps->height - ctb_size; if (y && x) - sao_filter_CTB(s, x - ctb_size, y - ctb_size); + sao_filter_CTB(lc, s, x - ctb_size, y - ctb_size); if (x && y_end) - sao_filter_CTB(s, x - ctb_size, y); + sao_filter_CTB(lc, s, x - ctb_size, y); if (y && x_end) { - sao_filter_CTB(s, x, y - ctb_size); + sao_filter_CTB(lc, s, x, y - ctb_size); if (s->threads_type & FF_THREAD_FRAME ) ff_thread_report_progress(&s->ref->tf, y, 0); } if (x_end && y_end) { - sao_filter_CTB(s, x , y); + sao_filter_CTB(lc, s, x , y); if (s->threads_type & FF_THREAD_FRAME ) ff_thread_report_progress(&s->ref->tf, y + ctb_size, 0); } @@ -873,14 +874,14 @@ void ff_hevc_hls_filter(HEVCContext *s, int x, int y, int ctb_size) ff_thread_report_progress(&s->ref->tf, y + ctb_size - 4, 0); } -void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size) +void ff_hevc_hls_filters(HEVCLocalContext *lc, int x_ctb, int y_ctb, int ctb_size) { - int x_end = x_ctb >= s->ps.sps->width - ctb_size; - int y_end = y_ctb >= s->ps.sps->height - ctb_size; + int x_end = x_ctb >= lc->parent->ps.sps->width - ctb_size; + int y_end = y_ctb >= lc->parent->ps.sps->height - ctb_size; if (y_ctb && x_ctb) - ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb - ctb_size, ctb_size); + ff_hevc_hls_filter(lc, x_ctb - ctb_size, y_ctb - ctb_size, ctb_size); if (y_ctb && x_end) - ff_hevc_hls_filter(s, x_ctb, y_ctb - ctb_size, ctb_size); + ff_hevc_hls_filter(lc, x_ctb, y_ctb - ctb_size, ctb_size); if (x_ctb && y_end) - ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb, ctb_size); + ff_hevc_hls_filter(lc, x_ctb - ctb_size, y_ctb, ctb_size); } diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 4786282669..33c9d74e5f 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -1137,7 +1137,7 @@ static int hls_transform_unit(HEVCContext *s, int x0, int y0, return AVERROR_INVALIDDATA; } - ff_hevc_set_qPy(s, cb_xBase, cb_yBase, log2_cb_size); + ff_hevc_set_qPy(lc, cb_xBase, cb_yBase, log2_cb_size); } if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma && @@ -1431,7 +1431,7 @@ do { } } if (!s->sh.disable_deblocking_filter_flag) { - ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size); + ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_trafo_size); if (s->ps.pps->transquant_bypass_enable_flag && lc->cu.cu_transquant_bypass_flag) set_deblocking_bypass(s, x0, y0, log2_trafo_size); @@ -1460,7 +1460,7 @@ static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size) int ret; if (!s->sh.disable_deblocking_filter_flag) - ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size); + ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size); ret = init_get_bits(&gb, pcm, length); if (ret < 0) @@ -2224,7 +2224,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) intra_prediction_unit_default_value(s, x0, y0, log2_cb_size); if (!s->sh.disable_deblocking_filter_flag) - ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size); + ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size); } else { int pcm_flag = 0; @@ -2312,13 +2312,13 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) return ret; } else { if (!s->sh.disable_deblocking_filter_flag) - ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size); + ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size); } } } if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0) - ff_hevc_set_qPy(s, x0, y0, log2_cb_size); + ff_hevc_set_qPy(lc, x0, y0, log2_cb_size); x = y_cb * min_cb_width + x_cb; for (y = 0; y < length; y++) { @@ -2473,6 +2473,7 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, static int hls_decode_entry(AVCodecContext *avctxt, void *isFilterThread) { HEVCContext *s = avctxt->priv_data; + HEVCLocalContext *const lc = s->HEVClc; int ctb_size = 1 << s->ps.sps->log2_ctb_size; int more_data = 1; int x_ctb = 0; @@ -2521,12 +2522,12 @@ static int hls_decode_entry(AVCodecContext *avctxt, void *isFilterThread) ctb_addr_ts++; ff_hevc_save_states(s, ctb_addr_ts); - ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filters(lc, x_ctb, y_ctb, ctb_size); } if (x_ctb + ctb_size >= s->ps.sps->width && y_ctb + ctb_size >= s->ps.sps->height) - ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filter(lc, x_ctb, y_ctb, ctb_size); return ctb_addr_ts; } @@ -2593,7 +2594,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *input_ctb_row, int ff_hevc_save_states(s, ctb_addr_ts); ff_thread_report_progress2(s->avctx, ctb_row, thread, 1); - ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filters(lc, x_ctb, y_ctb, ctb_size); if (!more_data && (x_ctb+ctb_size) < s->ps.sps->width && ctb_row != s->sh.num_entry_point_offsets) { atomic_store(&s1->wpp_err, 1); @@ -2602,7 +2603,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *input_ctb_row, int } if ((x_ctb+ctb_size) >= s->ps.sps->width && (y_ctb+ctb_size) >= s->ps.sps->height ) { - ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size); + ff_hevc_hls_filter(lc, x_ctb, y_ctb, ctb_size); ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP); return ctb_addr_ts; } diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index 3bb3fdb90a..e2dba54f26 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -676,16 +676,16 @@ void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, 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_set_qPy(HEVCContext *s, int xBase, int yBase, +void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size); +void ff_hevc_hls_filters(HEVCLocalContext *lc, int x_ctb, int y_ctb, int ctb_size); +void ff_hevc_set_qPy(HEVCLocalContext *lc, int xBase, int yBase, int log2_cb_size); -void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, +void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0, int log2_trafo_size); int ff_hevc_cu_qp_delta_sign_flag(HEVCContext *s); int ff_hevc_cu_qp_delta_abs(HEVCContext *s); int ff_hevc_cu_chroma_qp_offset_flag(HEVCContext *s); int ff_hevc_cu_chroma_qp_offset_idx(HEVCContext *s); -void ff_hevc_hls_filter(HEVCContext *s, int x, int y, int ctb_size); -void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size); void ff_hevc_hls_residual_coding(HEVCContext *s, int x0, int y0, int log2_trafo_size, enum ScanType scan_idx, int c_idx);