From patchwork Wed Jan 26 21:34:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33872 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1882965iov; Wed, 26 Jan 2022 13:36:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjUzyUc7pqKOqzWqaHJlXxJeZL3wD0H6Blom7aK4LrR1UovNgLgYl1lOo+XjEHfNwov6pH X-Received: by 2002:a05:6402:348b:: with SMTP id v11mr812987edc.353.1643232991568; Wed, 26 Jan 2022 13:36:31 -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 qw41si242968ejc.443.2022.01.26.13.36.31; Wed, 26 Jan 2022 13:36:31 -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=jw0jaxL0; 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 A325468B19A; Wed, 26 Jan 2022 23:35:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072020.outbound.protection.outlook.com [40.92.72.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C871768B11F for ; Wed, 26 Jan 2022 23:35:17 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P7Cnf7mgqdHfOHzc5vtaW3nuCIBT3fhcqwFoEfA84+ZaM/eMwCmeNUM4aFySa/09OoVLHt053WqCzbvssLdYf59+iLY87gsv8qUa3P2HeE962qPZNTujZ5ksgoqjCvaw+zGcT6X4T63+G101i8ihn/Se8PzLe5j4URobFcYnRphsL1km4gHfxKQne9/ekRhaWJdR9ZWV1x0tHVyggpHl+6hrX3My8cPLthbrArsnGVQVYc2oEo7GlMz2I4Xo6HoKTWjKN4ihSNuYlW1Kqnz1yVBfLyMyr0B8V6l/QZybk98rydOiK8tvxDVk2VQX7s3coaEkoyCqWm0l2RTdKuuJfQ== 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=dap5mqj94pwTBS1ZHc3p08ANjq14/10IBaMjdzzz/Oo=; b=RyUnvipCS6NopJTdDl4JD5pQsTr1Do16/sQsZky44eMYLlYfe+SvXuBGAuNlbquj5nBrszja+Sj6o8PcbVs70bfXQvOWHjhZULXYLFX4MNYHT0jas8CTauS6hCnoxd68wZ3b/6EQOozjB9lObrkeismXm7sCDktYSo8stBhSWCZec6XGZc8eOE/B/ZkIX7stc2Xi5jg4snNXvcK2gEZKeyZUeyNBRbXO+Q6qv/JeTFm1DYmjeulqy5t5yi+bJxZQEOySZDm31sz2ITmBkY08FraxbAQAnGsiDdtqQHhhqsGIX3zyuw6+MfY8eNarOdjtIelPJi1ZM2Fy5To5S8pR8A== 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=dap5mqj94pwTBS1ZHc3p08ANjq14/10IBaMjdzzz/Oo=; b=jw0jaxL0y9zQDbA0eXMAcnaNpGKMULQOBft9YPapHo+YYEAoRQk4KwyTLZDSJVWOwCrmtVmxKQXKnHwQ0m1G/2WT8tlbSIIiyOLJ+NTGGL7PpKwt28UQflt2huuiAOiPI9NYXFwZrK+rimBlbLkiHBUN37s+Vdiv+JgXNlk5WBzaTk9I9v0lGifuYUBC647SofC1LKO6YMIZA/IPOmeqsGRBubswYm2vDO0esg1e/RUr+FR8mMRc35sRDyykLRGk6Ixt6jQzOe8kexkNcGIokU/HGRUJoKVhTp2GvQnN2aTn5vxpz9ezD4zGT3vZmgjVSNBkZKjfvt4RIElxqStWCA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM9PR03MB7852.eurprd03.prod.outlook.com (2603:10a6:20b:433::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17; Wed, 26 Jan 2022 21:35:16 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%4]) with mapi id 15.20.4930.017; Wed, 26 Jan 2022 21:35:16 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jan 2022 22:34:48 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [htoB9CLkTfbAh4ChUBu716/FJT+fbpIK] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220126213451.1887291-9-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a5099dc-f76f-49d4-5b5e-08d9e113be35 X-MS-TrafficTypeDiagnostic: AM9PR03MB7852:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jyp9D9sxj+O1k10MJjm3RdY0J6h0dw0g++7IF9RJAa5bEkKjQjfOvPHYpJB4imq0sRlhzK7AYyYu9wW5tcxscvUcPGvK4/ZB4u/mUyD7P1WrIwDtGbCP3F+eKW+gItm5alqpOsCU54jwCdQ5WbqAIqxhWs6HyA82IwKHO/HUnwz2WwDUij1k2fPnetieVxt3W6I7qEjOft0xBbp4Fh4WzHVVvyp4oQiDzlIYd8fflXoPp/HKyyE835911o01V5RlObmcsfuYOYVeGWEpxKDjteG7T8XRpcLuMAfC+gi3npmAChHlr8buj+msm+MQSFHKYS4Ugsg1WhnbuA5yKEg0ckW0JZApH+xgvLxMwXSoz4xaHXpMPrJ7SaFgHaWixFHHZE3K4FsidOWRUUOYJUsF/7V5hKQy7cmeI5Mg+VkkO5ZHg/3Opn56qg9QpLlYcZO9czHsNoVzp37VLCR9DByIzX+dDouvpsq37wRTnSQO55uQUCsFYJyWmA/QpLTabcnpqYJrtJgo32gP2/5U0qeMv3ySXduzZg1VSGSDqSweKtW0VpB3B5dgHnFPRTZ5WOI8 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QlDb59d75aDnwe4JiUtEhNHLLjzy0qFyvp0rghV74elPxTgfR46m46RX73rFayEQ0D2PBxukeGJAHTCRZG+85tiobYdySciM+pWvSQnFv2xThZA0yUaVizlMnoC+9dsp5MD9Dim5GrRFSREYuryJjae2nJt8FyWEi03wqF3xRRA9ugeTRo8tIJr8UEAS4uSCrPbMfQhONBhRHQ86svTlABeV841ZDPQl/L1tIbW0GSSQAfazdzcGIuDT3yadcGYf/HwgZ5j2feqXb7y/eREWAXMzUD5TvZxHhBvoWkhaKcvlkvneYzMe9OwhOZoUjqG6RdTMMqHt+ecJZjqi/1YAbAgmDnSgG2bBTm09I/4rCeGKp6Ju44GrmmzdLNUEf56J7WQS2mH62J68UJGb0a6Eyiem9sDDxUBxsny6Sd2xdw/7IOcQjEimLMJLs5ZOpxBvs0jqSnblKLyQmlfcw+Rj0TmVcxGayNDrkgphBrCw7rxF/PZVteRZGb7le9Ni0mpf7eUp7iD/tJ1aLvIUaqs1+NRAk9E6IrfD5U1+6ZKnnUnNSy51ok6Fy9psaQrRnkSW5oEkl8dbaFZeXzxpBtm1IXpl90myuCU6kUz/cUC9lYCg23jyXhU31ss8LZShuCvv4qKF+VexbVMcN+ECjysnP5SVlc4BxjmhTBBAy104bETKgOQi1JyNfbrGx7yr1DBWpncXZftYzhzV6w2PxG3fMbebkssxdLNUKG+G9MuUHgyVSOkwh6Ndr5ICeNfntVMNh5Rmon6n+pHMK2nW/Dd1y8SdnxicgOUFCT822ck2RdE1gx5u6wg0NB3Ce8I0soihLxH4XG2yJaRXP3lcXlJJVjmVHoymF4ixIbQZGluWOr1K3Ja3GJYHzVNb5QKrXa4wCYrtbUAKMgg2Sv1/WaXzLZbqwGXNPaILcp2Jg0CHADOJgUn68BCGB6J9TwYQALdB9OCQTo7+jfRkJ272Rf4bcA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a5099dc-f76f-49d4-5b5e-08d9e113be35 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 21:35:16.2213 (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: AM9PR03MB7852 Subject: [FFmpeg-devel] [PATCH 30/33] avcodec/mpegpicture: Add function to completely free MPEG-Picture 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: O4mBCDJelPvh Also use said function in mpegvideo.c and mpegvideo_enc.c; and make ff_free_picture_tables() static as it isn't needed anymore outside of mpegpicture.c. Signed-off-by: Andreas Rheinhardt --- The new_picture is actually only used by encoders; if it were not for svq1enc (which relies on ff_mpv_common_init() and ff_mpv_common_end() to allocate and free it), I'd have moved everything related to it to mpegvideo_enc.c. I probably do it later anyway. (And yes, I am aware of the fact that freeing this frame in ff_mpv_encode_end() is redundant.) libavcodec/mpegpicture.c | 47 +++++++++++++++++++++----------------- libavcodec/mpegpicture.h | 2 +- libavcodec/mpegvideo.c | 25 +++++--------------- libavcodec/mpegvideo_enc.c | 3 +-- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index f78a3c23e3..349ab81055 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -30,6 +30,24 @@ #include "mpegpicture.h" #include "mpegutils.h" +static void av_noinline free_picture_tables(Picture *pic) +{ + pic->alloc_mb_width = + pic->alloc_mb_height = 0; + + av_buffer_unref(&pic->mb_var_buf); + av_buffer_unref(&pic->mc_mb_var_buf); + av_buffer_unref(&pic->mb_mean_buf); + av_buffer_unref(&pic->mbskip_table_buf); + av_buffer_unref(&pic->qscale_table_buf); + av_buffer_unref(&pic->mb_type_buf); + + for (int i = 0; i < 2; i++) { + av_buffer_unref(&pic->motion_val_buf[i]); + av_buffer_unref(&pic->ref_index_buf[i]); + } +} + static int make_tables_writable(Picture *pic) { int ret, i; @@ -240,7 +258,7 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, if (pic->qscale_table_buf) if ( pic->alloc_mb_width != mb_width || pic->alloc_mb_height != mb_height) - ff_free_picture_tables(pic); + free_picture_tables(pic); if (shared) { av_assert0(pic->f->data[0]); @@ -285,7 +303,7 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, fail: av_log(avctx, AV_LOG_ERROR, "Error allocating a picture.\n"); ff_mpeg_unref_picture(avctx, pic); - ff_free_picture_tables(pic); + free_picture_tables(pic); return AVERROR(ENOMEM); } @@ -310,7 +328,7 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic) av_buffer_unref(&pic->hwaccel_priv_buf); if (pic->needs_realloc) - ff_free_picture_tables(pic); + free_picture_tables(pic); memset((uint8_t*)pic + off, 0, sizeof(*pic) - off); } @@ -331,7 +349,7 @@ int ff_update_picture_tables(Picture *dst, Picture *src) } if (ret < 0) { - ff_free_picture_tables(dst); + free_picture_tables(dst); return ret; } @@ -450,22 +468,9 @@ int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared) return ret; } -void ff_free_picture_tables(Picture *pic) +void av_cold ff_free_picture(AVCodecContext *avctx, Picture *pic) { - int i; - - pic->alloc_mb_width = - pic->alloc_mb_height = 0; - - av_buffer_unref(&pic->mb_var_buf); - av_buffer_unref(&pic->mc_mb_var_buf); - av_buffer_unref(&pic->mb_mean_buf); - av_buffer_unref(&pic->mbskip_table_buf); - av_buffer_unref(&pic->qscale_table_buf); - av_buffer_unref(&pic->mb_type_buf); - - for (i = 0; i < 2; i++) { - av_buffer_unref(&pic->motion_val_buf[i]); - av_buffer_unref(&pic->ref_index_buf[i]); - } + free_picture_tables(pic); + ff_mpeg_unref_picture(avctx, pic); + av_frame_free(&pic->f); } diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index a354c2a83c..cee16c07d3 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -108,7 +108,7 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src); void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *picture); -void ff_free_picture_tables(Picture *pic); +void ff_free_picture(AVCodecContext *avctx, Picture *pic); int ff_update_picture_tables(Picture *dst, Picture *src); int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared); diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 3b889e0791..7c63c738f3 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -874,8 +874,6 @@ void ff_mpv_free_context_frame(MpegEncContext *s) /* init common structure for both encoder and decoder */ void ff_mpv_common_end(MpegEncContext *s) { - int i; - if (!s) return; @@ -895,25 +893,14 @@ void ff_mpv_common_end(MpegEncContext *s) return; if (s->picture) { - for (i = 0; i < MAX_PICTURE_COUNT; i++) { - ff_free_picture_tables(&s->picture[i]); - ff_mpeg_unref_picture(s->avctx, &s->picture[i]); - av_frame_free(&s->picture[i].f); - } + for (int i = 0; i < MAX_PICTURE_COUNT; i++) + ff_free_picture(s->avctx, &s->picture[i]); } av_freep(&s->picture); - ff_free_picture_tables(&s->last_picture); - ff_mpeg_unref_picture(s->avctx, &s->last_picture); - av_frame_free(&s->last_picture.f); - ff_free_picture_tables(&s->current_picture); - ff_mpeg_unref_picture(s->avctx, &s->current_picture); - av_frame_free(&s->current_picture.f); - ff_free_picture_tables(&s->next_picture); - ff_mpeg_unref_picture(s->avctx, &s->next_picture); - av_frame_free(&s->next_picture.f); - ff_free_picture_tables(&s->new_picture); - ff_mpeg_unref_picture(s->avctx, &s->new_picture); - av_frame_free(&s->new_picture.f); + ff_free_picture(s->avctx, &s->last_picture); + ff_free_picture(s->avctx, &s->current_picture); + ff_free_picture(s->avctx, &s->next_picture); + ff_free_picture(s->avctx, &s->new_picture); s->context_initialized = 0; s->context_reinit = 0; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 9a5634c505..baa45d20ab 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -941,8 +941,7 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++) av_frame_free(&s->tmp_frames[i]); - ff_free_picture_tables(&s->new_picture); - ff_mpeg_unref_picture(avctx, &s->new_picture); + ff_free_picture(avctx, &s->new_picture); av_freep(&avctx->stats_out); av_freep(&s->ac_stats);