Skip to content

Commit

Permalink
Merge pull request #21585 from brave/issues/35318
Browse files Browse the repository at this point in the history
Remove dynamic allocation of ffmpeg ff_tx tables.
  • Loading branch information
goodov authored and mkarolin committed Jan 17, 2024
1 parent 0dd9bd2 commit f82b072
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions patches/third_party/ffmpeg/libavutil-tx_template.c.patch
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
diff --git a/libavutil/tx_template.c b/libavutil/tx_template.c
index 8dc3d2519c13abec090b374fa5ed0f11f7153849..a5d156d2789ec521c034edd929e04b2ad09a833b 100644
index a2c27465cbcabe242325f4126b74b4aa53f1aae8..c6cf1c2ddb3ca9a84ed344748ba560a5647edac8 100644
--- a/libavutil/tx_template.c
+++ b/libavutil/tx_template.c
@@ -27,6 +27,29 @@
#define TABLE_DEF(name, size) \
DECLARE_ALIGNED(32, TXSample, TX_TAB(ff_tx_tab_ ##name))[size]

+#ifdef _WIN32
+
+#include <malloc.h>
+
+// Declares aligned ff_tx_tab_* pointer.
+#define TABLE_DEF_PTR(name, size) \
+ DECLARE_ALIGNED(32, TXSample*, TX_TAB(ff_tx_tab_##name))
+
+// Allocates aligned memory for ff_tx_tab_* variable.
+#define ALLOCATE_FF_TX_TABLE(len) \
+ if (!TX_TAB(ff_tx_tab_##len)) { \
+ TX_TAB(ff_tx_tab_##len) = \
+ _aligned_malloc((len / 4 + 1) * sizeof(TXSample), 32); \
+ }
+
+#else
+
+// Use static arrays on non-Windows targets as usual.
+#define TABLE_DEF_PTR(name, size) TABLE_DEF(name, size)
+#define ALLOCATE_FF_TX_TABLE(len)
+
+#endif
+
#define SR_POW2_TABLES \
SR_TABLE(8) \
SR_TABLE(16) \
@@ -43,13 +66,9 @@
@@ -43,10 +43,6 @@
SR_TABLE(32768) \
SR_TABLE(65536) \
SR_TABLE(131072) \
Expand All @@ -42,20 +12,8 @@ index 8dc3d2519c13abec090b374fa5ed0f11f7153849..a5d156d2789ec521c034edd929e04b2a
- SR_TABLE(2097152) \

#define SR_TABLE(len) \
- TABLE_DEF(len, len/4 + 1);
+ TABLE_DEF_PTR(len, len/4 + 1);
/* Power of two tables */
SR_POW2_TABLES
#undef SR_TABLE
@@ -68,6 +87,7 @@ typedef struct FFTabInitData {
static av_cold void TX_TAB(ff_tx_init_tab_ ##len)(void) \
{ \
double freq = 2*M_PI/len; \
+ ALLOCATE_FF_TX_TABLE(len); \
TXSample *tab = TX_TAB(ff_tx_tab_ ##len); \
\
for (int i = 0; i < len/4; i++) \
@@ -721,10 +741,6 @@ DECL_SR_CODELET(16384,8192,4096)
TABLE_DEF(len, len/4 + 1);
@@ -722,10 +718,6 @@ DECL_SR_CODELET(16384,8192,4096)
DECL_SR_CODELET(32768,16384,8192)
DECL_SR_CODELET(65536,32768,16384)
DECL_SR_CODELET(131072,65536,32768)
Expand All @@ -66,7 +24,7 @@ index 8dc3d2519c13abec090b374fa5ed0f11f7153849..a5d156d2789ec521c034edd929e04b2a

static av_cold int TX_NAME(ff_tx_fft_init)(AVTXContext *s,
const FFTXCodelet *cd,
@@ -2157,10 +2173,6 @@ const FFTXCodelet * const TX_NAME(ff_tx_codelet_list)[] = {
@@ -2158,10 +2150,6 @@ const FFTXCodelet * const TX_NAME(ff_tx_codelet_list)[] = {
&TX_NAME(ff_tx_fft32768_ns_def),
&TX_NAME(ff_tx_fft65536_ns_def),
&TX_NAME(ff_tx_fft131072_ns_def),
Expand Down

0 comments on commit f82b072

Please sign in to comment.