* [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()
@ 2022-09-28 10:48 Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse() Anton Khirnov
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Anton Khirnov @ 2022-09-28 10:48 UTC (permalink / raw)
To: ffmpeg-devel
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)
/**
* @}
--
2.35.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse()
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
@ 2022-09-28 10:48 ` Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 3/6] lavc: " Anton Khirnov
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2022-09-28 10:48 UTC (permalink / raw)
To: ffmpeg-devel
---
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 */
--
2.35.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH 3/6] lavc: replace av_fast_realloc() with av_realloc_reuse()
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse() Anton Khirnov
@ 2022-09-28 10:48 ` Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 4/6] lavfi: " Anton Khirnov
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2022-09-28 10:48 UTC (permalink / raw)
To: ffmpeg-devel
---
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;
--
2.35.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH 4/6] lavfi: replace av_fast_realloc() with av_realloc_reuse()
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse() Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 3/6] lavc: " Anton Khirnov
@ 2022-09-28 10:48 ` Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 5/6] lavf: " Anton Khirnov
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2022-09-28 10:48 UTC (permalink / raw)
To: ffmpeg-devel
---
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;
--
2.35.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH 5/6] lavf: replace av_fast_realloc() with av_realloc_reuse()
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
` (2 preceding siblings ...)
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 4/6] lavfi: " Anton Khirnov
@ 2022-09-28 10:48 ` Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 6/6] sws: " Anton Khirnov
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2022-09-28 10:48 UTC (permalink / raw)
To: ffmpeg-devel
---
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 */
--
2.35.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH 6/6] sws: replace av_fast_realloc() with av_realloc_reuse()
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
` (3 preceding siblings ...)
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 5/6] lavf: " Anton Khirnov
@ 2022-09-28 10:48 ` Anton Khirnov
2022-09-28 10:51 ` [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Rémi Denis-Courmont
2022-09-28 11:48 ` Tomas Härdin
6 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2022-09-28 10:48 UTC (permalink / raw)
To: ffmpeg-devel
---
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;
--
2.35.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
` (4 preceding siblings ...)
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 6/6] sws: " Anton Khirnov
@ 2022-09-28 10:51 ` Rémi Denis-Courmont
2022-09-28 10:55 ` Rémi Denis-Courmont
2022-09-28 11:48 ` Tomas Härdin
6 siblings, 1 reply; 11+ messages in thread
From: Rémi Denis-Courmont @ 2022-09-28 10:51 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Le 28 septembre 2022 13:48:49 GMT+03:00, Anton Khirnov <anton@khirnov.net> a écrit :
>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;
Isn't this leaking the existing allocation?
>+ }
>+
>+ 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)
>
> /**
> * @}
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()
2022-09-28 10:51 ` [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Rémi Denis-Courmont
@ 2022-09-28 10:55 ` Rémi Denis-Courmont
0 siblings, 0 replies; 11+ messages in thread
From: Rémi Denis-Courmont @ 2022-09-28 10:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Le 28 septembre 2022 13:51:43 GMT+03:00, "Rémi Denis-Courmont" <remi@remlab.net> a écrit :
>Le 28 septembre 2022 13:48:49 GMT+03:00, Anton Khirnov <anton@khirnov.net> a écrit :
>>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;
>
>Isn't this leaking the existing allocation?
>
>>+ }
>>+
>>+ 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)
>>
>> /**
>> * @}
>
>_______________________________________________
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>To unsubscribe, visit link above, or email
>ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Nevermind. This follows the realloc() convention that the caller retains the reference on failure.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
` (5 preceding siblings ...)
2022-09-28 10:51 ` [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Rémi Denis-Courmont
@ 2022-09-28 11:48 ` Tomas Härdin
2022-09-28 15:04 ` Anton Khirnov
2022-09-28 15:33 ` Andreas Rheinhardt
6 siblings, 2 replies; 11+ messages in thread
From: Tomas Härdin @ 2022-09-28 11:48 UTC (permalink / raw)
To: FFmpeg development discussions and patches
ons 2022-09-28 klockan 12:48 +0200 skrev Anton Khirnov:
>
> +/**
> + * 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);
Isn't it better to return int like av_realloc_array_reuse() and leave
*ptr and *size untouched on error just as it does? If we're in the
business of straightening this all out then having all functions work
the same is less mental load down the line.
/Tomas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()
2022-09-28 11:48 ` Tomas Härdin
@ 2022-09-28 15:04 ` Anton Khirnov
2022-09-28 15:33 ` Andreas Rheinhardt
1 sibling, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2022-09-28 15:04 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Tomas Härdin (2022-09-28 13:48:01)
> ons 2022-09-28 klockan 12:48 +0200 skrev Anton Khirnov:
> >
> > +/**
> > + * 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);
>
> Isn't it better to return int like av_realloc_array_reuse() and leave
> *ptr and *size untouched on error just as it does? If we're in the
> business of straightening this all out then having all functions work
> the same is less mental load down the line.
I suppose you're right, it's just more work to convert all the callers.
Will do and resend.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()
2022-09-28 11:48 ` Tomas Härdin
2022-09-28 15:04 ` Anton Khirnov
@ 2022-09-28 15:33 ` Andreas Rheinhardt
1 sibling, 0 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-09-28 15:33 UTC (permalink / raw)
To: ffmpeg-devel
Tomas Härdin:
> ons 2022-09-28 klockan 12:48 +0200 skrev Anton Khirnov:
>>
>> +/**
>> + * 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);
>
> Isn't it better to return int like av_realloc_array_reuse() and leave
> *ptr and *size untouched on error just as it does? If we're in the
> business of straightening this all out then having all functions work
> the same is less mental load down the line.
>
IMO size should be unchanged on error, but returning an int is IMO
overblown. I only did it for my version because there is the possibility
of the multiplication overflowing, but that is not the case here.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-09-28 15:33 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 10:48 [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse() Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 3/6] lavc: " Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 4/6] lavfi: " Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 5/6] lavf: " Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 6/6] sws: " Anton Khirnov
2022-09-28 10:51 ` [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Rémi Denis-Courmont
2022-09-28 10:55 ` Rémi Denis-Courmont
2022-09-28 11:48 ` Tomas Härdin
2022-09-28 15:04 ` Anton Khirnov
2022-09-28 15:33 ` Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git