[FFmpeg-devel] [PATCH] Don't needlessly reinitialize ff_cos_## tables.

wm4 nfxjfg at googlemail.com
Wed Oct 21 09:39:37 CEST 2015


On Tue, 20 Oct 2015 16:57:49 -0700
Dale Curtis <dalecurtis at chromium.org> wrote:

> Minor waste and more annoyingly triggers race detectors when the
> re-initialization happens across multiple threads. cos(0) == 1 and by
> default statics initialize to 0, so this check is safe.
> 
> Signed-off-by: Dale Curtis <dalecurtis at chromium.org>
> ---
>  libavcodec/fft_template.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/fft_template.c b/libavcodec/fft_template.c
> index 23ea453..2165ed0 100644
> --- a/libavcodec/fft_template.c
> +++ b/libavcodec/fft_template.c
> @@ -92,6 +92,8 @@ av_cold void ff_init_ff_cos_tabs(int index)
>      int m = 1<<index;
>      double freq = 2*M_PI/m;
>      FFTSample *tab = FFT_NAME(ff_cos_tabs)[index];
> +    if (tab[0])
> +        return;
>      for(i=0; i<=m/4; i++)
>          tab[i] = FIX15(cos(i*freq));
>      for(i=1; i<m/4; i++)

Haven't looked at the surrounding code yet, but the proper fix is to
wrap this into a ff_thread_once() call. Not sure what to do about the
index argument though. A possible alternative is moving the global
variables into a context.


More information about the ffmpeg-devel mailing list