From 766a36afc7208388bb0b44b2235329d3e9ab837d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 1 Jul 2017 15:13:49 +0200 Subject: [PATCH] Avoid AVX-related crashes in FFmpeg by aligning buffer --- src/spek-fft.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/spek-fft.h b/src/spek-fft.h index 76595fa..990e482 100644 --- a/src/spek-fft.h +++ b/src/spek-fft.h @@ -3,6 +3,11 @@ #include #include +extern "C" { +#include +} + + class FFTPlan; class FFT @@ -17,8 +22,17 @@ class FFTPlan public: FFTPlan(int nbits) : input_size(1 << nbits), output_size((1 << (nbits - 1)) + 1), - input(input_size), output(output_size) {} - virtual ~FFTPlan() {} + output(output_size) + { + // FFmpeg uses various assembly optimizations which expect + // input data to be aligned by up to 32 bytes (e.g. AVX) + this->input = (float*) av_malloc(sizeof(float) * input_size); + } + + virtual ~FFTPlan() + { + av_freep(this->input); + } int get_input_size() const { return this->input_size; } int get_output_size() const { return this->output_size; } @@ -30,11 +44,11 @@ public: virtual void execute() = 0; protected: - float *get_input() { return this->input.data(); } + float *get_input() { return this->input; } private: int input_size; int output_size; - std::vector input; + float *input; std::vector output; };