avcodec/ac3enc: Deduplicate copying input samples

These memcpy operands only depend upon sizeof(SampleType)
(and this size is actually the same for both the fixed-point
and the floating-point encoders for most (all supported?)
systems).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-04-07 19:15:39 +02:00
parent 7311a9086e
commit 3cd136bc12
3 changed files with 26 additions and 28 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;