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).
Showing the changes to libavcodec (3 of 3 files). Show all
Unified · Split
| @@ -503,6 +503,27 @@ static void ac3_adjust_frame_size(AC3EncodeContext *s) · 502 unmodified lines | |||
| 503 | s->samples_written += AC3_BLOCK_SIZE * s->num_blocks; | 503 | s->samples_written += AC3_BLOCK_SIZE * s->num_blocks; |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 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 | } | ||
| 506 | 527 | ||
| 507 | /** | 528 | /** |
| 508 | * Set the initial coupling strategy parameters prior to coupling analysis. | 529 | * 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 | |||
| 1996 | if (s->bit_alloc.sr_code == 1 || s->eac3) | 2017 | if (s->bit_alloc.sr_code == 1 || s->eac3) |
| 1997 | ac3_adjust_frame_size(s); | 2018 | ac3_adjust_frame_size(s); |
| 1998 | 2019 | ||
| 1999 | s->encode_frame(s, frame); | 2020 | copy_input_samples(s, frame->extended_data); |
| 2021 | |||
| 2022 | s->encode_frame(s); | ||
| 2000 | 2023 | ||
| 2001 | ac3_apply_rematrixing(s); | 2024 | ac3_apply_rematrixing(s); |
| 2002 | 2025 | ||
| @@ -255,7 +255,7 @@ typedef struct AC3EncodeContext { · 254 unmodified lines | |||
| 255 | int ref_bap_set; ///< indicates if ref_bap pointers have been set | 255 | int ref_bap_set; ///< indicates if ref_bap pointers have been set |
| 256 | 256 | ||
| 257 | /** fixed vs. float function pointers */ | 257 | /** fixed vs. float function pointers */ |
| 258 | void (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame); | 258 | void (*encode_frame)(struct AC3EncodeContext *s); |
| 259 | 259 | ||
| 260 | /* fixed vs. float function pointers */ | 260 | /* fixed vs. float function pointers */ |
| 261 | int (*mdct_init)(struct AC3EncodeContext *s); | 261 | int (*mdct_init)(struct AC3EncodeContext *s); |
| @@ -38,29 +38,6 @@ · 37 unmodified lines | |||
| 38 | #include "eac3enc.h" | 38 | #include "eac3enc.h" |
| 39 | 39 | ||
| 40 | 40 | ||
| 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 | |||
| 64 | /* | 41 | /* |
| 65 | * Apply the MDCT to input samples to generate frequency coefficients. | 42 | * Apply the MDCT to input samples to generate frequency coefficients. |
| 66 | * This applies the KBD window and normalizes the input to reduce precision | 43 | * 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 | |||
| 353 | } | 330 | } |
| 354 | 331 | ||
| 355 | 332 | ||
| 356 | static void encode_frame(AC3EncodeContext *s, const AVFrame *frame) | 333 | static void encode_frame(AC3EncodeContext *s) |
| 357 | { | 334 | { |
| 358 | copy_input_samples(s, (SampleType **)frame->extended_data); | ||
| 359 | |||
| 360 | apply_mdct(s); | 335 | apply_mdct(s); |
| 361 | 336 | ||
| 362 | s->cpl_on = s->cpl_enabled; | 337 | s->cpl_on = s->cpl_enabled; |