diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-03-21 23:47:44 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-03-22 00:40:11 +0100 |
commit | 967facb6950549d0cc4e0ba79a056ebc6f93a049 (patch) | |
tree | 872266e5d486be0ab8cf9e378bf567c191fba71a /libavcodec/wmaenc.c | |
parent | f1fdd208cc0a1fce7aaaf6b0fe72b013525f49e0 (diff) | |
parent | 6aba117f1273c7704312c6d892c9f552fa0661bb (diff) | |
download | ffmpeg-967facb6950549d0cc4e0ba79a056ebc6f93a049.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (26 commits)
adxenc: use AVCodec.encode2()
adxenc: Use the AVFrame in ADXContext for coded_frame
indeo4: fix out-of-bounds function call.
configure: Restructure help output.
configure: Internal-only components should not be command-line selectable.
vorbisenc: use AVCodec.encode2()
libvorbis: use AVCodec.encode2()
libopencore-amrnbenc: use AVCodec.encode2()
ra144enc: use AVCodec.encode2()
nellymoserenc: use AVCodec.encode2()
roqaudioenc: use AVCodec.encode2()
libspeex: use AVCodec.encode2()
libvo_amrwbenc: use AVCodec.encode2()
libvo_aacenc: use AVCodec.encode2()
wmaenc: use AVCodec.encode2()
mpegaudioenc: use AVCodec.encode2()
libmp3lame: use AVCodec.encode2()
libgsmenc: use AVCodec.encode2()
libfaac: use AVCodec.encode2()
g726enc: use AVCodec.encode2()
...
Conflicts:
configure
libavcodec/Makefile
libavcodec/ac3enc.c
libavcodec/adxenc.c
libavcodec/libgsm.c
libavcodec/libvorbis.c
libavcodec/vorbisenc.c
libavcodec/wmaenc.c
tests/ref/acodec/g722
tests/ref/lavf/asf
tests/ref/lavf/ffm
tests/ref/lavf/mkv
tests/ref/lavf/mpg
tests/ref/lavf/rm
tests/ref/lavf/ts
tests/ref/seek/lavf_asf
tests/ref/seek/lavf_ffm
tests/ref/seek/lavf_mkv
tests/ref/seek/lavf_mpg
tests/ref/seek/lavf_rm
tests/ref/seek/lavf_ts
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/wmaenc.c')
-rw-r--r-- | libavcodec/wmaenc.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c index 019176a6d4..0b252663ed 100644 --- a/libavcodec/wmaenc.c +++ b/libavcodec/wmaenc.c @@ -20,6 +20,7 @@ */ #include "avcodec.h" +#include "internal.h" #include "wma.h" #include "libavutil/avassert.h" @@ -87,7 +88,12 @@ static int encode_init(AVCodecContext * avctx){ avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate / s->frame_len; //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", s->block_align, avctx->bit_rate, s->frame_len, avctx->sample_rate); - avctx->frame_size= s->frame_len; + avctx->frame_size = avctx->delay = s->frame_len; + +#if FF_API_OLD_ENCODE_AUDIO + avctx->coded_frame = &s->frame; + avcodec_get_frame_defaults(avctx->coded_frame); +#endif return 0; } @@ -341,16 +347,17 @@ static int encode_frame(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], return put_bits_count(&s->pb)/8 - s->block_align; } -static int encode_superframe(AVCodecContext *avctx, - unsigned char *buf, int buf_size, void *data){ +static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt, + const AVFrame *frame, int *got_packet_ptr) +{ WMACodecContext *s = avctx->priv_data; - const short *samples = data; - int i, total_gain; + const int16_t *samples = (const int16_t *)frame->data[0]; + int i, total_gain, ret; s->block_len_bits= s->frame_len_bits; //required by non variable block len s->block_len = 1 << s->block_len_bits; - apply_window_and_mdct(avctx, samples, avctx->frame_size); + apply_window_and_mdct(avctx, samples, frame->nb_samples); if (s->ms_stereo) { float a, b; @@ -364,24 +371,25 @@ static int encode_superframe(AVCodecContext *avctx, } } - if (buf_size < 2 * MAX_CODED_SUPERFRAME_SIZE) { - av_log(avctx, AV_LOG_ERROR, "output buffer size is too small\n"); - return AVERROR(EINVAL); + if ((ret = ff_alloc_packet(avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE))) { + av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + return ret; } #if 1 total_gain= 128; for(i=64; i; i>>=1){ - int error= encode_frame(s, s->coefs, buf, buf_size, total_gain-i); + int error = encode_frame(s, s->coefs, avpkt->data, avpkt->size, + total_gain - i); if(error<0) total_gain-= i; } #else total_gain= 90; - best= encode_frame(s, s->coefs, buf, buf_size, total_gain); + best = encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain); for(i=32; i; i>>=1){ - int scoreL= encode_frame(s, s->coefs, buf, buf_size, total_gain-i); - int scoreR= encode_frame(s, s->coefs, buf, buf_size, total_gain+i); + int scoreL = encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain - i); + int scoreR = encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain + i); av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, total_gain); if(scoreL < FFMIN(best, scoreR)){ best = scoreL; @@ -393,7 +401,7 @@ static int encode_superframe(AVCodecContext *avctx, } #endif - encode_frame(s, s->coefs, buf, buf_size, total_gain); + encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain); av_assert0((put_bits_count(&s->pb) & 7) == 0); i= s->block_align - (put_bits_count(&s->pb)+7)/8; av_assert0(i>=0); @@ -402,7 +410,13 @@ static int encode_superframe(AVCodecContext *avctx, flush_put_bits(&s->pb); av_assert0(put_bits_ptr(&s->pb) - s->pb.buf == s->block_align); - return s->block_align; + + if (frame->pts != AV_NOPTS_VALUE) + avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay); + + avpkt->size = s->block_align; + *got_packet_ptr = 1; + return 0; } AVCodec ff_wmav1_encoder = { @@ -411,7 +425,7 @@ AVCodec ff_wmav1_encoder = { .id = CODEC_ID_WMAV1, .priv_data_size = sizeof(WMACodecContext), .init = encode_init, - .encode = encode_superframe, + .encode2 = encode_superframe, .close = ff_wma_end, .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"), @@ -423,7 +437,7 @@ AVCodec ff_wmav2_encoder = { .id = CODEC_ID_WMAV2, .priv_data_size = sizeof(WMACodecContext), .init = encode_init, - .encode = encode_superframe, + .encode2 = encode_superframe, .close = ff_wma_end, .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"), |