diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-02-26 00:24:33 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-02-27 00:11:21 +0100 |
commit | a6aa043baa06c1b3296b02245c9d71aca273f2ef (patch) | |
tree | beb938a215b2be5ddf6a89a4d917ff05718e7758 /libavcodec/aacenc.h | |
parent | 6c92347ab9fb1a07664577a1b68e0a1724799e2b (diff) | |
download | ffmpeg-a6aa043baa06c1b3296b02245c9d71aca273f2ef.tar.gz |
avcodec/aac: Split ChannelElement in decoder and encoder structs
The AAC decoders share no common code with the AAC encoder,
so they are not restricted to using the same structures.
This implies that one can use different structs for each
component and remove elements not used by the decoders/
the encoder. This leads to quite sizeable savings:
sizeof(ChannelElement) for the encoder went down to 134432B
here from 547552B; for the decoder it went down to 512800B.
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/aacenc.h')
-rw-r--r-- | libavcodec/aacenc.h | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h index 18b424736d..752f1c26b2 100644 --- a/libavcodec/aacenc.h +++ b/libavcodec/aacenc.h @@ -22,9 +22,12 @@ #ifndef AVCODEC_AACENC_H #define AVCODEC_AACENC_H +#include <stdint.h> + #include "libavutil/channel_layout.h" #include "libavutil/float_dsp.h" #include "libavutil/mem_internal.h" +#include "libavutil/tx.h" #include "avcodec.h" #include "put_bits.h" @@ -35,6 +38,8 @@ #include "lpc.h" +#define CLIP_AVOIDANCE_FACTOR 0.95f + typedef enum AACCoder { AAC_CODER_ANMR = 0, AAC_CODER_TWOLOOP, @@ -54,6 +59,90 @@ typedef struct AACEncOptions { int intensity_stereo; } AACEncOptions; +/** + * Long Term Prediction + */ +typedef struct LongTermPrediction { + int8_t present; + int16_t lag; + int coef_idx; + float coef; + int8_t used[MAX_LTP_LONG_SFB]; +} LongTermPrediction; + +/** + * Individual Channel Stream + */ +typedef struct IndividualChannelStream { + uint8_t max_sfb; ///< number of scalefactor bands per group + enum WindowSequence window_sequence[2]; + uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sine window. + uint8_t group_len[8]; + LongTermPrediction ltp; + const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window + const uint8_t *swb_sizes; ///< table of scalefactor band sizes for a particular window + int num_swb; ///< number of scalefactor window bands + int num_windows; + int tns_max_bands; + int predictor_present; + int predictor_initialized; + int predictor_reset_group; + int predictor_reset_count[31]; ///< used to count prediction resets + uint8_t prediction_used[41]; + uint8_t window_clipping[8]; ///< set if a certain window is near clipping + float clip_avoidance_factor; ///< set if any window is near clipping to the necessary atennuation factor to avoid it +} IndividualChannelStream; + +/** + * Temporal Noise Shaping + */ +typedef struct TemporalNoiseShaping { + int present; + int n_filt[8]; + int length[8][4]; + int direction[8][4]; + int order[8][4]; + int coef_idx[8][4][TNS_MAX_ORDER]; + float coef[8][4][TNS_MAX_ORDER]; +} TemporalNoiseShaping; + +/** + * Single Channel Element - used for both SCE and LFE elements. + */ +typedef struct SingleChannelElement { + IndividualChannelStream ics; + TemporalNoiseShaping tns; + Pulse pulse; + enum BandType band_type[128]; ///< band types + enum BandType band_alt[128]; ///< alternative band type + int sf_idx[128]; ///< scalefactor indices + uint8_t zeroes[128]; ///< band is not coded + uint8_t can_pns[128]; ///< band is allowed to PNS (informative) + float is_ener[128]; ///< Intensity stereo pos + float pns_ener[128]; ///< Noise energy values + DECLARE_ALIGNED(32, float, pcoeffs)[1024]; ///< coefficients for IMDCT, pristine + DECLARE_ALIGNED(32, float, coeffs)[1024]; ///< coefficients for IMDCT, maybe processed + DECLARE_ALIGNED(32, float, ret_buf)[2048]; ///< PCM output buffer + DECLARE_ALIGNED(16, float, ltp_state)[3072]; ///< time signal for LTP + DECLARE_ALIGNED(32, float, lcoeffs)[1024]; ///< MDCT of LTP coefficients + DECLARE_ALIGNED(32, float, prcoeffs)[1024]; ///< Main prediction coefs + PredictorState predictor_state[MAX_PREDICTORS]; +} SingleChannelElement; + +/** + * channel element - generic struct for SCE/CPE/CCE/LFE + */ +typedef struct ChannelElement { + // CPE specific + int common_window; ///< Set if channels share a common 'IndividualChannelStream' in bitstream. + int ms_mode; ///< Signals mid/side stereo flags coding mode + uint8_t is_mode; ///< Set if any bands have been encoded using intensity stereo + uint8_t ms_mask[128]; ///< Set if mid/side stereo is used for each scalefactor window band + uint8_t is_mask[128]; ///< Set if intensity stereo is used + // shared + SingleChannelElement ch[2]; +} ChannelElement; + struct AACEncContext; typedef struct AACCoefficientsEncoder { |