/* * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef AVUTIL_TX_PRIV_H #define AVUTIL_TX_PRIV_H #include "tx.h" #include "thread.h" #include "mem_internal.h" #include "common.h" #include "attributes.h" #ifdef TX_FLOAT #define TX_TAB(x) … #define TX_NAME(x) … #define TX_NAME_STR(x) … #define TX_TYPE(x) … #define TX_FN_NAME(fn, suffix) … #define TX_FN_NAME_STR(fn, suffix) … #define MULT(x, m) … #define SCALE_TYPE … TXSample; TXUSample; TXComplex; #elif defined(TX_DOUBLE) #define TX_TAB … #define TX_NAME … #define TX_NAME_STR … #define TX_TYPE … #define TX_FN_NAME … #define TX_FN_NAME_STR … #define MULT … #define SCALE_TYPE … typedef double TXSample; typedef double TXUSample; typedef AVComplexDouble TXComplex; #elif defined(TX_INT32) #define TX_TAB … #define TX_NAME … #define TX_NAME_STR … #define TX_TYPE … #define TX_FN_NAME … #define TX_FN_NAME_STR … #define MULT … #define SCALE_TYPE … typedef int32_t TXSample; typedef uint32_t TXUSample; typedef AVComplexInt32 TXComplex; #else typedef void TXComplex; #endif #define TX_DECL_FN(fn, suffix) … #define TX_DEF(fn, tx_type, len_min, len_max, f1, f2, \ p, init_fn, suffix, cf, cd_flags, cf2) … #if defined(TX_FLOAT) || defined(TX_DOUBLE) #define CMUL(dre, dim, are, aim, bre, bim) … #define SMUL(dre, dim, are, aim, bre, bim) … #define UNSCALE(x) … #define RESCALE(x) … #define FOLD(a, b) … #define BF(x, y, a, b) … #elif defined(TX_INT32) /* Properly rounds the result */ #define CMUL … #define SMUL … #define UNSCALE … #define RESCALE … #define FOLD … #define BF … #endif /* TX_INT32 */ #define CMUL3(c, a, b) … /* Codelet flags, used to pick codelets. Must be a superset of enum AVTXFlags, * but if it runs out of bits, it can be made separate. */ #define FF_TX_OUT_OF_PLACE … #define FF_TX_ALIGNED … #define FF_TX_PRESHUFFLE … #define FF_TX_INVERSE_ONLY … #define FF_TX_FORWARD_ONLY … #define FF_TX_ASM_CALL … FFTXCodeletPriority; FFTXMapDirection; /* Codelet options */ FFTXCodeletOptions; /* Maximum number of factors a codelet may have. Arbitrary. */ #define TX_MAX_FACTORS … /* Maximum amount of subtransform functions, subtransforms and factors. Arbitrary. */ #define TX_MAX_SUB … /* Maximum number of returned results for ff_tx_decompose_length. Arbitrary. */ #define TX_MAX_DECOMPOSITIONS … FFTXCodelet; struct AVTXContext { … }; /* This function embeds a Ruritanian PFA input map into an existing lookup table * to avoid double permutation. This allows for compound factors to be * synthesized as fast PFA FFTs and embedded into either other or standalone * transforms. * The output CRT map must still be pre-baked into the transform. */ #define TX_EMBED_INPUT_PFA_MAP(map, tot_len, d1, d2) … /* This function generates a Ruritanian PFA input map into s->map. */ int ff_tx_gen_pfa_input_map(AVTXContext *s, FFTXCodeletOptions *opts, int d1, int d2); /* Create a subtransform in the current context with the given parameters. * The flags parameter from FFTXCodelet.init() should be preserved as much * as that's possible. * MUST be called during the sub() callback of each codelet. */ int ff_tx_init_subtx(AVTXContext *s, enum AVTXType type, uint64_t flags, FFTXCodeletOptions *opts, int len, int inv, const void *scale); /* Clear the context by freeing all tables, maps and subtransforms. */ void ff_tx_clear_ctx(AVTXContext *s); /* Attempt to factorize a length into 2 integers such that * len / dst1 == dst2, where dst1 and dst2 are coprime. */ int ff_tx_decompose_length(int dst[TX_MAX_DECOMPOSITIONS], enum AVTXType type, int len, int inv); /* Generate a default map (0->len or 0, (len-1)->1 for inverse transforms) * for a context. */ int ff_tx_gen_default_map(AVTXContext *s, FFTXCodeletOptions *opts); /* * Generates the PFA permutation table into AVTXContext->pfatab. The end table * is appended to the start table. * The `inv` flag should only be enabled if the lookup tables of subtransforms * won't get flattened. */ int ff_tx_gen_compound_mapping(AVTXContext *s, FFTXCodeletOptions *opts, int inv, int n, int m); /* * Generates a standard-ish (slightly modified) Split-Radix revtab into * AVTXContext->map. Invert lookup changes how the mapping needs to be applied. * If it's set to 0, it has to be applied like out[map[i]] = in[i], otherwise * if it's set to 1, has to be applied as out[i] = in[map[i]] */ int ff_tx_gen_ptwo_revtab(AVTXContext *s, FFTXCodeletOptions *opts); /* * Generates an index into AVTXContext->inplace_idx that if followed in the * specific order, allows the revtab to be done in-place. The sub-transform * and its map should already be initialized. */ int ff_tx_gen_inplace_map(AVTXContext *s, int len); /* * This generates a parity-based revtab of length len and direction inv. * * Parity means even and odd complex numbers will be split, e.g. the even * coefficients will come first, after which the odd coefficients will be * placed. For example, a 4-point transform's coefficients after reordering: * z[0].re, z[0].im, z[2].re, z[2].im, z[1].re, z[1].im, z[3].re, z[3].im * * The basis argument is the length of the largest non-composite transform * supported, and also implies that the basis/2 transform is supported as well, * as the split-radix algorithm requires it to be. * * The dual_stride argument indicates that both the basis, as well as the * basis/2 transforms support doing two transforms at once, and the coefficients * will be interleaved between each pair in a split-radix like so (stride == 2): * tx1[0], tx1[2], tx2[0], tx2[2], tx1[1], tx1[3], tx2[1], tx2[3] * A non-zero number switches this on, with the value indicating the stride * (how many values of 1 transform to put first before switching to the other). * Must be a power of two or 0. Must be less than the basis. * Value will be clipped to the transform size, so for a basis of 16 and a * dual_stride of 8, dual 8-point transforms will be laid out as if dual_stride * was set to 4. * Usually you'll set this to half the complex numbers that fit in a single * register or 0. This allows to reuse SSE functions as dual-transform * functions in AVX mode. * * If length is smaller than basis/2 this function will not do anything. * * If inv_lookup is set to 1, it will flip the lookup from out[map[i]] = src[i] * to out[i] = src[map[i]]. */ int ff_tx_gen_split_radix_parity_revtab(AVTXContext *s, int len, int inv, FFTXCodeletOptions *opts, int basis, int dual_stride); /* Typed init function to initialize shared tables. Will initialize all tables * for all factors of a length. */ void ff_tx_init_tabs_float (int len); void ff_tx_init_tabs_double(int len); void ff_tx_init_tabs_int32 (int len); /* Typed init function to initialize an MDCT exptab in a context. * If pre_tab is set, duplicates the entire table, with the first * copy being shuffled according to pre_tab, and the second copy * being the original. */ int ff_tx_mdct_gen_exp_float (AVTXContext *s, int *pre_tab); int ff_tx_mdct_gen_exp_double(AVTXContext *s, int *pre_tab); int ff_tx_mdct_gen_exp_int32 (AVTXContext *s, int *pre_tab); /* Lists of codelets */ extern const FFTXCodelet * const ff_tx_codelet_list_float_c []; extern const FFTXCodelet * const ff_tx_codelet_list_float_x86 []; extern const FFTXCodelet * const ff_tx_codelet_list_float_aarch64 []; extern const FFTXCodelet * const ff_tx_codelet_list_double_c []; extern const FFTXCodelet * const ff_tx_codelet_list_int32_c []; #endif /* AVUTIL_TX_PRIV_H */