diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-03-05 00:02:58 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-03-05 00:15:55 +0100 |
commit | 2af8f2cea6c94eba3a15820194cb7374b366976a (patch) | |
tree | 634d34b8adf1c35cc1bb7c3eb1f2b49775ffbb56 /libavcodec/nellymoserenc.c | |
parent | 33a183df46355e4b281517e14c9b3c7e2b558dcf (diff) | |
parent | 3faa141d15bf9945fa54331e51b3f10b9970d5d2 (diff) | |
download | ffmpeg-2af8f2cea6c94eba3a15820194cb7374b366976a.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (27 commits)
cmdutils: use new avcodec_is_decoder/encoder() functions.
lavc: make codec_is_decoder/encoder() public.
lavc: deprecate AVCodecContext.sub_id.
libcdio: add a forgotten AVClass to the private context.
swscale: remove "cpu flags" from -sws_flags description.
proresenc: give user a possibility to alter some encoding parameters
vorbisenc: add output buffer overwrite protection
libopencore-amrnbenc: fix end-of-stream handling
ra144enc: fix end-of-stream handling
nellymoserenc: zero any leftover packet bytes
nellymoserenc: use proper MDCT overlap delay
qpeg: Use bytestream2 functions to prevent buffer overreads.
swscale: make %rep unconditional.
vp8: convert simple loopfilter x86 assembly to use named arguments.
vp8: convert idct x86 assembly to use named arguments.
vp8: convert mc x86 assembly to use named arguments.
vp8: convert loopfilter x86 assembly to use cpuflags().
vp8: convert idct/mc x86 assembly to use cpuflags().
swscale: remove now unnecessary hack.
x86inc: don't "bake" stack_offset in named arguments.
...
Conflicts:
cmdutils.c
doc/APIchanges
libavcodec/mpeg12.c
libavcodec/options.c
libavcodec/qpeg.c
libavcodec/utils.c
libavcodec/version.h
libavdevice/libcdio.c
tests/lavf-regression.sh
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/nellymoserenc.c')
-rw-r--r-- | libavcodec/nellymoserenc.c | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c index 8e018c1b7f..29ad7a2e26 100644 --- a/libavcodec/nellymoserenc.c +++ b/libavcodec/nellymoserenc.c @@ -52,13 +52,11 @@ typedef struct NellyMoserEncodeContext { AVCodecContext *avctx; int last_frame; - int bufsel; - int have_saved; DSPContext dsp; FFTContext mdct_ctx; DECLARE_ALIGNED(32, float, mdct_out)[NELLY_SAMPLES]; DECLARE_ALIGNED(32, float, in_buff)[NELLY_SAMPLES]; - DECLARE_ALIGNED(32, float, buf)[2][3 * NELLY_BUF_LEN]; ///< sample buffer + DECLARE_ALIGNED(32, float, buf)[3 * NELLY_BUF_LEN]; ///< sample buffer float (*opt )[NELLY_BANDS]; uint8_t (*path)[NELLY_BANDS]; } NellyMoserEncodeContext; @@ -115,16 +113,17 @@ static const uint8_t quant_lut_offset[8] = { 0, 0, 1, 4, 11, 32, 81, 230 }; static void apply_mdct(NellyMoserEncodeContext *s) { - s->dsp.vector_fmul(s->in_buff, s->buf[s->bufsel], ff_sine_128, NELLY_BUF_LEN); - s->dsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN, ff_sine_128, - NELLY_BUF_LEN); + float *in0 = s->buf; + float *in1 = s->buf + NELLY_BUF_LEN; + float *in2 = s->buf + 2 * NELLY_BUF_LEN; + + s->dsp.vector_fmul (s->in_buff, in0, ff_sine_128, NELLY_BUF_LEN); + s->dsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, in1, ff_sine_128, NELLY_BUF_LEN); s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out, s->in_buff); - s->dsp.vector_fmul(s->buf[s->bufsel] + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN, - ff_sine_128, NELLY_BUF_LEN); - s->dsp.vector_fmul_reverse(s->buf[s->bufsel] + 2 * NELLY_BUF_LEN, s->buf[1 - s->bufsel], ff_sine_128, - NELLY_BUF_LEN); - s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN); + s->dsp.vector_fmul (s->in_buff, in1, ff_sine_128, NELLY_BUF_LEN); + s->dsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, in2, ff_sine_128, NELLY_BUF_LEN); + s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->in_buff); } static av_cold int encode_end(AVCodecContext *avctx) @@ -161,6 +160,7 @@ static av_cold int encode_init(AVCodecContext *avctx) } avctx->frame_size = NELLY_SAMPLES; + avctx->delay = NELLY_BUF_LEN; s->avctx = avctx; if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0) goto error; @@ -363,38 +363,33 @@ static void encode_block(NellyMoserEncodeContext *s, unsigned char *output, int } flush_put_bits(&pb); + memset(put_bits_ptr(&pb), 0, output + output_size - put_bits_ptr(&pb)); } static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data) { NellyMoserEncodeContext *s = avctx->priv_data; const float *samples = data; - int i; if (s->last_frame) return 0; + memcpy(s->buf, s->buf + NELLY_SAMPLES, NELLY_BUF_LEN * sizeof(*s->buf)); if (data) { - memcpy(s->buf[s->bufsel], samples, avctx->frame_size * sizeof(*samples)); - for (i = avctx->frame_size; i < NELLY_SAMPLES; i++) { - s->buf[s->bufsel][i] = 0; - } - s->bufsel = 1 - s->bufsel; - if (!s->have_saved) { - s->have_saved = 1; - return 0; + memcpy(s->buf + NELLY_BUF_LEN, samples, avctx->frame_size * sizeof(*s->buf)); + if (avctx->frame_size < NELLY_SAMPLES) { + memset(s->buf + NELLY_BUF_LEN + avctx->frame_size, 0, + (NELLY_SAMPLES - avctx->frame_size) * sizeof(*s->buf)); + if (avctx->frame_size >= NELLY_BUF_LEN) + s->last_frame = 1; } } else { - memset(s->buf[s->bufsel], 0, sizeof(s->buf[0][0]) * NELLY_BUF_LEN); - s->bufsel = 1 - s->bufsel; + memset(s->buf + NELLY_BUF_LEN, 0, NELLY_SAMPLES * sizeof(*s->buf)); s->last_frame = 1; } - if (s->have_saved) { - encode_block(s, frame, buf_size); - return NELLY_BLOCK_LEN; - } - return 0; + encode_block(s, frame, buf_size); + return NELLY_BLOCK_LEN; } AVCodec ff_nellymoser_encoder = { |