[FFmpeg-devel] [PATCH 1/2] Add av_fd_dump(): read from fd into buffer up to EOF

wm4 nfxjfg at googlemail.com
Wed Jun 25 10:01:05 CEST 2014


On Tue, 24 Jun 2014 17:25:47 +0200
Michael Niedermayer <michaelni at gmx.at> wrote:

> On Tue, Jun 24, 2014 at 04:27:27PM +0300, Andrey Utkin wrote:
> > ---

> > + * @param spare_trailing_bytes how many allocated bytes to hold for later
> > + * buffer finalization. Set to 0 if not needed, set to 1 if you need to
> > + * null-terminate the buffer.

This looks really weird. Maybe best to remove this parameter, and just
guarantee null-termination in case the contents are used as string?

> > + * @param buf_incr amount of bytes to increase the buffer size when needed
> 
> its probably better to increase the buffer by some factor like
> make it 10% bigger each time
> a constant addition is harder to choose when the file size isnt
> known

+1

Constant addition also isn't very efficient. You'll get file_size/N
reallocations.

Also, maybe use fstat() to estimate the file size? Then in the ideal
case, reallocations could be avoided completely. It's better not to
rely on the fstat() size completely. (It's subject to race conditions,
and won't work with FIFOs.)


More information about the ffmpeg-devel mailing list