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 */