From patchwork Thu Mar 24 20:21:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 34954 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:ab0:5fda:0:0:0:0:0 with SMTP id g26csp1216568uaj; Thu, 24 Mar 2022 13:22:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJlh+WGImE3haEaMve6kYaLbQjPwP4PfwXLIONW8VT6uJWdKrpDsQQKihTrznh8E8trAlX X-Received: by 2002:a05:6402:1912:b0:418:cd23:3742 with SMTP id e18-20020a056402191200b00418cd233742mr8918871edz.412.1648153335809; Thu, 24 Mar 2022 13:22:15 -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 hs32-20020a1709073ea000b006df838687e7si455282ejc.20.2022.03.24.13.22.15; Thu, 24 Mar 2022 13:22:15 -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=AQkUzl5T; 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 265D768B1D9; Thu, 24 Mar 2022 22:22:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073088.outbound.protection.outlook.com [40.92.73.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E19D8680AC0 for ; Thu, 24 Mar 2022 22:22:06 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZvpKxrMVCahzacXBV56oAvHISZsq8Z4VBrssDVXHhz0p+YjbeQw5FuPLVoGRssIz4ZjzxpsT2NrH9eFJtlQijRznRVkjKaUa/awu5NCAvmFuh50JnL6nFf3CU5ul3z1ZWlJosBZ+G1UTmIffEBJxbtU9dCGnBYTJ9ksZXFLZGSGF2Qp7j9viMrclaTwXhjztXL2YzFYerd/8mTEQoCQftylC7UoPDgXkfLrNW4hL/euiX5hacbktK10kTKyhdT7rGVQnn7K4Phrl7Maygl47fdAcIWBT0JSmH6c9H1h/kTHhfgcxB2Fo96JQD2W5vf/fo1UX3XpodE0rGbz1NliD2g== 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=P8QqH4DWvhFkdJm2F8kpHbhc4JWR9ZF/Xf56mMpo/KE=; b=ALmO4OeZCLZStIEw7vQZmhrM5eFT8jm50nV3JfzYH9mvjT+SFMNAA0HuseG+jSyo++DsS8kAtfPRVe9bPRCVPYTasyrONOI7xTRk0h7DpbJ6adSuw8RZULHo9cQ1ZyOHMFVL7s5IElNgm2rS/aBi1r+26rxe+OwXuK3tLypD8GWlbU/dy3vpnk+mmkv/JKAHHBvSrQGs/AZ1iOZ7G/V8gwa7Gqh6dPG5KaQX7VMHyZ/ClBddTElJpXntOW+009mioyOkprq76JQeHSz1mNH4AlQe6Vq8B6nF1JI+/EuHYvsQmcV800/5qp3ID3/pdhGKwfQG+dkE/D7CKSU0gqv2YQ== 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=P8QqH4DWvhFkdJm2F8kpHbhc4JWR9ZF/Xf56mMpo/KE=; b=AQkUzl5T675mzwNyhEF34XTpOBlR9kmaGo9/u7pUAS1Z3vvCRmgbPSNRbczjEfcoH+dpwftroA9KgGqX1ok1RSQne+Ea6byRPeXeguaumHpY2MsD1RbP6HsrX4GsUO413G3yXdQ46P6aPsO7ydXJ/gJYNn7yPNb0/Grlg24pKdCtZ6zRq4sOXRhBMRq/2YHecCaGanAzhDLcXUADfTWGPL3kae04/fnQUAGT9GaPT0NN2FllapYqs+knV+zSYB0LZt0gT8/uPh19QZ/5XMCAH4fmT77GvvkPTys3xSd7JA8hGWqaBC210os7lREZt+jVUXOl0bleloaRDl8wLan8rg== Received: from AS1PR01MB9564.eurprd01.prod.exchangelabs.com (2603:10a6:20b:4d1::16) by AS4PR01MB9375.eurprd01.prod.exchangelabs.com (2603:10a6:20b:4c8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17; Thu, 24 Mar 2022 20:22:05 +0000 Received: from AS1PR01MB9564.eurprd01.prod.exchangelabs.com ([fe80::9070:a5fd:e532:bdf8]) by AS1PR01MB9564.eurprd01.prod.exchangelabs.com ([fe80::9070:a5fd:e532:bdf8%3]) with mapi id 15.20.5081.022; Thu, 24 Mar 2022 20:22:05 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Mar 2022 21:21:50 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [qNhHqFNKxDFNYQ+TXGoHXr3cNhuUzjUg] X-ClientProxiedBy: AS9PR06CA0286.eurprd06.prod.outlook.com (2603:10a6:20b:45a::32) To AS1PR01MB9564.eurprd01.prod.exchangelabs.com (2603:10a6:20b:4d1::16) X-Microsoft-Original-Message-ID: <20220324202151.1016018-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9a4fc91-891f-4c4a-83c7-08da0dd3f685 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRPXK2pYrYpBDVwwV2vfGTGKRxCxdmgz/iY5b/2l5k4B8Iiv4PMdpEU5pBaR3Zl1Y6HPWu4AdPUynv9dsHthwodq3foqTiK+NmFspNrZ98/7aOHnOj1HBdmU41uAYMOjwl3iYnrhDlvLax4t6osTMgC58BjteSbhKs39cKk0/1TGFqYYAiEgDvNsSioXkgIEM/Q0O7zYXAw8IBOVOeXeIm8fDo2lXtGZnAXUK85zEj31CFh+7Qjy9PjJ77hOx1jixvBHMBk1g65F/YzXduLQwZRKUIgnNoditx0IbHHWLPSENomPjo2xYxMo6AqzCCrDC1FPboMp9tZtaOLZezzl7UULr/CR/C653Ljtrgfc1jR/UVnvxbuH375gRru2dvpF3v/EUFa6LdIvBMsRAiE47zHxv57JBtfJMfI+Fgmjwd8xvdIR3eFQkD7duJFIx1CcY+MAMV15F4yYpV/H9+TwWd4yhs5SUUriGa3f0Bax+rBDRuyCrwos0ulGD8swR9ZeLB/Je0Td1c3m8Bdu+bJGEUbqi3JsmmILVqGfV9rtlkwq7MZaD8FFG0gFjbFpUP0wd6fDDJN9sICzTPPZYFEPueLDwbfoFIdsq3IcVQIO6W6ThfG2TA9fmPUoUnRspQBxxA2ZAHQ+PZO30WsnnsQgpogkVzKEbgOfjgOaEMMR5i7QYo1JbRo89s3ll9WCiw6SIXEaLy51PBDW1ezoS3JD9UKwpTtXJbbwKflpvIUvNz+ni7A1M8FzYOKIf5e+7pRQs0= X-MS-TrafficTypeDiagnostic: AS4PR01MB9375:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cUMWznH4ZQD9l38dWZOqKiBFn3//OcNT0O2GNrRXrvu1zqGXAlkQ5l5rVrlhoTirpVvbXTczVi2vKjgN60yx5Mmrt4DYEBe6dtc0yROhC6H85UVIvMaAIA9VbObTBgCq74uqy5vrJtlbRcsy4Ts6phmwKzNA8SenK728/uc3By65otcPfiy+hn1eP+44ksNZDB5mEoXpQtpzGnuVIJQYiPBIXkLx2ceP3p1emGtIMUgm/gxCqSME4UNDfze62GO0ekkOup++aX3l+Iv2irAg0kGPFX+uJ0E6wWQ42COHeK8lm8QzijAJmTAY6OYiqfjAkmhup7CD68jwYGS0fVOAqOX+zZLD86VCC3x2Y02z9xVPvGoJWAKL6wtYn/oxqcrfO1KviTMU5G55/ONbwid7GONqjgQpmqJiEyOT+bksSOzLSOv9cOQDa+PMAG71VdHMhTpzTE9UwOZmctBijqjsrQe5BtDvSlCl1S+C8HZzl27c5/wMBzereqfGdw7rd1tdxGkkhNHk7JPQmcBv+BXBN83DHpYU/eO91ENKwdEcGUenqtWBbzLFdP4V7m7/Cvru5tppxiGcUWsRlgwcdELEyQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bdmNXo4KMjoqnPTjAF22lwg0gPAIbTy2wTiXmifpozfX5b1RYH4toNhkHYmbaz/FxaIJEwG829JtVES8Zqsp5bOTVP0VicDDxhUbRXxVhos7RWW6WxUB1Wwnq23dVerHKv1Ps7XPWOxIWPfF9vMsZkvcowFNpLricUHpHr+K2F0KlHOwD6bvPm7frkRlroILApBHEKH2nMknwV5Ve2OBziwTrBztaENrAnmK3gLjc8KW781h7oGebSTr7LlPNIINu/HbOD+HqqYhuqoWlKR+XWviY4gJzbp6yiPdmRr4TVQaVCSCFfSXh1ACcAxAeM+w4uXHIg1D8AgjaGtFWyOXQPot3GEzoNaRJlvkUW6UEVkEhBU+jQ6rlMXJLz5YXlC4z6nqz0P6o2L+Q9u+ymb6gWE4psYA7ub/5sJ3CWXXJPgebsf8+gcE9VEiZctujY3GBZEJtptTaFpI2gHU6PZuynjiOXUctFXiwMdhY1B5WRxdkmgnDg1+nmpB1JsSHYP/5SWy3wPdQHQLlgL9sFRBqd4TOO1d2mCZ+uLQp4Jn9eGv4WjGr8BsbVWDEQcGGZLgHLkTK90I0f6xKlPJSkQDAhmOaxPktpXYac4mtjdx0mN9znmU9VUUIjN9yJjc1SHUSD2f6jxECQAv5rcbEtS50H9sRqn2xd9zNHNhWNhAUWsLitEVgQexSbmFzxMd510RkdJi20z3mIABDDLfjmjW4idUYMz93kvOOzwhBdmqBeDURrmmNyJV2zyxIB3VnMPkS/GLWnnfWyI8ZUCOFXSKiSGwYLa2E4NxtBXSroGpIVDWXRkZO77h/SBO42hS9bUNNE5sUwSCU1hzqzCy5KLe0ErzIxWe+aRtRODYBiJ/cyRbOQLnelB48iSvnO4ClwkbKfhCOui1+Fz62deN2vrOQ/IOYqVEl1uEslMbDUiEOZleoV0sapmSslsEM/OAUdimsTEfxnBQs7KKM2iwzcWPSueb44g6sUfTwiSx6rahd4cQiLm0Gl5nIz9UWLUt9jrWGN6QO7KJFyF8h8Mj0WUGCgfNxyxGUJM+qg79DKr+HPS8885re18kWKNJcvbdAoB9yZpKtGK89QuxkLMxvbxI3uAyT18+sacYvvfXED3vsO+qvZFz5u7/wEgyirO3NJ4489IseURJSMRTSqW2Nd4zjE9M9s2THNtpLdmTCeYcQIw= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9a4fc91-891f-4c4a-83c7-08da0dd3f685 X-MS-Exchange-CrossTenant-AuthSource: AS1PR01MB9564.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2022 20:22:05.3583 (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: AS4PR01MB9375 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/h264dec: Move ERContext to H264Context 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: UEWz9WSGPOC7 Since 7be2d2a70cd20d88fd826a83f87037d14681a579 only one context is used. Moving it to H264Context from H264SliceContext is natural. One could access the ERContext from H264SliceContext via H264SliceContext.h264->er; yet H264SliceContext.h264 should naturally be const-qualified, because slice threads should not modify the main context. The ERContext is an exception to this, as ff_er_add_slice() is intended to be called simultaneously by multiple threads. And for this one needs a pointer whose pointed-to-type is not const-qualified. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_slice.c | 31 ++++++--------- libavcodec/h264dec.c | 86 ++++++++++++++++++++--------------------- libavcodec/h264dec.h | 7 ++-- 3 files changed, 56 insertions(+), 68 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index f6104dde89..d56722a5c2 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -537,7 +537,7 @@ static int h264_frame_start(H264Context *h) h->cur_pic_ptr = pic; ff_h264_unref_picture(h, &h->cur_pic); if (CONFIG_ERROR_RESILIENCE) { - ff_h264_set_erpic(&h->slice_ctx[0].er.cur_pic, NULL); + ff_h264_set_erpic(&h->er.cur_pic, NULL); } if ((ret = ff_h264_ref_picture(h, &h->cur_pic, h->cur_pic_ptr)) < 0) @@ -549,9 +549,9 @@ static int h264_frame_start(H264Context *h) } if (CONFIG_ERROR_RESILIENCE && h->enable_er) { - ff_er_frame_start(&h->slice_ctx[0].er); - ff_h264_set_erpic(&h->slice_ctx[0].er.last_pic, NULL); - ff_h264_set_erpic(&h->slice_ctx[0].er.next_pic, NULL); + ff_er_frame_start(&h->er); + ff_h264_set_erpic(&h->er.last_pic, NULL); + ff_h264_set_erpic(&h->er.next_pic, NULL); } for (i = 0; i < 16; i++) { @@ -1004,11 +1004,7 @@ static int h264_slice_header_init(H264Context *h) ff_videodsp_init(&h->vdsp, sps->bit_depth_luma); if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) { - ret = ff_h264_slice_context_init(h, &h->slice_ctx[0]); - if (ret < 0) { - av_log(h->avctx, AV_LOG_ERROR, "context_init() failed.\n"); - goto fail; - } + ff_h264_slice_context_init(h, &h->slice_ctx[0]); } else { for (i = 0; i < h->nb_slice_ctx; i++) { H264SliceContext *sl = &h->slice_ctx[i]; @@ -1018,10 +1014,7 @@ static int h264_slice_header_init(H264Context *h) sl->mvd_table[0] = h->mvd_table[0] + i * 8 * 2 * h->mb_stride; sl->mvd_table[1] = h->mvd_table[1] + i * 8 * 2 * h->mb_stride; - if ((ret = ff_h264_slice_context_init(h, sl)) < 0) { - av_log(h->avctx, AV_LOG_ERROR, "context_init() failed.\n"); - goto fail; - } + ff_h264_slice_context_init(h, sl); } } @@ -2667,7 +2660,7 @@ static void decode_finish_row(const H264Context *h, H264SliceContext *sl) ff_h264_draw_horiz_band(h, sl, top, height); - if (h->droppable || sl->h264->slice_ctx[0].er.error_occurred) + if (h->droppable || h->er.error_occurred) return; ff_thread_report_progress(&h->cur_pic_ptr->tf, top + height - 1, @@ -2682,9 +2675,7 @@ static void er_add_slice(H264SliceContext *sl, return; if (CONFIG_ERROR_RESILIENCE) { - ERContext *er = &sl->h264->slice_ctx[0].er; - - ff_er_add_slice(er, startx, starty, endx, endy, status); + ff_er_add_slice(sl->er, startx, starty, endx, endy, status); } } @@ -2713,13 +2704,13 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME || (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY)); - if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && h->slice_ctx[0].er.error_status_table) { + if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && sl->er->error_status_table) { const int start_i = av_clip(sl->resync_mb_x + sl->resync_mb_y * h->mb_width, 0, h->mb_num - 1); if (start_i) { - int prev_status = h->slice_ctx[0].er.error_status_table[h->slice_ctx[0].er.mb_index2xy[start_i - 1]]; + int prev_status = sl->er->error_status_table[sl->er->mb_index2xy[start_i - 1]]; prev_status &= ~ VP_START; if (prev_status != (ER_MV_END | ER_DC_END | ER_AC_END)) - h->slice_ctx[0].er.error_occurred = 1; + sl->er->error_occurred = 1; } } diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 2a510b0a01..f438376431 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -154,14 +154,16 @@ void ff_h264_free_tables(H264Context *h) av_buffer_pool_uninit(&h->motion_val_pool); av_buffer_pool_uninit(&h->ref_index_pool); +#if CONFIG_ERROR_RESILIENCE + av_freep(&h->er.mb_index2xy); + av_freep(&h->er.error_status_table); + av_freep(&h->er.er_temp_buffer); + av_freep(&h->dc_val_base); +#endif + for (i = 0; i < h->nb_slice_ctx; i++) { H264SliceContext *sl = &h->slice_ctx[i]; - av_freep(&sl->dc_val_base); - av_freep(&sl->er.mb_index2xy); - av_freep(&sl->er.error_status_table); - av_freep(&sl->er.er_temp_buffer); - av_freep(&sl->bipred_scratchpad); av_freep(&sl->edge_emu_buffer); av_freep(&sl->top_borders[0]); @@ -176,6 +178,7 @@ void ff_h264_free_tables(H264Context *h) int ff_h264_alloc_tables(H264Context *h) { + ERContext *const er = &h->er; const int big_mb_num = h->mb_stride * (h->mb_height + 1); const int row_mb_num = 2*h->mb_stride*FFMAX(h->nb_slice_ctx, 1); const int st_size = big_mb_num + h->mb_stride; @@ -208,33 +211,11 @@ int ff_h264_alloc_tables(H264Context *h) h->mb2br_xy[mb_xy] = 8 * (FMO ? mb_xy : (mb_xy % (2 * h->mb_stride))); } - return 0; -} - -/** - * Init context - * Allocate buffers which are not shared amongst multiple threads. - */ -int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) -{ - ERContext *er = &sl->er; - int mb_array_size = h->mb_height * h->mb_stride; - int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1); - int c_size = h->mb_stride * (h->mb_height + 1); - int yc_size = y_size + 2 * c_size; - int x, y, i; - - sl->ref_cache[0][scan8[5] + 1] = - sl->ref_cache[0][scan8[7] + 1] = - sl->ref_cache[0][scan8[13] + 1] = - sl->ref_cache[1][scan8[5] + 1] = - sl->ref_cache[1][scan8[7] + 1] = - sl->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE; - - if (sl != h->slice_ctx) { - memset(er, 0, sizeof(*er)); - } else if (CONFIG_ERROR_RESILIENCE) { + if (CONFIG_ERROR_RESILIENCE) { const int er_size = h->mb_height * h->mb_stride * (4*sizeof(int) + 1); + int mb_array_size = h->mb_height * h->mb_stride; + int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1); + int yc_size = y_size + 2 * big_mb_num; /* init ER */ er->avctx = h->avctx; @@ -252,7 +233,7 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) if (!FF_ALLOCZ_TYPED_ARRAY(er->mb_index2xy, h->mb_num + 1) || !FF_ALLOCZ_TYPED_ARRAY(er->error_status_table, mb_array_size) || !FF_ALLOCZ_TYPED_ARRAY(er->er_temp_buffer, er_size) || - !FF_ALLOCZ_TYPED_ARRAY(sl->dc_val_base, yc_size)) + !FF_ALLOCZ_TYPED_ARRAY(h->dc_val_base, yc_size)) return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us for (y = 0; y < h->mb_height; y++) @@ -261,16 +242,31 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) er->mb_index2xy[h->mb_height * h->mb_width] = (h->mb_height - 1) * h->mb_stride + h->mb_width; - er->dc_val[0] = sl->dc_val_base + h->mb_width * 2 + 2; - er->dc_val[1] = sl->dc_val_base + y_size + h->mb_stride + 1; - er->dc_val[2] = er->dc_val[1] + c_size; - for (i = 0; i < yc_size; i++) - sl->dc_val_base[i] = 1024; + er->dc_val[0] = h->dc_val_base + h->mb_width * 2 + 2; + er->dc_val[1] = h->dc_val_base + y_size + h->mb_stride + 1; + er->dc_val[2] = er->dc_val[1] + big_mb_num; + for (int i = 0; i < yc_size; i++) + h->dc_val_base[i] = 1024; } return 0; } +/** + * Init slice context + */ +void ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) +{ + sl->ref_cache[0][scan8[5] + 1] = + sl->ref_cache[0][scan8[7] + 1] = + sl->ref_cache[0][scan8[13] + 1] = + sl->ref_cache[1][scan8[5] + 1] = + sl->ref_cache[1][scan8[7] + 1] = + sl->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE; + + sl->er = &h->er; +} + static int h264_init_pic(H264Picture *pic) { pic->f = av_frame_alloc(); @@ -739,7 +735,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) goto end; // set decode_error_flags to allow users to detect concealed decoding errors - if ((ret < 0 || h->slice_ctx->er.error_occurred) && h->cur_pic_ptr) { + if ((ret < 0 || h->er.error_occurred) && h->cur_pic_ptr) { h->cur_pic_ptr->f->decode_error_flags |= FF_DECODE_ERROR_DECODE_SLICES; } @@ -764,25 +760,25 @@ end: H264SliceContext *sl = h->slice_ctx; int use_last_pic = h->last_pic_for_ec.f->buf[0] && !sl->ref_count[0]; - ff_h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr); + ff_h264_set_erpic(&h->er.cur_pic, h->cur_pic_ptr); if (use_last_pic) { - ff_h264_set_erpic(&sl->er.last_pic, &h->last_pic_for_ec); + ff_h264_set_erpic(&h->er.last_pic, &h->last_pic_for_ec); sl->ref_list[0][0].parent = &h->last_pic_for_ec; memcpy(sl->ref_list[0][0].data, h->last_pic_for_ec.f->data, sizeof(sl->ref_list[0][0].data)); memcpy(sl->ref_list[0][0].linesize, h->last_pic_for_ec.f->linesize, sizeof(sl->ref_list[0][0].linesize)); sl->ref_list[0][0].reference = h->last_pic_for_ec.reference; } else if (sl->ref_count[0]) { - ff_h264_set_erpic(&sl->er.last_pic, sl->ref_list[0][0].parent); + ff_h264_set_erpic(&h->er.last_pic, sl->ref_list[0][0].parent); } else - ff_h264_set_erpic(&sl->er.last_pic, NULL); + ff_h264_set_erpic(&h->er.last_pic, NULL); if (sl->ref_count[1]) - ff_h264_set_erpic(&sl->er.next_pic, sl->ref_list[1][0].parent); + ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent); - sl->er.ref_count = sl->ref_count[0]; + h->er.ref_count = sl->ref_count[0]; - ff_er_frame_end(&sl->er); + ff_er_frame_end(&h->er); if (use_last_pic) memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0])); } diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 6ad2333419..0b9c5784a2 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -170,7 +170,7 @@ typedef struct H264Ref { typedef struct H264SliceContext { struct H264Context *h264; GetBitContext gb; - ERContext er; + ERContext *er; int slice_num; int slice_type; @@ -271,7 +271,6 @@ typedef struct H264SliceContext { unsigned int pps_id; const uint8_t *intra_pcm_ptr; - int16_t *dc_val_base; uint8_t *bipred_scratchpad; uint8_t *edge_emu_buffer; @@ -543,6 +542,8 @@ typedef struct H264Context { int height_from_caller; int enable_er; + ERContext er; + int16_t *dc_val_base; H264SEIContext sei; @@ -784,7 +785,7 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src); int ff_h264_replace_picture(H264Context *h, H264Picture *dst, const H264Picture *src); void ff_h264_unref_picture(H264Context *h, H264Picture *pic); -int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl); +void ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl); void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height);