From patchwork Sat May 11 20:50:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48752 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1706:b0:1af:cdee:28c5 with SMTP id nv6csp298708pzb; Sat, 11 May 2024 13:55:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW8oGKV4u8v9Qj+YTFqRI2SnPAbYD+oGluK+/BdJehKFLwUPtGSkng0rzTquEQemhjVA9cpK59LNqZKtDz+t9yPXt47dG1Ndak/jQ== X-Google-Smtp-Source: AGHT+IFoTkGg36Q5sDMz4v6k6ZNGptgI0d0BI1uaRcrBTxXs/qasHPZTSHLA9gej4WdjBE4RRScr X-Received: by 2002:a05:6512:312a:b0:51f:f8b:dcfb with SMTP id 2adb3069b0e04-5220fc6d7ccmr3359303e87.41.1715460930970; Sat, 11 May 2024 13:55:30 -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 a640c23a62f3a-a5a17b21b09si324345666b.282.2024.05.11.13.55.30; Sat, 11 May 2024 13:55:30 -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=PZNVLJ78; 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 81DED68D67E; Sat, 11 May 2024 23:53:17 +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-am6eur05olkn2080.outbound.protection.outlook.com [40.92.91.80]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 80F2068D67E for ; Sat, 11 May 2024 23:53:15 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jIBk9/vN3m/s3MVg5b42ggu8u4OlS38xKnPimWcKLnP94q+vS6IiaF6embVAm1wfNEMLDwhO1EgD0J/FpSrXI921L4JE5qW/COz7nkqQWY1S2zPCACJq78XJHxhaAe2h+ieKGAh3fdH4B55AFjdXFTkFQ9QSMGqShcssP1yN7RUOql7KA/haWlUH17Ya/yhIEZDDKMhl1P3ld8GH/pOMxe5/LD/NANRSLc6zHRU3c8iP7kNVR2NNL1QulHNLcnEamLdnpIUNGXWW2fPNhsiO8J4d6dUn/AgQyClRzOuy03AfNS+Zd9IskSRGfIYvarGyl9ai2x0fIL7DH+w5PiSmZQ== 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=MnADxi/TM8wWlY8TUCd/lND/MvKq/ThFP/ge8WJfmTU=; b=huGgKg1uq8kWdZ0IHpLFwaiC2nERSck/5R2L1WrtSamMo8mqhyID0gllDGFveh4mqC9Fx7JUtMG8gGq8fA+q4EVBYlO2Npy6Xkrf3lzjYl8LFYZRmNKb6DvW/vcjVh1MAiypEKHz2dtMsJ2rO2xnR2knkfb4Dk0vZ5m+GUgcYzJFBQa2PM3WTmY5b6/+xR2A4EASWbNCrYR4D+h7WkGGQSj0WOE5q6la+A4KJI9buwEYj79imi2LkliG9cUpQ7ZrxaK2dBLT9IvraqncT0wKbX0E7VMEswr7tDHSaM6VQzkA8gzY3+gPORE0k/GWLC8muE8seAuzRl11ZvWvT8q+kg== 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=MnADxi/TM8wWlY8TUCd/lND/MvKq/ThFP/ge8WJfmTU=; b=PZNVLJ78Qyb07rFXEUkyYhlHYc+lRg9bD4EaHmlsJrdu0Q0gtZl12GaLnq2I+7cmEWSL/xRTRwzPFoCwBvdBHZEDNz4lBWtTNNQpbp5BtpqBHFY3dQtbGwBCJyxTfVmVQs9/f28JjrMlI3+Xq6xHOBWF4IIH2Vt1KLveFYE+yRQSxFm6xgo5dvJscPRhjcBoedCH871TSnnIlr/bn4ojDf6HAnd2GZUIHaLFAHzqDbIvrR/p/cyzMApQ2RjRB/lSiYmBgruFNcvrhIe3pmj5PCN8JXOPywJrzC61AVNdH15Zfr0mBDLkZsf5p/cYHSzE3XdrFBjmPaeIErT6OlV41w== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PR3P250MB0370.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:17d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Sat, 11 May 2024 20:53:13 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::d6a1:e3af:a5f1:b614]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::d6a1:e3af:a5f1:b614%7]) with mapi id 15.20.7544.052; Sat, 11 May 2024 20:53:13 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 May 2024 22:50:49 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [496WfODqlu3fSKcHArL2cLpvsqh78TLseDTo1kuDkgM=] X-ClientProxiedBy: ZR0P278CA0172.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:45::6) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240511205135.2411886-24-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PR3P250MB0370:EE_ X-MS-Office365-Filtering-Correlation-Id: ce962cac-276e-4253-6f0f-08dc71fc5fd9 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: iGxl6NKdpFaxSbGmFWl5KS2wyNsR4DB4SQFgXeuHzdDtLtlhsCuWwx09pfC4e6DyCnL4me2gFSKv6i++qx9ugYiAxk3qQvh6/+ytBNBBypzmtwBcQsfHJMq6f2xAjcKGVReFv9ziGh1kQYid0YBu++/id40R/y/4WqQHLPjAxeyuKmbbELvoLW5emsEeANk162G6SQbMsFItU5kkAhjYyCVl4tLS89Kb5sjgQsveh9UKvgwrkpL38L5kF8fP5iq/OghsRpZQm0wrKmmuNkYAV5kr+SC5RsQLIV4AJADBQdrhpjeY/K5FTlelJEoiGr1065czrv/AqGM5SJ3j/MkIMy3d0UlvTOnOXqoUPqDuBw/5zF1mrZltKM2K5aYquget1xiOyacYMfmHrYorrPpSw/2K1+8aevqjjTHwjqdFKv8bBAhwwNd0wL+035Z/BHPk14BhZtvYBSUtFhj7LhZzmLSVzB+xMgw22IgfQm0bT2nX9/yC1jy0ElGAKjzrXY4C/lOM9bRXFYE4Q9N+5FsoYdUkAJ3zfOlzpO7drR2m7P9j7pgfpllvjNjUg/9O3wQz7+QJFKknzEj2MR9gEzIg4XNvprOyXhgV8iZGkrATuDYwBfVO/7jmFEHCFoqUmTfp X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2/62vB8d1YhySDSTqHoCXFhg0uQm4P6wR33cnOQXgxFvW1ytJDcuCANj0IAmJw3mdFUw1Cz/tSNi6wETb7kOA4u5huThiwQ9XMNpKzyAlLJ32HZ71vKpX6qTV6bMSXgMr/rtyUZnvVkkNgQm8gmQxOX8+HmOu1LbiHUBey4fSbpemp1tosJZ7Y8EmgA4l2QqPw4DcEEUyEb+7XT1JmzFMdAVd94qevkbxj88nobhAB7pjvDFkpOecq+/5xWmY3XkVJuBYgoujXtIrIdZmhITZzfVIPB2wnWrGeBaOF3HwLd2+mVkiGKg7HNfffmJ1/2dH1mejaY/gstyCnILK7J5P6KxFbc/37avvnLWq3c7O+1qi2mGTeZeVCgn9yc91KDs8FLryAWO7fjQt4wZ2zk4tGYK7W48tkabp4MIeKqvG475YxVHqE9ErhtTB6eviwdiKy5eOgHbzG/XrGLiwz5JhHlY91U46ifyqGMQvztqW4pn8M/coIqiE1ymfs4weiVs4vrn/LcPLNzsDerdIAJ4iq0DC50ZrGJrO5y+jIo1u/DdOW8JgT8IIvtYAZGC7IxWM2j8Xgc+5eu57Q9YcngpF6Y1oC15FfpHh+Od43YAcz53Rtgaez3yM2ws3aQhZRyBwgUwbKUec9+azqX22YEfWKCmuU8E1sd9ZTHnVtJi82fGXYtuQ7D0IwU/1ce4T7o80CWalVbOdX1jVd8CVkcGjmRuuuoOSaJbqe9dBYCeSPAHxshr5SRBqjZ29QhEhWRmZGRRn2APEGpC2/DF3ZJ3rA+Dx85/3CGTHyxMgBei5KVPo8cLo1Rnnqpffq+3ZSy2C9qDahbAWbMwSHbVB4DaXfJrX3WdKYn8C7y15s30ZsH+8xx81INH2fkdDWM2UHLSaXIbjzIc2J1N79o33zI+sQQJArUCiUS4JsRpPafqx0Fx+L2XY+O9s8nkUnREzV1qSZR2+dZYPGaTc/GsVgmhl7UPQq/atrVO4Ov3aVaPrSJy6Qd5tA6LtFdH+CUA7Tty2EGUgNXWkEwawVzQ55IgdmTFDk79PygnO1mKurTa0crizG0wvNd1JaNMLfy/awihc2xDlnfNXxC7FUz3vKVkW0UlDD17C+Frnt/7D8dzSj2SAB2wJjvfUmwxp5eHddRkl4TeL3AzmHbuiRQQiM/rndsTQ3LGjFG+BF1x2QqIq0fBn537fqgc6H1mHsSweT1tKSZolsQ7i7sSdt90jcE0M1nIbUw1WWQdlcmK8gQ6A5G7phnxTFFVbrXxxrLQvAf1XaZuE+OuX2ziGvB1diH4xQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce962cac-276e-4253-6f0f-08dc71fc5fd9 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2024 20:53:13.6108 (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: PR3P250MB0370 Subject: [FFmpeg-devel] [PATCH v2 25/71] avcodec/mpegpicture: Use RefStruct-pool API 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: oomM2/jQGJwX It involves less allocations and therefore has less potential errors to be checked. One consequence thereof is that updating the picture tables can no longer fail. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegpicture.c | 82 ++++++++++++++-------------------------- libavcodec/mpegpicture.h | 21 ++++------ libavcodec/mpegvideo.c | 28 ++++++++------ 3 files changed, 53 insertions(+), 78 deletions(-) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index 32ca037526..ad6157f0c1 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include "libavutil/avassert.h" #include "libavutil/common.h" #include "libavutil/mem.h" @@ -34,13 +32,13 @@ static void av_noinline free_picture_tables(Picture *pic) { - av_buffer_unref(&pic->mbskip_table_buf); - av_buffer_unref(&pic->qscale_table_buf); - av_buffer_unref(&pic->mb_type_buf); + ff_refstruct_unref(&pic->mbskip_table); + ff_refstruct_unref(&pic->qscale_table_base); + ff_refstruct_unref(&pic->mb_type_base); for (int i = 0; i < 2; i++) { - av_buffer_unref(&pic->motion_val_buf[i]); - av_buffer_unref(&pic->ref_index_buf[i]); + ff_refstruct_unref(&pic->motion_val_base[i]); + ff_refstruct_unref(&pic->ref_index[i]); } pic->mb_width = @@ -135,18 +133,18 @@ static int handle_pic_linesizes(AVCodecContext *avctx, Picture *pic, static int alloc_picture_tables(BufferPoolContext *pools, Picture *pic, int mb_height) { -#define GET_BUFFER(name, idx_suffix) do { \ - pic->name ## _buf idx_suffix = av_buffer_pool_get(pools->name ## _pool); \ - if (!pic->name ## _buf idx_suffix) \ +#define GET_BUFFER(name, buf_suffix, idx_suffix) do { \ + pic->name ## buf_suffix idx_suffix = ff_refstruct_pool_get(pools->name ## _pool); \ + if (!pic->name ## buf_suffix idx_suffix) \ return AVERROR(ENOMEM); \ } while (0) - GET_BUFFER(mbskip_table,); - GET_BUFFER(qscale_table,); - GET_BUFFER(mb_type,); + GET_BUFFER(mbskip_table,,); + GET_BUFFER(qscale_table, _base,); + GET_BUFFER(mb_type, _base,); if (pools->motion_val_pool) { for (int i = 0; i < 2; i++) { - GET_BUFFER(motion_val, [i]); - GET_BUFFER(ref_index, [i]); + GET_BUFFER(ref_index,, [i]); + GET_BUFFER(motion_val, _base, [i]); } } #undef GET_BUFFER @@ -166,7 +164,7 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, ScratchpadContext *sc, BufferPoolContext *pools, int mb_height, ptrdiff_t *linesize, ptrdiff_t *uvlinesize) { - int i, ret; + int ret; if (handle_pic_linesizes(avctx, pic, me, sc, *linesize, *uvlinesize) < 0) @@ -179,20 +177,12 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, if (ret < 0) goto fail; - pic->mbskip_table = pic->mbskip_table_buf->data; - memset(pic->mbskip_table, 0, pic->mbskip_table_buf->size); - pic->qscale_table = pic->qscale_table_buf->data + 2 * pic->mb_stride + 1; - pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * pic->mb_stride + 1; - - if (pic->motion_val_buf[0]) { - for (i = 0; i < 2; i++) { - pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4; - pic->ref_index[i] = pic->ref_index_buf[i]->data; - /* FIXME: The output of H.263 with OBMC depends upon - * the earlier content of the buffer; therefore we - * reset it here. */ - memset(pic->motion_val_buf[i]->data, 0, pic->motion_val_buf[i]->size); - } + pic->qscale_table = pic->qscale_table_base + 2 * pic->mb_stride + 1; + pic->mb_type = pic->mb_type_base + 2 * pic->mb_stride + 1; + + if (pic->motion_val_base[0]) { + for (int i = 0; i < 2; i++) + pic->motion_val[i] = pic->motion_val_base[i] + 4; } return 0; @@ -224,36 +214,24 @@ void ff_mpeg_unref_picture(Picture *pic) pic->coded_picture_number = 0; } -static int update_picture_tables(Picture *dst, const Picture *src) +static void update_picture_tables(Picture *dst, const Picture *src) { - int i, ret; - - ret = av_buffer_replace(&dst->mbskip_table_buf, src->mbskip_table_buf); - ret |= av_buffer_replace(&dst->qscale_table_buf, src->qscale_table_buf); - ret |= av_buffer_replace(&dst->mb_type_buf, src->mb_type_buf); - for (i = 0; i < 2; i++) { - ret |= av_buffer_replace(&dst->motion_val_buf[i], src->motion_val_buf[i]); - ret |= av_buffer_replace(&dst->ref_index_buf[i], src->ref_index_buf[i]); - } - - if (ret < 0) { - free_picture_tables(dst); - return ret; + ff_refstruct_replace(&dst->mbskip_table, src->mbskip_table); + ff_refstruct_replace(&dst->qscale_table_base, src->qscale_table_base); + ff_refstruct_replace(&dst->mb_type_base, src->mb_type_base); + for (int i = 0; i < 2; i++) { + ff_refstruct_replace(&dst->motion_val_base[i], src->motion_val_base[i]); + ff_refstruct_replace(&dst->ref_index[i], src->ref_index[i]); } - dst->mbskip_table = src->mbskip_table; dst->qscale_table = src->qscale_table; dst->mb_type = src->mb_type; - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) dst->motion_val[i] = src->motion_val[i]; - dst->ref_index[i] = src->ref_index[i]; - } dst->mb_width = src->mb_width; dst->mb_height = src->mb_height; dst->mb_stride = src->mb_stride; - - return 0; } int ff_mpeg_ref_picture(Picture *dst, Picture *src) @@ -269,9 +247,7 @@ int ff_mpeg_ref_picture(Picture *dst, Picture *src) if (ret < 0) goto fail; - ret = update_picture_tables(dst, src); - if (ret < 0) - goto fail; + update_picture_tables(dst, src); ff_refstruct_replace(&dst->hwaccel_picture_private, src->hwaccel_picture_private); diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index a0bfd8250f..363732910a 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -23,9 +23,6 @@ #include -#include "libavutil/buffer.h" -#include "libavutil/frame.h" - #include "avcodec.h" #include "motion_est.h" #include "threadframe.h" @@ -43,11 +40,11 @@ typedef struct ScratchpadContext { } ScratchpadContext; typedef struct BufferPoolContext { - AVBufferPool *mbskip_table_pool; - AVBufferPool *qscale_table_pool; - AVBufferPool *mb_type_pool; - AVBufferPool *motion_val_pool; - AVBufferPool *ref_index_pool; + struct FFRefStructPool *mbskip_table_pool; + struct FFRefStructPool *qscale_table_pool; + struct FFRefStructPool *mb_type_pool; + struct FFRefStructPool *motion_val_pool; + struct FFRefStructPool *ref_index_pool; int alloc_mb_width; ///< mb_width used to allocate tables int alloc_mb_height; ///< mb_height used to allocate tables int alloc_mb_stride; ///< mb_stride used to allocate tables @@ -60,19 +57,17 @@ typedef struct Picture { struct AVFrame *f; ThreadFrame tf; - AVBufferRef *qscale_table_buf; + int8_t *qscale_table_base; int8_t *qscale_table; - AVBufferRef *motion_val_buf[2]; + int16_t (*motion_val_base[2])[2]; int16_t (*motion_val[2])[2]; - AVBufferRef *mb_type_buf; + uint32_t *mb_type_base; uint32_t *mb_type; ///< types and macros are defined in mpegutils.h - AVBufferRef *mbskip_table_buf; uint8_t *mbskip_table; - AVBufferRef *ref_index_buf[2]; int8_t *ref_index[2]; /// RefStruct reference for hardware accelerator private data diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 5728f4cee3..eab4451e1e 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -41,6 +41,7 @@ #include "mpegutils.h" #include "mpegvideo.h" #include "mpegvideodata.h" +#include "refstruct.h" static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, int16_t *block, int n, int qscale) @@ -536,11 +537,11 @@ void ff_mpv_common_defaults(MpegEncContext *s) static void free_buffer_pools(BufferPoolContext *pools) { - av_buffer_pool_uninit(&pools->mbskip_table_pool); - av_buffer_pool_uninit(&pools->qscale_table_pool); - av_buffer_pool_uninit(&pools->mb_type_pool); - av_buffer_pool_uninit(&pools->motion_val_pool); - av_buffer_pool_uninit(&pools->ref_index_pool); + ff_refstruct_pool_uninit(&pools->mbskip_table_pool); + ff_refstruct_pool_uninit(&pools->qscale_table_pool); + ff_refstruct_pool_uninit(&pools->mb_type_pool); + ff_refstruct_pool_uninit(&pools->motion_val_pool); + ff_refstruct_pool_uninit(&pools->ref_index_pool); pools->alloc_mb_height = pools->alloc_mb_width = pools->alloc_mb_stride = 0; } @@ -641,15 +642,15 @@ int ff_mpv_init_context_frame(MpegEncContext *s) return AVERROR(ENOMEM); memset(s->mbintra_table, 1, mb_array_size); -#define ALLOC_POOL(name, size) do { \ - pools->name ##_pool = av_buffer_pool_init((size), av_buffer_allocz); \ +#define ALLOC_POOL(name, size, flags) do { \ + pools->name ##_pool = ff_refstruct_pool_alloc((size), (flags)); \ if (!pools->name ##_pool) \ return AVERROR(ENOMEM); \ } while (0) - ALLOC_POOL(mbskip_table, mb_array_size + 2); - ALLOC_POOL(qscale_table, mv_table_size); - ALLOC_POOL(mb_type, mv_table_size * sizeof(uint32_t)); + ALLOC_POOL(mbskip_table, mb_array_size + 2, FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME); + ALLOC_POOL(qscale_table, mv_table_size, 0); + ALLOC_POOL(mb_type, mv_table_size * sizeof(uint32_t), 0); if (s->out_format == FMT_H263 || s->encoding || (s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS)) { @@ -657,8 +658,11 @@ int ff_mpv_init_context_frame(MpegEncContext *s) int mv_size = 2 * (b8_array_size + 4) * sizeof(int16_t); int ref_index_size = 4 * mb_array_size; - ALLOC_POOL(motion_val, mv_size); - ALLOC_POOL(ref_index, ref_index_size); + /* FIXME: The output of H.263 with OBMC depends upon + * the earlier content of the buffer; therefore we set + * the flags to always reset returned buffers here. */ + ALLOC_POOL(motion_val, mv_size, FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME); + ALLOC_POOL(ref_index, ref_index_size, 0); } #undef ALLOC_POOL pools->alloc_mb_width = s->mb_width;