From patchwork Mon Apr 29 21:14:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48386 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1509:b0:1a9:af23:56c1 with SMTP id nq9csp2271327pzb; Mon, 29 Apr 2024 14:17:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXbNp4utYdcSC6BJr+UKe9RsygjVvsyq6BH67LN19ySqybb61nIdE+TolV9KnKw+gnazfrcTU83S2df5k0qqMTi0sD9TsDr5n+B0g== X-Google-Smtp-Source: AGHT+IHeVD9OkU851X7mokGIVlXnlnxcMTtPAqcX4a736tDa4NkisCgUz8BWVnqTcM4v0qgQmSzf X-Received: by 2002:a19:3808:0:b0:51b:ada6:f1a2 with SMTP id f8-20020a193808000000b0051bada6f1a2mr6042677lfa.3.1714425423395; Mon, 29 Apr 2024 14:17:03 -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 h21-20020a056512221500b0051af998d072si7246668lfu.129.2024.04.29.14.17.03; Mon, 29 Apr 2024 14:17:03 -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=oSPgF0+j; 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 939AB68D568; Tue, 30 Apr 2024 00:15:56 +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-am6eur05olkn2079.outbound.protection.outlook.com [40.92.91.79]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE97068D558 for ; Tue, 30 Apr 2024 00:15:52 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hzTSkjZD/bJ2z8M9PTxzFHwNSudySf2iJtUIf3hrCTEnaQfkgiIlrfKpijmE415XJ+ZQt3ynjk6JiTtroC+Wetv1C1luuxkiKC+RqjUTrYjMR6mExTH1hlbT8F9LJ7tqA7VhmuTyseIO+vi3LBzenG+SdGqSMf2paqRPOQT8CBoOJQ5MLwa0mPaqWlMce0Cbi8cXaHwaKuy3Tk4tWlITS2a+Da4FdpUIYlcvFQPsD+nKXTDJY5P4twflx8lB/W2LIDxEmK75AmXWk5qm7NGM4V5/8xjWNPyL0t4JusSvrS2nCmjkcSeRAYZOiagEJrzI+yM6WHd7cCdzxXay6O8CkA== 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=0uT2SzMT1btgsiGfgkur+f6ptLnIBnPHUXAfTspBg0M=; b=STutemnTdk7rsNjjMrgLfJaEsr6Ckhcoq450uON2/s2P4cqkM6Fge0IbWNyn7ZzU8hKeZAfMNb7yVpkb9e2TK0t7h8w6yeWpTFU66/vlZGrjPz4fKQ5N0Ju0kYNjJl6d5SO2sTu97Bt/cnYTlGptjNu4B55iCX6NGV0VmErXwvVH5pOBof40fnZbygSacVxArHK0WIFjJ+BEH9/xH320N5Tdmc321yew2xPa2AbY6e14LyUZencXRnNgGV4eS3m7fqwyZh7H5NyrFFzGrF8pc15HO14FizMqufvEaLAuSXuXZjVrFEw9SyTFP8jT/enQh22ulhj6vYa62KJyUiJ6rg== 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=0uT2SzMT1btgsiGfgkur+f6ptLnIBnPHUXAfTspBg0M=; b=oSPgF0+jsidsghXZZEmwm6Mh68C4wh8CCvOfJ5LKWzSND+BTNJISZmcTC52whsVBV3Q/z0/CwtQAMpC9Sx7oHX4H4oMCPybzk3FWdwHbNXpcegkQc919m3+EtqIL33aBfQ5lKv6py6nQRQWaUzRUa9eyxH40LwuELoUgj7XipMW1K94Qr37zZQeyulG8xumepOt6nlSYZbjudhdABCIcuaJQSSZUbEzDAwbzsR03TqlETqcnKuTwpxp/QIQtcV7il2ud1eee4zt9k6qP63lfWLS39JHsP/5NLvKYvA5KmRR/AxlwOe2IQjyNj4FsJ1POcWVzcrkNc/uA7iAgktdKgg== 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:51 +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:51 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Apr 2024 23:14:08 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [oVj8LvhvDDvxxAJk9Zh9pO7l1TMtm6woNJtFq8PCPiQ=] 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-13-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: e136e8e2-1c47-470d-03d1-08dc68918c3a X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|56899024|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: Q7BCNdNiJ5meJZrMGafWor/CIy1lCz79wWM7xc2yoS+JdiI8VhEMzrFgg+DBoNTzBTP9mC8F/Ak8es5DOYP5CRFN84Jzt+nj9fp6d0D1A2KNXBXK9bSPWp6+7/ujVEYICMMTjcJNUTSk/7zNcERMQTpUKT8iywaHrXQ2pVxxXQTuUZ2rM1AEFDgcDs+ujjZU318RDNOauvConm/LSpyG3dQQ0DKScavCtKX9pSLjmqL3KE6lWqIlVcb9NGwW3UwQwCT7B9QlZEJkrnGJiX62uJ87hIH3w7Wu1s1knyqBW/+Rl46SSC0KctLAfgA6YxQ1s1KGgANCujvhD1ANMVEDjB9zkeAR6RUNNt0ZJZBq41O5YAja0ebCXkZtsMhRawnEExtM1XrfVBQGAn71gB5ffE23LBMD9S74EYbH7J/bGra2uD0VmCGW3PqiIlpRD150yeDUYKpsEIVCmnfHth9KTLJjuo6mJ30vj/u2t2MIbms3tFBd6YOXx3zh8q72GLJk7KfxWHkXsTlTIz+0nca4zHo/Hb2b1zH8gUpwF7+8lFx+w8gEExv5VuUH+/YEh7BplpgshNfGnsUBEXqugZwi1GT3pf2/lZReipS7jO3MLDpiuvHXqq4ACro3Kb5ApvOD X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HLrbmWqpDw9co7bKrbV1aUcq6kyjH/W80dKqBTHMJcjYi3HNU/vxhLhhli2oWzPLpBZzoaL/qpc5ajmWbAvzeYml11RDAHf8pMQ81ZEzQBZYH32PF8LeG5Ozk6hVbMrB7C6nQPXuvwhbau+G2Oi8D9et7GZFQn4OVXF9ZUugE1HKIp4b6Hh8d2/f4IbuIIrccl+Qq34XVKxmjn6LXg4PwKJ8p3ChWINj933xOc6O1Gum7UKNOIML1zAQ4+Myrt6SrlDunSuXErvLIp2vqSHyEG15o80iMPJuds/tIth9rKw30hlp2h0/0z8KAbsgbDvDp2nxC1+QyMy2vsZcbxygjAI34R7ZUuHBmyknXppX5+wsKeQ3X3BefMtqcTIbB7pkKWDVTx+0nPLIxs5AfvsW+0Gf/rZ2JgTlsnsA1vHYBmsJVKhxt/VK/q+7mR8bi7NoVUn8n6psfhsP31jnlxw3FnU6xDcFw4BCIh9Hh0pQnt9xPOJ5qSy9JH4g/O1I94gW66SZT6FUUJLUEmxup5qigN/IS/62/tP//fv+RX2KQGosHwXcQtHhmjdhz6Oyhb/eY8PSJKk7ZDn5Nm0FyNeONjh0asGSZs+dhtaKVg9eOj7e/MWJtrgaCnqlzipa/e6Sx/LWLmG0GwfEbOqIbeIs1U7xjkU2V8SRtfCOwq4cMh4Pxn/Aowz8cZXQck69Vp0Q9wG3hRzssWAqymaPalybDTx91GrjDhkklBGBBYqO3fgZYbTDbhCQYRU8KqxRv7wPNaaj2C8vpohCoTEZGT0Rrnbu+iYteWupV1mrGgVff7F6/D3RbxlHB7Uzx8ZwhER+Ref7LPmIpyJ9xBImJxidKj190CmPRNnIEfPu8VYE5UGo6Co3S7cta4Kl8V4EMdq+9G++7uHvX6/BxUvQPPyfUxfapaQR0NjaUv7NcbGwj1PhgS6Ypxaq8W7b/zyt4zdmC1o88fXihg03zACyEbza2w74IxUKyD7DRMPftQ/h1ywd1frPaD3JkSKRw9aSffoydxgja9eW3QXobyuE+Xu+8v8UqemthMsCJET5QAoSdNjr2+n/dyRAEk8LaTS4VboIkNgIKg3javR13C25T6I8McnzGgpkcMqxOEa2VRMfkeHljIEenB5hMUtV+VSPi3dwkhKxYpZhV8eM2Lhq6ujgVQADggLiQliTp48nuPpZACb5eZej8JPsRNCr74tHgfWtVXAz3XTQvAi54F5IaFzxwEMt1f9EOlxS8UVDOpBCeutZFUepqQOOKYaPdfp/r3eyrA1TV8MC0AoJqF7hRkUwBg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e136e8e2-1c47-470d-03d1-08dc68918c3a 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:51.5068 (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 27/57] 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: lq7agyIuo2Vw 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 d0b529dc37..8a058c4a77 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; } @@ -155,28 +142,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; @@ -191,9 +172,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 15c6a90e9e..8e1ea36022 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; }