diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index c090948221..48ab52e49c 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -503,6 +503,27 @@ static void ac3_adjust_frame_size(AC3EncodeContext *s) s->samples_written += AC3_BLOCK_SIZE * s->num_blocks; } +/* + * Copy input samples. + * Channels are reordered from FFmpeg's default order to AC-3 order. + */ +static void copy_input_samples(AC3EncodeContext *s, uint8_t * const *samples) +{ + const unsigned sampletype_size = SAMPLETYPE_SIZE(s); + + /* copy and remap input samples */ + for (int ch = 0; ch < s->channels; ch++) { + /* copy last 256 samples of previous frame to the start of the current frame */ + memcpy(&s->planar_samples[ch][0], + s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size * s->num_blocks, + AC3_BLOCK_SIZE * sampletype_size); + + /* copy new samples for current frame */ + memcpy(s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size, + samples[s->channel_map[ch]], + sampletype_size * AC3_BLOCK_SIZE * s->num_blocks); + } +} /** * Set the initial coupling strategy parameters prior to coupling analysis. @@ -1996,7 +2017,9 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (s->bit_alloc.sr_code == 1 || s->eac3) ac3_adjust_frame_size(s); - s->encode_frame(s, frame); + copy_input_samples(s, frame->extended_data); + + s->encode_frame(s); ac3_apply_rematrixing(s); diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index 8d6cb3b3de..271f0eb8eb 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -255,7 +255,7 @@ typedef struct AC3EncodeContext { int ref_bap_set; ///< indicates if ref_bap pointers have been set /** fixed vs. float function pointers */ - void (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame); + void (*encode_frame)(struct AC3EncodeContext *s); /* fixed vs. float function pointers */ int (*mdct_init)(struct AC3EncodeContext *s); diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index 3646e1dcaa..b0f9e69ee8 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -38,29 +38,6 @@ #include "eac3enc.h" -/* - * Copy input samples. - * Channels are reordered from FFmpeg's default order to AC-3 order. - */ -static void copy_input_samples(AC3EncodeContext *s, SampleType **samples) -{ - int ch; - - /* copy and remap input samples */ - for (ch = 0; ch < s->channels; ch++) { - /* copy last 256 samples of previous frame to the start of the current frame */ - memcpy(&s->planar_samples[ch][0], - (SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE * s->num_blocks, - AC3_BLOCK_SIZE * sizeof(SampleType)); - - /* copy new samples for current frame */ - memcpy((SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE, - samples[s->channel_map[ch]], - AC3_BLOCK_SIZE * s->num_blocks * sizeof(SampleType)); - } -} - - /* * Apply the MDCT to input samples to generate frequency coefficients. * This applies the KBD window and normalizes the input to reduce precision @@ -353,10 +330,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) } -static void encode_frame(AC3EncodeContext *s, const AVFrame *frame) +static void encode_frame(AC3EncodeContext *s) { - copy_input_samples(s, (SampleType **)frame->extended_data); - apply_mdct(s); s->cpl_on = s->cpl_enabled;