From patchwork Mon Apr 29 21:14:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48378 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1509:b0:1a9:af23:56c1 with SMTP id nq9csp2270620pzb; Mon, 29 Apr 2024 14:15:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW8PqnzzHaW8JLmiqii8vqqkfAPcw+soVkWfNCO+Ih6aZcI8fNYRqtUV2NDHkSjyEb9U73PoyKb8la4d6C+2XQfvxEiV7j7tF6MpA== X-Google-Smtp-Source: AGHT+IENRqANW7IzSZdAB68fgR/E1Q+qiAN7WnxK0I08R8civDBN6eSUTaIRm4jESt0adJYieRYN X-Received: by 2002:a17:906:c1d6:b0:a55:bf86:3ccd with SMTP id bw22-20020a170906c1d600b00a55bf863ccdmr9015653ejb.40.1714425338466; Mon, 29 Apr 2024 14:15:38 -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 he42-20020a1709073daa00b00a58a3b858a1si6532696ejc.172.2024.04.29.14.15.37; Mon, 29 Apr 2024 14:15:38 -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=KLqvtMeL; 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 36CC268D546; Tue, 30 Apr 2024 00:15:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02olkn2025.outbound.protection.outlook.com [40.92.50.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A557A68D532 for ; Tue, 30 Apr 2024 00:15:12 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kPw/yxlS4Tjo/pKQeeGHFdIiDXaeGaGlsGGNElz3eOIda5KvTam8gm/9ohdN1v75355Hpj+Y7tZWa5qRLDyQJU2IijxGaNuf+/nk0B0dgH8HU2u4ZuRW4xT/eOVMjddTrEpsIB2cXgxAs3n75xQAXWJq5oa3MkcUdAbbHpSmlJI4XbdWI6RjqK3Hol8VOafdSXmrvuwfspQWKYwR1dXAEGXb9OKNekliNaT1iRns5poj5VCKzFTmSmkZ16aHQHXudPZQRHQAn2xs+csZ3jHP2PTKBLrooSjlehDR+kYYmZDIp+kxRaNvVroEE+lFBpJQ9z59Ii0u2dQeLNFpkKcFTQ== 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=q4F7SAPu0k+78QjFKVFhTrzy+Z6S3i5+Iitk71sXfhI=; b=T2QSpZ97Gk9TA5xFoZVLn+hvyNifMCM91PHyaVpFjuhh6t5if4ho94Fkf2gKzj7ZDDZpJ2M8egKoEJIgzSwCV/A3oAnrYRDkFXY/WjTrSt9VCc8Fug+lh0RzUfY5JXhV32FRuouwSaluppbe5YhmgXHONUlIP3DF4E2gt0CFYfL0+JFBVwdkvyVWww0tNy7bhPcUxA3kwgbI1qIidEO62jdnGv13lHl7I1ugvo/LjPXNYBlLm2Agvk8wUTITf+fijfk/3rFvMyTzjTPNdVLcO2dqJ13lSr6hEV2L0/Dvb5Qi8i9phILSeeheE/uRswNzXUrGkP680FPsSnbbMzli0Q== 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=q4F7SAPu0k+78QjFKVFhTrzy+Z6S3i5+Iitk71sXfhI=; b=KLqvtMeLpyEkfQwP7bMEHH46psX8DdCJ/DIb3cwV2ESoZhyGKvpLtRVvpCQ8I7JpVlC+u7/2SYftBDRn6T9vP2PJ5NOu0epWYCrMXlnYJbMHVJEUaKDCXfFaBzgGl+JhpHaYtMz4QVmz2AVEgwULEKSQ5+QlqZRk/Z4GrSMFGPPZMj9FkwFNHR6nEVTDTPMC8hC5CCS/D9ej5lxbvvhhQfSLfIknvikt03D4kVFxSoT/sIcjifM3CWIv+HBHEWbEvH10Qn57H5wMzITHectUryjhjA/lYPVVQk/wpZjfYsazieFEuI4kcU0z8/0mg03ivI2vt1HiIkdUcooYx2XDDw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PR3P250MB0372.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:17f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Mon, 29 Apr 2024 21:15:10 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb%3]) with mapi id 15.20.7519.031; Mon, 29 Apr 2024 21:15:10 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Apr 2024 23:14:00 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [8E9TvK8VtyjJAwTqJtdY0Uah2LkmQUIjRh+5t5vPu2M=] X-ClientProxiedBy: ZR0P278CA0199.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:6a::21) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240429211438.3274834-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PR3P250MB0372:EE_ X-MS-Office365-Filtering-Correlation-Id: 625895a0-24f7-42fd-4f4c-08dc689173d3 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: NFvg3cyigivoKCCVYUmhLjw/ueuvuaCChcD3y8E5WweH9cU7MBc5/tqkSvRKoqI+dHqld4QSZjTDteLJHBoIwTIfY0/e2kqTgm6ZkgbYStc5EN7YT41K6aCGvn2snA+FLruHvF2LtS90kNGy2FVm7An2eUOvhW2XXPXFEUuabwqwMRNe/tipnxFGuyfezPfk5kABwP0wzOXFF6zw1/zQ63mYu4F114MevdF8SLd0v7XJI00LoOompctp5Ik/84xLcSALZ+by5MXScCQR3Cu7vjC5KT9DT3MIioY/BAFXn2ibqD3lmfhEJYqb2VF7/Bcwdgk32hiOgyLjZMfFtMpkgnzelFcMiOIXyoXlhMSHCzT0vdwX7aqz2nflbUP4ARcQTqrJ/xNF0bFBglUtf2zbETR0flv9ORvh/yygftb4aW7FCRsb4gN0iQ0aK9RM02Z9DD4FBO7hX1SbuuTU9EMggRy4jD0w/pxzkCJPKuVs2z2dPjW76XXSmi77HJKEAKXxc3cb11vZHl1Kg+kRls/t/YURhFHldJ3j48FgXisOEKIDpx03SeYGiJJ3XEWyOWnrD9ygyrT9gjbO7V7aSAelHPEbUid5ZBeyy9bBqSWkJILT0KDpPT7F2+sAZsaGAHI+ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W4BMvG5SZH4foHdUgqTcTfYWlAB5LzahZ92zmJnq9VqF0x2cAduprQ9zkQoCM0N/3FM48MKlJeJjy26AtsFl02nMgX8ln1UOwpLEHkNyv5TypGWBsa+Mcx9KcGxccEK6Tampr44VFGSgcKvHp53QGoqnuJBQz5q9iwtn74V558I5/ysQ+oedOIbnC+vsLvolHLYTP7H8yayba841FhwBd7/GhZfG5LPEXR4CPbLG+3/qU7msgtKK2ViKMP6r1oo6pAGBCJIzxZPWb3I8IssPjlT+VcAKZ0H1bz36LSD7Akr/lM2rlUeZE7hvZxnbOD7McD5qipCyhD8TMG/DgRddeAlxY9/rwwwnJHG4kmNARfZEItRpsrhO9dmIssTfzqU3IdQewf9Py4+nd9CrGgbfiVf2Oa8eNw0Tyda3pUY07sDBcaugeouXMIoNTepm/qNLoZyxbaM+GNQAKB3BXP+6O4hZLNTypKudhf4zPBVh28J+xpLUyV61k/026Vf69SFYPXIcB0+eykRAFyYDkTvlhJM6aqvQ+mjZ1O2S6nHfc9ccFh7e4sjeUTwFo7xqnKF9SvWbF6d6oi6ki+ZA43TRmD61rKlmoVslAWN3Ovt5AmujVw3Aizoi4AhFpmpkaKd4kc8as45EF0EmZJWHD3gRzFfeDRvn2pg1sYnLYBzEQQ84iyWVyxRYr2Jf0B0K8uDul287shtIeRoU7hbkx0WCvSxVH0WUCm1ClDhxBjZntgC4UyJ0i2BBafKlJWIqj37X2j1F0tdKglpz/tvRJ8WOWuJPVau6WUrdlSNJXYwwQCENgXTFsYQa9Nz4IFmQNIXmoszX328wCZsdN/CvXJ/mc3Jo5dpurCWWQNrhHtrTGsdV7+sl8cQfsp0dfciCMeHEpxubUNWvCWa2Du5nyGXKgqy1pWlPm9C6gafOztqWRivV+AztTpY0+lWpn+sGM5tlG1nVqXozXhmFZEcN6fW4yTzDklq5mWAn/2Ilo/On8xTA29axjTHvHyRdrPigxQ+AIyyLb/h9XB9eNtokDzKG98D2MiMlujeSnPln9j8RtIiKhrWATXw3zkvaHB7Mw1znETvbfQz2Q+kS5/UUhkaLJTVV0BcQNBx8/mvagCKFawx4R+eB2Mb2mj/zB2O4PLefYJOfymHWoHrqgH++ZJhVODl9WXz351HJ8i5DosJTn8bpxozzAYU4T4F9T1HPyM+B3+PfSussTibOpwSAPv3Qo1r2vUGf7Kin8hAhQGTOWYKu7MgbBApwqQ7HkaPvjFuFyh75haz3BcEp6DOTvB5fZg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 625895a0-24f7-42fd-4f4c-08dc689173d3 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:15:10.4140 (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: PR3P250MB0372 Subject: [FFmpeg-devel] [PATCH 19/57] 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: 38nFRiXVkF3b 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 | 81 ++++++++++++++-------------------------- libavcodec/mpegpicture.h | 21 ++++------- libavcodec/mpegvideo.c | 28 ++++++++------ 3 files changed, 53 insertions(+), 77 deletions(-) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index b83fee67f8..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,19 +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; - 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; @@ -223,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) @@ -268,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..487ffa41fd 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, 0); + 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;