diff options
author | Andrey Semashev <andysem@mail.ru> | 2013-06-02 22:57:31 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2013-06-04 15:05:12 +0300 |
commit | 3b4feac1ec14f861bdd7f494f288f4d8dd7f449e (patch) | |
tree | 7eaccfd14d395c5c1c58ea3ccb98eab6f841dd63 /libavformat/movenc.c | |
parent | fc962d4e7a7c3d799d9364d5427564c22ee3880c (diff) | |
download | ffmpeg-3b4feac1ec14f861bdd7f494f288f4d8dd7f449e.tar.gz |
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@martin.st>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r-- | libavformat/movenc.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 4ed99b7ea3..e2591681a5 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; |