summaryrefslogtreecommitdiff
path: root/libavcodec/libfaac.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/libfaac.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/libfaac.c')
-rw-r--r--libavcodec/libfaac.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c
index 31dc1a41ed..4fa570e155 100644
--- a/libavcodec/libfaac.c
+++ b/libavcodec/libfaac.c
@@ -38,28 +38,47 @@ static const int channel_maps[][6] = {
{ 2, 0, 1, 4, 5, 3 }, //< C L R Ls Rs LFE
};
+static av_cold int Faac_encode_close(AVCodecContext *avctx)
+{
+ FaacAudioContext *s = avctx->priv_data;
+
+ av_freep(&avctx->coded_frame);
+ av_freep(&avctx->extradata);
+
+ if (s->faac_handle)
+ faacEncClose(s->faac_handle);
+ return 0;
+}
+
static av_cold int Faac_encode_init(AVCodecContext *avctx)
{
FaacAudioContext *s = avctx->priv_data;
faacEncConfigurationPtr faac_cfg;
unsigned long samples_input, max_bytes_output;
+ int ret;
/* number of channels */
if (avctx->channels < 1 || avctx->channels > 6) {
av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed\n", avctx->channels);
- return -1;
+ ret = AVERROR(EINVAL);
+ goto error;
}
s->faac_handle = faacEncOpen(avctx->sample_rate,
avctx->channels,
&samples_input, &max_bytes_output);
+ if (!s->faac_handle) {
+ av_log(avctx, AV_LOG_ERROR, "error in faacEncOpen()\n");
+ ret = AVERROR_UNKNOWN;
+ goto error;
+ }
/* check faac version */
faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle);
if (faac_cfg->version != FAAC_CFG_VERSION) {
av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version);
- faacEncClose(s->faac_handle);
- return -1;
+ ret = AVERROR(EINVAL);
+ goto error;
}
/* put the options in the configuration struct */
@@ -79,8 +98,8 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
break;
default:
av_log(avctx, AV_LOG_ERROR, "invalid AAC profile\n");
- faacEncClose(s->faac_handle);
- return -1;
+ ret = AVERROR(EINVAL);
+ goto error;
}
faac_cfg->mpegVersion = MPEG4;
faac_cfg->useTns = 0;
@@ -100,7 +119,10 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
avctx->frame_size = samples_input / avctx->channels;
avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
+ if (!avctx->coded_frame) {
+ ret = AVERROR(ENOMEM);
+ goto error;
+ }
/* Set decoder specific info */
avctx->extradata_size = 0;
@@ -112,6 +134,10 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer,
&decoder_specific_info_size)) {
avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!avctx->extradata) {
+ ret = AVERROR(ENOMEM);
+ goto error;
+ }
avctx->extradata_size = decoder_specific_info_size;
memcpy(avctx->extradata, buffer, avctx->extradata_size);
faac_cfg->outputFormat = 0;
@@ -123,10 +149,14 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) {
av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n");
- return -1;
+ ret = AVERROR(EINVAL);
+ goto error;
}
return 0;
+error:
+ Faac_encode_close(avctx);
+ return ret;
}
static int Faac_encode_frame(AVCodecContext *avctx,
@@ -145,17 +175,6 @@ static int Faac_encode_frame(AVCodecContext *avctx,
return bytes_written;
}
-static av_cold int Faac_encode_close(AVCodecContext *avctx)
-{
- FaacAudioContext *s = avctx->priv_data;
-
- av_freep(&avctx->coded_frame);
- av_freep(&avctx->extradata);
-
- faacEncClose(s->faac_handle);
- return 0;
-}
-
static const AVProfile profiles[] = {
{ FF_PROFILE_AAC_MAIN, "Main" },
{ FF_PROFILE_AAC_LOW, "LC" },