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

Justin Ruggles justin.ruggles
Thu Jun 10 21:41:32 CEST 2010


Michael Niedermayer wrote:

> On Thu, Jun 10, 2010 at 01:22:23PM -0400, Justin Ruggles wrote:
>> Michael Niedermayer wrote:
>>
>>> 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?
>> Yeah, that sounds better.  New patch attached.  This patch also changes
>> the last small frame encoding to also read the remaining FIFO data to
>> audio_buf, for the same reason.
>>
>> Thanks,
>> Justin
>>
> 
>>  ffmpeg.c |    9 +++++----
>>  1 file changed, 5 insertions(+), 4 deletions(-)
>> 931f26b48a130b93813b79f4e228ff2e608fe141  audio_buf_size_2.patch
> 
> ok if tested

tested and applied.

Thanks,
Justin




More information about the ffmpeg-devel mailing list