On Tue, 16 Oct 2012 14:19:42 -0400, Justin Ruggles <[email protected]> wrote: > The LAME API documentation for the required buffer size refers to the size for > a single encode call. However, we store multiple frames in the same output > buffer but only read 1 frame at a time out of it. As a result, the buffer size > given in lame_encode_buffer() is actually smaller than what it should be. > Since we do not know how many frames it will end up buffering, it is best to > just reallocate if needed. > --- > libavcodec/libmp3lame.c | 34 +++++++++++++++++++++++++++++++--- > 1 files changed, 31 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c > index 871156f..f1a1952 100644 > --- a/libavcodec/libmp3lame.c > +++ b/libavcodec/libmp3lame.c > @@ -44,8 +44,9 @@ typedef struct LAMEContext { > AVClass *class; > AVCodecContext *avctx; > lame_global_flags *gfp; > - uint8_t buffer[BUFFER_SIZE]; > + uint8_t *buffer; > int buffer_index; > + int buffer_size; > int reservoir; > float *samples_flt[2]; > AudioFrameQueue afq; > @@ -53,6 +54,23 @@ typedef struct LAMEContext { > } LAMEContext; > > > +static int realloc_buffer(LAMEContext *s) > +{ > + if (!s->buffer || s->buffer_size - s->buffer_index < BUFFER_SIZE) { > + int new_size = s->buffer_index + 2 * BUFFER_SIZE; > + > + av_dlog(s->avctx, "resizing output buffer: %d -> %d\n", > s->buffer_size, > + new_size); > + s->buffer = av_realloc(s->buffer, new_size); > + if (!s->buffer) {
Leaking s->buffer here. -- Anton Khirnov _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
