mem: Add av_realloc_array and av_reallocp_array

These help avoiding overflows and simplify error handling.
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
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
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
avio: Add a function for reusing a dyn buffer

This avoids having to free and realloc a growing array for cases
where a similar buffer is used repeatedly.

Bug-Id: 525
movenc: Use avio_reset_dyn_buf for fragment data payloads

This avoids reallocations for subsequent fragments (when all
fragments are roughly the same size).

Bug-Id: 525