From patchwork Fri Dec 3 18:27:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31921 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1030593iog; Fri, 3 Dec 2021 10:27:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJT856Fg1DdB+0doDo9VPFsfFzRidOW7ZLD25QstFveKnL1zPdJZ8dnXeomv5jPW5jQ+9U X-Received: by 2002:a17:906:5d0b:: with SMTP id g11mr25090240ejt.110.1638556071955; Fri, 03 Dec 2021 10:27:51 -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 aq1si4563224ejc.438.2021.12.03.10.27.50; Fri, 03 Dec 2021 10:27:51 -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=TjNwKeRO; 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 A004168AE46; Fri, 3 Dec 2021 20:27:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2078.outbound.protection.outlook.com [40.92.89.78]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3529268A447 for ; Fri, 3 Dec 2021 20:27:40 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kc13fXYI7cAZtdIZ3THRoit5An8UdmOOxW7rkI3GJdP+S41WriQAqT+rj+QuTNqv2jk6OI18yJLlowRPUNR7fNwT0L+2tus1GHjPBC/6Rq2SeRorQKQWRX7ZKyjd3lYpl+o2djN1EpuApejqcLe2LTjboeo4tq8d/Jcx8A8Cv2dXYfJdveTsJlO42ypsYDcD7XGMPsH+KU4jEdtR0YGvopsjSdVy3lvNCCN0Tk/tuL/1ZfI+X88PXW6O9M6YC7tLcI3UVbnPfYwCzQ7BxArCQd7wk3gZKSz8UyF3NZpccGNJKDmnYl/dMdouP2RIDayTYLGfEZwR+zorPNP5gtiGhg== 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=eQRw3YB4bqFtOQ/JHr7CQDwSguxBLyFR50IpxzJIlno=; b=hJ32bIq3EF8pDTFVHINCVlhroWVdP2tWT3H1evyeOd/g+PMB+SwX6WlwHTT3iRN3HbMnmbMt2e7KVYHkdd/hqxKuFeoWs7rfqswkGZ2NUyNQmdBxNazv09OlxSmHZaQwvxFH8UGm8jtTc1ZzOVFXaht0ef9Yb1lwFMLLiYyfJi00pOkAAx88CDIvBRK9ii7XuydL8bOjHZsNHcx6t3/P+6cvZ/XXmuBTUWIaPv3+1yKZ8vfrgCCGOA7chehEcbo3tBZeQmJknaXB9ueLkNVTkF+k1IQTnSnfTNqutRgfiyjd7EyEX+sVpdzbBs8+KubotRZvpHWd4wlT9IPIrGzHBQ== 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=eQRw3YB4bqFtOQ/JHr7CQDwSguxBLyFR50IpxzJIlno=; b=TjNwKeRODzmvOu7XsOZpYr3DcT7zddaSQ9x3mCXCFy06mZQ+RVrVHNWXAW4oiOxndCkEGZLn8MoEOGCigbsjDK8roJVM7kIMgnnG+lPQYDQ97unHSnZvTOOStCObHTGVAAf3rcmEEu6FghLLem/RxGpg6ucUGOxoWDTC4pCUYzloUxTZ2+ze/EgKo/oZuzskrKZr6MOrAso1Ji3c78v9BrRPDuYcIjopdGBe/RoXq7OeRZUrXWaNYPgzJPSDBOHQMyX5ftWPPAU0lPuGLn8AVjM9YMy6r4hyzqdDgSqKhfzoCT8KpxN2WXRmfgbp7uZ81VsDmmH+xtqsOzuyefy3ow== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM5PR03MB3090.eurprd03.prod.outlook.com (2603:10a6:206:17::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 18:27:38 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.016; Fri, 3 Dec 2021 18:27:38 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 19:27:27 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 X-TMN: [VgfGKVXR92tEwWSyzQ7+ha3d0rWIWeS1] X-ClientProxiedBy: AM6PR08CA0006.eurprd08.prod.outlook.com (2603:10a6:20b:b2::18) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211203182730.1688737-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM6PR08CA0006.eurprd08.prod.outlook.com (2603:10a6:20b:b2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.16 via Frontend Transport; Fri, 3 Dec 2021 18:27:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 637a7209-258d-4301-4c7e-08d9b68a955d X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQtx8w+3h2yNNoYV95SbXd9Ns2X746EKTF1Z4Kk+v+B2Lvmknqj3qsgfaH6CnnRtROJJCEWFGXpEIPysHCjEdq3gXj6IVql1h7svlwowOOK1GHnk6YQoL5/ZwhDV2li3U3smOhX1HwkjPDmJps3Pp6/EFgYSQq+aCJDr4qHl/ZY8GML4hA1Ok5oD/fOepqmLAAtzBGFjqIymtMjur7fuFCOduMqB0KbW0Ppu8p8AO7MbgtT3Ty3uUZYti2mM7b1dpIHjF4nWmZKz7ZG8sinVVTQl9WzHPrJKhfY3rFAtI4WpCEu8LcDR+vuzaJ8YzbV1e10hPwecD2IDASOYfpdCYRmf8puhpRDTVmOQdP0057bptcVaosV9wu5OXc2B/jAAXd0bPq8Ph1B3fQ0cC6Az4+OvVOnOjVazV06Vr7O3e9on9EwDsJRKUbCbXQ9yFRwAaSTW1A0VrUP38qD5Gogedb1j1WoXK6p2eyGP4/C5VNVEcZlqSNpJRx2IOsEgfWq6zq2U7b5oS/gQAX2MnqSSNdrel26wHJ4Arfairv8iTQNndXKOPW4MK/pSHvYfYKj2qlOV94K70t6UyBIGyVUV0ZRelo1Ddf1frQPViGmMLIsOmIIGtROQqulWkNj3uF4aHMEBR/c4WFT38rev/aGc2WDQBsAgu4tHLQJcYHO02Jr1Eix69oJIesWMBQ9Qz5F1r1h03Kk1rEARSfHWKwa/EWaLNl98VyzzOGx9szeUHbk4YYyrTLXtWd3n1lVq23ok/I= X-MS-TrafficTypeDiagnostic: AM5PR03MB3090: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1iowmLxlTNaDivKKI3mPP/dJuRGkJvsPCeO7f90ndfdwxM0GJAaoDhpal4wI/uirFM0rWDWckk69jyeGlCXrlq05cNwl+gWQp4WHFqfkBNa0pnJ4keF8Mb5GYk5pdY1of/zE1EfXYi8d/iQfHjCrqm10bVUWao0vBqWgJ4CtXjiwhdhaSPDxtK5zr8/HJQPuLpWd20inIymFOBSc3MqKON0+5nhuOBX4p92zOJBF+7j6VvntBAv3fWe6vCTfxt93AimaaCVUdH8t620wL2pXyfxguv6RgRHYE6kxkgjIznOzVCPlBUYgzwrPyKM4t4U6+0RUQVtTnkRH2r4ahb4jbfqaPi143Za9HRMq++1Cpv1/zTR2tQ+5YhWPq/1AExJiIcHfnGs3vCtatccBAzIl2kFrM4E6KivzhrVshlr6hvw65nro1IYkJ3c6XmsoiOXMBARKmviUXRTL8YSDqZuDmfwPyIuvaNRj4vhEshpACe+4e/tmViMO05zdAOcVNIVYOzcsWGXf3iwogPstqLXHEdsIQd4ZxT6BJHBWqhXGgXSqWCMVPCur94iYPdzl0NUR0S9ujGz/4LuQa/edEQbw2A== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jrh8IL35PsQCyzff6a0k07k9eO6d5rUFj+myIJHFDf0H355ioR3USd/7DlzY7Ie22pJdAvF6lM/ve+U2EG/LJmvz391L7i7hg/gUIgq/SXoWB1T3AEs/gQC9G67gdo7H20lcbaLS4n/nKOz8hkyTeak8YDCpnbPSvzncNrkRr/L6/ra/ax8oWFyc/XmutRUUX5crjSzPuie0/s+1sk9iH3kxGF6b1ElC54TRDH11JpMPGrcsR9R8HcA1fvigYFEzxKb1UV89T9/s/pBd0CF6EifkQnsQlD8ACtfowACRrJjckfYpoh4ZbxFvBaqPRyoZjsTH0Py+GQpNN9mJfrK/BJkReRKRXYreDCNdl/JAI6b6aBNAd6xx4tptUkWJnLz+dQaTYy/S7Zb5zQm4rA0p3GIjcovxAsvXHD1m5kDSLCqx13FqmEBLjlQ6UfPHswCbXfJSAq4HveYHtaSyEc4m+zPcsPaBPZ5u7+6+dDHRfY4tfxl+QQ6zyiY/A9UPND7+0Mv9SSSfWS5M6BDMV6pHbw5pIYJ4IXBBbEnMXSnQugjjQHBCr80TyK5KsCl3e9QMQ5RfktdvULPXLNmUFDZhaE+HKSjkRDrvgGzRScVNtrtFAK8/RqoKvyQqBjnsRJ+MZq039Z3J7f+HJIzfx5NICC+ZbxhW8yh55f4tWg5zLBr+Jz3nYOLgOtCa6UQtFty8Pqksze33t2bmLz5wdST4/AevEBmF7+iq65Y3DWm+IPR5btKg4h85JPW7exK9jb0kWQViaQYUwahvjzcTavmaLs7VTVDGpDp/0wiT6zhgp9UUkGTVnJ1Ju4oLXAGwEU/19/So59G2r++npfoiguF2kSCiKRVzsA2VsATTXvQwWykYQKyf/g2Q5YzWjj0HsASTxyUU9pfJkmSghPJ9l1gTVSTE2/lOP1GZD1Vp7Rm9lprTmi3W+ElpupC8/GfsdNqNlG1F9VBg1AdkCpwSuh6hoA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 637a7209-258d-4301-4c7e-08d9b68a955d X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 18:27:38.1671 (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: AM5PR03MB3090 Subject: [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: Atomically add elements to list of pointers, fix crash 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: sMgn7mI5Cft2 Currently, adding a (separately allocated) element to a list of pointers works by first reallocating the array of pointers and (on success) incrementing its size and only then allocating the new element. If the latter allocation fails, the size is inconsistent, i.e. array[nb_array_elems - 1] is NULL. Our cleanup code crashes in such scenarios. Fix this by adding an auxiliary function that atomically allocates and adds a new element to a list of pointers. Signed-off-by: Andreas Rheinhardt --- fftools/cmdutils.c | 16 ++++++++++++++++ fftools/cmdutils.h | 17 +++++++++++++++++ fftools/ffmpeg_filter.c | 17 ++++------------- fftools/ffmpeg_opt.c | 22 ++++++---------------- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 45322f8c71..1464b122df 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -2214,6 +2214,22 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) return array; } +void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) +{ + void *new_elem, **array = (void**)ptr; + + if (*nb_elems == INT_MAX) { + av_log(NULL, AV_LOG_ERROR, "Array too big.\n"); + exit_program(1); + } + new_elem = av_mallocz(elem_size); + if (!new_elem) + exit_program(1); + GROW_ARRAY(array, *nb_elems); + array[*nb_elems - 1] = new_elem; + return array; +} + double get_rotation(int32_t *displaymatrix) { double theta = 0; diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 64dd7266bc..ae78e60f4c 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -628,11 +628,28 @@ FILE *get_preset_file(char *filename, size_t filename_size, */ void *grow_array(void *array, int elem_size, int *size, int new_size); +/** + * Atomically add a new element to an array of pointers, i.e. allocate + * a new entry, reallocate the array of pointers and make the new last + * member of this array point to the newly allocated buffer. + * Calls exit() on failure. + * + * @param array array of pointers to reallocate + * @param elem_size size of the new element to allocate + * @param nb_elems pointer to the number of elements of the array array; + * *nb_elems will be incremented by one by this function. + * @return reallocated array + */ +void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); + #define media_type_string av_get_media_type_string #define GROW_ARRAY(array, nb_elems)\ array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1) +#define ALLOC_ARRAY_ELEM(array, nb_elems)\ + array = allocate_array_elem(array, sizeof(*array[0]), &nb_elems) + #define GET_PIX_FMT_NAME(pix_fmt)\ const char *name = av_get_pix_fmt_name(pix_fmt); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index dab0f28819..75194fe66e 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -164,18 +164,14 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) exit_program(1); fg->index = nb_filtergraphs; - GROW_ARRAY(fg->outputs, fg->nb_outputs); - if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0])))) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); fg->outputs[0]->ost = ost; fg->outputs[0]->graph = fg; fg->outputs[0]->format = -1; ost->filter = fg->outputs[0]; - GROW_ARRAY(fg->inputs, fg->nb_inputs); - if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0])))) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); fg->inputs[0]->ist = ist; fg->inputs[0]->graph = fg; fg->inputs[0]->format = -1; @@ -280,9 +276,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ist->decoding_needed |= DECODING_FOR_FILTER; ist->st->discard = AVDISCARD_NONE; - GROW_ARRAY(fg->inputs, fg->nb_inputs); - if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0])))) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); fg->inputs[fg->nb_inputs - 1]->ist = ist; fg->inputs[fg->nb_inputs - 1]->graph = fg; fg->inputs[fg->nb_inputs - 1]->format = -1; @@ -318,10 +312,7 @@ int init_complex_filtergraph(FilterGraph *fg) init_input_filter(fg, cur); for (cur = outputs; cur;) { - GROW_ARRAY(fg->outputs, fg->nb_outputs); - fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0])); - if (!fg->outputs[fg->nb_outputs - 1]) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); fg->outputs[fg->nb_outputs - 1]->graph = fg; fg->outputs[fg->nb_outputs - 1]->out_tmp = cur; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index a27263b879..ffba7010e3 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1265,11 +1265,8 @@ static int open_input_file(OptionsContext *o, const char *filename) /* dump the file content */ av_dump_format(ic, nb_input_files, filename, 0); - GROW_ARRAY(input_files, nb_input_files); - f = av_mallocz(sizeof(*f)); - if (!f) - exit_program(1); - input_files[nb_input_files - 1] = f; + ALLOC_ARRAY_ELEM(input_files, nb_input_files); + f = input_files[nb_input_files - 1]; f->ctx = ic; f->ist_index = nb_input_streams - ic->nb_streams; @@ -2261,11 +2258,8 @@ static int open_output_file(OptionsContext *o, const char *filename) } } - GROW_ARRAY(output_files, nb_output_files); - of = av_mallocz(sizeof(*of)); - if (!of) - exit_program(1); - output_files[nb_output_files - 1] = of; + ALLOC_ARRAY_ELEM(output_files, nb_output_files); + of = output_files[nb_output_files - 1]; of->ost_index = nb_output_streams; of->recording_time = o->recording_time; @@ -3262,9 +3256,7 @@ static int opt_audio_qscale(void *optctx, const char *opt, const char *arg) static int opt_filter_complex(void *optctx, const char *opt, const char *arg) { - GROW_ARRAY(filtergraphs, nb_filtergraphs); - if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0])))) - return AVERROR(ENOMEM); + ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs); filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1; filtergraphs[nb_filtergraphs - 1]->graph_desc = av_strdup(arg); if (!filtergraphs[nb_filtergraphs - 1]->graph_desc) @@ -3281,9 +3273,7 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char * if (!graph_desc) return AVERROR(EINVAL); - GROW_ARRAY(filtergraphs, nb_filtergraphs); - if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0])))) - return AVERROR(ENOMEM); + ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs); filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1; filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc; From patchwork Fri Dec 3 18:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31919 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1031744iog; Fri, 3 Dec 2021 10:28:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwQ9yN60QDEBZetCQP+h1HclZThPsVUUu4xmkyG5zYFZ2eot5sG9/GSCuC/wUb9s0GVfrY X-Received: by 2002:a50:d883:: with SMTP id p3mr28255378edj.94.1638556126431; Fri, 03 Dec 2021 10:28:46 -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 nb37si6022906ejc.170.2021.12.03.10.28.46; Fri, 03 Dec 2021 10:28:46 -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=gZxbQ6k+; 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 E5F1468AE64; Fri, 3 Dec 2021 20:28:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.92.90.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E6D568ADF7 for ; Fri, 3 Dec 2021 20:28:37 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G4KRYXnlHOldjZuExC/V19JrdsIFtS8kufXaLaoHDDx8uFY3dMpyPi1rrliYEi0iCkfYvtGfs1W/TGR2kLlJjv9SChbdijUwM3i/Nb+4Imyn2WuzkKKP6nkCdSlpTeA1UB9SSYvRJzLZ6nE3KLaZV7BoOfANg22csl/PWeu8SKRMQWMhzDGy6PwnQAb8IajfjXesadM7qmemlAsuESV29jguYbYm+nDfX/J3F+XpQGrujwgcrucqP/SO9VfVx2jC0UwQ8Knl9y3OoMgiwK9ts7Y9huXM82A0ks9AXOxhqqlNC9DnPNavY0qNv5A7NSOVrfVcIG//Lr6iwqlYyieFWA== 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=xiy7HnUUmh6p4wzlpO+kWnXuMtZC5TWU80lFV3mJcZQ=; b=ZK7UWIwwN4h0dunfkPnprL/iC/d2KEyozYOg6SmcWsi7CU5sFVmbY49xTRqbF1Vdt/cxFBusDS65XGEAY4YyxAoro0eQXb22zruUTrTisOHKIhUhgglkAqErMch4v6sM+FRzVc81TrGXhMxcK4fMr+Hmc810VMFs+FHdqOqNC2wse+87kaLjd0vvNIbXWLJXMMD4EQ5CFSZ9Eos5IGjtb5NWpUJKCIvAyHuVDybvkNRCBEyeu8nmkwsPc+SEGmNky+DeB73UV/WiroK248gl6c79lTvbHjOsaOlEc2xdDcVd+2k+AA4FD/u/svEcBpKOJK7eIJAAU7QkUABikaCfVw== 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=xiy7HnUUmh6p4wzlpO+kWnXuMtZC5TWU80lFV3mJcZQ=; b=gZxbQ6k+TRYOBG1+3qlXtvVIqwgovFlDpXwoEmRe+dDtBc0ODexNE13m2UEFbFuWRnGxCxcBG1it/yziUz4cZL2lcdomazTPt8vJTqZ7f4BQFnKvpn9Al8YDf7r7zHWbSsYf2HZkX7ggnpzKgxguHj1FYB1/2QovYw5TPpBWffD3drHmnipZ3Vw66F/iWntyfMPAllzDfbtf8Uyk7X8fLxnrPE6kTCmJw6edQtEw8fZXIJp0GtTOFXkHUFEDS4+ZUs6ZzNHDpANaX4j6yBqKjrWwMsBXm2N1OC+pZXcoTsgHvIKjZ2TaiI2aTbR+I1xuOrBfD33ZnKVG1ofeSFzwuQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3605.eurprd03.prod.outlook.com (2603:10a6:209:2f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 18:28:35 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.016; Fri, 3 Dec 2021 18:28:35 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 19:28:26 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [Ljtyg75LOstv2LMxW5Xmjy7r2V327qoA] X-ClientProxiedBy: AM6PR0502CA0055.eurprd05.prod.outlook.com (2603:10a6:20b:56::32) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211203182828.1688841-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM6PR0502CA0055.eurprd05.prod.outlook.com (2603:10a6:20b:56::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.14 via Frontend Transport; Fri, 3 Dec 2021 18:28:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f8aa224-f3b3-4e89-2735-08d9b68ab7f0 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQtx8w+3h2yNNoYV95SbXd9n8o+rrc61BJvrr666Ep80cISORDR8sE6rb50T8lua0FwsRAjWl6/hcsxY8o+5VsmwgQgdlIuGEmyMw/uSRQFmv6mP3JaIYRIZK7L+ADelAk5nV97zLhGJ6VVrAmQdcdFhUhKk4op4K+BOXrW1G7B+ERWDeWsjCSFcz9EDgVLNWPbdod05G4/T7uq4hny/TUTiar+oCoTud039aglLAO6G70wKDRN4kqvaHoqeY8sCuHMN7KauCm43md59HXMMn8zhIDciZYa+ZaY4p3SM7BD57CLh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VS1PFdlbOu52IpEQ5Qpw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f8aa224-f3b3-4e89-2735-08d9b68ab7f0 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 18:28:35.9065 (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: AM6PR03MB3605 Subject: [FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg_(filter|opt): Use dedicated pointer for array elem access 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: fxZ0EarlAFui Signed-off-by: Andreas Rheinhardt --- fftools/ffmpeg_filter.c | 56 +++++++++++++++++++++++------------------ fftools/ffmpeg_opt.c | 14 +++++++---- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 75194fe66e..04253a9b21 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -159,29 +159,33 @@ DEF_CHOOSE_FORMAT(channel_layouts, uint64_t, channel_layout, channel_layouts, 0, int init_simple_filtergraph(InputStream *ist, OutputStream *ost) { FilterGraph *fg = av_mallocz(sizeof(*fg)); + OutputFilter *ofilter; + InputFilter *ifilter; if (!fg) exit_program(1); fg->index = nb_filtergraphs; ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); - fg->outputs[0]->ost = ost; - fg->outputs[0]->graph = fg; - fg->outputs[0]->format = -1; + ofilter = fg->outputs[0]; + ofilter->ost = ost; + ofilter->graph = fg; + ofilter->format = -1; - ost->filter = fg->outputs[0]; + ost->filter = ofilter; ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); - fg->inputs[0]->ist = ist; - fg->inputs[0]->graph = fg; - fg->inputs[0]->format = -1; + ifilter = fg->inputs[0]; + ifilter->ist = ist; + ifilter->graph = fg; + ifilter->format = -1; - fg->inputs[0]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*)); - if (!fg->inputs[0]->frame_queue) + ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*)); + if (!ifilter->frame_queue) exit_program(1); GROW_ARRAY(ist->filters, ist->nb_filters); - ist->filters[ist->nb_filters - 1] = fg->inputs[0]; + ist->filters[ist->nb_filters - 1] = ifilter; GROW_ARRAY(filtergraphs, nb_filtergraphs); filtergraphs[nb_filtergraphs - 1] = fg; @@ -210,6 +214,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) { InputStream *ist = NULL; enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx); + InputFilter *ifilter; int i; // TODO: support other filter types @@ -277,18 +282,19 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ist->st->discard = AVDISCARD_NONE; ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); - fg->inputs[fg->nb_inputs - 1]->ist = ist; - fg->inputs[fg->nb_inputs - 1]->graph = fg; - fg->inputs[fg->nb_inputs - 1]->format = -1; - fg->inputs[fg->nb_inputs - 1]->type = ist->st->codecpar->codec_type; - fg->inputs[fg->nb_inputs - 1]->name = describe_filter_link(fg, in, 1); - - fg->inputs[fg->nb_inputs - 1]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*)); - if (!fg->inputs[fg->nb_inputs - 1]->frame_queue) + ifilter = fg->inputs[fg->nb_inputs - 1]; + ifilter->ist = ist; + ifilter->graph = fg; + ifilter->format = -1; + ifilter->type = ist->st->codecpar->codec_type; + ifilter->name = describe_filter_link(fg, in, 1); + + ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*)); + if (!ifilter->frame_queue) exit_program(1); GROW_ARRAY(ist->filters, ist->nb_filters); - ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1]; + ist->filters[ist->nb_filters - 1] = ifilter; } int init_complex_filtergraph(FilterGraph *fg) @@ -312,15 +318,17 @@ int init_complex_filtergraph(FilterGraph *fg) init_input_filter(fg, cur); for (cur = outputs; cur;) { + OutputFilter *ofilter; ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); + ofilter = fg->outputs[fg->nb_outputs - 1]; - fg->outputs[fg->nb_outputs - 1]->graph = fg; - fg->outputs[fg->nb_outputs - 1]->out_tmp = cur; - fg->outputs[fg->nb_outputs - 1]->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, + ofilter->graph = fg; + ofilter->out_tmp = cur; + ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, cur->pad_idx); - fg->outputs[fg->nb_outputs - 1]->name = describe_filter_link(fg, cur, 0); + ofilter->name = describe_filter_link(fg, cur, 0); cur = cur->next; - fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL; + ofilter->out_tmp->next = NULL; } fail: diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ffba7010e3..6f971bc922 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -3256,10 +3256,12 @@ static int opt_audio_qscale(void *optctx, const char *opt, const char *arg) static int opt_filter_complex(void *optctx, const char *opt, const char *arg) { + FilterGraph *fg; ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs); - filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1; - filtergraphs[nb_filtergraphs - 1]->graph_desc = av_strdup(arg); - if (!filtergraphs[nb_filtergraphs - 1]->graph_desc) + fg = filtergraphs[nb_filtergraphs - 1]; + fg->index = nb_filtergraphs - 1; + fg->graph_desc = av_strdup(arg); + if (!fg->graph_desc) return AVERROR(ENOMEM); input_stream_potentially_available = 1; @@ -3269,13 +3271,15 @@ static int opt_filter_complex(void *optctx, const char *opt, const char *arg) static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg) { + FilterGraph *fg; uint8_t *graph_desc = read_file(arg); if (!graph_desc) return AVERROR(EINVAL); ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs); - filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1; - filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc; + fg = filtergraphs[nb_filtergraphs - 1]; + fg->index = nb_filtergraphs - 1; + fg->graph_desc = graph_desc; input_stream_potentially_available = 1; From patchwork Fri Dec 3 18:28:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31922 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1032272iog; Fri, 3 Dec 2021 10:29:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUho96XyCpVpofow073gqQXtlZH5X4R5RTZqf0SNiRePYmpFTsf6iz7PJBsrpFVJeD4kBO X-Received: by 2002:a17:907:75f0:: with SMTP id jz16mr26009449ejc.77.1638556153681; Fri, 03 Dec 2021 10:29:13 -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 q19si5191879edr.184.2021.12.03.10.29.13; Fri, 03 Dec 2021 10:29:13 -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=dfAp3L3D; 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 F077B68AE7A; Fri, 3 Dec 2021 20:29:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.92.90.78]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F01A668ADF7 for ; Fri, 3 Dec 2021 20:29:03 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=De+uMnSoVQTqSMhNY3fjNW0hDYo6N+ZsF8vszSk9KizKHfBUMix5d/QLB7DK52RMYUiDmafE1PUpxdDXDxHYIehzs3N6LuW879N/We/UJN3YJLPD4Pd1besvkFfcY0yc5X1gP2YnmKcQo7J0CwL/U6YHRMPNFHGz8jAL50Lb2bBRJbKume4OtdU6G6eVWaETs9EPHIlGdIChaES6lXCtK+/3iDculgREugWDfVYgTsCaIXaF/WJvO9RXcI8evWfgq6TY9F0sdiouHwfzkMLVv5p3eRDQaY2pdRh4WJPTCsXvJut/w3pH4raTm9KZhBcHq+MM4aZFvXV0G9Cx2+X+Ew== 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=AQYbJMcbltOLIuMTtk8AXvraaeFYz4mhko+PAyYEvFk=; b=NY9FxLFZmQopvlTouyK/VPucfCCLiBXBOwR1kpNBtDy2TMW6RipZfJA11Rxgw+5Tad+vmlo5Zxp8z1zUS1kxRiJ+3O5bD3G0w9en4c4u8GOcCinav3Jtdj4mVySc0gBJ4O0a90rxGJnxriDQM5oKfaWiHtUAOmX8MvLXIApslnKbDEdq4DP8HSMPYv+2okw2SOUMOIS2PEJEyebY3Yre/R3rm1yT2LjN8xBGk5KBc99grjcGVwK8CqjMqi2j4kwxqfnQoh1VQPiq90IPN7SkNHrGqt9UBQvp5FULLg2GLv6CXKjYMx+nLsW+rgAl3oQKnsJbyTwsGkBGaFipXpWSsg== 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=AQYbJMcbltOLIuMTtk8AXvraaeFYz4mhko+PAyYEvFk=; b=dfAp3L3D+27ls2O8exYjjOrzyBTZSui3JmcOWGnVn4hJb8OVITixwwuv6ab42+EU+JER2ASyqoMgeVyxuyfuQ0GAH6+zRTLxsYdFanapFD4EXeioNtoOtZST1HowwYSC3VjEcizEynwnlgFoHDchACHymFY4Uuw0zxWqLm8dQr0TD0EVoWIZVggj5+sDp5dpm74uMKG8U36K0XOZXK9UqunRbOf/76Zvimdmo6UK5xBFa3AOLXCj2Rzss8wLYDRtlEXuSrtPhVDxWh7Yge2kRWieV4ZUK8BDkLFCjCI2GKgltrVUrNftyTOPnTxUf4YtmdjCEoFdcpskxubHQvVuvw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3605.eurprd03.prod.outlook.com (2603:10a6:209:2f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 18:29:03 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.016; Fri, 3 Dec 2021 18:29:03 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 19:28:54 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [fqtuPbSgc565FLk8LJWqBTj9rLtGol39] X-ClientProxiedBy: AS9PR0301CA0058.eurprd03.prod.outlook.com (2603:10a6:20b:469::17) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211203182855.1688900-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AS9PR0301CA0058.eurprd03.prod.outlook.com (2603:10a6:20b:469::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23 via Frontend Transport; Fri, 3 Dec 2021 18:29:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d33af617-2801-4b67-2a61-08d9b68ac823 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQtx8w+3h2yNNoYV95SbXd9n8o+rrc61BJvrr666Ep80Wkd/L67UTNAsPvvE/Fc9mJpTUaK4FEol9fDgvOQKrtiXSanVdG6hodZVXOek7a65SYLpkGvLq9JMqWTotodU4QwNqiWmxF3ECQWPxZ5zPqwGHgf9diAR6D3Yhffp09z/2mOHERYP+XJoBMtnOw/vWP9HstJgljvrfnhmvTlJ+bnRYa+2nPXp8EplSnLaE50wABsIxOpdHG9BTjqumD3Rpka0TRoDIamkfcGgsMvqSYZhDhgGG3Nr2KGiXdQ5qrQHDmMh3IQ9ADvr6jfKnHbAsP5nVUuRig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== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d33af617-2801-4b67-2a61-08d9b68ac823 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 18:29:03.0700 (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: AM6PR03MB3605 Subject: [FFmpeg-devel] [PATCH 3/4] fftools/cmdutils: Make allocate_array_elem() return ptr to new element 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: cyIrlCSjxZUG Signed-off-by: Andreas Rheinhardt --- fftools/cmdutils.c | 6 ++++-- fftools/cmdutils.h | 4 ++-- fftools/ffmpeg_filter.c | 13 ++++--------- fftools/ffmpeg_opt.c | 9 +++------ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 1464b122df..0b57552e5c 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -2216,8 +2216,9 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) { - void *new_elem, **array = (void**)ptr; + void *new_elem, **array; + memcpy(&array, ptr, sizeof(array)); if (*nb_elems == INT_MAX) { av_log(NULL, AV_LOG_ERROR, "Array too big.\n"); exit_program(1); @@ -2226,8 +2227,9 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) if (!new_elem) exit_program(1); GROW_ARRAY(array, *nb_elems); + memcpy(ptr, &array, sizeof(array)); array[*nb_elems - 1] = new_elem; - return array; + return new_elem; } double get_rotation(int32_t *displaymatrix) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index ae78e60f4c..82cda208be 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -638,7 +638,7 @@ void *grow_array(void *array, int elem_size, int *size, int new_size); * @param elem_size size of the new element to allocate * @param nb_elems pointer to the number of elements of the array array; * *nb_elems will be incremented by one by this function. - * @return reallocated array + * @return pointer to the newly allocated entry */ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); @@ -648,7 +648,7 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1) #define ALLOC_ARRAY_ELEM(array, nb_elems)\ - array = allocate_array_elem(array, sizeof(*array[0]), &nb_elems) + allocate_array_elem(&array, sizeof(*array[0]), &nb_elems) #define GET_PIX_FMT_NAME(pix_fmt)\ const char *name = av_get_pix_fmt_name(pix_fmt); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 04253a9b21..bd48098bff 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -166,16 +166,14 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) exit_program(1); fg->index = nb_filtergraphs; - ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); - ofilter = fg->outputs[0]; + ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); ofilter->ost = ost; ofilter->graph = fg; ofilter->format = -1; ost->filter = ofilter; - ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); - ifilter = fg->inputs[0]; + ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); ifilter->ist = ist; ifilter->graph = fg; ifilter->format = -1; @@ -281,8 +279,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ist->decoding_needed |= DECODING_FOR_FILTER; ist->st->discard = AVDISCARD_NONE; - ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); - ifilter = fg->inputs[fg->nb_inputs - 1]; + ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); ifilter->ist = ist; ifilter->graph = fg; ifilter->format = -1; @@ -318,9 +315,7 @@ int init_complex_filtergraph(FilterGraph *fg) init_input_filter(fg, cur); for (cur = outputs; cur;) { - OutputFilter *ofilter; - ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); - ofilter = fg->outputs[fg->nb_outputs - 1]; + OutputFilter *const ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); ofilter->graph = fg; ofilter->out_tmp = cur; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 6f971bc922..17e4cdd2d6 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1265,8 +1265,7 @@ static int open_input_file(OptionsContext *o, const char *filename) /* dump the file content */ av_dump_format(ic, nb_input_files, filename, 0); - ALLOC_ARRAY_ELEM(input_files, nb_input_files); - f = input_files[nb_input_files - 1]; + f = ALLOC_ARRAY_ELEM(input_files, nb_input_files); f->ctx = ic; f->ist_index = nb_input_streams - ic->nb_streams; @@ -2258,8 +2257,7 @@ static int open_output_file(OptionsContext *o, const char *filename) } } - ALLOC_ARRAY_ELEM(output_files, nb_output_files); - of = output_files[nb_output_files - 1]; + of = ALLOC_ARRAY_ELEM(output_files, nb_output_files); of->ost_index = nb_output_streams; of->recording_time = o->recording_time; @@ -3276,8 +3274,7 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char * if (!graph_desc) return AVERROR(EINVAL); - ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs); - fg = filtergraphs[nb_filtergraphs - 1]; + fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs); fg->index = nb_filtergraphs - 1; fg->graph_desc = graph_desc; From patchwork Fri Dec 3 18:28:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31920 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1032441iog; Fri, 3 Dec 2021 10:29:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyTQnAfz1O6wRzoJgDnF15Nytqo+9yWp9aplmMs7qtsGfXAj9qCwwnwDG9J4XCACCIOmDG X-Received: by 2002:a05:6402:845:: with SMTP id b5mr28749480edz.392.1638556163711; Fri, 03 Dec 2021 10:29:23 -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 o5si4942486eds.560.2021.12.03.10.29.23; Fri, 03 Dec 2021 10:29:23 -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=NN7ezWIA; 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 61C1968AE8E; Fri, 3 Dec 2021 20:29:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.92.90.78]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C3E968ADF7 for ; Fri, 3 Dec 2021 20:29:09 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hFQAFS6AWEXriWG5jDIuW37h+oCzkHh+wFln6nkQe0J1YRKK4irDcDfrI9LkoiTvdMAa0Ik5tkASLpRbua846UtKW7IHBc3kUbekNctkvaMH4EZV8jjyAWS6LUm5MoaO296n+ZSE91vt8zNWqBDxf5PqgCprLqL1HhQgzc+FLg8kDnkGHFG44DdZrYVHHU974Xct4jXq17S3pbD41Ot0YoDiYofm5kn4NAjmgY4tX4Ibxl+ci+UiC7g3U153sy6byoKyKa2kLEzG+s9hCj7p78mojWtYNSCObuthnaCxpCj44/yX0F7gbvhryZegoBPltQYPc3F+VyHihyqC4Bc52Q== 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=P4TC63Ub1QJ8HKgbTU0B/id1sdl3rdInurWXWIJvZ6g=; b=Xy/WiJKG8kLJHrmifbqId9GpjQXzjWLczdz+hZ4XbobAonfoNUvkbtzVv4Cm3My1szx0TlvU0pwu5WydtN49g+er3vQQCNAuWSvO8pfyQo8RAfskVX7czL5kv1L1UpdhWj0xaU5tcMvG6TwJApvwYqtS+0IyhGJ1feEV7ebsR7lTYoPYWaogyf4OWQoZqLLNU4QCHMsO8Bz/aTfrTfFvmP4JCUgxeENenOZpiPKjDfQ8H3OiMt601DNP1a5myMt8U4ROassP+gKqJDHUPGbjByjKILQnyPW+ebz2Fj+boy3UwpVBLlmUMdm7+maDpCvEymWUGlOX2FU04nwegeuogA== 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=P4TC63Ub1QJ8HKgbTU0B/id1sdl3rdInurWXWIJvZ6g=; b=NN7ezWIA3/znvCaJgpc88T7nnIj//Y1JXHNEiESLfySMvE16w0aniHkHs67+HCBs65rd9MXpVF3wscX1LmyST0LpFuX0ju84Xsycmzm5XHouqQsrdEesy4MWVGOYSCPVmFN0SC/8SPbHH4nHANsCzGK7USfVjMbQzoNrozZNtg9oh46crS1iONLgpTKGtbLtpnueGAC+IiiYYVb1m5oM4r9rwZW1UNRcpSPMRQQgt3vXMxJwD2pbuHEDEtZ9vsdLTGUJbifjAR6161JT9ZCEoy+6vSjYEcryjd129MG1imd3VDg+kV/4Uaq4vDkn7j6kvlbaEevwZrfC94Q/yY4M7g== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3605.eurprd03.prod.outlook.com (2603:10a6:209:2f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 18:29:04 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.016; Fri, 3 Dec 2021 18:29:04 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 19:28:55 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [uJfskU4f1+r6LAl6TQNqcvYz5PqP+wGk] X-ClientProxiedBy: AS9PR0301CA0058.eurprd03.prod.outlook.com (2603:10a6:20b:469::17) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211203182855.1688900-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AS9PR0301CA0058.eurprd03.prod.outlook.com (2603:10a6:20b:469::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23 via Frontend Transport; Fri, 3 Dec 2021 18:29:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd4861f9-dd27-4bb2-5ce2-08d9b68ac8f0 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQtx8w+3h2yNNoYV95SbXd9f+mywLsfOIKZislwOY2GiNcLiIAYN/OGm0wcpSsjWtUo4S8tK5spACSqd/pKUUPDm1DjodGTLKYsvsb2nPb7HDYmzwcQbl3Xfrc0CEV3Ag7kbeE3nqoYmpPfSg8QOIlWiJI6EO/B+ASB2ok1j+LDC87xPAOQfGL2XRRU43GQAaDb6DOjUUxj2mjVK3kK6nLRiF3AkWc+PPImqDZMXRrfNHW14a9rcBS8wMG9J5KnDanTwOzsWtG4eu9ZaLrEmDHWmoO6zhIWRCWi3sC56DB/HUWDZHGRxyAsX4EkC6HiLb5wEN3T4Tg/sZA6BQUJHDsgTJuujAtMXD+NY7HnQYFHU3Q2wjgK0jPcATnNOfLj3AH+qyQ/jJGw9h+8Ph2pW65CzFsn1ocdGqxTe76DatWKq3YowW3KlC77YwIdWx+bihgoTnuezi7yfq8scnd96rForeJ1ysKZQNnz809nlJIOEXCd3xL3sW9A63gAh3qe/T8+mDi+FyDPaxfqYD6KZ596+FgrJqu2+XqIix6ar+YiL+CmmebcvoTRLdMBvLab86ibqLTNk4mwAgBOX7MK7ZmKBDdKyPXJSbyunbmYAtHWIT+mrP0q3fOfURSBFwHNNQNyeKxWagehmV4czrVUdJgKagD4M9e/hoyJkFDzje1cp9T8+Kh3UZshdwEpvBVHgmCBndEs1Hdwn64oLVSil2NNSIvodCsMRRrMJlqiWha1qKj0INHPUfty2zhz3a5+WPc= X-MS-TrafficTypeDiagnostic: AM6PR03MB3605: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D9Khd2z0st0rULJ7BlGbQZn9uJOfnuDm1VnqxW/5igOTfKcv81O5erVxwv0uAgxjtC6VIAU1CtHTgrLaahtgojO2OafPtUHfa9Rw7FhjFolxebMGWJKk7oooFh9rKKgOyMaS87SmoOcbEmcbuW1hBQ/Cqqh5gLONLjNog1xeQs+++6CN7KJW2Ao2qDiUL2tKf8rAjfJpnbRA3RkBXqjNwm8TuBNukrrET/SpkawixBqmb7e35wn+mctPYnHHeWH4wxLtoHD7ETeM1WX5cym4gEyrhH4WFtUGdZBK6i4PD3Vr/Tt04nwVnWUD3fP48XNvIQczrtX5NCL8mEDAZ39VIWUWW/CSaBIywrkPmSWzbGX2tijFtNhbTknxDnQL3KaI3+Nn94qA4tsvJpKQhJgt+4SCMOuuGI1Z542Js8qB2h/gPw/PaQhGB61pjouMu/W1eTWcghwSRGQgnp173rIV6UyyaUs29hVf8tIkGHrVEAo2i6wJIVHnhM2h1ojqFv7bO+LP6Jvx6TGqPJ8oOqgjYStZeY6t7zp3HBezU5lz5GY9wL+H1OIieZ8bU1Ri2wqR+Txb8dmb9AnfnPTpzIGKhQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HU2jStya1e7c99RfWvuYGlnwzeb/5OrJHwk97QLoHvG02p2BgNTRwI5y7YvrAgfdifdgcUb55gSF9HiZGA/8nQZ4vQTxJiHDE5WQ4Liv1QQN1h5pC+fkaI+kxEbt3OxhZjNBJUj581lWKUTHdmwRKhKj05Lq9MF7N+fAuReNY6SX/rq7X9vzmVRIejrihjF0U/vQ3t2mJRsJgfWC2IRSfKBZc64F4M11CzaOcg7buodb2wfzvdgcnXT7X9toO8KRzVlGi550MaV66XNsG2NuMoecTx2FYLm5mRRJpwumJV9pHt8iJYUTot6IPspIO5QrDKFOUo2knPWq5A7NMDa3pwQ5Q/WCZZkE15P9WP2G2lFiS9PFgCCKBghjYY8en2+C3xjBQQTW+VRqNEwHNao7vb2/k02nG8WueOHBvxRGhy3lDjfZ3AS+mChuqZVCDh1Gbr984ZvH6+0oNbC75Q09NEBGwqktaQN4RMoJXfX9bCgGWLDFlRi7ae+n6gnKmtCKJoLm8IiVHR4KymYlLhTXypWxwPMYx3W9z9anJd1EMh9SnPyg4RsgRX2nuzeZQVFfZfwy/y+CcjzIpB9xq83akb0/iZ6+8M0ekKvrZPTVVpEXWL08Tru0zcExtakqjPviqXUBS0pDmci11U1HOTqnpSK6e4CnhO3qtEN8G5yRmNeL0PtqtqLzaB/Zy5fDG1j2kagLhUYbb/maG+0DLQaVLqlh6ekl8bn3gW5inXWUacLDe3HyC1UE4AnA7Y0MSLvB6hNlGPed8p+iixI3AFIyqIRE2rWkWI9Z4PG6qorkWxlolEgh9TVsoERj7ZZ78h5UFDwAY/WLDnvIPQgUDVx+JCJRbABngl5uNyR5DhwKU28l9Sr50nLOE/Rw3+KJDJryej8XFNmeTWm13ud5Bz9mdzPgkb5+g1I+dqMjlJhYHMcJ5s1qGELgNhWWYKCOwoLRoYJS3FNcBxXIDrK6GmeTaQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd4861f9-dd27-4bb2-5ce2-08d9b68ac8f0 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 18:29:04.4135 (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: AM6PR03MB3605 Subject: [FFmpeg-devel] [PATCH 4/4] fftools/cmdutils: Use av_dynarray_add_nofree() 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: Zge/6Y+U0jXV Simplifies code and reduces the number of allocations a bit by overallocating. Signed-off-by: Andreas Rheinhardt --- fftools/cmdutils.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 0b57552e5c..3c8e5a82cd 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -2216,19 +2216,13 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) { - void *new_elem, **array; + void *new_elem; - memcpy(&array, ptr, sizeof(array)); - if (*nb_elems == INT_MAX) { - av_log(NULL, AV_LOG_ERROR, "Array too big.\n"); + if (!(new_elem = av_mallocz(elem_size)) || + av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) { + av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n"); exit_program(1); } - new_elem = av_mallocz(elem_size); - if (!new_elem) - exit_program(1); - GROW_ARRAY(array, *nb_elems); - memcpy(ptr, &array, sizeof(array)); - array[*nb_elems - 1] = new_elem; return new_elem; } From patchwork Fri Dec 3 20:45:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31945 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1173351iog; Fri, 3 Dec 2021 12:46:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqscD9S79lA2N0F39ig5Dd8ODC8rxQal4P3WybuRJMtK1rwDPuuenK71b3WLvHw6bz4V5q X-Received: by 2002:a05:6402:510b:: with SMTP id m11mr30109180edd.165.1638564373118; Fri, 03 Dec 2021 12:46:13 -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 x15si6809931edd.589.2021.12.03.12.46.12; Fri, 03 Dec 2021 12:46:13 -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=lzdXvpkI; 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 DEF1068AE3C; Fri, 3 Dec 2021 22:46:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075052.outbound.protection.outlook.com [40.92.75.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 459C168ADCE for ; Fri, 3 Dec 2021 22:46:01 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FOyNwM20b14RIAgnsEXNmy+TZb5aKSFIH2UhA5X/D4tiCP+HP9J42iSKQYddeMGewmBwiJPgf3E65XbWsBrjER80F5Dzy8YiDh1z+lbZQo9SzcmkxMnRo0am6pSn/3gleOZjsBH5ajKFjZ1yZE6PX6WoaF8T9nXILkrJGbtd3XypMUPjvdOaAoV1n3WA1CxsYdc0ZZt4vEVePsEWaHEKRAeMalvUv5svjfwNGh8Ad1jNRCwSQkDDI3eiVOz/1hTGvWpr5mNbhaXtt4qgCBnOCVAgyllLfZ3v/fIuiH8+TNv5hHVNjvLanGCxnuhcLGQrPM0HdV3GRBp/3r0RuHPyrQ== 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=WhL06D9zaEMYLYzhrqbgrpYq/SN5u4bLx+crjCHZR7w=; b=GK9FMCtSIPxX4xAs+DRVAtyJTy1NbW+PudYI6yz7throsibLr64kpHOAPvgeZfFCGpHuEKMZS3bJZa33IMsTqyg6MuHtumRFC7QfAaPeUeXgcH7qQDVsYbheMadp0E4SlRJv7y6mUFhCFAHKp6n8vzZ+syxL7XrF7Z0SIYcnRnZzV3piFW7SYzHm4vlYWIYmxD0+50jcZnBrljlHGIhzEIfCu+n+VjLZ6PFDbrppen1N9fRgEvtgfmceImr2EEiQ6JbHQ9Mk+mf06Nwl3wg319KqvorcPKGIptu9IFgEBWyYmaYAS1Lj6L9uA6HvA1H25C7IY7OZckU6ujo4oazgAQ== 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=WhL06D9zaEMYLYzhrqbgrpYq/SN5u4bLx+crjCHZR7w=; b=lzdXvpkItPj+Clb/Zwkn23aJRaiRk73htFckqpzvGCORKJxmIPn2+9ovBKexrhx8pZAFMz9k5Bdj2kHCR8sRQxQrLAHlaFZjQ20sJ4jRJ+MHjnyC4ERTfmo832hnaAEclFZyyv8nT9zY8o1wCkHfvqt56eQYGJdrdqj8CqDk2qmTo8EoCXkskTgU9gliicAGhx7E+4NSUhj1CpHvb70qeIBTtbxZjYK486ipKDnyzDn4CrbqvtGhKCupYiclH64qgc5uq6KKLXZE4R7tsxfS6ONQn300ekn+VVk+LU2b6aLkUEexdnFx4pXwYTGy34xZTMIN9i+5VbXTsGiFaGlaLw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3831.eurprd03.prod.outlook.com (2603:10a6:20b:17::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 20:45:59 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.019; Fri, 3 Dec 2021 20:45:58 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 21:45:46 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [0C+WV/3SzlCQMCgNKpneYpJpeG31cWY9] X-ClientProxiedBy: AM5PR0301CA0023.eurprd03.prod.outlook.com (2603:10a6:206:14::36) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211203204548.2005738-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM5PR0301CA0023.eurprd03.prod.outlook.com (2603:10a6:206:14::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Fri, 3 Dec 2021 20:45:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3dcbcde9-3089-4c27-e07f-08d9b69de8f4 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQtx8w+3h2yNIIsmVb5543qgsBLjkbpu3u6oyjdh+rKYA5GG8NHdwnWa44NU1tD0NVUJxFbHJHXsqQIDKE945v2wQD6X4b/cZIk4z16/TxjN95i9+aBqQN1NtAJw7BCsIqov+KuY/YeoAHS0zR0VbRZF85VsYpjHLi7fovJgebJ8S7Cz3eym0zxorSluQ7LKunsbhJ149MXF+w31bEX1mSGLidROgcOEF+dCTYYdQwyxeWJrdIWtkvfUe+jNDfSlPXUZ3nB59xLKt1JETw8jMRicOa3dfE+CmDyKlFKfXJrqB/u808YUOcSdFOz8b1B6XHTAPznN9kjjg710wvJ2e+9oNjd+IKE5U7dt1LA+XRL53Uo+F3oHnRFWMC6e5BXp4qn8c0nku3GUcKakv5nqTN7pTsGuOu7IuMlQETrygvju/PXaiRigWV5/g95vPvLOaKZ+8v4VZ/q/HCnHkhjK82usz4sQA3E8MgZ53em4MJqETX/SBt9yLy4ePWhjstVxFA/7f+2B5efVJ8VmoUYi7EX26kFy4ZkqoNTd/A+Q229dLhuKgX5buMsCGkdUXON2OoRLkvSdA0jn/89i+gRAsXwGneDTo35SUbwOaxwWw2yM04TN6p41y9zSI5LA93hcyMqPqadyycowo+51KDP+sjPQJnCHBIij+Xzx4ie8heJLZVDb6n9ujrbs3M5mlWaQa74OKga6NmOz33yaCmeq+hFX1yOp1Fkf8mtZrpS3zUP/i02bzbzMNh5hYgB2nPtGxY= X-MS-TrafficTypeDiagnostic: AM6PR03MB3831: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NFcM+xOtYw89bC8lAF1e5jt7xAt0aLDYNdjoTe2eAxBVwaLO+3tNRL9r0Za8guqIuLAfsXsRFJZj/QF5A89wx2dX9FSMJBMHD6ycgvYmW/iG2085xNg32p96UI0RdZYMYZAcOowhyFBzh0FdDmu17JwpslIaoQlWWmWVNABXxPYcH0Fi3XLJgRCuwJzXHfuLvoHMa4y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jaX3U7fmqQN5xtvRoquOLge6EihtgxlJNySxvohVjD9K5QESjsh7NlxHEMbketFaCYLAF4inHFpz+QvF14qy2I7jeTFBpgn1wkhjhHWLKQHGjo/9Vs936BLC5wdlCLyJoLqFOA8kz8PHMrgk29FlQ55iviagafOWhc2ZgLjtalUWuf9urYma5mAKob8j6G4sc9lh24QeRE662JPu5Cim6z0vRQJi9x+8gjcjIuLuII3UG59cOzypq8rZGtTc3Nu+aQQX41giTGKvOzv5h5+PSC5SkK7d8iVe4JuHDc29PMSmzli4LnxPaUQQarWN8OKmdbT5721MN6X20Vv9G66Q86t4b+AooaV4yRZSOJM21xvT/8YQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3dcbcde9-3089-4c27-e07f-08d9b69de8f4 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 20:45:58.9118 (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: AM6PR03MB3831 Subject: [FFmpeg-devel] [PATCH 5/7] fftools/ffmpeg: Avoid allocating+freeing frame, check allocations 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: J+3+wO1fcKMO Fixes a potential crash upon av_frame_alloc() failure. Signed-off-by: Andreas Rheinhardt --- fftools/ffmpeg.c | 11 ++++------- fftools/ffmpeg_opt.c | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index cfb04d5eff..8c3a4f7c0c 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1291,7 +1291,7 @@ static void do_video_out(OutputFile *of, int forced_keyframe = 0; double pts_time; - if (i < nb0_frames && ost->last_frame) { + if (i < nb0_frames && ost->last_frame->buf[0]) { in_picture = ost->last_frame; } else in_picture = next_picture; @@ -1419,13 +1419,10 @@ static void do_video_out(OutputFile *of, do_video_stats(ost, frame_size); } - if (!ost->last_frame) - ost->last_frame = av_frame_alloc(); av_frame_unref(ost->last_frame); - if (next_picture && ost->last_frame) - av_frame_ref(ost->last_frame, next_picture); - else - av_frame_free(&ost->last_frame); + if (next_picture) + if (av_frame_ref(ost->last_frame, next_picture) < 0) + goto error; return; error: diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 17e4cdd2d6..6d091d3e23 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1903,6 +1903,10 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->avfilter = get_ost_filters(o, oc, ost); if (!ost->avfilter) exit_program(1); + + ost->last_frame = av_frame_alloc(); + if (!ost->last_frame) + exit_program(1); } else { MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st); } From patchwork Fri Dec 3 20:45:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31944 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1173496iog; Fri, 3 Dec 2021 12:46:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7Xw8TA+NnETg/4jbC2c9w5TCplooDGdoVGStiYgX/R+Smv9aBwwsOefstMHFZoVg/Oohy X-Received: by 2002:a05:6402:3595:: with SMTP id y21mr29655893edc.332.1638564383447; Fri, 03 Dec 2021 12:46:23 -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 h27si5590058edj.431.2021.12.03.12.46.23; Fri, 03 Dec 2021 12:46:23 -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=otzSUxvY; 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 0C72568AE7A; Fri, 3 Dec 2021 22:46:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075052.outbound.protection.outlook.com [40.92.75.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E19068ADF7 for ; Fri, 3 Dec 2021 22:46:06 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aH2dt0bxKFKUv5GAZWCr1S1VcATxtnkArjBvDV8IvVyfa5dUPPG3XOHJZNB1R9gWXqucjd4xIpwtnr0AnoKfjcjkmppij7J0WDcgx8AL9yhzzxhGCzLcwuetgbLMydTeH0OI917qwmWzrFGCSB51bz5lRn7rjr70cHbj6ITJw24ShvDCfqSXITLbJ3sWTmBvTIkKiaGLd3XoZfo5+wAIewPhy+zrWeg9G7OLYLA9sfFS5qEjvodwrLuKC76MOX3ugNHP+Q5xnfWh+/v+pzcDDXCJZ7mFtlgkhr4F/TRfC215t/LE3oPWNsxokdyQYy1+VKQadGo5mCAodsjUwPp6+g== 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=daWdRFqaJRhWQcyqQWETNnXhZTwulAZ7uRkENI8udCQ=; b=WFoo/6b2CrV0BFtEoUMPB75XaCAWmjGY8ab+bLB1z+WzeGHhur7qqVqeHt2HWAPxNg5ZQX+jvBrQ8cveSZWLp4+lGW9HdmgbEPz9xoBezqb/H7YQBlCiuJo3IYG5RLeQrtjvbeIwQut40GwdzOZJKAzgcUKv4nZ/7nNqkCHx5fd51wisodRlKTjiOzRZhsVZSdsYJgF23AvyyawX7ufm7sCvnPxWXCXog4kro4P+C5xXALT74qocuIyQVt125O/8KZ32PTvMw9o3J6COu4SA9vfe8fZxx5Y/ikBLIM40EnXaA0F95h7WKD8fhwlubRoZW4RBa5GWh0a3wvgsgnKz/Q== 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=daWdRFqaJRhWQcyqQWETNnXhZTwulAZ7uRkENI8udCQ=; b=otzSUxvYl370wznY8m03OwcIct/GzAoEiqmKHWww+r8WOMil0cMCYSsc6ZQ+7U9dJdziZmjtqMpvWH3OfDlh9v7WyctT4N/nJztS1ZZ1aGE7HkZRoBqiBx/kd42V/ED2k7MFuIV7yzPkxa2zH6d64kai/jpLccKARwnaBJr8+6u1QY8K6Qp976L6dbD66oCF31D+0nT+aZ/249BJfhvEEgxAmecGnI+MXj34wtIJLIqmO+owjLK9fw+Kvv72NOvzmh+uq78BGHxeOHPij9J5tbuKqjOxq/LftgSd9CHXrLDaSNy2nLxLxEcUsQRT87gmr9NphVmyFG6kwsoa73E4eA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3831.eurprd03.prod.outlook.com (2603:10a6:20b:17::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 20:46:05 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.019; Fri, 3 Dec 2021 20:46:05 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 21:45:47 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [sUZWJqr4ILCZ2BhX5K7xQtgf4z8nPGFH] X-ClientProxiedBy: AM5PR0301CA0023.eurprd03.prod.outlook.com (2603:10a6:206:14::36) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211203204548.2005738-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM5PR0301CA0023.eurprd03.prod.outlook.com (2603:10a6:206:14::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Fri, 3 Dec 2021 20:46:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 32e6da5e-3beb-41af-e684-08d9b69ded36 X-MS-Exchange-SLB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p0bIP85ZfeOA/osDGUPIWbp3SzT54PIJhO9QURAgpP3AC97Cewd9VBCs6SQ4c8wq1MLFyxnUPX8uYaB0bEdWgc7mKI6xsNjfdOQDHHG1R+F3YMawURwtqCpNWEorl5m6jOoEHqIs/nYL/+ghYpTynTmKjsHegQOG6Pxd9RywJ4GeXB0IpqFlEQCoMvptVKgINvh6jhn2HUPzKAs7HL7OGg8b8jqC3e3CU5ZS6Mj/040Ta0qskXb1Uz9jZLnyoH/BHoAZeDKiWDpeUJWIkHKIFoHtKPuBf//iHQcfDX/IuG6bzyxFZOwdT2pwLI0fZIkr5W+RMIIy8YgtnSQa7jPwWGPPSdVl9yklVN5w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32e6da5e-3beb-41af-e684-08d9b69ded36 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 20:46:05.7428 (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: AM6PR03MB3831 Subject: [FFmpeg-devel] [PATCH 6/7] fftools/ffmpeg: Avoid creating unnecessary reference 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: TP9c91iHMrDp The only caller of do_video_out() doesn't need the frame afterwards, ergo one can replace an av_frame_ref() by av_frame_move_ref(). Signed-off-by: Andreas Rheinhardt --- fftools/ffmpeg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 8c3a4f7c0c..638a6441c4 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1138,6 +1138,7 @@ static void do_subtitle_out(OutputFile *of, } } +/* May modify/reset next_picture */ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *next_picture) @@ -1421,8 +1422,7 @@ static void do_video_out(OutputFile *of, av_frame_unref(ost->last_frame); if (next_picture) - if (av_frame_ref(ost->last_frame, next_picture) < 0) - goto error; + av_frame_move_ref(ost->last_frame, next_picture); return; error: From patchwork Fri Dec 3 20:45:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31946 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1173672iog; Fri, 3 Dec 2021 12:46:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGtgMIX40p9OBzxlAA8mcOL2fosmz2dXpfRnmp6VNMzAj1De0aUZCnKUIwyll+wDbS8eaY X-Received: by 2002:aa7:cd5c:: with SMTP id v28mr29559478edw.6.1638564392689; Fri, 03 Dec 2021 12:46:32 -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 y17si8125446edc.415.2021.12.03.12.46.32; Fri, 03 Dec 2021 12:46:32 -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=QbuHjEk0; 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 3AAB668AE9B; Fri, 3 Dec 2021 22:46:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075052.outbound.protection.outlook.com [40.92.75.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7602E68AE42 for ; Fri, 3 Dec 2021 22:46:11 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bc2oTndd+FeCGPOq2kWIEFo+GPm/l4fn9fKtutehwC2J5XG83VyPh3oN0kETpRz+8TqJ4gmnD7RtQDHTaLeAnPNRyB9dRc+J09zPfMzYuZYy0tuot1RKqjV5S1BfCufvV1pPY3TPHETS5KHrqiLRxtLee8C7SOrbrqN/W4z8SjOdmYb7/67G5N1tJ657klddjfVyH4AnEh4CORzm1t/bGgbMm8djpluG8Hvj3qkiNj2DyhZhKGY7ymkH4gf40/453w0lVPa7XQ3WWZXWx6xwreHVIXsgKSACudMLCuJ66aVY3TVyaGKIfOL2E+6UekQCBE5NVILg6ZOO02VDWGgtFg== 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=3gyNSHLft3qZ/rsuFOsQe7Sfxjed3neXTi3yKh5xfoU=; b=JcxNyXNNKqhj6OJp/VfwwoogFPNEHRL3V7dTy3a1FnT7IN5eV+7TU9baEcL7fCMUpIjcecCJToJbbC1sh/yDzlrR0FamYwF3yp1Uuw25SpVxd1Ce1F1Zoc0D1rPVU0juFzdm2yfLkB2SpYUNLIFBJ99K+1vSWzHEU57wwaR0u71sVpozFyIeFp1cip6ZBXUWtb1UzrS4sAUYo46clMcNbktWHnBuaQtw3BSnxKDP2Op72DozbEqrsq2BT6Lgod9b8ZchxfmZmXUb9c7rscsQ9N+LdUIoLEfjXhmZKkza90LmpdKboN6Ab69djgoVBFG9tRx5GwkHPT3PAVwSYTXn5w== 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=3gyNSHLft3qZ/rsuFOsQe7Sfxjed3neXTi3yKh5xfoU=; b=QbuHjEk0VbrBffl7+m6SNOMUDhHFjCQL9wb+wdgfakChDEEtpUqBP/0+SjlOq+3aeMjHHvlHvSAWBKo2RmpdFCOe7s9LLqlL+yBOhVbyNIS1BxjX0tSVNPw74qmL++gmii7J0QiOAxSXX0f8Yq6Jy9UBbLbX9yhBgmtRpTdibenAfL4slUpGriPxeOLha2d8MlSuykwatDKZ+gIij1TPMcHANVAdEGdI3l9YZWSJXKzNvXpq6W9Hi+t9juCR7nFPIBqSTjubuBJB2Z1ZYPqPBqTDwj0ezfn+rqyqCTgBdGt6kCpId4I1BGJV/MLgJiehwd1WX/PJs+GqeK6dK/75UA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3831.eurprd03.prod.outlook.com (2603:10a6:20b:17::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 20:46:10 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.019; Fri, 3 Dec 2021 20:46:10 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 21:45:48 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [kilT/CIJzHWkyl0lYccuhSDYu+nvtyIg] X-ClientProxiedBy: AM5PR0301CA0023.eurprd03.prod.outlook.com (2603:10a6:206:14::36) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211203204548.2005738-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM5PR0301CA0023.eurprd03.prod.outlook.com (2603:10a6:206:14::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Fri, 3 Dec 2021 20:46:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b0e899b-95c2-40dd-e572-08d9b69df01e X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQtx8w+3h2yNIIsmVb5543q8ijmTa9I306ABzV80yHbg6rUjIfqYKMRMwa7VKVDmS5MgoPinG1tzIHwF2iF3BWmD93ZQSYdPemvguJgHrXk71E/uG8DTM9E2odwHNmTp8lhDajX536lygGrM32zXGx2YmnjDrQkF4N5mbSI3qeki4GSUQN2E2QOnJWQ2pUZpoIte65lEQKJI5NzyhgwvEU691Kan9G8iwePPUmbwRHEV7suXVlGIKCNEhNIR4UpTJDLgOVb80A90sqAAt1+w1+v5HDokjSBqHdAphJbd5zTDTlLSZrEEla/VroTiAXU0z1xdaUFno4mjI/W8OVO+1CL9RZazWrfRBi0rqUDRakuQ/F2Bf0rYyCrXmNSGyIV4PQ3JCrJm6eDFDBCgBYVtrFmWBj8t2j1S14R+3zkQZfSlBqLrRxfF/3ixFfwaGkE43arinbXZscYa7Avk1094ZMcoWffL5wX3EVy7FnH1aiatdwZYo21lh7l6gXISSV4967kXKqnGAn9uwx0PuxbOyBKBpQNFe1+K5iMcFhD06gA08xTCddKgPATf0QJAyuNMTSyQfvwkrIgJLUwp7kfZLw397S3paysMAbd0+N5BHv82G5tCoh0AZYjnNKb8c1FFjs6V4m/+9yCSjqoU2kNs9YIMaohMFuvBu0iYrCTKWouGaZwrhzkiTrxyEK+SiRlbBH14fR+qnyo5obio01GAUEKZhZQDZIgkuvYoRmyEIavvUjuJ15Pw6UohCNmtP8Q6yM= X-MS-TrafficTypeDiagnostic: AM6PR03MB3831: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TJZunDR9YtdhzK79qcvI8LIImFHlxy92o3pmWhCDc0p0tyOj547r22t0aqLfm2bcn8BnXo3e8nsWHLamKLyMphj00VrTQsLWISTnyBLZe/itRV/7hQQS+2q0dSIj0vRyzeUBFy/o4r1ibWVlshsY9p7gQgUUfe9BhvHxD2bqQqM0gBvb4wJ662qyOfPg+oKPZkOeFdYUamCJdvIzYgEquy8kHBnJ6TdC8dQKw7qaVjJTapg/eD3MwNbO71g6SednzwL5p54fjTtD+p+3rp7uHEt2lrQkBmOJHawd9AE5JI/g8L35YIF7d6LuRVEWpQLph7By1TQye9b8xn+lFFPhKGwye2KBc7Cj4TL5rM+ynqdJ02ZxeRgDEF2I6v65Q8XvvaLVYZsi4hLpAIKkLv11wMLwZ+RKmdFTvr6jxlx/xEpRKy5g8l5azCbwMA3vhjN+WXIJAj4QmLv+x/Dg0MxW9w3edIYugnHqmDVjQISDrh21PnlVyDOiEvWn8bS0j87V8bba6cX/IVceP7hTkbvB9/4ybcKLD+50G2DSAHjNz1+aDt+eDyE+bOcd2jRUjm2kTpA0XAUy1g5oPtVXGzKnFg== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MmalUbO+deEzuvTRlkVSb98FekCHFHp7joa1tO8d8jfHNLQkWmpikchcCmyUG6gIWfPj6nMiLfyY5QkBbg2zO/yR0tKgQAdA/Onx/WeZu+Ygs7GzyIUAKaGVkgqdZIZ4nsO6GrTXcwJDEtYZHN/ejLHSwLnVGbUxfzNm8pYlIPTC+HDnffGmf/3/eyI0gVbVVMlw6oxTg63EIR8ZgM62A7PfBe+NmBW1KaocJbuVyZjVpsw+ORnWSyCIHqpHaYnRLx2td+MViRGZPbMghwe1zAAHnRm2rNZIP8JKjUgl29pFkH6RMQ1n1CR08f2utSZXMtFSiNouocozhyXqbUs1uk5JqnD0I0dJa+DfGsuI7gUJ2TsQM9zO+kB4sg45RnXC09SWCboHDQMaYObWrlmvQbdrBwgnG49nVcMHWVKyaQGT3Iwl6b1lKTeOsH+vcm9sATyY3LeJS19+3GNN2XJxt/3FFDekCk0ZGEHYkhSQ3QrgeThsswovZXhWaXGHQmtKoeiEV93SYfu6TibmxxwSvJMAcGA7Cy8yXd7spijxEnaQUklacHPiXfFsUJscYcHpfAYzQfvv4uGOS8+rOLSdPGRaQbb5PouXrAmSbvIKFP9UD1kHpwyjX9K0KlJVrBhROnLN70ed6GHbBRBgXs5yAygUUfVNkSawsO2IyNyFzq+Thvd/vkWgF3ZeeY1YxOEtRUaey6oef1UzfR12KQ6pJFh6jok55vHjVF9Hiq/ZoEIXgt2Pz5H7jULPyeZoA/pMv4q8HaFVvgvLk6kpZSLPpErNgMb3owVXyCy1y54CcLWtClMhYHwVA7/1baO6+XKPZp0n77fZQjQ6xSbzVqAUGXCXRopyPzV3z5coKGbyMvBbV13OXKM7s0itWZYYaIGZXVhBZ896EHnTC5y8aslW3Ckwch3YHtWWeedsd1sYVWODC8WpqEMt2U8ZcUtlLf7K5D7GURV58pU5HsYhyfTndw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b0e899b-95c2-40dd-e572-08d9b69df01e X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2021 20:46:10.6188 (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: AM6PR03MB3831 Subject: [FFmpeg-devel] [PATCH 7/7] avutil/frame: Treat frame as uninitialized in get_frame_defaults() 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: H2PtTkAeYZIG Currently, it also tests whether extended_data points to something different than the AVFrame's data array and frees extended_data if it is different. Yet this is only necessary for one of its three callers, namely av_frame_unref(); meanwhile the other two callers took measures to avoid this (or rather, to make it to an av_free(NULL)). This commit moves this chunk to av_frame_unref() (so that get_frame_defaults() now treats its input as uninitialized) and removes the now superfluous code in the other two callers. Signed-off-by: Andreas Rheinhardt --- No code actually tests the scenario in which data != extended_data. Of the 7984267 calls to get_frame_defaults() during FATE, 2784297 freed the extended_data, but in all these scenarios (which all came from av_frame_alloc() and av_frame_move_ref()) extended_data was NULL. libavutil/frame.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index d4d3ad6988..95bdc0be72 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -52,9 +52,6 @@ const char *av_get_colorspace_name(enum AVColorSpace val) #endif static void get_frame_defaults(AVFrame *frame) { - if (frame->extended_data != frame->data) - av_freep(&frame->extended_data); - memset(frame, 0, sizeof(*frame)); frame->pts = @@ -98,12 +95,11 @@ static void wipe_side_data(AVFrame *frame) AVFrame *av_frame_alloc(void) { - AVFrame *frame = av_mallocz(sizeof(*frame)); + AVFrame *frame = av_malloc(sizeof(*frame)); if (!frame) return NULL; - frame->extended_data = NULL; get_frame_defaults(frame); return frame; @@ -455,6 +451,9 @@ void av_frame_unref(AVFrame *frame) av_buffer_unref(&frame->opaque_ref); av_buffer_unref(&frame->private_ref); + if (frame->extended_data != frame->data) + av_freep(&frame->extended_data); + get_frame_defaults(frame); } @@ -466,7 +465,6 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src) *dst = *src; if (src->extended_data == src->data) dst->extended_data = dst->data; - memset(src, 0, sizeof(*src)); get_frame_defaults(src); }