From patchwork Sat May 11 20:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48764 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1706:b0:1af:cdee:28c5 with SMTP id nv6csp299103pzb; Sat, 11 May 2024 13:57:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXQLXU1xqar7H0sONg5OfL8lo7Dis5Uhd49XsyGf8KsN3e00/PTYfhOJni2akdT+FTSNDpy0fKZ2U/Hm0UJ3Zym1kQlKqJnWqe7/A== X-Google-Smtp-Source: AGHT+IFcXMUmQFKrivZ4j6CcG1uDrJSrVNA1VsU3NXakaQ+LPmRdjjlaqSGoDZicUsSCG6dM/Pz/ X-Received: by 2002:a17:906:17c5:b0:a59:c9ad:bd26 with SMTP id a640c23a62f3a-a5a2d54c601mr370267966b.12.1715461041515; Sat, 11 May 2024 13:57:21 -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-a5a17b21ceesi325105366b.402.2024.05.11.13.57.21; Sat, 11 May 2024 13:57:21 -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=j+wPcN+T; 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 66F0868D740; Sat, 11 May 2024 23:54:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04olkn2033.outbound.protection.outlook.com [40.92.74.33]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1FE9468D739 for ; Sat, 11 May 2024 23:54:24 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FQvhBdnm8qYKo3XxyVjKniPKBJ0Yr8IxJzJIijW0/U9pZMNbE2J19F0MoUt6Db/STmROfX1YiFGqHZcBBmuLDPhNHDXvf09lRNvx0UZn9+DNfLOK1HWPXsU6T65BZ+YF+LDvNG7f4ov1sgjmdIBnBDvlCpMSd4W8py03LEzvTC8ZIHan1dc4iIWH3JIMrvpaGgrCdtE/BIO9NZKSkHoaE13rSGQybwO/7ZT//8Hv5PUXL/9gmHYGs/zoH3xUC+4l7ymimTyfZvZlBjAOcpz4ZW18DoLRrlqHrJ/nT9P1d0fqIWesK5MF0Xf8u03f/fZzEZdjdDYlkpwgAHfjo3X9DA== 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=VF1B9B5tZbfY/HW9Hc9xulW7hAAOu5/xIhP+rKWSeLA=; b=Ndh9nwQMXWKKwdOklc3G2Seb3xwvolj2/UunSs1c6iEhmPNXZ5FGd0XB2V6iSPuLZ50WrMSS+MydTNoKl1yvQUVgg7VQIohdOL6RUChDGpYjDz1U6Q1fqGLe5/dynTz559JE8+FCp7ee/e7gl6PmwJN1rrHjTrbDkjtKtHhBBFW1xu0BMJl/5yf7GJ4me3wP970ifERjBXV4x0PgxKS+bnIAfNuYTatLwBSMknp6hcUZ+5wg9CNybYOHK1R4XuM/0EVHrEeKqvVNC/SN/V7ekq5Vni8VuFnITcHUAfwiwWUHnaWsARPMLDKACinryUWy6nlTOo0PMtF/rAePSp71sw== 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=VF1B9B5tZbfY/HW9Hc9xulW7hAAOu5/xIhP+rKWSeLA=; b=j+wPcN+TJmv7lk9sAmuAkeDwiyMIvlpvaiHH4lzfszGv6ZBE7NPUYUMb8fhPEI/iQXaJjU2fbMtHUS5wvTdViHtEn+bjaQBfxY2CPRPsqH6prUsudQ7EjtnngRg1XLBss+P6hwOmaN5UH6ykNcTFw9T0MCz3MoV1jsGB3qCOiwD/bVp72FoECcBBm/gSOYzXu1+uSxKW6xiJvaS8kGBd5Ez0HuWvbobkR0mFEwOJn2zNXEKFI6PpvyHq88RDmjS7ZJ3MvtPDjBhJoIBrjOrSMBYrPByIJc0aNgC50VwCLvk60JbAu1GnLEFWtReMDi8p6VxUbr9vrcGTcMZS8KkKEg== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DB9P250MB0403.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:327::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.54; Sat, 11 May 2024 20:54:22 +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:54:22 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 May 2024 22:51:02 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [fVYB/A1cxMXayvOUORXJV51GBCCiAtYkghax7OKGtg0=] 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-37-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DB9P250MB0403:EE_ X-MS-Office365-Filtering-Correlation-Id: 98315a5a-5bc4-4958-38db-08dc71fc88fe X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|56899024|1710799017; X-Microsoft-Antispam-Message-Info: lbsuLEjhAmnyw/CCqE00XkYL2TW9ttvbamzZo01QTrt6QnlnYT3cz+AS+9o/DfM/jzePQxZFTuA5yjBFIK5sMmLoXbjnduZaDp7rE/dS3WS5YY8G7YHV9VEdsSHqmsQHV11mESKqOQbBSAfzVOn5FvfiKksaUkaoGwuNQ2V5HKAkXxjqrpbLz7e/wCuJyfyBInWhXwTbRui+8mdNdNV76z/I3Y7joo7UeIjaG/1TiYbyEdqH3mrwSHnQbdJPPRan71RhSAOxl286XeCp4o4imKLP3AcCAz5G8EpHnRP5rn3QdJ/5DDrxH2Pem1jyTFJHC+11tOnV5//HVkSoHbkGMeQfE7mlcyA8DXPTOmNbpSRbGUaWzhXLqmaeELYK2t2KZr7gM25EJuXSj1KtHrPwUhuuCZF1tBGNN5XgIAr4OYSUyIF4PaS0OOATJwkBF6p7VfdSZ2/ZaMF4/C8GL2/gdYhUjiG6stbbKhQTghbgw7FD6Gl0+21kV4qTxs9b19tG8jZE9JVWRkJyfFGr7uJLu/z3dxldmG07g4PyTWbptuIvZcvsNNOhR+q9Q5M3lzYWCRb1tSaFnCi5tdIAbRjE+0FAYIOJ0zeQIKeNrR8iNmlT0RN9RfoxU25PZzLmGFs4 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +lr0pANX7cn6JxACh5+MLptswXXXOnWU1K1JL7lqPBz39q/D/0gKL+8x2TirhWPgDlcTOjkTV8bRMWjL4IsBnR6vXAgv5LScHO1V3q1gL7tcdINzb2coyOaPoAqGeeeOcb/jmZIO0SJ5WoEas4tsCGGnMzGkbj+ak5Opx7SDilW3u94/NOS7eWRGtnn8P4s1UvtGxJjI0hgusIkqMJQVBREvYYNhemw3nxznVldZfa9e46k8KsY0FQQ315nqrYRNoFKCVJFASkUB8eMMW4klbA6dR1wwQcWOH+AF8sGpe8vGnVUnKcl4fsmiApBo4+xi240LkTKLmRj9XUzmLIa2pQgqbTdXDqgrqi3Vc6KoQlV25WPuoXqcHUR448zUu+JA4WfdjUokVHdMRJeUf5WGTEeXGpAc1ps1j9rmwfcHEV8z3Ly7BJdBV8sQK3jQblSyNSxhbL7yj5UCjYAunCtVq03YjvsoK2zs+EtCKfV/A2cmQhb0wvjdFI8MSoAbR6Y3Vk/hxd/yWqLa/6ADBAwV+l6yQaGLHQFrnQSTxpTigzOOuWymep/Caz9esDitqjc8zZRg+/GdTNY04BcSKEtqAd2j1Sa/3wGKv7tQz6gU/dhVodGsT//dt3i2b9yGAU8yyz+mdot05jnMAfUsOqx3qg6+ktVfjm+aaYbF6TDy3GFYKou9x9LIqtysuoIOdP8H7hqxseDfvNbx6ZpI3TwX5FoS6zm4/jiKzkZFwFiPJNBHxn5su8Y2OnHXwTgQTGf160wmIZaXwjBDSgcjLSKIAoDoVJzK9Vcd1b4VhPOnReRooNdZLhWOuI7YaL0Sr1wEo5PFUkuutAaFIUIdEHLId2pd1o+Tr8wLt4HPM685szdnnv8Q5id3edEo5ye7vqoN+QQ9e4SII6NRFabtGugYjHhtSIPDJZt6n4DCRKaMSd3p3Y11V/cEJ6RPmA/WEDCVo+udZKeeHvE2UNcU2zSXx4UZ1CLQ5kn9Z0KXQQqdL32kXBmZ9dbwIR+dLzBw2RF3HictzioxczhzHqZ+wV4uuN3bo2k2+FBZfPHUaI3BLZ3Fa61DZvkYDD7KCmS9aoYMa46TtFOuOisUyJ8aP+GVwnpyJ4lzjV38IR85nysbxPBlqq+vCnm9j4VwMcyNmpkipD2aUb7aeaBNYbZkAlHW0CJK/eVcSwsVAlEQkGb5E9tjb60AUyQNbZSvHIk8OwqxaWTvOuZWdEn3fVVAR8d0eSR4oOK9HV+PgMonxjJg4t878lv5D99v+/jOmz1rozibnhhDxzu0scIflQ5Mh74Biw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98315a5a-5bc4-4958-38db-08dc71fc88fe 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:54:22.6403 (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: DB9P250MB0403 Subject: [FFmpeg-devel] [PATCH v2 38/71] avcodec/mpegpicture: Split ff_alloc_picture() into check and alloc part 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: SdX4aoWKJmfF ff_alloc_picture() currently does two things: It checks the consistency of the linesize (which should not be necessary, but is) and it allocates certain buffers. (It does not actually allocate the picture buffers, so its name is misleading.) This commit splits it into two separate functions. The rationale for this is that for the encoders, every picture needs its linesizes checked, but not every picture needs these extra buffers. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegpicture.c | 70 ++++++++++++++------------------------ libavcodec/mpegpicture.h | 15 ++++++-- libavcodec/mpegvideo_dec.c | 8 +++-- libavcodec/mpegvideo_enc.c | 57 ++++++++++++++----------------- 4 files changed, 69 insertions(+), 81 deletions(-) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index f605338845..840aa23c38 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -91,40 +91,27 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, return 0; } -/** - * Check the pic's linesize and allocate linesize dependent scratch buffers - */ -static int handle_pic_linesizes(AVCodecContext *avctx, Picture *pic, - MotionEstContext *me, ScratchpadContext *sc, - int linesize, int uvlinesize) +int ff_mpv_pic_check_linesize(void *logctx, const AVFrame *f, + ptrdiff_t *linesizep, ptrdiff_t *uvlinesizep) { - int ret; - - if ((linesize && linesize != pic->f->linesize[0]) || - (uvlinesize && uvlinesize != pic->f->linesize[1])) { - av_log(avctx, AV_LOG_ERROR, "Stride change unsupported: " - "linesize=%d/%d uvlinesize=%d/%d)\n", - linesize, pic->f->linesize[0], - uvlinesize, pic->f->linesize[1]); - ff_mpeg_unref_picture(pic); + ptrdiff_t linesize = *linesizep, uvlinesize = *uvlinesizep; + + if ((linesize && linesize != f->linesize[0]) || + (uvlinesize && uvlinesize != f->linesize[1])) { + av_log(logctx, AV_LOG_ERROR, "Stride change unsupported: " + "linesize=%"PTRDIFF_SPECIFIER"/%d uvlinesize=%"PTRDIFF_SPECIFIER"/%d)\n", + linesize, f->linesize[0], + uvlinesize, f->linesize[1]); return AVERROR_PATCHWELCOME; } - if (av_pix_fmt_count_planes(pic->f->format) > 2 && - pic->f->linesize[1] != pic->f->linesize[2]) { - av_log(avctx, AV_LOG_ERROR, "uv stride mismatch unsupported\n"); - ff_mpeg_unref_picture(pic); + if (av_pix_fmt_count_planes(f->format) > 2 && + f->linesize[1] != f->linesize[2]) { + av_log(logctx, AV_LOG_ERROR, "uv stride mismatch unsupported\n"); return AVERROR_PATCHWELCOME; } - - ret = ff_mpeg_framesize_alloc(avctx, me, sc, - pic->f->linesize[0]); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, - "get_buffer() failed to allocate context scratch buffers.\n"); - ff_mpeg_unref_picture(pic); - return ret; - } + *linesizep = f->linesize[0]; + *uvlinesizep = f->linesize[1]; return 0; } @@ -156,28 +143,22 @@ static int alloc_picture_tables(BufferPoolContext *pools, Picture *pic, return 0; } -/** - * Allocate a Picture. - * The pixels are allocated/set by calling get_buffer() if shared = 0 - */ -int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, - ScratchpadContext *sc, BufferPoolContext *pools, - int mb_height, ptrdiff_t *linesize, ptrdiff_t *uvlinesize) +int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, Picture *pic, + MotionEstContext *me, ScratchpadContext *sc, + BufferPoolContext *pools, int mb_height) { int ret; - if (handle_pic_linesizes(avctx, pic, me, sc, - *linesize, *uvlinesize) < 0) - return -1; - - *linesize = pic->f->linesize[0]; - *uvlinesize = pic->f->linesize[1]; - for (int i = 0; i < MPV_MAX_PLANES; i++) { pic->data[i] = pic->f->data[i]; pic->linesize[i] = pic->f->linesize[i]; } + ret = ff_mpeg_framesize_alloc(avctx, me, sc, + pic->f->linesize[0]); + if (ret < 0) + goto fail; + ret = alloc_picture_tables(pools, pic, mb_height); if (ret < 0) goto fail; @@ -192,9 +173,8 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, return 0; fail: - av_log(avctx, AV_LOG_ERROR, "Error allocating a picture.\n"); - ff_mpeg_unref_picture(pic); - return AVERROR(ENOMEM); + av_log(avctx, AV_LOG_ERROR, "Error allocating picture accessories.\n"); + return ret; } /** diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index 814f71213e..6589b38262 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -96,9 +96,18 @@ typedef struct Picture { /** * Allocate a Picture's accessories, but not the AVFrame's buffer itself. */ -int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, - ScratchpadContext *sc, BufferPoolContext *pools, - int mb_height, ptrdiff_t *linesize, ptrdiff_t *uvlinesize); +int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, Picture *pic, + MotionEstContext *me, ScratchpadContext *sc, + BufferPoolContext *pools, int mb_height); + +/** + * Check that the linesizes of an AVFrame are consistent with the requirements + * of mpegvideo. + * FIXME: There should be no need for this function. mpegvideo should be made + * to work with changing linesizes. + */ +int ff_mpv_pic_check_linesize(void *logctx, const struct AVFrame *f, + ptrdiff_t *linesizep, ptrdiff_t *uvlinesizep); int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, ScratchpadContext *sc, int linesize); diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 570a422b6f..663d97e60f 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -259,6 +259,10 @@ static int alloc_picture(MpegEncContext *s, Picture **picp, int reference) if (ret < 0) goto fail; + ret = ff_mpv_pic_check_linesize(avctx, pic->f, &s->linesize, &s->uvlinesize); + if (ret < 0) + goto fail; + ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private); if (ret < 0) goto fail; @@ -267,8 +271,8 @@ static int alloc_picture(MpegEncContext *s, Picture **picp, int reference) av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height || FFALIGN(s->mb_height, 2) == s->buffer_pools.alloc_mb_height); av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride); - ret = ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, &s->buffer_pools, - s->mb_height, &s->linesize, &s->uvlinesize); + ret = ff_mpv_alloc_pic_accessories(s->avctx, pic, &s->me, &s->sc, + &s->buffer_pools, s->mb_height); if (ret < 0) goto fail; *picp = pic; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 21626b58a0..d4b280da05 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1103,6 +1103,10 @@ static int alloc_picture(MpegEncContext *s, Picture *pic) if (ret < 0) return ret; + ret = ff_mpv_pic_check_linesize(avctx, pic->f, &s->linesize, &s->uvlinesize); + if (ret < 0) + return ret; + for (int i = 0; pic->f->data[i]; i++) { int offset = (EDGE_WIDTH >> (i ? s->chroma_y_shift : 0)) * pic->f->linesize[i] + @@ -1112,11 +1116,7 @@ static int alloc_picture(MpegEncContext *s, Picture *pic) pic->f->width = avctx->width; pic->f->height = avctx->height; - av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width); - av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height); - av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride); - return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, &s->buffer_pools, - s->mb_height, &s->linesize, &s->uvlinesize); + return 0; } static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) @@ -1188,7 +1188,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) } else { ret = alloc_picture(s, pic); if (ret < 0) - return ret; + goto fail; ret = av_frame_copy_props(pic->f, pic_arg); if (ret < 0) { ff_mpeg_unref_picture(pic); @@ -1258,6 +1258,9 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) s->input_picture[encoding_delay] = pic; return 0; +fail: + ff_mpeg_unref_picture(pic); + return ret; } static int skip_check(MpegEncContext *s, const Picture *p, const Picture *ref) @@ -1600,45 +1603,37 @@ no_output_pic: s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_B ? 3 : 0; - if ((ret = av_frame_ref(s->new_pic, - s->reordered_input_picture[0]->f))) - goto fail; - if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) { // input is a shared pix, so we can't modify it -> allocate a new // one & ensure that the shared one is reuseable - - Picture *pic; - int i = ff_find_unused_picture(s->avctx, s->picture, 0); - if (i < 0) - return i; - pic = &s->picture[i]; - - pic->reference = s->reordered_input_picture[0]->reference; - ret = alloc_picture(s, pic); + av_frame_move_ref(s->new_pic, s->reordered_input_picture[0]->f); + ret = alloc_picture(s, s->reordered_input_picture[0]); if (ret < 0) goto fail; - ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f); - if (ret < 0) { - ff_mpeg_unref_picture(pic); + ret = av_frame_copy_props(s->reordered_input_picture[0]->f, s->new_pic); + if (ret < 0) goto fail; - } - pic->coded_picture_number = s->reordered_input_picture[0]->coded_picture_number; - pic->display_picture_number = s->reordered_input_picture[0]->display_picture_number; - - /* mark us unused / free shared pic */ - ff_mpeg_unref_picture(s->reordered_input_picture[0]); - - s->cur_pic_ptr = pic; } else { // input is not a shared pix -> reuse buffer for current_pix - s->cur_pic_ptr = s->reordered_input_picture[0]; + ret = av_frame_ref(s->new_pic, s->reordered_input_picture[0]->f); + if (ret < 0) + goto fail; for (int i = 0; i < MPV_MAX_PLANES; i++) { if (s->new_pic->data[i]) s->new_pic->data[i] += INPLACE_OFFSET; } } + s->cur_pic_ptr = s->reordered_input_picture[0]; + av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width); + av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height); + av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride); + ret = ff_mpv_alloc_pic_accessories(s->avctx, s->cur_pic_ptr, &s->me, + &s->sc, &s->buffer_pools, s->mb_height); + if (ret < 0) { + ff_mpeg_unref_picture(s->cur_pic_ptr); + return ret; + } s->picture_number = s->cur_pic_ptr->display_picture_number; }