[FFmpeg-cvslog] movenc: Grow the frag_info array in chunks
Andrey Semashev
git at videolan.org
Wed Jun 5 11:37:41 CEST 2013
ffmpeg | branch: master | Andrey Semashev <andysem at mail.ru> | Sun Jun 2 23:26:18 2013 +0300| [7c020e1ad37d27c9d5db4d714401f09c80e3cc44] | committer: Martin Storsjö
movenc: Grow the frag_info array in chunks
Previously it was grown one element at a time, which leads to
excessive reallocations.
Bug-Id: 525
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7c020e1ad37d27c9d5db4d714401f09c80e3cc44
---
libavformat/movenc.c | 11 ++++++++---
libavformat/movenc.h | 2 ++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index e819d75..1dde214 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2757,9 +2757,14 @@ static int mov_flush_fragment(AVFormatContext *s)
MOVFragmentInfo *info;
avio_flush(s->pb);
track->nb_frag_info++;
- track->frag_info = av_realloc(track->frag_info,
- sizeof(*track->frag_info) *
- track->nb_frag_info);
+ if (track->nb_frag_info >= track->frag_info_capacity) {
+ unsigned new_capacity = track->nb_frag_info + MOV_FRAG_INFO_ALLOC_INCREMENT;
+ if (av_reallocp_array(&track->frag_info,
+ new_capacity,
+ sizeof(*track->frag_info)))
+ return AVERROR(ENOMEM);
+ track->frag_info_capacity = new_capacity;
+ }
info = &track->frag_info[track->nb_frag_info - 1];
info->offset = avio_tell(s->pb);
info->time = mov->tracks[i].frag_start;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 103b918..d15d69c 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -26,6 +26,7 @@
#include "avformat.h"
+#define MOV_FRAG_INFO_ALLOC_INCREMENT 64
#define MOV_INDEX_CLUSTER_SIZE 1024
#define MOV_TIMESCALE 1000
@@ -121,6 +122,7 @@ typedef struct MOVTrack {
int nb_frag_info;
MOVFragmentInfo *frag_info;
+ unsigned frag_info_capacity;
struct {
int64_t struct_offset;
More information about the ffmpeg-cvslog
mailing list