aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/ac3enc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-04-07 18:26:19 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-04-11 12:53:26 +0200
commit7311a9086eb12573f89a05e200f9c11a8d47ee26 (patch)
treee551549a51baf30880576edd4705f75d2414d723 /libavcodec/ac3enc.c
parent2fcc50d1f536a76978d39396afb43f885cc89667 (diff)
downloadffmpeg-7311a9086eb12573f89a05e200f9c11a8d47ee26.tar.gz
avcodec/ac3enc: Deduplicate allocating buffers
These allocations 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>
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r--libavcodec/ac3enc.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index e5b0be0969..c090948221 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -52,6 +52,9 @@
#include "ac3enc.h"
#include "eac3enc.h"
+#define SAMPLETYPE_SIZE(ctx) (sizeof(float) == sizeof(int32_t) ? sizeof(float) : \
+ (ctx)->fixed_point ? sizeof(int32_t) : sizeof(float))
+
typedef struct AC3Mant {
int16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4
int mant1_cnt, mant2_cnt, mant4_cnt; ///< mantissa counts for bap=1,2,4
@@ -2430,10 +2433,21 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
int channels = s->channels + 1; /* includes coupling channel */
int channel_blocks = channels * s->num_blocks;
int total_coefs = AC3_MAX_COEFS * channel_blocks;
+ const unsigned sampletype_size = SAMPLETYPE_SIZE(s);
+
+ if (!(s->windowed_samples = av_malloc(sampletype_size * AC3_WINDOW_SIZE)))
+ return AVERROR(ENOMEM);
- if (s->allocate_sample_buffers(s))
+ if (!FF_ALLOCZ_TYPED_ARRAY(s->planar_samples, s->channels))
return AVERROR(ENOMEM);
+ for (int ch = 0; ch < s->channels; ch++) {
+ s->planar_samples[ch] = av_mallocz((AC3_FRAME_SIZE + AC3_BLOCK_SIZE) *
+ sampletype_size);
+ if (!s->planar_samples[ch])
+ return AVERROR(ENOMEM);
+ }
+
if (!FF_ALLOC_TYPED_ARRAY(s->bap_buffer, total_coefs) ||
!FF_ALLOC_TYPED_ARRAY(s->bap1_buffer, total_coefs) ||
!FF_ALLOCZ_TYPED_ARRAY(s->mdct_coef_buffer, total_coefs) ||