diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-10-18 10:29:17 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-10-18 10:48:00 +0200 |
commit | 17e4b0644b5ad13733bd863b14ab11ffa955009c (patch) | |
tree | 46cc4748ea765ca0553bac23a49d502c9aed5038 /libavcodec/libmp3lame.c | |
parent | eb19d89d8eb51f20299d59558d69d0f057583e7c (diff) | |
parent | 292d1e78743855404c7d07e3e7cb3f9c9ae6275b (diff) | |
download | ffmpeg-17e4b0644b5ad13733bd863b14ab11ffa955009c.tar.gz |
Merge commit '292d1e78743855404c7d07e3e7cb3f9c9ae6275b'
* commit '292d1e78743855404c7d07e3e7cb3f9c9ae6275b':
fate: dependencies for acodec tests
fate: dependencies for vsynth tests
fate: add macros useful for conditionally enabling things
libmp3lame: resize the output buffer if needed
Conflicts:
tests/fate/acodec.mak
tests/fate/vcodec.mak
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/libmp3lame.c')
-rw-r--r-- | libavcodec/libmp3lame.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index ce17e06ef8..b2669c837b 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,26 @@ typedef struct LAMEContext { } LAMEContext; +static int realloc_buffer(LAMEContext *s) +{ + if (!s->buffer || s->buffer_size - s->buffer_index < BUFFER_SIZE) { + uint8_t *tmp; + int new_size = s->buffer_index + 2 * BUFFER_SIZE; + + av_dlog(s->avctx, "resizing output buffer: %d -> %d\n", s->buffer_size, + new_size); + tmp = av_realloc(s->buffer, new_size); + if (!tmp) { + av_freep(&s->buffer); + s->buffer_size = s->buffer_index = 0; + return AVERROR(ENOMEM); + } + s->buffer = tmp; + s->buffer_size = new_size; + } + return 0; +} + static av_cold int mp3lame_encode_close(AVCodecContext *avctx) { LAMEContext *s = avctx->priv_data; @@ -62,6 +83,7 @@ static av_cold int mp3lame_encode_close(AVCodecContext *avctx) #endif av_freep(&s->samples_flt[0]); av_freep(&s->samples_flt[1]); + av_freep(&s->buffer); ff_af_queue_close(&s->afq); @@ -142,6 +164,10 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) } } + ret = realloc_buffer(s); + if (ret < 0) + goto error; + ff_dsputil_init(&s->dsp, avctx); return 0; @@ -155,7 +181,7 @@ error: (const buf_type *)buf_name[0], \ (const buf_type *)buf_name[1], frame->nb_samples, \ s->buffer + s->buffer_index, \ - BUFFER_SIZE - s->buffer_index); \ + s->buffer_size - s->buffer_index); \ } while (0) static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, @@ -198,11 +224,16 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (lame_result == -1) { av_log(avctx, AV_LOG_ERROR, "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", - s->buffer_index, BUFFER_SIZE - s->buffer_index); + s->buffer_index, s->buffer_size - s->buffer_index); } return -1; } s->buffer_index += lame_result; + ret = realloc_buffer(s); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "error reallocating output buffer\n"); + return ret; + } /* add current frame to the queue */ if (frame) { |