From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 1/6] avcodec/ac3enc: Avoid allocation for windowed_samples
Date: Sun, 14 Apr 2024 20:28:12 +0200
Message-ID: <AS8P250MB0744432E9416A30719F18EDF8F0A2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ac3enc.c | 4 ----
libavcodec/ac3enc.h | 7 ++++++-
libavcodec/ac3enc_template.c | 12 +++++++++---
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1ba4ba549e..a31b528597 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2184,7 +2184,6 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
AC3EncodeContext *s = avctx->priv_data;
av_freep(&s->mdct_window);
- av_freep(&s->windowed_samples);
if (s->planar_samples)
for (ch = 0; ch < s->channels; ch++)
av_freep(&s->planar_samples[ch]);
@@ -2459,9 +2458,6 @@ static av_cold int allocate_buffers(AC3EncodeContext *s)
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 (!FF_ALLOCZ_TYPED_ARRAY(s->planar_samples, s->channels))
return AVERROR(ENOMEM);
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 227744d27f..618c952a18 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -30,6 +30,7 @@
#include <stdint.h>
+#include "libavutil/mem_internal.h"
#include "libavutil/opt.h"
#include "libavutil/tx.h"
@@ -232,7 +233,6 @@ typedef struct AC3EncodeContext {
int frame_bits; ///< all frame bits except exponents and mantissas
int exponent_bits; ///< number of bits used for exponents
- void *windowed_samples;
uint8_t **planar_samples;
uint8_t *bap_buffer;
uint8_t *bap1_buffer;
@@ -259,6 +259,11 @@ typedef struct AC3EncodeContext {
/* AC-3 vs. E-AC-3 function pointers */
void (*output_frame_header)(struct AC3EncodeContext *s);
+
+ union {
+ DECLARE_ALIGNED(32, float, windowed_samples_float)[AC3_WINDOW_SIZE];
+ DECLARE_ALIGNED(32, int32_t, windowed_samples_fixed)[AC3_WINDOW_SIZE];
+ };
} AC3EncodeContext;
extern const AVChannelLayout ff_ac3_ch_layouts[19];
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index b0f9e69ee8..6070e14961 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -37,6 +37,11 @@
#include "ac3enc.h"
#include "eac3enc.h"
+#if AC3ENC_FLOAT
+#define RENAME(element) element ## _float
+#else
+#define RENAME(element) element ## _fixed
+#endif
/*
* Apply the MDCT to input samples to generate frequency coefficients.
@@ -51,15 +56,16 @@ static void apply_mdct(AC3EncodeContext *s)
for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
const SampleType *input_samples = (SampleType*)s->planar_samples[ch] + blk * AC3_BLOCK_SIZE;
+ SampleType *windowed_samples = s->RENAME(windowed_samples);
- s->fdsp->vector_fmul(s->windowed_samples, input_samples,
+ s->fdsp->vector_fmul(windowed_samples, input_samples,
s->mdct_window, AC3_BLOCK_SIZE);
- s->fdsp->vector_fmul_reverse((SampleType*)s->windowed_samples + AC3_BLOCK_SIZE,
+ s->fdsp->vector_fmul_reverse(windowed_samples + AC3_BLOCK_SIZE,
&input_samples[AC3_BLOCK_SIZE],
s->mdct_window, AC3_BLOCK_SIZE);
s->tx_fn(s->tx, block->mdct_coef[ch+1],
- s->windowed_samples, sizeof(float));
+ windowed_samples, sizeof(*windowed_samples));
}
}
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2024-04-14 18:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-14 18:28 Andreas Rheinhardt [this message]
2024-04-14 18:30 ` [FFmpeg-devel] [PATCH 2/6] avcodec/ac3enc: Avoid allocation for mdct_window Andreas Rheinhardt
2024-04-14 18:30 ` [FFmpeg-devel] [PATCH 3/6] avcodec/ac3enc: Avoid indirections, allocations of small arrays Andreas Rheinhardt
2024-04-14 18:30 ` [FFmpeg-devel] [PATCH 4/6] avcodec/ac3enc: Combine loops Andreas Rheinhardt
2024-04-14 18:30 ` [FFmpeg-devel] [PATCH 5/6] avcodec/ac3enc: Combine cpl_coord buffers Andreas Rheinhardt
2024-04-14 18:30 ` [FFmpeg-devel] [PATCH 6/6] avcodec/ac3enc: Avoid copying samples Andreas Rheinhardt
2024-04-17 15:04 ` [FFmpeg-devel] [PATCH 1/6] avcodec/ac3enc: Avoid allocation for windowed_samples Andreas Rheinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8P250MB0744432E9416A30719F18EDF8F0A2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git