[FFmpeg-cvslog] movenc: Keep track of the allocated size for the cluster array

Andrey Semashev git at videolan.org
Wed Jun 5 11:26:22 CEST 2013


ffmpeg | branch: master | Andrey Semashev <andysem at mail.ru> | Sun Jun  2 22:57:31 2013 +0300| [3b4feac1ec14f861bdd7f494f288f4d8dd7f449e] | committer: Martin Storsjö

movenc: Keep track of the allocated size for the cluster array

When writing fragmented mp4, the cluster array is reset when a
fragment is written. Instead of starting off reallocating the
array only based on the number of current elements in it, keep
track of how many elements there were allocated earlier.

This avoids reallocating this array needlessly when writing
fragmented mp4 files.

Bug-Id: 525
Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3b4feac1ec14f861bdd7f494f288f4d8dd7f449e
---

 libavformat/movenc.c |   10 ++++++----
 libavformat/movenc.h |    1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4ed99b7..e259168 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2869,10 +2869,12 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
         memcpy(trk->vos_data, pkt->data, size);
     }
 
-    if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) {
-        trk->cluster = av_realloc(trk->cluster, (trk->entry + MOV_INDEX_CLUSTER_SIZE) * sizeof(*trk->cluster));
-        if (!trk->cluster)
-            return -1;
+    if (trk->entry >= trk->cluster_capacity) {
+        unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE;
+        if (av_reallocp_array(&trk->cluster, new_capacity,
+                              sizeof(*trk->cluster)))
+            return AVERROR(ENOMEM);
+        trk->cluster_capacity = new_capacity;
     }
 
     trk->cluster[trk->entry].pos = avio_tell(pb) - size;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 879c942a..2aa8ffb 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -93,6 +93,7 @@ typedef struct MOVTrack {
     int         vos_len;
     uint8_t     *vos_data;
     MOVIentry   *cluster;
+    unsigned    cluster_capacity;
     int         audio_vbr;
     int         height; ///< active picture (w/o VBI) height for D-10/IMX
     uint32_t    tref_tag;



More information about the ffmpeg-cvslog mailing list