From patchwork Tue Feb 1 13:06:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 34031 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp612282iov; Tue, 1 Feb 2022 05:22:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJztwp+np2xEiBhErwkNusZP7/dVVsxGu2YNCErIDMGrcdrPGbv3qh/JDZKxLxwm+g1n9tLe X-Received: by 2002:a17:907:7da7:: with SMTP id oz39mr14614539ejc.324.1643721747963; Tue, 01 Feb 2022 05:22:27 -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 4si8975543ejl.73.2022.02.01.05.22.27; Tue, 01 Feb 2022 05:22:27 -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=MBHOIVKf; 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 0912168B454; Tue, 1 Feb 2022 15:09:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2057.outbound.protection.outlook.com [40.92.91.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42F3568B383 for ; Tue, 1 Feb 2022 15:08:51 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OOndWZoED972bHkwD43AKXQ0WNBE+2ooceMS4mKebkdKaOlNJGOfCID9JIZjVAF+hiVSZYUgkfkc2b43kYqQKu/db34ypEnPzrN+IRxRVn4Ih0klPUTMffmGEuhJ/nJjdeHw6xx0wWHLHyZsq5eCjymHSbFZKtCKky2Pu8r6iTAR9KaW5ZfBhU5wod+YKEh3xDYr+xtaoiTAa9auHJ48C+ye6jORiV48t43xjhMB0wOdrgCDKIjwn9H2rv07YFWenwPM8aWlM7hxKmvogoSymm9/DJ2um+QAjKa9hlijcIxvg3Osv0ArbulyntklE7Gqbm2w2gP7YffSkukPyUxYPA== 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=WPRYeS507bdalWf9Fledjr/JNi/rRnKmIPEQo/xXwcg=; b=niJP2Lu1OcZDJnvZj8rzCFn3IvKRot6l6acCfjfg4a/fCZSTnJo9/IqQ5q3CzA+0htVNALgXD8bT8zh9kGRy+WHgwE8JLy0dCcGGNnIoc3Isfllg4uxXccWUkMhZ1uWpMYkcUeKn0Z4NOpfXy1he+QNsD6ClSOtDrHukFfMKXLcakq2UI6S++dzB+7jpvoVySXwH2EqmoVo4SfDLWHZbCta1bq7jyWBPt2vUN33Uyptcu/f8MvAH1H+ASNu72+7jkKvtT+yiWBRxAMOi9Hcv4gv1tsGXcq5LuCzPtcHulHX+/wJTkf8gmGVuL2Xc3b2hqPTPc/Qg6C3pJ5/Nn10IJg== 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=WPRYeS507bdalWf9Fledjr/JNi/rRnKmIPEQo/xXwcg=; b=MBHOIVKfqBDhpfjlp3/qw6u1LSjagW96bUoHzEoWmzqBWkCPxVxSnK+AnzvMyX2Z3RlKVNEcMQqxAzYXq4OPfI7Q7Ji6ViY69KpPDrUhKSIkeTPCqbXHXDuErtj22c0IiWdvYoTnMtRmQjv1R6n6N6+/UdRIE0UQUw5IUXGa1AKRoQGcjRX9fp53c0/dC4ix5Oet8edmYe6vzYcKlBdT8qBgt7eurOT3BgnwVpxIlsUE7VX0bDwXdAabXPinIjBLeGyWKvRwmpN5pjQfFjQLqHnRsMpPMrldE9f+GsEY1qFOoVnImVXHr6Z0ztjrmj5Vs7NIQgB4K7sgaDM7OU6L7A== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM9PR03MB7962.eurprd03.prod.outlook.com (2603:10a6:20b:439::17) 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:50 +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:50 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 14:06:58 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [mhPYKYSmnQQ1kiWwNrJ5NZhrLNvKy4EA] 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-60-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 120ac214-3845-4144-440c-08d9e583fd86 X-MS-TrafficTypeDiagnostic: AM9PR03MB7962:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 58twTGNODDT0k+xgZMKkMQvzqkVsFz706S2r6N8uotoAZx7M4E06k9JMK9Kw/92ueCTspseTBuKuizdUPnYC5Cv5HwYZzzEBDRSby+ND6BEXNNbZ+sOSNlAdgdWwg0aeuetIpb+dSYnKqfaDHzpRIHMf6JwSkMdinScc3CS2xax3/lGYlM/QGyaPEjINI0anJ1CUkbeOHtHNib0ewhPA+bYla0Wa2EU9rR5d1zTiIDKAfUUg2TIhHWaJewFwyp1dNUjSyNPHEScq5uCJXyy3hTHhyDWo1367kQgDIatnBgUOJP++AKHXQWKYrm4BalyhEvcLVHVeDUYvATxXr/S02CtcRrzKZkFz0F/fBIho2iSVDjwEljukt9iGujLdkUoGrtWdWfbyHSQXk0U5Bs/3jND1kVoNjOhqDeg1NcTkWBKB1av83v4PKNlOsxbmBGkftP2Dc1dYNUnw4ooiv18l2jTECLLwxiNskDfFi/MJ4vPKdAw8a3ocuZyEIi3EPSy89USQUjV2m9BzTzuhGfJtUA00XLvFIkWOztMwklaILxFLY1atcfNIkdtaTDYysuRr X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0r3qRgCWTqQ2qa/fDzXQp28wYwDYnFvdAdeD7qaDAVDiRLE5VW1mCmfHbLLGMMjcyjpH89mLqkstUUxZTj543DA37nIMz+DjE2FRaA/y06qiuxRPgBNGqtML2/becKfOEeWOEhAqX/dnEkJ8TsTockVH5BuNFud/VNALiKbdKl4j2oc8erKbz3LJj/X0JJ1YJVvfreNBIlQ6QLdgdyi4l4OIpHgnkDhkMsDHmREteiFJZLrItSgzTQg4NjaHGFuXyq2Dy/Pl3x8DBy3rQyY0YkEcMkV/MbCFh7ZBrW7n3cBptNI09VEbvtUFb5otiaIDY6KIJhivZMTwv1pwe199fZscxhBu8ea/NOc8xZUsQ96hgB34sfIlqf3U7K6aHBPP4BbU32E3Rz/+RuJaphlOinxZkpU9MVua2s9C2y+/MKPF+RVn2ECJJv9vta8p5ry3KrI9PKmquS4TR05uC8GWXVnaZr/TtVFwVp7hLuijSWqNcKGIULC5q0YiHX4FMycXQKd/zH3i3+47bEgJPV8Z74bOAfLF2GZey27l5WqodCdpoKXq+FP5bFdloAnKXGmIwc3xH7fvjGQ0NJaOHlftGGJ7lIY00jo2oIwaG1U73tEYS4ddKefLjdaj1wFlshi9TQ88GpIwIbYlzxTH65Lc8a6E6GIIynrikrXaZjQLZwnVhFAwZXPVnDa1t37RD9yE7zXOOBDWR/H/5xcy+x92QiZ3Wc/arWbjzbmkt3pvrlvcQV8e8J5HaPNMUZjnpPB2lCGTjMgE9B6j+3pL3yIwqu0QJIBB7QfRZeSK0WVcN190A8DmZeiWzPdj9A3DeP2Si7TcEzILh+3Mx6TYfYiqF9VhycaF7/TLgqUY7QFLhPRwaTTsslzupZJXcKSyriAiHGqLmJQP8QJk/Pn3abQC9fYWl2O2h5UbgCUWacbTBCb74BBrrc4Bg8vueoWAeAvPrpKoWRReMagDuJDT5CNniQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 120ac214-3845-4144-440c-08d9e583fd86 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:50.7953 (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: AM9PR03MB7962 Subject: [FFmpeg-devel] [PATCH v2 61/69] avcodec/mpegvideo: Move reordered_input_picture to MPVMainEncContext 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: SRSzezKJTZ00 Also avoid an allocation while at it. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg4videoenc.c | 8 +++--- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 51 +++++++++++++++++++------------------- libavcodec/mpegvideoenc.h | 2 ++ 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 7ad93f9e4c..07c82cc54d 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -632,6 +632,8 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type == MV_TYPE_16X16) { + const MPVMainEncContext *const m = + (MPVMainEncContext *)s->parent_ctx; /* Check if the B-frames can skip it too, as we must skip it * if we skip here why didn't they just compress * the skip-mb bits instead of reusing them ?! */ @@ -648,9 +650,9 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], s->mb_skipped = 1; for (i = 0; i < s->max_b_frames; i++) { + const Picture *const pic = m->reordered_input_picture[i + 1]; uint8_t *b_pic; int diff; - Picture *pic = s->reordered_input_picture[i + 1]; if (!pic || pic->f->pict_type != AV_PICTURE_TYPE_B) break; @@ -890,8 +892,8 @@ static void mpeg4_encode_gop_header(MPVMainEncContext *m) put_bits(&s->pb, 16, GOP_STARTCODE); time = s->current_picture_ptr->f->pts; - if (s->reordered_input_picture[1]) - time = FFMIN(time, s->reordered_input_picture[1]->f->pts); + if (m->reordered_input_picture[1]) + time = FFMIN(time, m->reordered_input_picture[1]->f->pts); time = time * s->avctx->time_base.num; s->last_time_base = FFUDIV(time, s->avctx->time_base.den); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 4a03cde7fe..fefcb90188 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -115,7 +115,6 @@ typedef struct MPVContext { ptrdiff_t linesize; ///< line size, in bytes, may be different from width ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width Picture *picture; ///< main picture buffer - Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding /** bit output */ PutBitContext pb; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index aef4de0fe6..4a90799d17 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -871,8 +871,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } } - if (!(avctx->stats_out = av_mallocz(256)) || - !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT)) + if (!(avctx->stats_out = av_mallocz(256))) return AVERROR(ENOMEM); if (s->noise_reduction) { @@ -1017,7 +1016,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) av_freep(&m->cplx_tab); av_freep(&m->bits_tab); - av_freep(&s->reordered_input_picture); av_freep(&s->dct_offset); return 0; @@ -1438,11 +1436,11 @@ static int select_input_picture(MPVMainEncContext *m) int i, ret; for (i = 1; i < MAX_PICTURE_COUNT; i++) - s->reordered_input_picture[i - 1] = s->reordered_input_picture[i]; - s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; + m->reordered_input_picture[i - 1] = m->reordered_input_picture[i]; + m->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; /* set next picture type & ordering */ - if (!s->reordered_input_picture[0] && m->input_picture[0]) { + if (!m->reordered_input_picture[0] && m->input_picture[0]) { if (s->frame_skip_threshold || s->frame_skip_factor) { if (m->picture_in_gop_number < m->gop_size && s->next_picture_ptr && @@ -1458,9 +1456,9 @@ static int select_input_picture(MPVMainEncContext *m) if (/*s->picture_in_gop_number >= s->gop_size ||*/ !s->next_picture_ptr || s->intra_only) { - s->reordered_input_picture[0] = m->input_picture[0]; - s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; - s->reordered_input_picture[0]->f->coded_picture_number = + m->reordered_input_picture[0] = m->input_picture[0]; + m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; + m->reordered_input_picture[0]->f->coded_picture_number = s->coded_picture_number++; } else { int b_frames = 0; @@ -1543,16 +1541,16 @@ static int select_input_picture(MPVMainEncContext *m) m->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I) b_frames--; - s->reordered_input_picture[0] = m->input_picture[b_frames]; - if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) - s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; - s->reordered_input_picture[0]->f->coded_picture_number = + m->reordered_input_picture[0] = m->input_picture[b_frames]; + if (m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) + m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; + m->reordered_input_picture[0]->f->coded_picture_number = s->coded_picture_number++; for (i = 0; i < b_frames; i++) { - s->reordered_input_picture[i + 1] = m->input_picture[i]; - s->reordered_input_picture[i + 1]->f->pict_type = + m->reordered_input_picture[i + 1] = m->input_picture[i]; + m->reordered_input_picture[i + 1]->f->pict_type = AV_PICTURE_TYPE_B; - s->reordered_input_picture[i + 1]->f->coded_picture_number = + m->reordered_input_picture[i + 1]->f->coded_picture_number = s->coded_picture_number++; } } @@ -1560,15 +1558,16 @@ static int select_input_picture(MPVMainEncContext *m) no_output_pic: ff_mpeg_unref_picture(s->avctx, &s->new_picture); - if (s->reordered_input_picture[0]) { - s->reordered_input_picture[0]->reference = - s->reordered_input_picture[0]->f->pict_type != + if (m->reordered_input_picture[0]) { + m->reordered_input_picture[0]->reference = + m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_B ? 3 : 0; - if ((ret = ff_mpeg_ref_picture(s->avctx, &s->new_picture, s->reordered_input_picture[0]))) + if ((ret = ff_mpeg_ref_picture(s->avctx, &s->new_picture, + m->reordered_input_picture[0]))) return ret; - if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) { + if (m->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 @@ -1578,23 +1577,23 @@ no_output_pic: return i; pic = &s->picture[i]; - pic->reference = s->reordered_input_picture[0]->reference; + pic->reference = m->reordered_input_picture[0]->reference; if (alloc_picture(s, pic, 0) < 0) { return -1; } - ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f); + ret = av_frame_copy_props(pic->f, m->reordered_input_picture[0]->f); if (ret < 0) return ret; /* mark us unused / free shared pic */ - av_frame_unref(s->reordered_input_picture[0]->f); - s->reordered_input_picture[0]->shared = 0; + av_frame_unref(m->reordered_input_picture[0]->f); + m->reordered_input_picture[0]->shared = 0; s->current_picture_ptr = pic; } else { // input is not a shared pix -> reuse buffer for current_pix - s->current_picture_ptr = s->reordered_input_picture[0]; + s->current_picture_ptr = m->reordered_input_picture[0]; for (i = 0; i < 4; i++) { if (s->new_picture.f->data[i]) s->new_picture.f->data[i] += INPLACE_OFFSET; diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 6dc940d3aa..91d41f86e8 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -40,6 +40,8 @@ typedef struct MPVMainEncContext { MPVMainContext common; Picture *input_picture[MAX_PICTURE_COUNT]; ///< next pictures in display order + /** pointer to the next pictures in coded order */ + Picture *reordered_input_picture[MAX_PICTURE_COUNT]; int me_penalty_compensation; int me_pre; ///< prepass for motion estimation