From patchwork Wed Sep 28 10:48:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38435 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp121782pzh; Wed, 28 Sep 2022 03:49:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41oWFfD8/H1PygtyP5D/zilaTQMlT9ZFKM+wwTG2SeiJFGkIEy12226OV4fuNdKExEh/xk X-Received: by 2002:a17:906:dac8:b0:741:545b:796a with SMTP id xi8-20020a170906dac800b00741545b796amr26569590ejb.240.1664362178503; Wed, 28 Sep 2022 03:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664362178; cv=none; d=google.com; s=arc-20160816; b=DsBZyAp7K0c8pIVix6JUd1ym0CeApASK+wBdWHR6gG/Pioc8ZlCjwkheZHH48gstUY 3x7o3fFzkq75VocES4a8xGl5gIsMCTpOdHDF4Ee7cHz+gV45+VVoKcmu2Ml9XfKlz4qt bMOkMR1BvKHHTQs3Q3Rzeaf3Y5Uq67q92PD9PNdCiRB6PqOgZ3BdlQ278caV9z5bPBby zIiuHRRJcx6e+AVYaAZCmFzCuJadE+QrSpStt6KNH3sZzYKjZexWhIQw2DJL+E1nwNsQ Mf15EH/sxHlRr9RLY8Mj7K4a3XeITnATJX+gUnr03CKfSYKt9DvrFZTebrCHIxvPt8RW 4EAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=pRUOmEyds2g3nFbrWrRscF6i5RmAfcS3w8Q4xxtNFL8=; b=XJ9NyPIUGc+VM2XxPq5LsfNVctjie0pea+Qy9rRmQyraysZvGBTGksLQXHmb6tXPqT wnDoWxZHuC8iThkp+LYKx1gbrjGbC0An+WhxUBKOhg7p/54Vla1yvFDSQSuJe1hjNVYx 461+NjMJ4kbQlROE6K1YSMnobMdTC0pAfeB+mZoZcyT1pK4J6JkaAUXLxmYQw8tF+hFN m91zZYk4Enkd4EXk+NelIcXeO7KTGY4KADluGNIxmfqQ2pbF27di933SRmnE5ZMM30It dmJZ+mZuZpDic5aQddLZf11gt7m9OyCLR3ITd1wQif7spy6JPSbcn4cXzGUuKBjX9X9Z WrPg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p10-20020a50c94a000000b0043be773a90dsi4075586edh.45.2022.09.28.03.49.37; Wed, 28 Sep 2022 03:49:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0E77968BC84; Wed, 28 Sep 2022 13:49:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 779FA68BB56 for ; Wed, 28 Sep 2022 13:49:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 159412404F8 for ; Wed, 28 Sep 2022 12:49:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id UOp5Ksr58Ojx for ; Wed, 28 Sep 2022 12:48:59 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id C5DEB2404E4 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 96DDA3A014F for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 12:48:49 +0200 Message-Id: <20220928104854.18629-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VlGHEOMFWGUL It uses size_t rather than unsigned for the size and conforms to our standard naming scheme. --- configure | 5 ++++- doc/APIchanges | 3 +++ libavutil/mem.c | 30 ++++++++++++++++++++++++++++++ libavutil/mem.h | 37 +++++++++++++++++++++++++++++++++++-- libavutil/version.h | 3 ++- 5 files changed, 74 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 6712d045d9..fd0e6ae032 100755 --- a/configure +++ b/configure @@ -4360,7 +4360,10 @@ case "$toolchain" in target_exec_default="valgrind" case "$toolchain" in valgrind-massif) - target_exec_args="--tool=massif --alloc-fn=av_malloc --alloc-fn=av_mallocz --alloc-fn=av_calloc --alloc-fn=av_fast_padded_malloc --alloc-fn=av_fast_malloc --alloc-fn=av_realloc_f --alloc-fn=av_fast_realloc --alloc-fn=av_realloc" + target_exec_args="--tool=massif" + for func in av_malloc av_mallocz av_calloc av_fast_padded_malloc av_fast_malloc av_realloc_f av_fast_realloc av_realloc av_realloc_reuse; do + target_exec_args="$target_exec_args --alloc-fn=$func" + done ;; valgrind-memcheck) target_exec_args="--error-exitcode=1 --malloc-fill=0x2a --track-origins=yes --leak-check=full --gen-suppressions=all --suppressions=$source_path/tests/fate-valgrind.supp" diff --git a/doc/APIchanges b/doc/APIchanges index b0a41c9e37..9a735c27e7 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-xx-xx - xxxxxxxxxx - lavu 57.38.100 - mem.h + Add av_realloc_reuse(), deprecate av_fast_realloc(). + 2022-09-26 - xxxxxxxxxx - lavc 59.48.100 - avcodec.h Deprecate avcodec_enum_to_chroma_pos() and avcodec_chroma_pos_to_enum(). Use av_chroma_location_enum_to_pos() or av_chroma_location_pos_to_enum() diff --git a/libavutil/mem.c b/libavutil/mem.c index 18aff5291f..51fdc9155f 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -502,6 +502,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt) } } +void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size) +{ + size_t max_size; + + if (min_size <= *size) + return ptr; + + max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed); + + if (min_size > max_size) { + *size = 0; + return NULL; + } + + min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size)); + + ptr = av_realloc(ptr, min_size); + /* we could set this to the unmodified min_size but this is safer + * if the user lost the ptr and uses NULL now + */ + if (!ptr) + min_size = 0; + + *size = min_size; + + return ptr; +} + +#if FF_API_FAST_ALLOC void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) { size_t max_size; @@ -531,6 +560,7 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) return ptr; } +#endif static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) { diff --git a/libavutil/mem.h b/libavutil/mem.h index d91174196c..deb440ca1a 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -264,7 +264,7 @@ void *av_mallocz_array(size_t nmemb, size_t size) av_malloc_attrib av_alloc_size * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be * correctly aligned. The returned pointer must be freed after even * if size is zero. - * @see av_fast_realloc() + * @see av_realloc_reuse() * @see av_reallocp() */ void *av_realloc(void *ptr, size_t size) av_alloc_size(2); @@ -346,6 +346,35 @@ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size) */ int av_reallocp_array(void *ptr, size_t nmemb, size_t size); +/** + * Reallocate a data buffer, reusing the existing one if it is large enough. + * + * This function is similar to av_realloc(), but optimized for cases where the + * buffer may grow significantly and is not expected to shrink. + * + * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr` is `NULL`, a + * new uninitialized buffer is allocated. `ptr` is invalidated when this + * function returns non-`NULL` and must be replaced with its return value. + * + * @param[in,out] size Pointer to the allocated size of buffer `ptr`. This + * function updates `*size` to the new allocated size (which may be larger than + * `min_size`). `*size` is set to 0 on failure. + * + * @param[in] min_size Minimum size in bytes of the returned buffer. + * + * @return + * - An allocated buffer (to be freed with `av_free()`) that is large enough to + * hold at least `min_size` bytes. The first `*size` (value on entry to this + * function) bytes of the buffer remain the same as the data in `ptr`, the + * rest is uninitialized. + * - `NULL` on failure, then `*size` is set to 0 and ptr remains untouched. + * + * @see av_realloc() + * @see av_fast_malloc() + */ +void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size); + +#if FF_API_FAST_ALLOC /** * Reallocate the given buffer if it is not large enough, otherwise do nothing. * @@ -377,13 +406,17 @@ int av_reallocp_array(void *ptr, size_t nmemb, size_t size); * error * @see av_realloc() * @see av_fast_malloc() + * + * @deprecated use av_realloc_reuse() */ +attribute_deprecated void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size); +#endif /** * Allocate a buffer, reusing the given one if large enough. * - * Contrary to av_fast_realloc(), the current buffer contents might not be + * Contrary to av_realloc_reuse(), the current buffer contents might not be * preserved and on error the old buffer is freed, thus no special handling to * avoid memleaks is necessary. * diff --git a/libavutil/version.h b/libavutil/version.h index 9c44cef6aa..285a32f3d6 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 37 +#define LIBAVUTIL_VERSION_MINOR 38 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ @@ -115,6 +115,7 @@ #define FF_API_OLD_CHANNEL_LAYOUT (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_AV_FOPEN_UTF8 (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_PKT_DURATION (LIBAVUTIL_VERSION_MAJOR < 58) +#define FF_API_FAST_ALLOC (LIBAVUTIL_VERSION_MAJOR < 58) /** * @} From patchwork Wed Sep 28 10:48:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38437 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp121923pzh; Wed, 28 Sep 2022 03:49:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/wLFZmulTgcAlMwB9jt1zyXv4cKtOLzalfEclw8TRihNHXCXFpit0EcdhAdWxtHW3YfgZ X-Received: by 2002:a05:6402:33c5:b0:447:e4a3:c930 with SMTP id a5-20020a05640233c500b00447e4a3c930mr32650112edc.401.1664362196587; Wed, 28 Sep 2022 03:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664362196; cv=none; d=google.com; s=arc-20160816; b=juXnkpjzweJWiVUzQIVFQm0B3NESXTpsMOzMae1l1SYW2hz2xCBIYMLCSWK5nmHo85 FdbnPFnOTLVxItjWBAUigT0Vnd/ub8qXZgCx7zJuCzD9FwCrxN0zyUPD7k0w7Kf5TUBh 0rw48mqFpsiRa7MsHcl2vnqvPC82Pm6JD8QttL31rIIMBJH+oEvTPMJBEKnPvWpnB58O 9CMBvhYDmuNrOWmWEoYHo/szDp/iRlQ8f/R5uAlJuDMVMx0YP7POO/zVX5u+dlpszPZ4 C14N59/VGuLgT/irVL89k7JCRhgJtfTswGxL4pOYuzBDr+OD2yI23qKsy+LsC4ugz6Fx ssLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=LajfefaK52L4OcG6HZ3FA/vz40ax56U7Ayz9ZAJp2Nw=; b=nkDd03Kr8uQNmZtacNngwFTT/e7KuffQldO0TYPYQVkhlE/Es14UQjaThxR0XbexoY Ja89qH+uYf/Mt8isHYPutk0rn+PRc10j5pgd76ocQGfTVY9NKtydeEs2cEEtXfc4AcQV YdA02MThahV8twTOjysXfctykBbQMosi9vhw8CV5UVZ9Qg0hxQ5DE4dSYAXPelh1g6/L gsF/2Ia8worIaV6L4GukAQBFhZhQQ2+H0uMnGV78ePAWDXRD+Ch02ylAnVK4xMTQLDWS bw15JE2Rt7i0F7EyllX7HrcLHGmKLqWVsiH5pcasv+9vKEGeSm7un9rrzqB6ybwveAXD NCUg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sb35-20020a1709076da300b00741559ff58dsi4409455ejc.787.2022.09.28.03.49.56; Wed, 28 Sep 2022 03:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F312568BBDD; Wed, 28 Sep 2022 13:49:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 465D568BA2F for ; Wed, 28 Sep 2022 13:49:05 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D03F72404F5 for ; Wed, 28 Sep 2022 12:49:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id FdI7RuH15kA1 for ; Wed, 28 Sep 2022 12:49:00 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id C4FBA240183 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9A2193A0520 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 12:48:50 +0200 Message-Id: <20220928104854.18629-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220928104854.18629-1-anton@khirnov.net> References: <20220928104854.18629-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: V40yHhHpAh9S --- libavutil/hwcontext_vulkan.c | 6 +++--- libavutil/tx.c | 6 +++--- libavutil/vulkan.c | 40 ++++++++++++++++++------------------ libavutil/vulkan.h | 18 ++++++++-------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index f1db1c7291..907f3ecc77 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -65,7 +65,7 @@ typedef struct VulkanQueueCtx { /* Buffer dependencies */ AVBufferRef **buf_deps; int nb_buf_deps; - int buf_deps_alloc_size; + size_t buf_deps_alloc_size; } VulkanQueueCtx; typedef struct VulkanExecCtx { @@ -1226,8 +1226,8 @@ static int add_buf_dep_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd, if (!deps || !nb_deps) return 0; - dst = av_fast_realloc(q->buf_deps, &q->buf_deps_alloc_size, - (q->nb_buf_deps + nb_deps) * sizeof(*dst)); + dst = av_realloc_reuse(q->buf_deps, &q->buf_deps_alloc_size, + (q->nb_buf_deps + nb_deps) * sizeof(*dst)); if (!dst) goto err; diff --git a/libavutil/tx.c b/libavutil/tx.c index 0c16ecffc3..2ea56a732b 100644 --- a/libavutil/tx.c +++ b/libavutil/tx.c @@ -443,7 +443,7 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType type, int ret = 0; AVTXContext *sub = NULL; TXCodeletMatch *cd_tmp, *cd_matches = NULL; - unsigned int cd_matches_size = 0; + size_t cd_matches_size = 0; int nb_cd_matches = 0; #if !CONFIG_SMALL AVBPrint bp = { 0 }; @@ -533,8 +533,8 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType type, continue; /* Realloc array and append */ - cd_tmp = av_fast_realloc(cd_matches, &cd_matches_size, - sizeof(*cd_tmp) * (nb_cd_matches + 1)); + cd_tmp = av_realloc_reuse(cd_matches, &cd_matches_size, + sizeof(*cd_tmp) * (nb_cd_matches + 1)); if (!cd_tmp) { av_free(cd_matches); return AVERROR(ENOMEM); diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index 403f0b1f27..d70bc2e2af 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -284,8 +284,8 @@ int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer *buf, uint8_t *mem[], }; if (buf[i].flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) continue; - inval_list = av_fast_realloc(s->scratch, &s->scratch_size, - (++inval_count)*sizeof(*inval_list)); + inval_list = av_realloc_reuse(s->scratch, &s->scratch_size, + (++inval_count)*sizeof(*inval_list)); if (!inval_list) return AVERROR(ENOMEM); inval_list[inval_count - 1] = ival_buf; @@ -322,8 +322,8 @@ int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer *buf, int nb_buffers, }; if (buf[i].flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) continue; - flush_list = av_fast_realloc(s->scratch, &s->scratch_size, - (++flush_count)*sizeof(*flush_list)); + flush_list = av_realloc_reuse(s->scratch, &s->scratch_size, + (++flush_count)*sizeof(*flush_list)); if (!flush_list) return AVERROR(ENOMEM); flush_list[flush_count - 1] = flush_buf; @@ -516,43 +516,43 @@ int ff_vk_add_exec_dep(FFVulkanContext *s, FFVkExecContext *e, AVFrame *frame, int planes = av_pix_fmt_count_planes(fc->sw_format); for (int i = 0; i < planes; i++) { - e->sem_wait = av_fast_realloc(e->sem_wait, &e->sem_wait_alloc, - (e->sem_wait_cnt + 1)*sizeof(*e->sem_wait)); + e->sem_wait = av_realloc_reuse(e->sem_wait, &e->sem_wait_alloc, + (e->sem_wait_cnt + 1)*sizeof(*e->sem_wait)); if (!e->sem_wait) { ff_vk_discard_exec_deps(e); return AVERROR(ENOMEM); } - e->sem_wait_dst = av_fast_realloc(e->sem_wait_dst, &e->sem_wait_dst_alloc, - (e->sem_wait_cnt + 1)*sizeof(*e->sem_wait_dst)); + e->sem_wait_dst = av_realloc_reuse(e->sem_wait_dst, &e->sem_wait_dst_alloc, + (e->sem_wait_cnt + 1)*sizeof(*e->sem_wait_dst)); if (!e->sem_wait_dst) { ff_vk_discard_exec_deps(e); return AVERROR(ENOMEM); } - e->sem_wait_val = av_fast_realloc(e->sem_wait_val, &e->sem_wait_val_alloc, - (e->sem_wait_cnt + 1)*sizeof(*e->sem_wait_val)); + e->sem_wait_val = av_realloc_reuse(e->sem_wait_val, &e->sem_wait_val_alloc, + (e->sem_wait_cnt + 1)*sizeof(*e->sem_wait_val)); if (!e->sem_wait_val) { ff_vk_discard_exec_deps(e); return AVERROR(ENOMEM); } - e->sem_sig = av_fast_realloc(e->sem_sig, &e->sem_sig_alloc, - (e->sem_sig_cnt + 1)*sizeof(*e->sem_sig)); + e->sem_sig = av_realloc_reuse(e->sem_sig, &e->sem_sig_alloc, + (e->sem_sig_cnt + 1)*sizeof(*e->sem_sig)); if (!e->sem_sig) { ff_vk_discard_exec_deps(e); return AVERROR(ENOMEM); } - e->sem_sig_val = av_fast_realloc(e->sem_sig_val, &e->sem_sig_val_alloc, - (e->sem_sig_cnt + 1)*sizeof(*e->sem_sig_val)); + e->sem_sig_val = av_realloc_reuse(e->sem_sig_val, &e->sem_sig_val_alloc, + (e->sem_sig_cnt + 1)*sizeof(*e->sem_sig_val)); if (!e->sem_sig_val) { ff_vk_discard_exec_deps(e); return AVERROR(ENOMEM); } - e->sem_sig_val_dst = av_fast_realloc(e->sem_sig_val_dst, &e->sem_sig_val_dst_alloc, - (e->sem_sig_cnt + 1)*sizeof(*e->sem_sig_val_dst)); + e->sem_sig_val_dst = av_realloc_reuse(e->sem_sig_val_dst, &e->sem_sig_val_dst_alloc, + (e->sem_sig_cnt + 1)*sizeof(*e->sem_sig_val_dst)); if (!e->sem_sig_val_dst) { ff_vk_discard_exec_deps(e); return AVERROR(ENOMEM); @@ -569,8 +569,8 @@ int ff_vk_add_exec_dep(FFVulkanContext *s, FFVkExecContext *e, AVFrame *frame, e->sem_sig_cnt++; } - dst = av_fast_realloc(q->frame_deps, &q->frame_deps_alloc_size, - (q->nb_frame_deps + 1) * sizeof(*dst)); + dst = av_realloc_reuse(q->frame_deps, &q->frame_deps_alloc_size, + (q->nb_frame_deps + 1) * sizeof(*dst)); if (!dst) { ff_vk_discard_exec_deps(e); return AVERROR(ENOMEM); @@ -645,8 +645,8 @@ int ff_vk_add_dep_exec_ctx(FFVulkanContext *s, FFVkExecContext *e, if (!deps || !nb_deps) return 0; - dst = av_fast_realloc(q->buf_deps, &q->buf_deps_alloc_size, - (q->nb_buf_deps + nb_deps) * sizeof(*dst)); + dst = av_realloc_reuse(q->buf_deps, &q->buf_deps_alloc_size, + (q->nb_buf_deps + nb_deps) * sizeof(*dst)); if (!dst) goto err; diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index d1ea1e24fb..ae5ae551f2 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -143,12 +143,12 @@ typedef struct FFVkQueueCtx { /* Buffer dependencies */ AVBufferRef **buf_deps; int nb_buf_deps; - int buf_deps_alloc_size; + size_t buf_deps_alloc_size; /* Frame dependencies */ AVFrame **frame_deps; int nb_frame_deps; - int frame_deps_alloc_size; + size_t frame_deps_alloc_size; } FFVkQueueCtx; typedef struct FFVkExecContext { @@ -165,24 +165,24 @@ typedef struct FFVkExecContext { FFVulkanPipeline *bound_pl; VkSemaphore *sem_wait; - int sem_wait_alloc; /* Allocated sem_wait */ + size_t sem_wait_alloc; /* Allocated sem_wait */ int sem_wait_cnt; uint64_t *sem_wait_val; - int sem_wait_val_alloc; + size_t sem_wait_val_alloc; VkPipelineStageFlagBits *sem_wait_dst; - int sem_wait_dst_alloc; /* Allocated sem_wait_dst */ + size_t sem_wait_dst_alloc; /* Allocated sem_wait_dst */ VkSemaphore *sem_sig; - int sem_sig_alloc; /* Allocated sem_sig */ + size_t sem_sig_alloc; /* Allocated sem_sig */ int sem_sig_cnt; uint64_t *sem_sig_val; - int sem_sig_val_alloc; + size_t sem_sig_val_alloc; uint64_t **sem_sig_val_dst; - int sem_sig_val_dst_alloc; + size_t sem_sig_val_dst_alloc; } FFVkExecContext; typedef struct FFVulkanContext { @@ -222,7 +222,7 @@ typedef struct FFVulkanContext { int pipelines_num; void *scratch; /* Scratch memory used only in functions */ - unsigned int scratch_size; + size_t scratch_size; } FFVulkanContext; /* Identity mapping - r = r, b = b, g = g, a = a */ From patchwork Wed Sep 28 10:48:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38432 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp121579pzh; Wed, 28 Sep 2022 03:49:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ga4dTHm5sCIY1e3qJPkjJeKR+ImXS0b7rtxQkVSO7bmr7WNpKSrnbLAM7L003Ps6uj8hc X-Received: by 2002:a17:907:160d:b0:782:bc5d:162e with SMTP id hb13-20020a170907160d00b00782bc5d162emr21755098ejc.291.1664362151652; Wed, 28 Sep 2022 03:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664362151; cv=none; d=google.com; s=arc-20160816; b=qs2BbqRGrNXrAyVNdiO/DuyCHZXLRuJdjeCY7HJiu1jZRuyDSs1vE86tS9GCHzsFrg YfGfnhtRslXOlvtym8OvGDjTGTQNmyEnvt44vGNJanJlOD/bQgA6u8t1UMYZGg16Uw9s Yvur6vw5qM6afF6hUFLkB6/uN+9v++V5Gjxzt1m9FzV1Q5M5LsedCFzFRz1TJ5NQ+6ls fLin/LCbxSqESbUUUR1AsH/fY+7o77OOHkdYaS26Z7LtK6rdv+ZUH/t47D+VdajOUHb/ o4rKtLQSmGpp9o+rWsRvPU9l6SMZk6u7F16kmYgfqDi7UFiJQ+12SQZpPBRuHZSvKxa7 i9bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=75VZ62xjYzZoNnWb04J9tYZds3oMt9SwCRhi4/JT3II=; b=Utq50mcrOvmEFxkTsE8ruKzMGAr196CacdnHnmdw6vDAUPF9oY9QPhCjSomi50RJLJ dSRuc+QF1vyjnEWf0PITyeWIAgbTfjKVusnuGSBXg/mTpftL5Cst93pynE/3vx0Lz/0M uEujmLrCoHTZuro2mzmeWtcfhb5dFxlAr3YQ+WKaPU+n4mlyj3Ah4JyrjZXcJs/+gxVb Rdxad60llPWH8VusqrDmlXN+d5EFFfZjCTvfQ/ZudWL9EETvr8jbnS5ZeKlTtJTa5C6O ECVkJ3OSzr6sKPUUpQd97mXrrVPDvkX8cBS5UOUMnylluj1M3pn58TyCevWl2Rv08qzb ozRw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dd11-20020a1709069b8b00b00782faf12c6esi5058528ejc.78.2022.09.28.03.49.10; Wed, 28 Sep 2022 03:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D7A768BC3F; Wed, 28 Sep 2022 13:49:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 02D0668BA2F for ; Wed, 28 Sep 2022 13:49:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 64DED2404F7 for ; Wed, 28 Sep 2022 12:48:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 7yBzOtQ2h8im for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id B966F2400F4 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9C26C3A0D7F for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 12:48:51 +0200 Message-Id: <20220928104854.18629-3-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220928104854.18629-1-anton@khirnov.net> References: <20220928104854.18629-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/6] lavc: replace av_fast_realloc() with av_realloc_reuse() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4+nywfdJh1qr --- libavcodec/4xm.c | 6 +++--- libavcodec/audio_frame_queue.c | 3 ++- libavcodec/audio_frame_queue.h | 2 +- libavcodec/av1_parse.c | 2 +- libavcodec/av1_parse.h | 2 +- libavcodec/dirac_parser.c | 10 +++++----- libavcodec/dxva2_av1.c | 6 +++--- libavcodec/flac_parser.c | 6 +++--- libavcodec/h2645_parse.c | 2 +- libavcodec/h2645_parse.h | 2 +- libavcodec/libaomenc.c | 10 +++++----- libavcodec/librav1e.c | 5 +++-- libavcodec/libtheoraenc.c | 5 +++-- libavcodec/libvpxenc.c | 10 +++++----- libavcodec/libx264.c | 5 +++-- libavcodec/libx265.c | 8 ++++---- libavcodec/movtextenc.c | 8 ++++---- libavcodec/nvdec.c | 4 ++-- libavcodec/nvdec.h | 4 ++-- libavcodec/nvdec_av1.c | 8 ++++---- libavcodec/nvdec_h264.c | 8 ++++---- libavcodec/nvdec_hevc.c | 8 ++++---- libavcodec/nvenc.c | 18 +++++++++--------- libavcodec/nvenc.h | 2 +- libavcodec/parser.c | 12 ++++++------ libavcodec/parser.h | 2 +- libavcodec/shorten.c | 10 +++++----- libavcodec/vdpau.c | 4 ++-- libavcodec/vdpau_internal.h | 2 +- libavcodec/videotoolbox.c | 12 ++++++------ libavcodec/vt_internal.h | 2 +- 31 files changed, 96 insertions(+), 92 deletions(-) diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index 5636fdef2d..e523a6ea96 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -129,7 +129,7 @@ static VLC block_type_vlc[2][4]; typedef struct CFrameBuffer { - unsigned int allocated_size; + size_t allocated_size; unsigned int size; int id; uint8_t *data; @@ -895,8 +895,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture, if (data_size > UINT_MAX - cfrm->size - AV_INPUT_BUFFER_PADDING_SIZE) return AVERROR_INVALIDDATA; - cfrm->data = av_fast_realloc(cfrm->data, &cfrm->allocated_size, - cfrm->size + data_size + AV_INPUT_BUFFER_PADDING_SIZE); + cfrm->data = av_realloc_reuse(cfrm->data, &cfrm->allocated_size, + cfrm->size + data_size + AV_INPUT_BUFFER_PADDING_SIZE); // explicit check needed as memcpy below might not catch a NULL if (!cfrm->data) { av_log(f->avctx, AV_LOG_ERROR, "realloc failure\n"); diff --git a/libavcodec/audio_frame_queue.c b/libavcodec/audio_frame_queue.c index 08b4b368c7..bd92fe23c0 100644 --- a/libavcodec/audio_frame_queue.c +++ b/libavcodec/audio_frame_queue.c @@ -43,7 +43,8 @@ void ff_af_queue_close(AudioFrameQueue *afq) int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f) { - AudioFrame *new = av_fast_realloc(afq->frames, &afq->frame_alloc, sizeof(*afq->frames)*(afq->frame_count+1)); + AudioFrame *new = av_realloc_reuse(afq->frames, &afq->frame_alloc, + sizeof(*afq->frames)*(afq->frame_count+1)); if(!new) return AVERROR(ENOMEM); afq->frames = new; diff --git a/libavcodec/audio_frame_queue.h b/libavcodec/audio_frame_queue.h index d8076eae54..8aa82ba5cf 100644 --- a/libavcodec/audio_frame_queue.h +++ b/libavcodec/audio_frame_queue.h @@ -35,7 +35,7 @@ typedef struct AudioFrameQueue { int remaining_samples; AudioFrame *frames; unsigned frame_count; - unsigned frame_alloc; + size_t frame_alloc; } AudioFrameQueue; /** diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c index 59ea0bc6e7..baab46016b 100644 --- a/libavcodec/av1_parse.c +++ b/libavcodec/av1_parse.c @@ -70,7 +70,7 @@ int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void *lo if (new_size >= INT_MAX / sizeof(*tmp)) return AVERROR(ENOMEM); - tmp = av_fast_realloc(pkt->obus, &pkt->obus_allocated_size, new_size * sizeof(*tmp)); + tmp = av_realloc_reuse(pkt->obus, &pkt->obus_allocated_size, new_size * sizeof(*tmp)); if (!tmp) return AVERROR(ENOMEM); diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h index f4a5d2830e..20ce94105d 100644 --- a/libavcodec/av1_parse.h +++ b/libavcodec/av1_parse.h @@ -63,7 +63,7 @@ typedef struct AV1Packet { AV1OBU *obus; int nb_obus; int obus_allocated; - unsigned obus_allocated_size; + size_t obus_allocated_size; } AV1Packet; /** diff --git a/libavcodec/dirac_parser.c b/libavcodec/dirac_parser.c index 912f594243..1de08e43db 100644 --- a/libavcodec/dirac_parser.c +++ b/libavcodec/dirac_parser.c @@ -46,7 +46,7 @@ typedef struct DiracParseContext { int sync_offset; int header_bytes_needed; int overread_index; - int buffer_size; + size_t buffer_size; int index; uint8_t *buffer; int dirac_unit_size; @@ -156,8 +156,8 @@ static int dirac_combine_frame(AVCodecParserContext *s, AVCodecContext *avctx, if (next == -1) { /* Found a possible frame start but not a frame end */ void *new_buffer = - av_fast_realloc(pc->buffer, &pc->buffer_size, - pc->index + (*buf_size - pc->sync_offset)); + av_realloc_reuse(pc->buffer, &pc->buffer_size, + pc->index + (*buf_size - pc->sync_offset)); if (!new_buffer) return AVERROR(ENOMEM); pc->buffer = new_buffer; @@ -168,8 +168,8 @@ static int dirac_combine_frame(AVCodecParserContext *s, AVCodecContext *avctx, } else { /* Found a possible frame start and a possible frame end */ DiracParseUnit pu1, pu; - void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, - pc->index + next); + void *new_buffer = av_realloc_reuse(pc->buffer, &pc->buffer_size, + pc->index + next); if (!new_buffer) return AVERROR(ENOMEM); pc->buffer = new_buffer; diff --git a/libavcodec/dxva2_av1.c b/libavcodec/dxva2_av1.c index 228f72ba18..6520f82c9f 100644 --- a/libavcodec/dxva2_av1.c +++ b/libavcodec/dxva2_av1.c @@ -33,7 +33,7 @@ struct AV1DXVAContext { FFDXVASharedContext shared; - unsigned int bitstream_allocated; + size_t bitstream_allocated; uint8_t *bitstream_cache; }; @@ -321,8 +321,8 @@ static int dxva2_av1_decode_slice(AVCodecContext *avctx, } /* allocate an internal buffer */ - tmp = av_fast_realloc(ctx->bitstream_cache, &ctx->bitstream_allocated, - ctx_pic->bitstream_size + size); + tmp = av_realloc_reuse(ctx->bitstream_cache, &ctx->bitstream_allocated, + ctx_pic->bitstream_size + size); if (!tmp) { return AVERROR(ENOMEM); } diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c index bd91cc1a05..c1a6529d3d 100644 --- a/libavcodec/flac_parser.c +++ b/libavcodec/flac_parser.c @@ -95,7 +95,7 @@ typedef struct FLACParseContext { can be verified */ int end_padded; /**< specifies if fifo_buf's end is padded */ uint8_t *wrap_buf; /**< general fifo read buffer when wrapped */ - int wrap_buf_allocated_size; /**< actual allocated size of the buffer */ + size_t wrap_buf_allocated_size;/**< actual allocated size of the buffer */ FLACFrameInfo last_fi; /**< last decoded frame header info */ int last_fi_valid; /**< set if last_fi is valid */ } FLACParseContext; @@ -160,7 +160,7 @@ static size_t flac_fifo_space(const FifoBuffer *f) * about a memory barrier for SMP. */ static uint8_t *flac_fifo_read_wrap(FLACParseContext *fpc, int offset, int len, - uint8_t **wrap_buf, int *allocated_size) + uint8_t **wrap_buf, size_t *allocated_size) { FifoBuffer *f = &fpc->fifo_buf; uint8_t *start = f->rptr + offset; @@ -171,7 +171,7 @@ static uint8_t *flac_fifo_read_wrap(FLACParseContext *fpc, int offset, int len, if (f->end - start >= len) return start; - tmp_buf = av_fast_realloc(*wrap_buf, allocated_size, len); + tmp_buf = av_realloc_reuse(*wrap_buf, allocated_size, len); if (!tmp_buf) { av_log(fpc->avctx, AV_LOG_ERROR, diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index 90944177c7..4fe71ec587 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -463,7 +463,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, if (new_size >= INT_MAX / sizeof(*pkt->nals)) return AVERROR(ENOMEM); - tmp = av_fast_realloc(pkt->nals, &pkt->nal_buffer_size, new_size * sizeof(*pkt->nals)); + tmp = av_realloc_reuse(pkt->nals, &pkt->nal_buffer_size, new_size * sizeof(*pkt->nals)); if (!tmp) return AVERROR(ENOMEM); diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h index 787ce971ee..ae5e298fe8 100644 --- a/libavcodec/h2645_parse.h +++ b/libavcodec/h2645_parse.h @@ -84,7 +84,7 @@ typedef struct H2645Packet { H2645RBSP rbsp; int nb_nals; int nals_allocated; - unsigned nal_buffer_size; + size_t nal_buffer_size; } H2645Packet; /** diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index bd576fdd3a..10c1b4001e 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -70,7 +70,7 @@ typedef struct AOMEncoderContext { struct aom_codec_ctx encoder; struct aom_image rawimg; struct aom_fixed_buf twopass_stats; - unsigned twopass_stats_size; + size_t twopass_stats_size; struct FrameListData *coded_frame_list; int cpu_used; int auto_alt_ref; @@ -1201,10 +1201,10 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out) case AOM_CODEC_STATS_PKT: { struct aom_fixed_buf *stats = &ctx->twopass_stats; - uint8_t *tmp = av_fast_realloc(stats->buf, - &ctx->twopass_stats_size, - stats->sz + - pkt->data.twopass_stats.sz); + uint8_t *tmp = av_realloc_reuse(stats->buf, + &ctx->twopass_stats_size, + stats->sz + + pkt->data.twopass_stats.sz); if (!tmp) { av_freep(&stats->buf); stats->sz = 0; diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c index 0601efed2c..6ce08a6fbb 100644 --- a/libavcodec/librav1e.c +++ b/libavcodec/librav1e.c @@ -45,6 +45,7 @@ typedef struct librav1eContext { uint8_t *pass_data; size_t pass_pos; + size_t pass_size_allocated; int pass_size; AVDictionary *rav1e_opts; @@ -116,8 +117,8 @@ static int get_stats(AVCodecContext *avctx, int eos) return 0; if (!eos) { - uint8_t *tmp = av_fast_realloc(ctx->pass_data, &ctx->pass_size, - ctx->pass_pos + buf->len); + uint8_t *tmp = av_realloc_reuse(ctx->pass_data, &ctx->pass_size_allocated, + ctx->pass_pos + buf->len); if (!tmp) { rav1e_data_unref(buf); return AVERROR(ENOMEM); diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c index da16c6372e..bdaa03cbe6 100644 --- a/libavcodec/libtheoraenc.c +++ b/libavcodec/libtheoraenc.c @@ -46,6 +46,7 @@ typedef struct TheoraContext { th_enc_ctx *t_state; uint8_t *stats; + size_t stats_size_allocated; int stats_size; int stats_offset; int uv_hshift; @@ -100,8 +101,8 @@ static int get_stats(AVCodecContext *avctx, int eos) return AVERROR_EXTERNAL; } if (!eos) { - void *tmp = av_fast_realloc(h->stats, &h->stats_size, - h->stats_offset + bytes); + void *tmp = av_realloc_reuse(h->stats, &h->stats_size_allocated, + h->stats_offset + bytes); if (!tmp) return AVERROR(ENOMEM); h->stats = tmp; diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 667cffc200..2d99b65ab0 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -80,7 +80,7 @@ typedef struct VPxEncoderContext { struct vpx_image rawimg_alpha; uint8_t is_alpha; struct vpx_fixed_buf twopass_stats; - unsigned twopass_stats_size; + size_t twopass_stats_size; int deadline; //i.e., RT/GOOD/BEST uint64_t sse[4]; int have_sse; /**< true if we have pending sse[] */ @@ -1368,10 +1368,10 @@ static int queue_frames(AVCodecContext *avctx, struct vpx_codec_ctx *encoder, uint8_t *tmp; if (!pkt_out) break; - tmp = av_fast_realloc(stats->buf, - &ctx->twopass_stats_size, - stats->sz + - pkt->data.twopass_stats.sz); + tmp = av_realloc_reuse(stats->buf, + &ctx->twopass_stats_size, + stats->sz + + pkt->data.twopass_stats.sz); if (!tmp) { av_freep(&stats->buf); stats->sz = 0; diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index ca0b5a145b..bbb013a698 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -359,7 +359,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, if (frame) { x264_sei_t *sei = &x4->pic.extra_sei; - unsigned int sei_data_size = 0; + size_t sei_data_size = 0; for (i = 0; i < x4->pic.img.i_plane; i++) { x4->pic.img.plane[i] = frame->data[i]; @@ -494,7 +494,8 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, x264_sei_payload_t *sei_payload; if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED) continue; - tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload)); + tmp = av_realloc_reuse(sei->payloads, &sei_data_size, + (sei->num_payloads + 1) * sizeof(*sei_payload)); if (!tmp) { free_picture(ctx); return AVERROR(ENOMEM); diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 4aa96e1f2d..fa54db25bd 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -54,7 +54,7 @@ typedef struct libx265Context { AVDictionary *x265_opts; void *sei_data; - int sei_data_size; + size_t sei_data_size; int udu_sei; /** @@ -555,9 +555,9 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED) continue; - tmp = av_fast_realloc(ctx->sei_data, - &ctx->sei_data_size, - (sei->numPayloads + 1) * sizeof(*sei_payload)); + tmp = av_realloc_reuse(ctx->sei_data, + &ctx->sei_data_size, + (sei->numPayloads + 1) * sizeof(*sei_payload)); if (!tmp) { av_freep(&x265pic.userData); av_freep(&x265pic.quantOffsets); diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 7aa74d7c9d..caeeba57e3 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -76,7 +76,7 @@ typedef struct { ASSStyle *ass_dialog_style; StyleBox *style_attributes; unsigned count; - unsigned style_attributes_bytes_allocated; + size_t style_attributes_bytes_allocated; StyleBox style_attributes_temp; AVBPrint buffer; HighlightBox hlit; @@ -354,9 +354,9 @@ static int mov_text_style_start(MovTextContext *s) // last style != defaults, end the style entry and start a new one if (s->count + 1 > FFMIN(SIZE_MAX / sizeof(*s->style_attributes), UINT16_MAX) || - !(tmp = av_fast_realloc(s->style_attributes, - &s->style_attributes_bytes_allocated, - (s->count + 1) * sizeof(*s->style_attributes)))) { + !(tmp = av_realloc_reuse(s->style_attributes, + &s->style_attributes_bytes_allocated, + (s->count + 1) * sizeof(*s->style_attributes)))) { mov_text_cleanup(s); av_bprint_clear(&s->buffer); s->box_flags &= ~STYL_BOX; diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index fbaedf0b6b..5bfef4d2d6 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -677,8 +677,8 @@ int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, NVDECContext *ctx = avctx->internal->hwaccel_priv_data; void *tmp; - tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, - (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); + tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated, + (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); if (!tmp) return AVERROR(ENOMEM); ctx->slice_offsets = tmp; diff --git a/libavcodec/nvdec.h b/libavcodec/nvdec.h index 66f3ca59e7..ce475702e2 100644 --- a/libavcodec/nvdec.h +++ b/libavcodec/nvdec.h @@ -58,12 +58,12 @@ typedef struct NVDECContext { uint8_t *bitstream; int bitstream_len; - unsigned int bitstream_allocated; + size_t bitstream_allocated; uint8_t *bitstream_internal; unsigned *slice_offsets; int nb_slices; - unsigned int slice_offsets_allocated; + size_t slice_offsets_allocated; int supports_444; } NVDECContext; diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c index 3bbcd76123..1409672748 100644 --- a/libavcodec/nvdec_av1.c +++ b/libavcodec/nvdec_av1.c @@ -293,8 +293,8 @@ static int nvdec_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, ctx->nb_slices = frame_header->tile_cols * frame_header->tile_rows; - tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, - ctx->nb_slices * 2 * sizeof(*ctx->slice_offsets)); + tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated, + ctx->nb_slices * 2 * sizeof(*ctx->slice_offsets)); if (!tmp) { return AVERROR(ENOMEM); } @@ -313,8 +313,8 @@ static int nvdec_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, return 0; } - tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated, - ctx->bitstream_len + size); + tmp = av_realloc_reuse(ctx->bitstream_internal, &ctx->bitstream_allocated, + ctx->bitstream_len + size); if (!tmp) { return AVERROR(ENOMEM); } diff --git a/libavcodec/nvdec_h264.c b/libavcodec/nvdec_h264.c index 116bd4fb5d..1f95470ce3 100644 --- a/libavcodec/nvdec_h264.c +++ b/libavcodec/nvdec_h264.c @@ -137,14 +137,14 @@ static int nvdec_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, const H264SliceContext *sl = &h->slice_ctx[0]; void *tmp; - tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated, - ctx->bitstream_len + size + 3); + tmp = av_realloc_reuse(ctx->bitstream, &ctx->bitstream_allocated, + ctx->bitstream_len + size + 3); if (!tmp) return AVERROR(ENOMEM); ctx->bitstream = tmp; - tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, - (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); + tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated, + (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); if (!tmp) return AVERROR(ENOMEM); ctx->slice_offsets = tmp; diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c index cd549d2ef6..002e8486c9 100644 --- a/libavcodec/nvdec_hevc.c +++ b/libavcodec/nvdec_hevc.c @@ -273,14 +273,14 @@ static int nvdec_hevc_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, NVDECContext *ctx = avctx->internal->hwaccel_priv_data; void *tmp; - tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated, - ctx->bitstream_len + size + 3); + tmp = av_realloc_reuse(ctx->bitstream, &ctx->bitstream_allocated, + ctx->bitstream_len + size + 3); if (!tmp) return AVERROR(ENOMEM); ctx->bitstream = tmp; - tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, - (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); + tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated, + (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); if (!tmp) return AVERROR(ENOMEM); ctx->slice_offsets = tmp; diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 11bd21f365..64d130fd5d 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -2202,9 +2202,9 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame) } if (a53_data) { - void *tmp = av_fast_realloc(ctx->sei_data, - &ctx->sei_data_size, - (sei_count + 1) * sizeof(*ctx->sei_data)); + void *tmp = av_realloc_reuse(ctx->sei_data, + &ctx->sei_data_size, + (sei_count + 1) * sizeof(*ctx->sei_data)); if (!tmp) { av_free(a53_data); res = AVERROR(ENOMEM); @@ -2228,9 +2228,9 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame) } if (tc_data) { - void *tmp = av_fast_realloc(ctx->sei_data, - &ctx->sei_data_size, - (sei_count + 1) * sizeof(*ctx->sei_data)); + void *tmp = av_realloc_reuse(ctx->sei_data, + &ctx->sei_data_size, + (sei_count + 1) * sizeof(*ctx->sei_data)); if (!tmp) { av_free(tc_data); res = AVERROR(ENOMEM); @@ -2255,9 +2255,9 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame) if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED) continue; - tmp = av_fast_realloc(ctx->sei_data, - &ctx->sei_data_size, - (sei_count + 1) * sizeof(*ctx->sei_data)); + tmp = av_realloc_reuse(ctx->sei_data, + &ctx->sei_data_size, + (sei_count + 1) * sizeof(*ctx->sei_data)); if (!tmp) { res = AVERROR(ENOMEM); goto error; diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 9eb129952e..17a80e2706 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -174,7 +174,7 @@ typedef struct NvencContext AVFifo *timestamp_list; NV_ENC_SEI_PAYLOAD *sei_data; - int sei_data_size; + size_t sei_data_size; struct { void *ptr; diff --git a/libavcodec/parser.c b/libavcodec/parser.c index 49de7e6a57..ba9af5daed 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -221,9 +221,9 @@ int ff_combine_frame(ParseContext *pc, int next, /* copy into buffer end return */ if (next == END_NOT_FOUND) { - void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, - *buf_size + pc->index + - AV_INPUT_BUFFER_PADDING_SIZE); + void *new_buffer = av_realloc_reuse(pc->buffer, &pc->buffer_size, + *buf_size + pc->index + + AV_INPUT_BUFFER_PADDING_SIZE); if (!new_buffer) { av_log(NULL, AV_LOG_ERROR, "Failed to reallocate parser buffer to %d\n", *buf_size + pc->index + AV_INPUT_BUFFER_PADDING_SIZE); @@ -243,9 +243,9 @@ int ff_combine_frame(ParseContext *pc, int next, /* append to buffer */ if (pc->index) { - void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, - next + pc->index + - AV_INPUT_BUFFER_PADDING_SIZE); + void *new_buffer = av_realloc_reuse(pc->buffer, &pc->buffer_size, + next + pc->index + + AV_INPUT_BUFFER_PADDING_SIZE); if (!new_buffer) { av_log(NULL, AV_LOG_ERROR, "Failed to reallocate parser buffer to %d\n", next + pc->index + AV_INPUT_BUFFER_PADDING_SIZE); pc->overread_index = diff --git a/libavcodec/parser.h b/libavcodec/parser.h index 2cee5ae4ff..908800fcce 100644 --- a/libavcodec/parser.h +++ b/libavcodec/parser.h @@ -29,7 +29,7 @@ typedef struct ParseContext{ uint8_t *buffer; int index; int last_index; - unsigned int buffer_size; + size_t buffer_size; uint32_t state; ///< contains the last few bytes in MSB order int frame_start_found; int overread; ///< the number of bytes which where irreversibly read from the next frame diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 1b2abd76b1..36b7349be3 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -97,7 +97,7 @@ typedef struct ShortenContext { uint8_t *bitstream; int bitstream_size; int bitstream_index; - unsigned int allocated_bitstream_size; + size_t allocated_bitstream_size; int header_size; uint8_t header[OUT_BUFFER_SIZE]; int version; @@ -535,8 +535,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (s->max_framesize == 0) { void *tmp_ptr; s->max_framesize = 8192; // should hopefully be enough for the first header - tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, - s->max_framesize + AV_INPUT_BUFFER_PADDING_SIZE); + tmp_ptr = av_realloc_reuse(s->bitstream, &s->allocated_bitstream_size, + s->max_framesize + AV_INPUT_BUFFER_PADDING_SIZE); if (!tmp_ptr) { s->max_framesize = 0; av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n"); @@ -585,8 +585,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame, void *tmp_ptr; max_framesize = FFMAX(s->max_framesize, s->blocksize * s->channels * 8); - tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, - max_framesize + AV_INPUT_BUFFER_PADDING_SIZE); + tmp_ptr = av_realloc_reuse(s->bitstream, &s->allocated_bitstream_size, + max_framesize + AV_INPUT_BUFFER_PADDING_SIZE); if (!tmp_ptr) { av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n"); return AVERROR(ENOMEM); diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c index 0bb793c010..a201b3024a 100644 --- a/libavcodec/vdpau.c +++ b/libavcodec/vdpau.c @@ -388,8 +388,8 @@ int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, { VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers; - buffers = av_fast_realloc(buffers, &pic_ctx->bitstream_buffers_allocated, - (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers)); + buffers = av_realloc_reuse(buffers, &pic_ctx->bitstream_buffers_allocated, + (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers)); if (!buffers) return AVERROR(ENOMEM); diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h index 347576e0c3..b0e97c0a6d 100644 --- a/libavcodec/vdpau_internal.h +++ b/libavcodec/vdpau_internal.h @@ -104,7 +104,7 @@ struct vdpau_picture_context { /** * Allocated size of the bitstream_buffers table. */ - int bitstream_buffers_allocated; + size_t bitstream_buffers_allocated; /** * Useful bitstream buffers in the bitstream buffers table. diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c index 1b1be8ddb4..c8d96f6794 100644 --- a/libavcodec/videotoolbox.c +++ b/libavcodec/videotoolbox.c @@ -76,9 +76,9 @@ int ff_videotoolbox_buffer_copy(VTContext *vtctx, { void *tmp; - tmp = av_fast_realloc(vtctx->bitstream, - &vtctx->allocated_size, - size); + tmp = av_realloc_reuse(vtctx->bitstream, + &vtctx->allocated_size, + size); if (!tmp) return AVERROR(ENOMEM); @@ -432,9 +432,9 @@ static int videotoolbox_common_decode_slice(AVCodecContext *avctx, VTContext *vtctx = avctx->internal->hwaccel_priv_data; void *tmp; - tmp = av_fast_realloc(vtctx->bitstream, - &vtctx->allocated_size, - vtctx->bitstream_size+size+4); + tmp = av_realloc_reuse(vtctx->bitstream, + &vtctx->allocated_size, + vtctx->bitstream_size+size+4); if (!tmp) return AVERROR(ENOMEM); diff --git a/libavcodec/vt_internal.h b/libavcodec/vt_internal.h index 9502d7c7dc..9cfd4722e5 100644 --- a/libavcodec/vt_internal.h +++ b/libavcodec/vt_internal.h @@ -30,7 +30,7 @@ typedef struct VTContext { int bitstream_size; // The reference size used for fast reallocation. - int allocated_size; + size_t allocated_size; // The core video buffer CVImageBufferRef frame; From patchwork Wed Sep 28 10:48:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38436 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp121848pzh; Wed, 28 Sep 2022 03:49:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uIC6bXEdnW5Qaxa9hGYZBsgOmGqvvMorNx3Ptlux5X9I3QHpTyznYjlxqMNMZ+zzkr0U9 X-Received: by 2002:aa7:d5cc:0:b0:456:f5f1:540 with SMTP id d12-20020aa7d5cc000000b00456f5f10540mr22250281eds.95.1664362187678; Wed, 28 Sep 2022 03:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664362187; cv=none; d=google.com; s=arc-20160816; b=0NKV/dc19UhoX1n/AR/oKl4UrWCIZSuHKL2BjHneWLvwOLxcQFfQTuPINU3wBzSEQ1 wgcMXC9sU5ZYtNIzd8kn5vn4JX1C59ZbUIVoY/4cGz6iCtU242Ya5yLOye7eYnBNcijg 4Kigx6A4+DatO9h5TtrMtNxaomuPKgTHZAWv5kH9aMZiuSCjx/WdQPA1yAeIybuDb/hx N9Uce3lDHdSyAf5HaXr8viF9RGh8PHYOjlzYKyu4eBaFOAguhZJfOm+SNneLT3h1EHNP FWMeQE1gRvEXKLX0woj4Fe422/YUsN32SukuOVZxmsBhYUJP3gXOae5sMhMV+D3CMeg1 5TUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=13q5jSkEG/gnCNeTcP7GPibLwcAohGRWNUG8dv5Q+HE=; b=koTKbOf8d+voPQdtSxK+r0C6tEkC9Ug9+Zkf9w8dohp2QuDi4sxVQwYAVgTl4jiPfR OF+JW9qeC9dCrZp/Al4nDyhVHgE3sc0At97pkp2q3nnLLHXSNAQnj+Da8HEpPCMTCYF6 5e9hTtgAF/Vj2gVoBj/PTR6MPcxLB4BoAbchMhe6iTdU1/pCBM7wM0bp3eSL1bpusw85 cSKN5M5MTllSNj5KA0urgxTuUDgBTaNhyvnsYT84jULhUgsDBveBWuC2oivTZo6PuynZ KmZ6bFjSl17XaZtmQIakp6thpDHkNPY9pvK8DkttRWJV28pdCHcB4EsTRWo8nrJfJx2o MLhA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t2-20020a056402524200b00457c9eddd10si3898866edd.617.2022.09.28.03.49.47; Wed, 28 Sep 2022 03:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A9F668BC07; Wed, 28 Sep 2022 13:49:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0CB0B68BA2F for ; Wed, 28 Sep 2022 13:49:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 999032404E4 for ; Wed, 28 Sep 2022 12:49:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NhvAk49Ia3n1 for ; Wed, 28 Sep 2022 12:48:59 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id C78302404F5 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9F1173A0DA0 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 12:48:52 +0200 Message-Id: <20220928104854.18629-4-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220928104854.18629-1-anton@khirnov.net> References: <20220928104854.18629-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] lavfi: replace av_fast_realloc() with av_realloc_reuse() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AL4ymDf9L5xf --- libavfilter/af_adelay.c | 4 ++-- libavfilter/asrc_afirsrc.c | 12 ++++++------ libavfilter/avf_showspectrum.c | 8 ++++---- libavfilter/f_drawgraph.c | 18 +++++++++--------- libavfilter/f_graphmonitor.c | 8 ++++---- libavfilter/f_reverse.c | 16 ++++++++-------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libavfilter/af_adelay.c b/libavfilter/af_adelay.c index 9e63e2d618..6eb2aa400c 100644 --- a/libavfilter/af_adelay.c +++ b/libavfilter/af_adelay.c @@ -31,7 +31,7 @@ typedef struct ChanDelay { int64_t delay; size_t delay_index; size_t index; - unsigned int samples_size; + size_t samples_size; uint8_t *samples; } ChanDelay; @@ -116,7 +116,7 @@ static int resize_samples_## name ##p(ChanDelay *d, int64_t new_delay) return 0; \ } \ \ - samples = (type *) av_fast_realloc(d->samples, &d->samples_size, new_delay * sizeof(type)); \ + samples = (type *) av_realloc_reuse(d->samples, &d->samples_size, new_delay * sizeof(type)); \ if (!samples) { \ return AVERROR(ENOMEM); \ } \ diff --git a/libavfilter/asrc_afirsrc.c b/libavfilter/asrc_afirsrc.c index 615242e0f5..ad65b7498b 100644 --- a/libavfilter/asrc_afirsrc.c +++ b/libavfilter/asrc_afirsrc.c @@ -43,9 +43,9 @@ typedef struct AudioFIRSourceContext { float *freq; float *magnitude; float *phase; - int freq_size; - int magnitude_size; - int phase_size; + size_t freq_size; + size_t magnitude_size; + size_t phase_size; int nb_freq; int nb_magnitude; int nb_phase; @@ -126,12 +126,12 @@ static av_cold int query_formats(AVFilterContext *ctx) return ff_set_common_samplerates_from_list(ctx, sample_rates); } -static int parse_string(char *str, float **items, int *nb_items, int *items_size) +static int parse_string(char *str, float **items, int *nb_items, size_t *items_size) { float *new_items; char *tail; - new_items = av_fast_realloc(NULL, items_size, 1 * sizeof(float)); + new_items = av_realloc_reuse(NULL, items_size, 1 * sizeof(float)); if (!new_items) return AVERROR(ENOMEM); *items = new_items; @@ -142,7 +142,7 @@ static int parse_string(char *str, float **items, int *nb_items, int *items_size do { (*items)[(*nb_items)++] = av_strtod(tail, &tail); - new_items = av_fast_realloc(*items, items_size, (*nb_items + 1) * sizeof(float)); + new_items = av_realloc_reuse(*items, items_size, (*nb_items + 1) * sizeof(float)); if (!new_items) return AVERROR(ENOMEM); *items = new_items; diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c index b111471116..a9ee8458f3 100644 --- a/libavfilter/avf_showspectrum.c +++ b/libavfilter/avf_showspectrum.c @@ -114,7 +114,7 @@ typedef struct ShowSpectrumContext { AVFrame **frames; unsigned int nb_frames; - unsigned int frames_size; + size_t frames_size; } ShowSpectrumContext; #define OFFSET(x) offsetof(ShowSpectrumContext, x) @@ -1300,8 +1300,8 @@ static int config_output(AVFilterLink *outlink) if (!s->in_frame) return AVERROR(ENOMEM); - s->frames = av_fast_realloc(NULL, &s->frames_size, - DEFAULT_LENGTH * sizeof(*(s->frames))); + s->frames = av_realloc_reuse(NULL, &s->frames_size, + DEFAULT_LENGTH * sizeof(*(s->frames))); if (!s->frames) return AVERROR(ENOMEM); @@ -1840,7 +1840,7 @@ static int showspectrumpic_filter_frame(AVFilterLink *inlink, AVFrame *insamples void *ptr; if (s->nb_frames + 1ULL > s->frames_size / sizeof(*(s->frames))) { - ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2); + ptr = av_realloc_reuse(s->frames, &s->frames_size, s->frames_size * 2); if (!ptr) return AVERROR(ENOMEM); s->frames = ptr; diff --git a/libavfilter/f_drawgraph.c b/libavfilter/f_drawgraph.c index 000255fc52..f616bd2c04 100644 --- a/libavfilter/f_drawgraph.c +++ b/libavfilter/f_drawgraph.c @@ -49,7 +49,7 @@ typedef struct DrawGraphContext { int prev_y[4]; int first[4]; float *values[4]; - int values_size[4]; + size_t values_size[4]; int nb_values; int64_t prev_pts; } DrawGraphContext; @@ -114,10 +114,10 @@ static av_cold int init(AVFilterContext *ctx) s->first[0] = s->first[1] = s->first[2] = s->first[3] = 1; if (s->slide == 4) { - s->values[0] = av_fast_realloc(NULL, &s->values_size[0], 2000); - s->values[1] = av_fast_realloc(NULL, &s->values_size[1], 2000); - s->values[2] = av_fast_realloc(NULL, &s->values_size[2], 2000); - s->values[3] = av_fast_realloc(NULL, &s->values_size[3], 2000); + s->values[0] = av_realloc_reuse(NULL, &s->values_size[0], 2000); + s->values[1] = av_realloc_reuse(NULL, &s->values_size[1], 2000); + s->values[2] = av_realloc_reuse(NULL, &s->values_size[2], 2000); + s->values[3] = av_realloc_reuse(NULL, &s->values_size[3], 2000); if (!s->values[0] || !s->values[1] || !s->values[2] || !s->values[3]) { @@ -174,22 +174,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) if (s->slide == 4 && s->nb_values >= s->values_size[0] / sizeof(float)) { float *ptr; - ptr = av_fast_realloc(s->values[0], &s->values_size[0], s->values_size[0] * 2); + ptr = av_realloc_reuse(s->values[0], &s->values_size[0], s->values_size[0] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[0] = ptr; - ptr = av_fast_realloc(s->values[1], &s->values_size[1], s->values_size[1] * 2); + ptr = av_realloc_reuse(s->values[1], &s->values_size[1], s->values_size[1] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[1] = ptr; - ptr = av_fast_realloc(s->values[2], &s->values_size[2], s->values_size[2] * 2); + ptr = av_realloc_reuse(s->values[2], &s->values_size[2], s->values_size[2] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[2] = ptr; - ptr = av_fast_realloc(s->values[3], &s->values_size[3], s->values_size[3] * 2); + ptr = av_realloc_reuse(s->values[3], &s->values_size[3], s->values_size[3] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[3] = ptr; diff --git a/libavfilter/f_graphmonitor.c b/libavfilter/f_graphmonitor.c index 016a707a27..3f0f35ea68 100644 --- a/libavfilter/f_graphmonitor.c +++ b/libavfilter/f_graphmonitor.c @@ -57,7 +57,7 @@ typedef struct GraphMonitorContext { uint8_t bg[4]; CacheItem *cache; - unsigned int cache_size; + size_t cache_size; unsigned int cache_index; } GraphMonitorContext; @@ -119,8 +119,8 @@ static av_cold int init(AVFilterContext *ctx) { GraphMonitorContext *s = ctx->priv; - s->cache = av_fast_realloc(NULL, &s->cache_size, - 8192 * sizeof(*(s->cache))); + s->cache = av_realloc_reuse(NULL, &s->cache_size, + 8192 * sizeof(*(s->cache))); if (!s->cache) return AVERROR(ENOMEM); @@ -314,7 +314,7 @@ static int draw_items(AVFilterContext *ctx, AVFrame *out, s->cache[s->cache_index].previous_pts_us = l->current_pts_us; if (s->cache_index + 1 >= s->cache_size / sizeof(*(s->cache))) { - void *ptr = av_fast_realloc(s->cache, &s->cache_size, s->cache_size * 2); + void *ptr = av_realloc_reuse(s->cache, &s->cache_size, s->cache_size * 2); if (!ptr) return AVERROR(ENOMEM); diff --git a/libavfilter/f_reverse.c b/libavfilter/f_reverse.c index 2c99557c75..301f36d823 100644 --- a/libavfilter/f_reverse.c +++ b/libavfilter/f_reverse.c @@ -31,8 +31,8 @@ typedef struct ReverseContext { int nb_frames; AVFrame **frames; - unsigned int frames_size; - unsigned int pts_size; + size_t frames_size; + size_t pts_size; int64_t *pts; int flush_idx; int64_t nb_samples; @@ -42,13 +42,13 @@ static av_cold int init(AVFilterContext *ctx) { ReverseContext *s = ctx->priv; - s->pts = av_fast_realloc(NULL, &s->pts_size, - DEFAULT_LENGTH * sizeof(*(s->pts))); + s->pts = av_realloc_reuse(NULL, &s->pts_size, + DEFAULT_LENGTH * sizeof(*(s->pts))); if (!s->pts) return AVERROR(ENOMEM); - s->frames = av_fast_realloc(NULL, &s->frames_size, - DEFAULT_LENGTH * sizeof(*(s->frames))); + s->frames = av_realloc_reuse(NULL, &s->frames_size, + DEFAULT_LENGTH * sizeof(*(s->frames))); if (!s->frames) { av_freep(&s->pts); return AVERROR(ENOMEM); @@ -77,14 +77,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) void *ptr; if (s->nb_frames + 1 > s->pts_size / sizeof(*(s->pts))) { - ptr = av_fast_realloc(s->pts, &s->pts_size, s->pts_size * 2); + ptr = av_realloc_reuse(s->pts, &s->pts_size, s->pts_size * 2); if (!ptr) return AVERROR(ENOMEM); s->pts = ptr; } if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) { - ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2); + ptr = av_realloc_reuse(s->frames, &s->frames_size, s->frames_size * 2); if (!ptr) return AVERROR(ENOMEM); s->frames = ptr; From patchwork Wed Sep 28 10:48:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38433 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp121655pzh; Wed, 28 Sep 2022 03:49:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5AiKB1ANMRBdsC2vjSTUUuCyVRhnLQwcoJOgxKr0lEP/FcLKhNc0oX5NwklOkJFck29RCj X-Received: by 2002:a05:6402:40cb:b0:451:2b71:9940 with SMTP id z11-20020a05640240cb00b004512b719940mr32754508edb.237.1664362161426; Wed, 28 Sep 2022 03:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664362161; cv=none; d=google.com; s=arc-20160816; b=zBwNrQzY7LP1sr58rtA2XqgNv3cdYxTblWUmz3J8brC9XxpB+61hbejUEizvX8KyXy mbVHrt7+oiTAXKauu0OAOSuyHSzfz6xaYKMZpSiBdx1JCQ917jddgvjlZXYZlKXKyFU7 BBi9/FtJjUyNuDJ00xBk0jrCWG6Eq5Cx7veDNSy5DsSe11U4oEBOqKtujNyaUSfEKbhp 4zhfGv9SP6Z5FHAtNWAcmrWNGCdyOvfq4IaUZim8rTec7EbwBJCq/NxTmm7G7wzfdPjl dwjJCZ5CNGMdWjrmFmDut8+rhpQC9oItxxYxLNpAqPvtFWJruw3ZgnrqwrJwU6Pxni1z x25g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=uiP5A30Y3rNGmqRXPQrZGXa+DCP4WtNeQaLrC8KOeFc=; b=W58FptycSBXEOHIGwnmdAub3/rBplU5arrmoIWEwYNe/+kWuwPO8ABRqBdvkzfXRgS thqO6JHvx2P7CWW4kkctt7reRR7tInvtDrdLRuMIwSEMbGWh3PEUG6ePCL3EzNSmQMMP uADtkC3Ua3SfAAFgj4+awaz0DkuGdsuU9myAt3AmxKhAhYApxfIPVJIfQyOyYMdBnUk2 CAi+0NoYSQxwLfDG+kkqPsyJqWmTogcNvqK0I/VaSwKonr45CAcYbVh/66jw8CVhAJ8Z h9aE6BvveRD1D/BIRKbkfFlTPyEI0J1tbHTqfsN25k6qczqiOgDj9syLKhXS/mL4EHXW 2lmw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z13-20020a50cd0d000000b004546a45e5d4si4026160edi.632.2022.09.28.03.49.21; Wed, 28 Sep 2022 03:49:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C6CC68BC54; Wed, 28 Sep 2022 13:49:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0638268BB56 for ; Wed, 28 Sep 2022 13:49:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 44B5D240591 for ; Wed, 28 Sep 2022 12:48:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 4DqX6m5Pxyu4 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id C912C2404F7 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AAEE23A13BB for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 12:48:53 +0200 Message-Id: <20220928104854.18629-5-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220928104854.18629-1-anton@khirnov.net> References: <20220928104854.18629-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/6] lavf: replace av_fast_realloc() with av_realloc_reuse() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Ui9SKysyH9+L --- libavformat/avc.c | 4 +-- libavformat/avc.h | 2 +- libavformat/bethsoftvid.c | 6 ++-- libavformat/cafenc.c | 8 ++--- libavformat/concat.c | 4 +-- libavformat/demux.h | 2 +- libavformat/hls.c | 4 +-- libavformat/imf.h | 2 +- libavformat/imf_cpl.c | 16 ++++----- libavformat/imfdec.c | 10 +++--- libavformat/internal.h | 2 +- libavformat/isom.h | 4 +-- libavformat/matroskadec.c | 8 ++--- libavformat/mms.c | 6 ++-- libavformat/mms.h | 2 +- libavformat/mov.c | 68 +++++++++++++++++++++------------------ libavformat/mxg.c | 8 ++--- libavformat/seek.c | 10 +++--- libavformat/spdifenc.c | 5 +-- libavformat/subtitles.c | 4 +-- libavformat/subtitles.h | 2 +- libavformat/wavenc.c | 4 +-- libavformat/wtvdec.c | 2 +- 23 files changed, 94 insertions(+), 89 deletions(-) diff --git a/libavformat/avc.c b/libavformat/avc.c index b0ceb1d2d8..cb5357fa4a 100644 --- a/libavformat/avc.c +++ b/libavformat/avc.c @@ -92,8 +92,8 @@ static int avc_parse_nal_units(AVIOContext *pb, NALUList *list, } else if (list->nb_nalus >= nalu_limit) { return AVERROR(ERANGE); } else { - NALU *tmp = av_fast_realloc(list->nalus, &list->nalus_array_size, - (list->nb_nalus + 1) * sizeof(*list->nalus)); + NALU *tmp = av_realloc_reuse(list->nalus, &list->nalus_array_size, + (list->nb_nalus + 1) * sizeof(*list->nalus)); if (!tmp) return AVERROR(ENOMEM); list->nalus = tmp; diff --git a/libavformat/avc.h b/libavformat/avc.h index 0ce95c194e..121155e0ba 100644 --- a/libavformat/avc.h +++ b/libavformat/avc.h @@ -33,7 +33,7 @@ typedef struct NALU { typedef struct NALUList { NALU *nalus; - unsigned nalus_array_size; + size_t nalus_array_size; unsigned nb_nalus; ///< valid entries in nalus } NALUList; diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c index cfb7d57332..1620fb5eaf 100644 --- a/libavformat/bethsoftvid.c +++ b/libavformat/bethsoftvid.c @@ -108,7 +108,7 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt, int code; int bytes_copied = 0; int position, duration, npixels; - unsigned int vidbuf_capacity; + size_t vidbuf_capacity; int ret = 0; AVStream *st; @@ -153,8 +153,8 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt, } do{ - uint8_t *tmp = av_fast_realloc(vidbuf_start, &vidbuf_capacity, - vidbuf_nbytes + BUFFER_PADDING_SIZE); + uint8_t *tmp = av_realloc_reuse(vidbuf_start, &vidbuf_capacity, + vidbuf_nbytes + BUFFER_PADDING_SIZE); if (!tmp) { ret = AVERROR(ENOMEM); goto fail; diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c index b90811d46f..d8d98fc5aa 100644 --- a/libavformat/cafenc.c +++ b/libavformat/cafenc.c @@ -31,7 +31,7 @@ typedef struct { int64_t data; - int size_buffer_size; + size_t size_buffer_size; int size_entries_used; int packets; } CAFContext; @@ -226,9 +226,9 @@ static int caf_write_packet(AVFormatContext *s, AVPacket *pkt) if (alloc_size < 0) return AVERROR(ERANGE); - pkt_sizes = av_fast_realloc(st->priv_data, - &caf->size_buffer_size, - alloc_size); + pkt_sizes = av_realloc_reuse(st->priv_data, + &caf->size_buffer_size, + alloc_size); if (!pkt_sizes) return AVERROR(ENOMEM); st->priv_data = pkt_sizes; diff --git a/libavformat/concat.c b/libavformat/concat.c index dc0985e40c..60c0ae158c 100644 --- a/libavformat/concat.c +++ b/libavformat/concat.c @@ -214,7 +214,7 @@ static av_cold int concatf_open(URLContext *h, const char *uri, int flags) AVIOContext *in = NULL; const char *cursor; int64_t total_size = 0; - unsigned int nodes_size = 0; + size_t nodes_size = 0; size_t i = 0; int err; @@ -280,7 +280,7 @@ static av_cold int concatf_open(URLContext *h, const char *uri, int flags) break; } - nodes = av_fast_realloc(data->nodes, &nodes_size, sizeof(*nodes) * len); + nodes = av_realloc_reuse(data->nodes, &nodes_size, sizeof(*nodes) * len); if (!nodes) { ffurl_close(uc); err = AVERROR(ENOMEM); diff --git a/libavformat/demux.h b/libavformat/demux.h index 1f57e062f6..af461e5ebd 100644 --- a/libavformat/demux.h +++ b/libavformat/demux.h @@ -135,7 +135,7 @@ int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, */ int ff_add_index_entry(AVIndexEntry **index_entries, int *nb_index_entries, - unsigned int *index_entries_allocated_size, + size_t *index_entries_allocated_size, int64_t pos, int64_t timestamp, int size, int distance, int flags); void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance); diff --git a/libavformat/hls.c b/libavformat/hls.c index e622425e80..cb5f0ded7c 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -148,7 +148,7 @@ struct playlist { int64_t id3_mpegts_timestamp; /* in mpegts tb */ int64_t id3_offset; /* in stream original tb */ uint8_t* id3_buf; /* temp buffer for id3 parsing */ - unsigned int id3_buf_size; + size_t id3_buf_size; AVDictionary *id3_initial; /* data from first id3 tag */ int id3_found; /* ID3 tag found at some point */ int id3_changed; /* ID3 tag data has changed at some point */ @@ -1225,7 +1225,7 @@ static void intercept_id3(struct playlist *pls, uint8_t *buf, * both of those cases together with the possibility for multiple * tags would make the handling a bit complex. */ - pls->id3_buf = av_fast_realloc(pls->id3_buf, &pls->id3_buf_size, id3_buf_pos + taglen); + pls->id3_buf = av_realloc_reuse(pls->id3_buf, &pls->id3_buf_size, id3_buf_pos + taglen); if (!pls->id3_buf) break; memcpy(pls->id3_buf + id3_buf_pos, buf, tag_got_bytes); diff --git a/libavformat/imf.h b/libavformat/imf.h index 4271cd9582..a599e42d58 100644 --- a/libavformat/imf.h +++ b/libavformat/imf.h @@ -111,7 +111,7 @@ typedef struct FFIMFTrackFileVirtualTrack { FFIMFBaseVirtualTrack base; uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */ FFIMFTrackFileResource *resources; /**< Resource elements of the Virtual Track */ - unsigned int resources_alloc_sz; /**< Size of the resources buffer */ + size_t resources_alloc_sz; /**< Size of the resources buffer */ } FFIMFTrackFileVirtualTrack; /** diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c index 474db6b7f5..7ce82b485e 100644 --- a/libavformat/imf_cpl.c +++ b/libavformat/imf_cpl.c @@ -495,10 +495,10 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp if (resource_elem_count > UINT32_MAX || vt->resource_count > UINT32_MAX - resource_elem_count) return AVERROR(ENOMEM); - tmp = av_fast_realloc(vt->resources, - &vt->resources_alloc_sz, - (vt->resource_count + resource_elem_count) - * sizeof(FFIMFTrackFileResource)); + tmp = av_realloc_reuse(vt->resources, + &vt->resources_alloc_sz, + (vt->resource_count + resource_elem_count) + * sizeof(FFIMFTrackFileResource)); if (!tmp) { av_log(NULL, AV_LOG_ERROR, "Cannot allocate Main Audio Resources\n"); return AVERROR(ENOMEM); @@ -577,10 +577,10 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL || (cpl->main_image_2d_track->resource_count + resource_elem_count) > INT_MAX / sizeof(FFIMFTrackFileResource)) return AVERROR(ENOMEM); - tmp = av_fast_realloc(cpl->main_image_2d_track->resources, - &cpl->main_image_2d_track->resources_alloc_sz, - (cpl->main_image_2d_track->resource_count + resource_elem_count) - * sizeof(FFIMFTrackFileResource)); + tmp = av_realloc_reuse(cpl->main_image_2d_track->resources, + &cpl->main_image_2d_track->resources_alloc_sz, + (cpl->main_image_2d_track->resource_count + resource_elem_count) + * sizeof(FFIMFTrackFileResource)); if (!tmp) { av_log(NULL, AV_LOG_ERROR, "Cannot allocate Main Image Resources\n"); return AVERROR(ENOMEM); diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 4e60dcc4ba..38e5aa8a56 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -109,7 +109,7 @@ typedef struct IMFVirtualTrackPlaybackCtx { AVRational current_timestamp; /**< Current temporal position */ AVRational duration; /**< Overall duration */ uint32_t resource_count; /**< Number of resources (<= INT32_MAX) */ - unsigned int resources_alloc_sz; /**< Size of the buffer holding the resource */ + size_t resources_alloc_sz; /**< Size of the buffer holding the resource */ IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the resources */ int32_t current_resource_index; /**< Index of the current resource in resources, or < 0 if a current resource has yet to be selected */ @@ -473,10 +473,10 @@ static int open_track_file_resource(AVFormatContext *s, || (track->resource_count + track_file_resource->base.repeat_count) > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx)) return AVERROR(ENOMEM); - tmp = av_fast_realloc(track->resources, - &track->resources_alloc_sz, - (track->resource_count + track_file_resource->base.repeat_count) - * sizeof(IMFVirtualTrackResourcePlaybackCtx)); + tmp = av_realloc_reuse(track->resources, + &track->resources_alloc_sz, + (track->resource_count + track_file_resource->base.repeat_count) + * sizeof(IMFVirtualTrackResourcePlaybackCtx)); if (!tmp) return AVERROR(ENOMEM); track->resources = tmp; diff --git a/libavformat/internal.h b/libavformat/internal.h index ce837fefc7..0be3517ba1 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -251,7 +251,7 @@ typedef struct FFStream { AVIndexEntry *index_entries; /**< Only used if the format does not support seeking natively. */ int nb_index_entries; - unsigned int index_entries_allocated_size; + size_t index_entries_allocated_size; int64_t interleaver_chunk_size; int64_t interleaver_chunk_duration; diff --git a/libavformat/isom.h b/libavformat/isom.h index 64fb7065d5..c150c29143 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -151,7 +151,7 @@ typedef struct MOVFragmentIndexItem { } MOVFragmentIndexItem; typedef struct MOVFragmentIndex { - int allocated_size; + size_t allocated_size; int complete; int current; int nb_items; @@ -175,7 +175,7 @@ typedef struct MOVStreamContext { unsigned int sdtp_count; uint8_t *sdtp_data; unsigned int ctts_count; - unsigned int ctts_allocated_size; + size_t ctts_allocated_size; MOVCtts *ctts_data; unsigned int stsc_count; MOVStsc *stsc_data; diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d582f566a2..53311294f2 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -129,7 +129,7 @@ typedef const struct EbmlSyntax { typedef struct EbmlList { int nb_elem; - unsigned int alloc_elem_size; + size_t alloc_elem_size; void *elem; } EbmlList; @@ -1315,9 +1315,9 @@ static int ebml_parse(MatroskaDemuxContext *matroska, if ((unsigned)list->nb_elem + 1 >= UINT_MAX / syntax->list_elem_size) return AVERROR(ENOMEM); - newelem = av_fast_realloc(list->elem, - &list->alloc_elem_size, - (list->nb_elem + 1) * syntax->list_elem_size); + newelem = av_realloc_reuse(list->elem, + &list->alloc_elem_size, + (list->nb_elem + 1) * syntax->list_elem_size); if (!newelem) return AVERROR(ENOMEM); list->elem = newelem; diff --git a/libavformat/mms.c b/libavformat/mms.c index 16babc0954..8850d80a2f 100644 --- a/libavformat/mms.c +++ b/libavformat/mms.c @@ -102,9 +102,9 @@ int ff_mms_asf_header_parser(MMSContext *mms) //Please see function send_stream_selection_request(). if (mms->stream_num < MMS_MAX_STREAMS && 46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) { - mms->streams = av_fast_realloc(mms->streams, - &mms->nb_streams_allocated, - (mms->stream_num + 1) * sizeof(MMSStream)); + mms->streams = av_realloc_reuse(mms->streams, + &mms->nb_streams_allocated, + (mms->stream_num + 1) * sizeof(MMSStream)); if (!mms->streams) return AVERROR(ENOMEM); mms->streams[mms->stream_num].id = stream_id; diff --git a/libavformat/mms.h b/libavformat/mms.h index 57e3d7e18a..c53b63e54f 100644 --- a/libavformat/mms.h +++ b/libavformat/mms.h @@ -54,7 +54,7 @@ typedef struct MMSContext { /*@}*/ int stream_num; ///< stream numbers. - unsigned int nb_streams_allocated; ///< allocated size of streams + size_t nb_streams_allocated; ///< allocated size of streams } MMSContext; int ff_mms_asf_header_parser(MMSContext * mms); diff --git a/libavformat/mov.c b/libavformat/mov.c index 1f436e21d6..5c69fec4b2 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -81,7 +81,7 @@ typedef struct MOVParseTableEntry { static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom); static int mov_read_mfra(MOVContext *c, AVIOContext *f); -static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size, +static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, size_t* allocated_size, int count, int duration); static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb, @@ -1347,10 +1347,10 @@ static int update_frag_index(MOVContext *c, int64_t offset) // offset is not yet in frag index. // Insert new item at index (sorted by moof offset) - item = av_fast_realloc(c->frag_index.item, - &c->frag_index.allocated_size, - (c->frag_index.nb_items + 1) * - sizeof(*c->frag_index.item)); + item = av_realloc_reuse(c->frag_index.item, + &c->frag_index.allocated_size, + (c->frag_index.nb_items + 1) * + sizeof(*c->frag_index.item)); if (!item) return -1; c->frag_index.item = item; @@ -2975,7 +2975,8 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; MOVStreamContext *sc; - unsigned int i, entries, alloc_size = 0; + unsigned int i, entries; + size_t alloc_size = 0; int64_t duration = 0; int64_t total_sample_count = 0; int64_t current_dts = 0; @@ -3004,8 +3005,8 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) unsigned int sample_duration; unsigned int sample_count; unsigned int min_entries = FFMIN(FFMAX(i + 1, 1024 * 1024), entries); - MOVStts *stts_data = av_fast_realloc(sc->stts_data, &alloc_size, - min_entries * sizeof(*sc->stts_data)); + MOVStts *stts_data = av_realloc_reuse(sc->stts_data, &alloc_size, + min_entries * sizeof(*sc->stts_data)); if (!stts_data) { av_freep(&sc->stts_data); sc->stts_count = 0; @@ -3153,7 +3154,7 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (entries >= UINT_MAX / sizeof(*sc->ctts_data)) return AVERROR_INVALIDDATA; av_freep(&sc->ctts_data); - sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, entries * sizeof(*sc->ctts_data)); + sc->ctts_data = av_realloc_reuse(NULL, &sc->ctts_allocated_size, entries * sizeof(*sc->ctts_data)); if (!sc->ctts_data) return AVERROR(ENOMEM); @@ -3471,9 +3472,9 @@ static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, if (sti->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) return -1; - entries = av_fast_realloc(sti->index_entries, - &sti->index_entries_allocated_size, - requested_size); + entries = av_realloc_reuse(sti->index_entries, + &sti->index_entries_allocated_size, + requested_size); if (!entries) return -1; @@ -3510,7 +3511,7 @@ static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_ * Append a new ctts entry to ctts_data. * Returns the new ctts_count if successful, else returns -1. */ -static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size, +static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, size_t* allocated_size, int count, int duration) { MOVCtts *ctts_buf_new; @@ -3523,7 +3524,7 @@ static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, uns if ((unsigned)(*ctts_count) >= UINT_MAX / sizeof(MOVCtts) - 1) return -1; - ctts_buf_new = av_fast_realloc(*ctts_data, allocated_size, requested_size); + ctts_buf_new = av_realloc_reuse(*ctts_data, allocated_size, requested_size); if (!ctts_buf_new) return -1; @@ -4114,8 +4115,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st) return; sc->ctts_count = 0; sc->ctts_allocated_size = 0; - sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, - sc->sample_count * sizeof(*sc->ctts_data)); + sc->ctts_data = av_realloc_reuse(NULL, &sc->ctts_allocated_size, + sc->sample_count * sizeof(*sc->ctts_data)); if (!sc->ctts_data) { av_free(ctts_data_old); return; @@ -5177,7 +5178,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; requested_size = (sti->nb_index_entries + entries) * sizeof(AVIndexEntry); - new_entries = av_fast_realloc(sti->index_entries, + new_entries = av_realloc_reuse(sti->index_entries, &sti->index_entries_allocated_size, requested_size); if (!new_entries) @@ -5186,8 +5187,8 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) requested_size = (sti->nb_index_entries + entries) * sizeof(*sc->ctts_data); old_ctts_allocated_size = sc->ctts_allocated_size; - ctts_data = av_fast_realloc(sc->ctts_data, &sc->ctts_allocated_size, - requested_size); + ctts_data = av_realloc_reuse(sc->ctts_data, &sc->ctts_allocated_size, + requested_size); if (!ctts_data) return AVERROR(ENOMEM); sc->ctts_data = ctts_data; @@ -6368,7 +6369,8 @@ static int mov_read_senc(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVEncryptionIndex *encryption_index; MOVStreamContext *sc; int use_subsamples, ret; - unsigned int sample_count, i, alloc_size = 0; + unsigned int sample_count, i; + size_t alloc_size = 0; ret = get_current_encryption_info(c, &encryption_index, &sc); if (ret != 1) @@ -6389,8 +6391,8 @@ static int mov_read_senc(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (i = 0; i < sample_count; i++) { unsigned int min_samples = FFMIN(FFMAX(i + 1, 1024 * 1024), sample_count); - encrypted_samples = av_fast_realloc(encryption_index->encrypted_samples, &alloc_size, - min_samples * sizeof(*encrypted_samples)); + encrypted_samples = av_realloc_reuse(encryption_index->encrypted_samples, &alloc_size, + min_samples * sizeof(*encrypted_samples)); if (encrypted_samples) { encryption_index->encrypted_samples = encrypted_samples; @@ -6424,7 +6426,7 @@ static int mov_parse_auxiliary_info(MOVContext *c, MOVStreamContext *sc, AVIOCon int64_t prev_pos; size_t sample_count, sample_info_size, i; int ret = 0; - unsigned int alloc_size = 0; + size_t alloc_size = 0; if (encryption_index->nb_encrypted_samples) return 0; @@ -6445,8 +6447,8 @@ static int mov_parse_auxiliary_info(MOVContext *c, MOVStreamContext *sc, AVIOCon for (i = 0; i < sample_count && !pb->eof_reached; i++) { unsigned int min_samples = FFMIN(FFMAX(i + 1, 1024 * 1024), sample_count); - encrypted_samples = av_fast_realloc(encryption_index->encrypted_samples, &alloc_size, - min_samples * sizeof(*encrypted_samples)); + encrypted_samples = av_realloc_reuse(encryption_index->encrypted_samples, &alloc_size, + min_samples * sizeof(*encrypted_samples)); if (!encrypted_samples) { ret = AVERROR(ENOMEM); goto finish; @@ -6489,11 +6491,12 @@ static int mov_try_read_block(AVIOContext *pb, size_t size, uint8_t **data) { const unsigned int block_size = 1024 * 1024; uint8_t *buffer = NULL; - unsigned int alloc_size = 0, offset = 0; + size_t alloc_size = 0; + unsigned int offset = 0; while (offset < size) { unsigned int new_size = alloc_size >= INT_MAX - block_size ? INT_MAX : alloc_size + block_size; - uint8_t *new_buffer = av_fast_realloc(buffer, &alloc_size, new_size); + uint8_t *new_buffer = av_realloc_reuse(buffer, &alloc_size, new_size); unsigned int to_read = FFMIN(size, alloc_size) - offset; if (!new_buffer) { av_free(buffer); @@ -6591,7 +6594,7 @@ static int mov_read_saio(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc; int i, ret; unsigned int version, entry_count, aux_info_type, aux_info_param; - unsigned int alloc_size = 0; + size_t alloc_size = 0; ret = get_current_encryption_info(c, &encryption_index, &sc); if (ret != 1) @@ -6645,7 +6648,7 @@ static int mov_read_saio(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (i = 0; i < entry_count && !pb->eof_reached; i++) { unsigned int min_offsets = FFMIN(FFMAX(i + 1, 1024), entry_count); - auxiliary_offsets = av_fast_realloc( + auxiliary_offsets = av_realloc_reuse( encryption_index->auxiliary_offsets, &alloc_size, min_offsets * sizeof(*auxiliary_offsets)); if (!auxiliary_offsets) { @@ -6687,7 +6690,8 @@ static int mov_read_pssh(MOVContext *c, AVIOContext *pb, MOVAtom atom) uint8_t *side_data, *extra_data, *old_side_data; size_t side_data_size, old_side_data_size; int ret = 0; - unsigned int version, kid_count, extra_data_size, alloc_size = 0; + unsigned int version, kid_count, extra_data_size; + size_t alloc_size = 0; if (c->fc->nb_streams < 1) return 0; @@ -6715,8 +6719,8 @@ static int mov_read_pssh(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (unsigned int i = 0; i < kid_count && !pb->eof_reached; i++) { unsigned int min_kid_count = FFMIN(FFMAX(i + 1, 1024), kid_count); - key_ids = av_fast_realloc(info->key_ids, &alloc_size, - min_kid_count * sizeof(*key_ids)); + key_ids = av_realloc_reuse(info->key_ids, &alloc_size, + min_kid_count * sizeof(*key_ids)); if (!key_ids) { ret = AVERROR(ENOMEM); goto finish; diff --git a/libavformat/mxg.c b/libavformat/mxg.c index b160ccb9f9..bf0732d5fc 100644 --- a/libavformat/mxg.c +++ b/libavformat/mxg.c @@ -34,7 +34,7 @@ typedef struct MXGContext { uint8_t *buffer; uint8_t *buffer_ptr; uint8_t *soi_ptr; - unsigned int buffer_size; + size_t buffer_size; int64_t dts; unsigned int cache_size; } MXGContext; @@ -108,9 +108,9 @@ static int mxg_update_cache(AVFormatContext *s, unsigned int cache_size) if (current_pos > current_pos + cache_size) return AVERROR(ENOMEM); soi_pos = mxg->soi_ptr - mxg->buffer; - buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size, - current_pos + cache_size + - AV_INPUT_BUFFER_PADDING_SIZE); + buffer = av_realloc_reuse(mxg->buffer, &mxg->buffer_size, + current_pos + cache_size + + AV_INPUT_BUFFER_PADDING_SIZE); if (!buffer) return AVERROR(ENOMEM); mxg->buffer = buffer; diff --git a/libavformat/seek.c b/libavformat/seek.c index a236e285c0..f4dd44d3ed 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -61,7 +61,7 @@ void ff_reduce_index(AVFormatContext *s, int stream_index) int ff_add_index_entry(AVIndexEntry **index_entries, int *nb_index_entries, - unsigned int *index_entries_allocated_size, + size_t *index_entries_allocated_size, int64_t pos, int64_t timestamp, int size, int distance, int flags) { @@ -80,10 +80,10 @@ int ff_add_index_entry(AVIndexEntry **index_entries, if (is_relative(timestamp)) //FIXME this maintains previous behavior but we should shift by the correct offset once known timestamp -= RELATIVE_TS_BASE; - entries = av_fast_realloc(*index_entries, - index_entries_allocated_size, - (*nb_index_entries + 1) * - sizeof(AVIndexEntry)); + entries = av_realloc_reuse(*index_entries, + index_entries_allocated_size, + (*nb_index_entries + 1) * + sizeof(AVIndexEntry)); if (!entries) return -1; diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c index 2861f828b4..7fb2d3b417 100644 --- a/libavformat/spdifenc.c +++ b/libavformat/spdifenc.c @@ -70,7 +70,8 @@ typedef struct IEC61937Context { int extra_bswap; ///< extra bswap for payload (for LE DTS => standard BE DTS) uint8_t *hd_buf[2]; ///< allocated buffers to concatenate hd audio frames - int hd_buf_size; ///< size of the hd audio buffer (eac3, dts4) + size_t hd_buf_size_s; ///< size of the hd audio buffer (eac3) + int hd_buf_size; ///< size of the hd audio buffer (dts4) int hd_buf_count; ///< number of frames in the hd audio buffer (eac3) int hd_buf_filled; ///< amount of bytes in the hd audio buffer (eac3, truehd) int hd_buf_idx; ///< active hd buffer index (truehd) @@ -128,7 +129,7 @@ static int spdif_header_eac3(AVFormatContext *s, AVPacket *pkt) if (bsid > 10 && (pkt->data[4] & 0xc0) != 0xc0) /* fscod */ repeat = eac3_repeat[(pkt->data[4] & 0x30) >> 4]; /* numblkscod */ - tmp = av_fast_realloc(ctx->hd_buf[0], &ctx->hd_buf_size, ctx->hd_buf_filled + pkt->size); + tmp = av_realloc_reuse(ctx->hd_buf[0], &ctx->hd_buf_size_s, ctx->hd_buf_filled + pkt->size); if (!tmp) return AVERROR(ENOMEM); ctx->hd_buf[0] = tmp; diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index 3ba5e2b217..0ab2fbe582 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -125,8 +125,8 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, if (q->nb_subs >= INT_MAX/sizeof(*q->subs) - 1) return NULL; - subs = av_fast_realloc(q->subs, &q->allocated_size, - (q->nb_subs + 1) * sizeof(*q->subs)); + subs = av_realloc_reuse(q->subs, &q->allocated_size, + (q->nb_subs + 1) * sizeof(*q->subs)); if (!subs) return NULL; q->subs = subs; diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h index 4460efacf3..7a1f7fc339 100644 --- a/libavformat/subtitles.h +++ b/libavformat/subtitles.h @@ -102,8 +102,8 @@ void ff_text_read(FFTextReader *r, char *buf, size_t size); typedef struct { AVPacket **subs; ///< array of subtitles packets + size_t allocated_size; ///< allocated size for subs int nb_subs; ///< number of subtitles packets - int allocated_size; ///< allocated size for subs int current_sub_idx; ///< current position for the read packet callback enum sub_sort sort; ///< sort method to use when finalizing subtitles int keep_duplicates; ///< set to 1 to keep duplicated subtitle events diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c index b08f862cf9..92372e7ccf 100644 --- a/libavformat/wavenc.c +++ b/libavformat/wavenc.c @@ -72,7 +72,7 @@ typedef struct WAVMuxContext { int64_t maxpts; int16_t *peak_maxpos, *peak_maxneg; uint32_t peak_num_frames; - unsigned peak_outbuf_size; + size_t peak_outbuf_size; uint32_t peak_outbuf_bytes; unsigned size_increment; uint8_t *peak_output; @@ -200,7 +200,7 @@ static int peak_write_frame(AVFormatContext *s) wav->write_peak = PEAK_OFF; return AVERROR(ERANGE); } - tmp = av_fast_realloc(wav->peak_output, &wav->peak_outbuf_size, new_size); + tmp = av_realloc_reuse(wav->peak_output, &wav->peak_outbuf_size, new_size); if (!tmp) { wav->write_peak = PEAK_OFF; return AVERROR(ENOMEM); diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c index 98128b7201..3f17715385 100644 --- a/libavformat/wtvdec.c +++ b/libavformat/wtvdec.c @@ -331,7 +331,7 @@ typedef struct WtvContext { start of the 'timeline' file, not the file system (AVFormatContext->pb) */ AVIndexEntry *index_entries; int nb_index_entries; - unsigned int index_entries_allocated_size; + size_t index_entries_allocated_size; } WtvContext; /* WTV GUIDs */ From patchwork Wed Sep 28 10:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38434 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp121720pzh; Wed, 28 Sep 2022 03:49:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ViCs61lDFcJ7MSrK5lbgx5VrRbI2jW8RXnbsM9B2631Kr7k5CQbdsK3e18MGdBd1YCPE9 X-Received: by 2002:a17:907:7287:b0:783:5e47:33a0 with SMTP id dt7-20020a170907728700b007835e4733a0mr14034056ejc.449.1664362170567; Wed, 28 Sep 2022 03:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664362170; cv=none; d=google.com; s=arc-20160816; b=IVJG02kQVXkKu+0BgclD7phwwi8cP1Cqljg30L8TIh1aeyNrJQ6MEwu3maBjw2xlSz sQtYbTbVkmIez/aOofzDEIxnvPkR/UFlpHJaz2tpBSarMcaVRePvtthbyILhbF30P3x1 /tcHyJ6PEN9UGhCSpn2psKyN6+Mq2WbSZXgVLEzHQFT56h3O4FpT74NNEl6v2dsdY2a/ 4gFquwMps64C42jaTOYVL8YNL8X04qC2zP1Lk75yaUyGjTeyPLJx1IZa830vJS8Mxtz5 OiNqlq1Z77XwPzT20KA2DHeqWnfu5/iJJi87S5vIyobE3h8m5DKjN+pppPxNrUeWDlCK CZfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=nZlQ8lQNslkGxeFOhnQEjxYEv6MzO9dOHALXj8NmfsQ=; b=yKDJMXyfTqLOQbisgGSPdlU/tx4Xp+yixZrqSXK9XdxFyIMZnV9NwfbmrNZJ4oqbiJ weS7UupcA328VIWGfjGY2JTfLBkZLSnb6iffUSm/SIDappGkVFcmf+36sIdYHCGgzTAW c0ESiYcp//AOMgPOru6r0nteOXJ6EM+bFhtR37/BQmN/PTiOF37wtvw7XN41HC0R9Ldr 5b/gR5O2i+tiRFd/EV/YjjzI5rUcC0uuAPxtavfuaKF4SLtW4eDPzaTNBhFcjPYRrzj2 XZDT/4Rgt9Xt+0paFCqKGBSaNNUJBGi+adCIgEwqlsgeGECZvDnnPVv8xertMxbo7eo+ bvCA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z3-20020a1709063ac300b007819c9c27e9si3894649ejd.624.2022.09.28.03.49.29; Wed, 28 Sep 2022 03:49:30 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F339F68BC66; Wed, 28 Sep 2022 13:49:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 383D268BB56 for ; Wed, 28 Sep 2022 13:49:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C7BCE2400F4 for ; Wed, 28 Sep 2022 12:48:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id uyxBLNuNubbg for ; Wed, 28 Sep 2022 12:48:59 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id CDC482404F8 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B6BDA3A15EA for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 12:48:54 +0200 Message-Id: <20220928104854.18629-6-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220928104854.18629-1-anton@khirnov.net> References: <20220928104854.18629-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] sws: replace av_fast_realloc() with av_realloc_reuse() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: gfZl7O5WIJSc --- libswscale/swscale_internal.h | 2 +- libswscale/utils.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index abeebbb002..1566bb50fe 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -91,7 +91,7 @@ typedef struct Range { typedef struct RangeList { Range *ranges; unsigned int nb_ranges; - int ranges_allocated; + size_t ranges_allocated; } RangeList; int ff_range_add(RangeList *r, unsigned int start, unsigned int len); diff --git a/libswscale/utils.c b/libswscale/utils.c index 45baa22b23..67d1cd9fd5 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2570,8 +2570,8 @@ int ff_range_add(RangeList *rl, unsigned int start, unsigned int len) return AVERROR(EINVAL); } - tmp = av_fast_realloc(rl->ranges, &rl->ranges_allocated, - (rl->nb_ranges + 1) * sizeof(*rl->ranges)); + tmp = av_realloc_reuse(rl->ranges, &rl->ranges_allocated, + (rl->nb_ranges + 1) * sizeof(*rl->ranges)); if (!tmp) return AVERROR(ENOMEM); rl->ranges = tmp;