From patchwork Tue Feb 1 13:06:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 34059 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a0c:e44f:0:0:0:0:0 with SMTP id d15csp3768578qvm; Tue, 1 Feb 2022 05:19:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZpJ2S536N2s39nM5NxMGdB2GzKNTquYU/QYR7KLvAuEBLxQLpHNfzKHfU9t+/MiVwtCuC X-Received: by 2002:a17:907:7241:: with SMTP id ds1mr21652351ejc.199.1643721555833; Tue, 01 Feb 2022 05:19:15 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s7si9678691edq.265.2022.02.01.05.19.14; Tue, 01 Feb 2022 05:19:15 -0800 (PST) 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=fSp+mB62; 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 03E5368B3FF; Tue, 1 Feb 2022 15:08:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075035.outbound.protection.outlook.com [40.92.75.35]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C82C468B3A8 for ; Tue, 1 Feb 2022 15:08:40 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RIq7oabks8BtW1ixFqz0Qn/ahUh72O52jFMD9D3uf/2ujLfVcl7gTOHNskctpNZ8n9A98ZH22GLOBuiZobGLJW8eWi+bG0lmkbZYC5kbApCXykVqMSrrQVQFpEVuqdo3AVvJP0rloEjtCTkFffLQSRZ/HmYDHKxcbng1FjuwqUKOBVpVXDeWnPRx5Nnj2Eiux9L+oSjZ9Nf9Vpxklw7a3Dltp2DwE5qgHzQ+opaaojswgJ26mi2jgACF3dI7i96VQJaK8SOQpTXVv76kX0zp0DQP3flnrZUR37mtP3wlzd34p2RkMgTxLK8u0c/q0Yd9ZL+T9rjSLnzb7panygcZPg== 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=Y6SV4GGHzzAqztA45nhQeJjo7pWYMmRykJvkPalxQDA=; b=APtMlhqUCKoQIPQZHWrJMHdr2xeRtfPRotLleyVZkFIfZglml5hRAMLfuhfJm84bqb1RdH2i+vkEPHQg2nxnydSililmX0HBRvp46GWQScrI9UAV3BuhCjjrewBVhRQUGyI/Urfe52vZHMS/0EXmVBnYZcA5RpOnEcHxk0otWXn8OPuOt7gKg1+F2mJycbYK4j4LqR/Tfq16aIACW1oNChS7X2ZpSot2/H474POOldQ5BvTWxGP3nWqStGfL1vHMyCyFYal26fJGixNMR9avHTuVb1C8A0KoM8QisrgH/y+E3zEX4w/eQ/3TGSHjZY+2uofeGSCJTVh59KH449S3rg== 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=Y6SV4GGHzzAqztA45nhQeJjo7pWYMmRykJvkPalxQDA=; b=fSp+mB62Fg2+Jl9z71/JNW5Q2DVJV+OhIybrfFb4m6HqMRkrEqNhdAcm7IjgYbrjdD26oFz3hr0wI2m/qTvSeHqAJoRMRXQUtSp+vcHwoTQu5lF3opEdpHlkF+8zhwyxab0FXax3UOC0iC4v0uWZKXT/dznbZrgrpAm3oGpV2lxZWBvZyXa42B9Gm3zLWIi+Bk1LQ1jM5FLqKilp8QSrKk1mBk5+Dl3lqZLAbywpdzOfv683pGqmrYlqVO1o+rbZXYmiPIgGl5DThp3lS1V7vIxmBSATWztTanFQfyGL5geYP8yIo5Ipqnk30IsyJ14cQd/IeHY6smzzo0pTsyZbUg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by HE1PR0301MB2330.eurprd03.prod.outlook.com (2603:10a6:3:73::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.22; Tue, 1 Feb 2022 13:08:37 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%6]) with mapi id 15.20.4951.011; Tue, 1 Feb 2022 13:08:37 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 14:06:42 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [byfjDtpnm+tEGoDqbrwULOOUrD/chU8b] X-ClientProxiedBy: AM6P195CA0092.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::33) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220201130706.1420875-44-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 40928543-2558-4898-748c-08d9e583ebec X-MS-TrafficTypeDiagnostic: HE1PR0301MB2330:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EUfHg2WLb/dxrG8mDzJ3J4Zm7tgxJf6ew0gFGpgWRbCUqkpq8EAk9L8xhnZ91g9hKN9c7JA+alWeUDCY65BcRrfnJ/ljou5BP3S/8Z/oForp+m6SP6TqrtlZpP5bWGFNsdY9CS0pHd5RRCbsu63IdHNvn+KmFlRd2gMepT8Gf6xsrOJeNsOS1zMv62sxsPINZvlCSizAp3qSwwJNZ61eBz6k/jJrnmvgrCqdXNSIb2I1EIz8mY5GrqpbPYCxYo2MCegy0IH57jZTCR+SybTCRLMzLH6qtK6ZMkcC6+w+CC9S+j+qjEMX45dWVthkvKj5pIJqqzrdvDc5czcOuwqf0GuOyaz+bJ+hDDND+zYq/FV6cFbaDv4KdZkWXI0pX0CxRRkHqqHYFEpO1bwu+dtq6i08A3fHGRgtDjDYoorcFYM81qlEP6iTP5ALpU7zvIejvpmuE7SUTey8yqOvxhq/AdFQixqyWpTOzrFhuKQtFe69IJbx3e8KY9qrj/apJxdqJY70e52EjgVixgTKlssM9L1Xqz5Q1HWdpsq4UuwhoXimmPksSqMGjdOvrrk6Lzcf X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BRYM5oW4YZhEc3YoGaVCcfPbhujeADqgv52zeJyAGneUkZMWri1oeYoxB4RdcEQvV/q4boQhK8qItuf3GNBPU7y9jnLsliEkMcw5p6ZAYNg1aO8vqGFuDZVcScd1ldKeXZd6FbegfdVviTM6EDXkpEfUmRtcu3ethbklp4/25tKvJwi+za9ObWDshnC/L63zklompUx+Wa9jzWPj8GOlJsBvyXiXyusH9pTRcWCXp2NQb4EAejvd/mr+wCMdAg3TL5bX2mpyRrlyYdk1sYvLmalFLC668Rco6lEw2AnqR+qRrn7K4cQUtGYHm6gRIlwIoq4s8uSBbxz6hI7oSPHZACUtrD3JRDT0BdxJEc5w3ayH29O39ZDkiFtVnooNxd3sHXz3PWJrQe7RnJSYRy5sZrHcl/7SJyvt7xmaUzNzxyWcOCVy15PuRO/zl3yuqZxKEHbRyJk2jsYIkFGqEedKh+5CDOiD4ZxlhjTg1nsTy8IlmK1jmN2SK8JsvIE1BlqqaTq2UcOdhAR8aFlFzyeHqEITkfNBxTOQ5m1fFgX1ubEDq2Qi6sjlxdHf7XzVsee4+MGitArxLofqMlD5F8S4glNBEUcYfVUpbQdFzw5Mw93wpdXwzj8IahXaB55HcnzluPsmMfQOHSHeKzKeOGyO7/duU3GWoDgY+2kAdsWN2Kq3OmusH02YgREIRdPTc/hVllti1fGfTyUoL6p+v7XtOl7ANp8Vj4hJPzVAdXLpvHeswWdh25RYFpWCcmEgbb2or6DHqr1YdIIiRmtLJ/Rxx2ie+Ig2A6aypF/Ww5dXUdstbB2u8I+r0pWMOceztirJ7eNWAZIgjUJykIDcu9UWzNi6bjN1qVxcZlk9C0iTd2GfPyp/XkFRtrnxsjJ7Y2ONOiOUmJTVn4NuRo7KogzzPXqhxnDZUzBoSUDSSfg1LGWiUdtj3pkKBlPIjamTMJdoI5e3FpJAxWciRyivuqLL8A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40928543-2558-4898-748c-08d9e583ebec X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 13:08:21.2972 (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: HE1PR0301MB2330 Subject: [FFmpeg-devel] [PATCH v2 45/69] avcodec/mpegvideo: Allocate encoder-only tables in mpegvideo_enc.c 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: zDRvhG+f/Qdp Content-Length: 12360 This commit moves the encoder-only allocations of the tables owned solely by the main encoder context to mpegvideo_enc.c. This avoids checks in mpegvideo.c for whether we are dealing with an encoder; it also improves modularity (if encoders are disabled, this code will no longer be included in the binary). And it also avoids having to reset these pointers at the beginning of ff_mpv_common_init() (in case the dst context is uninitialized, ff_mpeg_update_thread_context() simply copies the src context into dst which therefore may contain pointers not owned by it, but this does not happen for encoders at all). Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 118 +++---------------------------------- libavcodec/mpegvideo_enc.c | 68 ++++++++++++++++++++- 2 files changed, 74 insertions(+), 112 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 88cd9bc6ed..5a68a7cf07 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -557,61 +557,13 @@ int ff_mpv_init_context_frame(MPVMainContext *s) s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed? - if (s->encoding) { - /* Allocate MV tables */ - if (!FF_ALLOCZ_TYPED_ARRAY(s->p_mv_table_base, mv_table_size) || - !FF_ALLOCZ_TYPED_ARRAY(s->b_forw_mv_table_base, mv_table_size) || - !FF_ALLOCZ_TYPED_ARRAY(s->b_back_mv_table_base, mv_table_size) || - !FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_forw_mv_table_base, mv_table_size) || - !FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_back_mv_table_base, mv_table_size) || - !FF_ALLOCZ_TYPED_ARRAY(s->b_direct_mv_table_base, mv_table_size)) - return AVERROR(ENOMEM); - s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; - s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; - s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; - s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + s->mb_stride + 1; - s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + s->mb_stride + 1; - s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; - - /* Allocate MB type table */ - if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_type, mb_array_size) || - !FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size) || - !FF_ALLOC_TYPED_ARRAY (s->cplx_tab, mb_array_size) || - !FF_ALLOC_TYPED_ARRAY (s->bits_tab, mb_array_size)) - return AVERROR(ENOMEM); - -#define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p)))) - if (s->codec_id == AV_CODEC_ID_MPEG4 || - (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) { - int16_t (*tmp1)[2]; - uint8_t *tmp2; - if (!(tmp1 = ALLOCZ_ARRAYS(s->b_field_mv_table_base, 8, mv_table_size)) || - !(tmp2 = ALLOCZ_ARRAYS(s->b_field_select_table[0][0], 2 * 4, mv_table_size)) || - !ALLOCZ_ARRAYS(s->p_field_select_table[0], 2 * 2, mv_table_size)) - return AVERROR(ENOMEM); - - s->p_field_select_table[1] = s->p_field_select_table[0] + 2 * mv_table_size; - tmp1 += s->mb_stride + 1; - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < 2; j++) { - for (int k = 0; k < 2; k++) { - s->b_field_mv_table[i][j][k] = tmp1; - tmp1 += mv_table_size; - } - s->b_field_select_table[i][j] = tmp2; - tmp2 += 2 * mv_table_size; - } - } - } - } - if (s->codec_id == AV_CODEC_ID_MPEG4 || (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) { - int16_t (*tmp)[2]; /* interlaced direct mode decoding tables */ - if (!(tmp = ALLOCZ_ARRAYS(s->p_field_mv_table_base, 4, mv_table_size))) + int16_t (*tmp)[2] = av_calloc(mv_table_size, 4 * sizeof(*tmp)); + if (!tmp) return AVERROR(ENOMEM); + s->p_field_mv_table_base = tmp; tmp += s->mb_stride + 1; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { @@ -654,8 +606,6 @@ int ff_mpv_init_context_frame(MPVMainContext *s) static void clear_context(MPVMainContext *s) { - int i, j, k; - memset(&s->next_picture, 0, sizeof(s->next_picture)); memset(&s->last_picture, 0, sizeof(s->last_picture)); memset(&s->current_picture, 0, sizeof(s->current_picture)); @@ -684,31 +634,10 @@ static void clear_context(MPVMainContext *s) s->bitstream_buffer = NULL; s->allocated_bitstream_buffer_size = 0; s->picture = NULL; - s->mb_type = NULL; - s->p_mv_table_base = NULL; - s->b_forw_mv_table_base = NULL; - s->b_back_mv_table_base = NULL; - s->b_bidir_forw_mv_table_base = NULL; - s->b_bidir_back_mv_table_base = NULL; - s->b_direct_mv_table_base = NULL; - s->p_mv_table = NULL; - s->b_forw_mv_table = NULL; - s->b_back_mv_table = NULL; - s->b_bidir_forw_mv_table = NULL; - s->b_bidir_back_mv_table = NULL; - s->b_direct_mv_table = NULL; - s->b_field_mv_table_base = NULL; s->p_field_mv_table_base = NULL; - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - for (k = 0; k < 2; k++) { - s->b_field_mv_table[i][j][k] = NULL; - } - s->b_field_select_table[i][j] = NULL; + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) s->p_field_mv_table[i][j] = NULL; - } - s->p_field_select_table[i] = NULL; - } s->dc_val_base = NULL; s->coded_block_base = NULL; @@ -721,10 +650,6 @@ static void clear_context(MPVMainContext *s) s->er.error_status_table = NULL; s->er.er_temp_buffer = NULL; s->mb_index2xy = NULL; - s->lambda_table = NULL; - - s->cplx_tab = NULL; - s->bits_tab = NULL; } /** @@ -820,37 +745,12 @@ av_cold int ff_mpv_common_init(MPVMainContext *s) void ff_mpv_free_context_frame(MPVMainContext *s) { - int i, j, k; - free_duplicate_contexts(s); - av_freep(&s->mb_type); - av_freep(&s->p_mv_table_base); - av_freep(&s->b_forw_mv_table_base); - av_freep(&s->b_back_mv_table_base); - av_freep(&s->b_bidir_forw_mv_table_base); - av_freep(&s->b_bidir_back_mv_table_base); - av_freep(&s->b_direct_mv_table_base); - s->p_mv_table = NULL; - s->b_forw_mv_table = NULL; - s->b_back_mv_table = NULL; - s->b_bidir_forw_mv_table = NULL; - s->b_bidir_back_mv_table = NULL; - s->b_direct_mv_table = NULL; - av_freep(&s->b_field_mv_table_base); - av_freep(&s->b_field_select_table[0][0]); av_freep(&s->p_field_mv_table_base); - av_freep(&s->p_field_select_table[0]); - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - for (k = 0; k < 2; k++) { - s->b_field_mv_table[i][j][k] = NULL; - } - s->b_field_select_table[i][j] = NULL; + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) s->p_field_mv_table[i][j] = NULL; - } - s->p_field_select_table[i] = NULL; - } av_freep(&s->dc_val_base); av_freep(&s->coded_block_base); @@ -863,10 +763,6 @@ void ff_mpv_free_context_frame(MPVMainContext *s) av_freep(&s->er.error_status_table); av_freep(&s->er.er_temp_buffer); av_freep(&s->mb_index2xy); - av_freep(&s->lambda_table); - - av_freep(&s->cplx_tab); - av_freep(&s->bits_tab); s->linesize = s->uvlinesize = 0; } diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index da417acfae..1739472352 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -319,7 +319,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) MPVMainEncContext *const m = avctx->priv_data; MPVMainContext *const s = &m->common; AVCPBProperties *cpb_props; - int i, ret; + int i, ret, mv_table_size, mb_array_size; mpv_encode_defaults(m); @@ -820,6 +820,56 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) ff_pixblockdsp_init(&s->pdsp, avctx); ff_qpeldsp_init(&s->qdsp); + /* Allocate MV tables; the MV and MB tables will be copied + * to slice contexts by ff_update_duplicate_context(). */ + mv_table_size = (s->mb_height + 2) * s->mb_stride + 1; + if (!FF_ALLOCZ_TYPED_ARRAY(s->p_mv_table_base, mv_table_size) || + !FF_ALLOCZ_TYPED_ARRAY(s->b_forw_mv_table_base, mv_table_size) || + !FF_ALLOCZ_TYPED_ARRAY(s->b_back_mv_table_base, mv_table_size) || + !FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_forw_mv_table_base, mv_table_size) || + !FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_back_mv_table_base, mv_table_size) || + !FF_ALLOCZ_TYPED_ARRAY(s->b_direct_mv_table_base, mv_table_size)) + return AVERROR(ENOMEM); + s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; + s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; + s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; + s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + s->mb_stride + 1; + s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + s->mb_stride + 1; + s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; + + /* Allocate MB type table */ + mb_array_size = s->mb_height * s->mb_stride; + if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_type, mb_array_size) || + !FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size) || + !FF_ALLOC_TYPED_ARRAY (s->cplx_tab, mb_array_size) || + !FF_ALLOC_TYPED_ARRAY (s->bits_tab, mb_array_size)) + return AVERROR(ENOMEM); + +#define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p)))) + if (s->codec_id == AV_CODEC_ID_MPEG4 || + (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) { + int16_t (*tmp1)[2]; + uint8_t *tmp2; + if (!(tmp1 = ALLOCZ_ARRAYS(s->b_field_mv_table_base, 8, mv_table_size)) || + !(tmp2 = ALLOCZ_ARRAYS(s->b_field_select_table[0][0], 2 * 4, mv_table_size)) || + !ALLOCZ_ARRAYS(s->p_field_select_table[0], 2 * 2, mv_table_size)) + return AVERROR(ENOMEM); + + s->p_field_select_table[1] = s->p_field_select_table[0] + 2 * mv_table_size; + tmp1 += s->mb_stride + 1; + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + for (int k = 0; k < 2; k++) { + s->b_field_mv_table[i][j][k] = tmp1; + tmp1 += mv_table_size; + } + s->b_field_select_table[i][j] = tmp2; + tmp2 += 2 * mv_table_size; + } + } + } + if (!(avctx->stats_out = av_mallocz(256)) || !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix, 32) || !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) || @@ -945,6 +995,22 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) av_freep(&avctx->stats_out); + av_freep(&s->p_mv_table_base); + av_freep(&s->b_forw_mv_table_base); + av_freep(&s->b_back_mv_table_base); + av_freep(&s->b_bidir_forw_mv_table_base); + av_freep(&s->b_bidir_back_mv_table_base); + av_freep(&s->b_direct_mv_table_base); + av_freep(&s->b_field_mv_table_base); + av_freep(&s->b_field_select_table[0][0]); + av_freep(&s->p_field_select_table[0]); + + av_freep(&s->mb_type); + av_freep(&s->lambda_table); + + av_freep(&s->cplx_tab); + av_freep(&s->bits_tab); + if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); s->q_chroma_intra_matrix= NULL;