diff options
author | Peter Belkner <pbelkner@snafu.de> | 2011-04-19 12:00:01 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-04-19 13:25:05 +0200 |
commit | 39e69d0b88bf521097feeaa2ec5f390dd1e27723 (patch) | |
tree | 4e11770737f969da8fd005afac22953c53dc8378 /libavcodec | |
parent | 22fa406f384eb9d825b1d691332e1f928750d55b (diff) | |
download | ffmpeg-39e69d0b88bf521097feeaa2ec5f390dd1e27723.tar.gz |
32bit libmp3lame support.
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/libmp3lame.c | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 086c7dc7f9..5cfb122903 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -34,6 +34,10 @@ typedef struct Mp3AudioContext { int stereo; uint8_t buffer[BUFFER_SIZE]; int buffer_index; + struct { + int *left; + int *right; + } s32_data; } Mp3AudioContext; static av_cold int MP3lame_encode_init(AVCodecContext *avctx) @@ -76,6 +80,19 @@ static av_cold int MP3lame_encode_init(AVCodecContext *avctx) } avctx->coded_frame->key_frame= 1; + if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt && s->stereo) { + int nelem = 2 * avctx->frame_size; + + if(! (s->s32_data.left = av_malloc(nelem * sizeof(int)))) { + av_freep(&avctx->coded_frame); + lame_close(s->gfp); + + return AVERROR(ENOMEM); + } + + s->s32_data.right = s->s32_data.left + avctx->frame_size; + } + return 0; err_close: @@ -150,17 +167,35 @@ static int MP3lame_encode_frame(AVCodecContext *avctx, /* lame 3.91 dies on '1-channel interleaved' data */ - if(data){ + if(!data){ + lame_result= lame_encode_flush( + s->gfp, + s->buffer + s->buffer_index, + BUFFER_SIZE - s->buffer_index + ); +#if 2147483647 == INT_MAX + }else if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt){ if (s->stereo) { - lame_result = lame_encode_buffer_interleaved( + int32_t *rp = data; + int32_t *mp = rp + 2*avctx->frame_size; + int *wpl = s->s32_data.left; + int *wpr = s->s32_data.right; + + while (rp < mp) { + *wpl++ = *rp++; + *wpr++ = *rp++; + } + + lame_result = lame_encode_buffer_int( s->gfp, - data, + s->s32_data.left, + s->s32_data.right, avctx->frame_size, s->buffer + s->buffer_index, BUFFER_SIZE - s->buffer_index ); } else { - lame_result = lame_encode_buffer( + lame_result = lame_encode_buffer_int( s->gfp, data, data, @@ -169,12 +204,26 @@ static int MP3lame_encode_frame(AVCodecContext *avctx, BUFFER_SIZE - s->buffer_index ); } +#endif }else{ - lame_result= lame_encode_flush( + if (s->stereo) { + lame_result = lame_encode_buffer_interleaved( s->gfp, + data, + avctx->frame_size, s->buffer + s->buffer_index, BUFFER_SIZE - s->buffer_index ); + } else { + lame_result = lame_encode_buffer( + s->gfp, + data, + data, + avctx->frame_size, + s->buffer + s->buffer_index, + BUFFER_SIZE - s->buffer_index + ); + } } if(lame_result < 0){ @@ -210,6 +259,7 @@ static av_cold int MP3lame_encode_close(AVCodecContext *avctx) { Mp3AudioContext *s = avctx->priv_data; + av_freep(&s->s32_data.left); av_freep(&avctx->coded_frame); lame_close(s->gfp); @@ -226,7 +276,11 @@ AVCodec ff_libmp3lame_encoder = { MP3lame_encode_frame, MP3lame_encode_close, .capabilities= CODEC_CAP_DELAY, - .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16, +#if 2147483647 == INT_MAX + AV_SAMPLE_FMT_S32, +#endif + AV_SAMPLE_FMT_NONE}, .supported_samplerates= sSampleRates, .long_name= NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"), }; |