diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2011-06-13 17:44:50 -0400 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2011-06-13 17:49:37 -0400 |
commit | 99477adc31c0569b3cebe8004dd584aa4726a2d1 (patch) | |
tree | 1569d3312cf71e9a5c4b152c221d44205b744a54 | |
parent | 35bdaf3d427b6856df01d41ee826bd515440ec46 (diff) | |
download | ffmpeg-99477adc31c0569b3cebe8004dd584aa4726a2d1.tar.gz |
ac3enc: fix allocation of floating point samples.
sizeof(SampleType) is different for fixed and float encoders.
-rw-r--r-- | libavcodec/ac3enc.c | 16 | ||||
-rw-r--r-- | libavcodec/ac3enc.h | 5 | ||||
-rw-r--r-- | libavcodec/ac3enc_template.c | 20 |
3 files changed, 32 insertions, 9 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 78e81654e3..3426bd252a 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -2215,15 +2215,9 @@ static av_cold int allocate_buffers(AVCodecContext *avctx) AC3EncodeContext *s = avctx->priv_data; int channels = s->channels + 1; /* includes coupling channel */ - FF_ALLOC_OR_GOTO(avctx, s->windowed_samples, AC3_WINDOW_SIZE * - sizeof(*s->windowed_samples), alloc_fail); - FF_ALLOC_OR_GOTO(avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples), - alloc_fail); - for (ch = 0; ch < s->channels; ch++) { - FF_ALLOCZ_OR_GOTO(avctx, s->planar_samples[ch], - (AC3_FRAME_SIZE+AC3_BLOCK_SIZE) * sizeof(**s->planar_samples), - alloc_fail); - } + if (s->allocate_sample_buffers(s)) + goto alloc_fail; + FF_ALLOC_OR_GOTO(avctx, s->bap_buffer, AC3_MAX_BLOCKS * channels * AC3_MAX_COEFS * sizeof(*s->bap_buffer), alloc_fail); FF_ALLOC_OR_GOTO(avctx, s->bap1_buffer, AC3_MAX_BLOCKS * channels * @@ -2323,6 +2317,8 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) AC3EncodeContext *s = avctx->priv_data; int ret, frame_size_58; + s->avctx = avctx; + s->eac3 = avctx->codec_id == CODEC_ID_EAC3; avctx->frame_size = AC3_FRAME_SIZE; @@ -2355,6 +2351,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) s->apply_window = ff_ac3_fixed_apply_window; s->normalize_samples = ff_ac3_fixed_normalize_samples; s->scale_coefficients = ff_ac3_fixed_scale_coefficients; + s->allocate_sample_buffers = ff_ac3_fixed_allocate_sample_buffers; s->deinterleave_input_samples = ff_ac3_fixed_deinterleave_input_samples; s->apply_mdct = ff_ac3_fixed_apply_mdct; s->apply_channel_coupling = ff_ac3_fixed_apply_channel_coupling; @@ -2364,6 +2361,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) s->mdct_init = ff_ac3_float_mdct_init; s->apply_window = ff_ac3_float_apply_window; s->scale_coefficients = ff_ac3_float_scale_coefficients; + s->allocate_sample_buffers = ff_ac3_float_allocate_sample_buffers; s->deinterleave_input_samples = ff_ac3_float_deinterleave_input_samples; s->apply_mdct = ff_ac3_float_apply_mdct; s->apply_channel_coupling = ff_ac3_float_apply_channel_coupling; diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index 1d17484321..bf25298940 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -135,6 +135,7 @@ typedef struct AC3Block { typedef struct AC3EncodeContext { AVClass *av_class; ///< AVClass used for AVOption AC3EncOptions options; ///< encoding options + AVCodecContext *avctx; ///< parent AVCodecContext PutBitContext pb; ///< bitstream writer context DSPContext dsp; AC3DSPContext ac3dsp; ///< AC-3 optimized functions @@ -230,6 +231,7 @@ typedef struct AC3EncodeContext { void (*scale_coefficients)(struct AC3EncodeContext *s); /* fixed vs. float templated function pointers */ + int (*allocate_sample_buffers)(struct AC3EncodeContext *s); void (*deinterleave_input_samples)(struct AC3EncodeContext *s, const SampleType *samples); void (*apply_mdct)(struct AC3EncodeContext *s); @@ -276,6 +278,9 @@ void ff_ac3_float_scale_coefficients(AC3EncodeContext *s); /* prototypes for functions in ac3enc_template.c */ +int ff_ac3_fixed_allocate_sample_buffers(AC3EncodeContext *s); +int ff_ac3_float_allocate_sample_buffers(AC3EncodeContext *s); + void ff_ac3_fixed_deinterleave_input_samples(AC3EncodeContext *s, const SampleType *samples); void ff_ac3_float_deinterleave_input_samples(AC3EncodeContext *s, diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index d88fa225a1..0547165aaf 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -31,6 +31,26 @@ #include "ac3enc.h" +int AC3_NAME(allocate_sample_buffers)(AC3EncodeContext *s) +{ + int ch; + + FF_ALLOC_OR_GOTO(s->avctx, s->windowed_samples, AC3_WINDOW_SIZE * + sizeof(*s->windowed_samples), alloc_fail); + FF_ALLOC_OR_GOTO(s->avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples), + alloc_fail); + for (ch = 0; ch < s->channels; ch++) { + FF_ALLOCZ_OR_GOTO(s->avctx, s->planar_samples[ch], + (AC3_FRAME_SIZE+AC3_BLOCK_SIZE) * sizeof(**s->planar_samples), + alloc_fail); + } + + return 0; +alloc_fail: + return AVERROR(ENOMEM); +} + + /** * Deinterleave input samples. * Channels are reordered from Libav's default order to AC-3 order. |