[FFmpeg-devel] allocate enough memory for full audio frame in ffmpeg.c

Michael Niedermayer michaelni
Mon Jun 7 03:21:32 CEST 2010


On Sun, Jun 06, 2010 at 11:41:14AM -0400, Justin Ruggles wrote:
> Hi,
> 
> This patch fixes part of Issue 1921.
> 
> do_audio_out() in ffmpeg.c reads samples from the input to a FIFO until
> it has enough for a full output frame, then reads from that FIFO to
> audio_buf for encoding.  do_audio_out() is called for each input packet,
> and the allocated size of audio_buf is based on each single packet.
> However, it often takes multiple calls of do_audio_out() to fill the
> FIFO enough to encode a single output frame, so sometimes audio_buf is
> not large enough.  This patch ensures that audio_buf is large enough
> before reading from the FIFO.
> 
> This still doesn't fix the FLAC encoder part of Issue 1921, but that is
> a separate issue really.  The FLAC encoder is lazy and requires a large
> output buffer instead of checking the remaining buffer size before every
> write.
> 
> -Justin
> 

>  ffmpeg.c |    9 +++++++++
>  1 file changed, 9 insertions(+)
> 34c8e17759394eaba1c8c60f85b226de8f9e5d4c  audio_buf_size.patch
> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 23504)
> +++ ffmpeg.c	(working copy)
> @@ -962,6 +962,15 @@
>              AVPacket pkt;
>              av_init_packet(&pkt);
>  
> +            /* make sure audio_buf is large enough to hold the frame */
> +            if (allocated_audio_buf_size < frame_bytes) {
> +                av_fast_malloc(&audio_buf, &allocated_audio_buf_size, frame_bytes);

cant this size be considered where we allocate the buffer?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

> ... defining _GNU_SOURCE...
For the love of all that is holy, and some that is not, don't do that.
-- Luca & Mans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100607/be16afcd/attachment.pgp>



More information about the ffmpeg-devel mailing list