mem: Add av_realloc_array and av_reallocp_array

These help avoiding overflows and simplify error handling.

Signed-off-by: Martin Storsjö <martin@martin.st>
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>
movenc: Increase the cluster array allocation by doubling

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>
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@martin.st>