History

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).

Andreas Rheinhardt committed 2 years ago

Commit 3cd136b1 parent 7311a903 files · +26 −28Browse files

Showing the changes to libavcodec (3 of 3 files). Show all

Unified · Split

3 files
  1. libavcodec/ac3enc.c +24 −1
  2. libavcodec/ac3enc.h +1 −1
  3. libavcodec/ac3enc_template.c +1 −26
libavcodec/ac3enc.c+24−1
@@ -503,6 +503,27 @@ static void ac3_adjust_frame_size(AC3EncodeContext *s) · 502 unmodified lines
503503 s->samples_written += AC3_BLOCK_SIZE * s->num_blocks;
504504 }
505505
506+/*
507+ * Copy input samples.
508+ * Channels are reordered from FFmpeg's default order to AC-3 order.
509+ */
510+static void copy_input_samples(AC3EncodeContext *s, uint8_t * const *samples)
511+{
512+ const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
513+
514+ /* copy and remap input samples */
515+ for (int ch = 0; ch < s->channels; ch++) {
516+ /* copy last 256 samples of previous frame to the start of the current frame */
517+ memcpy(&s->planar_samples[ch][0],
518+ s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size * s->num_blocks,
519+ AC3_BLOCK_SIZE * sampletype_size);
520+
521+ /* copy new samples for current frame */
522+ memcpy(s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size,
523+ samples[s->channel_map[ch]],
524+ sampletype_size * AC3_BLOCK_SIZE * s->num_blocks);
525+ }
526+}
506527
507528 /**
508529 * Set the initial coupling strategy parameters prior to coupling analysis.
@@ -1996,7 +2017,9 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 1487 unmodified lines
19962017 if (s->bit_alloc.sr_code == 1 || s->eac3)
19972018 ac3_adjust_frame_size(s);
19982019
1999− s->encode_frame(s, frame);
2020+ copy_input_samples(s, frame->extended_data);
2021+
2022+ s->encode_frame(s);
20002023
20012024 ac3_apply_rematrixing(s);
20022025
libavcodec/ac3enc.h+1−1
@@ -255,7 +255,7 @@ typedef struct AC3EncodeContext { · 254 unmodified lines
255255 int ref_bap_set; ///< indicates if ref_bap pointers have been set
256256
257257 /** fixed vs. float function pointers */
258− void (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame);
258+ void (*encode_frame)(struct AC3EncodeContext *s);
259259
260260 /* fixed vs. float function pointers */
261261 int (*mdct_init)(struct AC3EncodeContext *s);
libavcodec/ac3enc_template.c+1−26
@@ -38,29 +38,6 @@ · 37 unmodified lines
3838 #include "eac3enc.h"
3939
4040
41−/*
42− * Copy input samples.
43− * Channels are reordered from FFmpeg's default order to AC-3 order.
44− */
45−static void copy_input_samples(AC3EncodeContext *s, SampleType **samples)
46−{
47− int ch;
48−
49− /* copy and remap input samples */
50− for (ch = 0; ch < s->channels; ch++) {
51− /* copy last 256 samples of previous frame to the start of the current frame */
52− memcpy(&s->planar_samples[ch][0],
53− (SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE * s->num_blocks,
54− AC3_BLOCK_SIZE * sizeof(SampleType));
55−
56− /* copy new samples for current frame */
57− memcpy((SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE,
58− samples[s->channel_map[ch]],
59− AC3_BLOCK_SIZE * s->num_blocks * sizeof(SampleType));
60− }
61−}
62−
63−
6441 /*
6542 * Apply the MDCT to input samples to generate frequency coefficients.
6643 * This applies the KBD window and normalizes the input to reduce precision
@@ -353,10 +330,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) · 286 unmodified lines
353330 }
354331
355332
356−static void encode_frame(AC3EncodeContext *s, const AVFrame *frame)
333+static void encode_frame(AC3EncodeContext *s)
357334 {
358− copy_input_samples(s, (SampleType **)frame->extended_data);
359−
360335 apply_mdct(s);
361336
362337 s->cpl_on = s->cpl_enabled;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t