movenc: Increase the cluster array allocation by doubling
authorAndrey Semashev <andysem@mail.ru>
Mon, 3 Jun 2013 10:32:48 +0000 (13:32 +0300)
committerMartin Storsjö <martin@martin.st>
Tue, 4 Jun 2013 12:05:31 +0000 (15:05 +0300)
The previous allocation increment of 16384 meant that the cluster
array was allocated for 0.6 MB initially, which is a bit excessive
for cases with fragmentation where only a fraction of that ever
actually is used.

Therefore, start off at a much smaller value, and increase by
doubling (to avoid reallocating too often when writing long
non-fragmented mp4 files).

Bug-Id: 525
Signed-off-by: Martin Storsjö <martin@martin.st>
libavformat/movenc.c
libavformat/movenc.h

index e259168..e819d75 100644 (file)
@@ -2870,7 +2870,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if (trk->entry >= trk->cluster_capacity) {
-        unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE;
+        unsigned new_capacity = 2*(trk->entry + MOV_INDEX_CLUSTER_SIZE);
         if (av_reallocp_array(&trk->cluster, new_capacity,
                               sizeof(*trk->cluster)))
             return AVERROR(ENOMEM);
index 2aa8ffb..103b918 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "avformat.h"
 
-#define MOV_INDEX_CLUSTER_SIZE 16384
+#define MOV_INDEX_CLUSTER_SIZE 1024
 #define MOV_TIMESCALE 1000
 
 #define RTP_MAX_PACKET_SIZE 1450