summaryrefslogtreecommitdiff
path: root/libavcodec/ra144enc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-02-26 04:47:56 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-02-26 05:11:21 +0100
commit305e4b35ea7b643ab3ce8a37fa8cb464e8adeb3f (patch)
tree9e3773a72155b936e1ca66d4f089fa1b7eeeb791 /libavcodec/ra144enc.c
parent8e039121335f482234214bc4e0322ac72c1089ef (diff)
parent0a9efe4c6eb48bf863e2e630b3ad907a198961c5 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (34 commits) mlp_parser: fix the channel mask value used for the top surround channel vorbisenc: check all allocations for failure roqaudioenc: return AVERROR codes instead of -1 roqaudioenc: set correct bit rate roqaudioenc: use AVCodecContext.frame_size correctly. roqaudioenc: remove unneeded sample_fmt check ra144enc: use int16_t* for input samples rather than void* ra144enc: set AVCodecContext.coded_frame ra144enc: remove unneeded sample_fmt check nellymoserenc: set AVCodecContext.coded_frame nellymoserenc: improve error checking in encode_init() nellymoserenc: return AVERROR codes instead of -1 libvorbis: improve error checking in oggvorbis_encode_init() mpegaudioenc: return AVERROR codes instead of -1 libfaac: improve error checking and handling in Faac_encode_init() avutil: add AVERROR_UNKNOWN check for coded_frame allocation failure in several audio encoders audio encoders: do not set coded_frame->key_frame. g722enc: check for trellis data allocation error libspeexenc: export encoder delay through AVCodecContext.delay ... Conflicts: doc/APIchanges libavcodec/avcodec.h libavcodec/fraps.c libavcodec/kgv1dec.c libavcodec/libfaac.c libavcodec/libgsm.c libavcodec/libvorbis.c libavcodec/mlp_parser.c libavcodec/roqaudioenc.c libavcodec/vorbisenc.c libavutil/avutil.h libavutil/error.c libavutil/error.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/ra144enc.c')
-rw-r--r--libavcodec/ra144enc.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index 91bf7e174f..b3710e871b 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -33,15 +33,20 @@
#include "ra144.h"
+static av_cold int ra144_encode_close(AVCodecContext *avctx)
+{
+ RA144Context *ractx = avctx->priv_data;
+ ff_lpc_end(&ractx->lpc_ctx);
+ av_freep(&avctx->coded_frame);
+ return 0;
+}
+
+
static av_cold int ra144_encode_init(AVCodecContext * avctx)
{
RA144Context *ractx;
int ret;
- if (avctx->sample_fmt != AV_SAMPLE_FMT_S16) {
- av_log(avctx, AV_LOG_ERROR, "invalid sample format\n");
- return -1;
- }
if (avctx->channels != 1) {
av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n",
avctx->channels);
@@ -55,15 +60,19 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx)
ractx->avctx = avctx;
ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER,
FF_LPC_TYPE_LEVINSON);
- return ret;
-}
+ if (ret < 0)
+ goto error;
+ avctx->coded_frame = avcodec_alloc_frame();
+ if (!avctx->coded_frame) {
+ ret = AVERROR(ENOMEM);
+ goto error;
+ }
-static av_cold int ra144_encode_close(AVCodecContext *avctx)
-{
- RA144Context *ractx = avctx->priv_data;
- ff_lpc_end(&ractx->lpc_ctx);
return 0;
+error:
+ ra144_encode_close(avctx);
+ return ret;
}
@@ -432,6 +441,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame,
int16_t block_coefs[NBLOCKS][LPC_ORDER];
int lpc_refl[LPC_ORDER]; /**< reflection coefficients of the frame */
unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */
+ const int16_t *samples = data;
int energy = 0;
int i, idx;
@@ -506,7 +516,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame,
ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];
FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
for (i = 0; i < NBLOCKS * BLOCKSIZE; i++)
- ractx->curr_block[i] = *((int16_t *)data + i) >> 2;
+ ractx->curr_block[i] = samples[i] >> 2;
return FRAMESIZE;
}