Showing the changes to libavcodec (6 of 6 files). Show all
Unified · Split
| @@ -32,10 +32,12 @@ · 31 unmodified lines | |||
| 32 | #include <limits.h> | 32 | #include <limits.h> |
| 33 | #include <stddef.h> | 33 | #include <stddef.h> |
| 34 | 34 | ||
| 35 | #include "libavcodec/aac.h" | ||
| 35 | #include "libavcodec/aacsbr.h" | 36 | #include "libavcodec/aacsbr.h" |
| 36 | #include "libavcodec/aacdec.h" | 37 | #include "libavcodec/aacdec.h" |
| 37 | #include "libavcodec/avcodec.h" | 38 | #include "libavcodec/avcodec.h" |
| 38 | #include "libavutil/attributes.h" | 39 | #include "libavutil/attributes.h" |
| 40 | #include "libavutil/error.h" | ||
| 39 | #include "libavutil/log.h" | 41 | #include "libavutil/log.h" |
| 40 | #include "libavutil/macros.h" | 42 | #include "libavutil/macros.h" |
| 41 | #include "libavutil/mem.h" | 43 | #include "libavutil/mem.h" |
| @@ -76,6 +78,46 @@ av_cold int ff_aac_decode_close(AVCodecContext *avctx) · 34 unmodified lines | |||
| 76 | return 0; | 78 | return 0; |
| 77 | } | 79 | } |
| 78 | 80 | ||
| 81 | av_cold int ff_aac_decode_init_common(AVCodecContext *avctx) | ||
| 82 | { | ||
| 83 | AACDecContext *ac = avctx->priv_data; | ||
| 84 | int is_fixed = ac->is_fixed, ret; | ||
| 85 | float scale_fixed, scale_float; | ||
| 86 | const float *const scalep = is_fixed ? &scale_fixed : &scale_float; | ||
| 87 | enum AVTXType tx_type = is_fixed ? AV_TX_INT32_MDCT : AV_TX_FLOAT_MDCT; | ||
| 88 | |||
| 89 | if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { | ||
| 90 | av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); | ||
| 91 | return AVERROR_INVALIDDATA; | ||
| 92 | } | ||
| 93 | |||
| 94 | ac->random_state = 0x1f2e3d4c; | ||
| 95 | |||
| 96 | #define MDCT_INIT(s, fn, len, sval) \ | ||
| 97 | scale_fixed = (sval) * 128.0f; \ | ||
| 98 | scale_float = (sval) / 32768.0f; \ | ||
| 99 | ret = av_tx_init(&s, &fn, tx_type, 1, len, scalep, 0); \ | ||
| 100 | if (ret < 0) \ | ||
| 101 | return ret | ||
| 102 | |||
| 103 | MDCT_INIT(ac->mdct120, ac->mdct120_fn, 120, 1.0/120); | ||
| 104 | MDCT_INIT(ac->mdct128, ac->mdct128_fn, 128, 1.0/128); | ||
| 105 | MDCT_INIT(ac->mdct480, ac->mdct480_fn, 480, 1.0/480); | ||
| 106 | MDCT_INIT(ac->mdct512, ac->mdct512_fn, 512, 1.0/512); | ||
| 107 | MDCT_INIT(ac->mdct960, ac->mdct960_fn, 960, 1.0/960); | ||
| 108 | MDCT_INIT(ac->mdct1024, ac->mdct1024_fn, 1024, 1.0/1024); | ||
| 109 | #undef MDCT_INIT | ||
| 110 | |||
| 111 | /* LTP forward MDCT */ | ||
| 112 | scale_fixed = -1.0; | ||
| 113 | scale_float = -32786.0*2 + 36; | ||
| 114 | ret = av_tx_init(&ac->mdct_ltp, &ac->mdct_ltp_fn, tx_type, 0, 1024, scalep, 0); | ||
| 115 | if (ret < 0) | ||
| 116 | return ret; | ||
| 117 | |||
| 118 | return 0; | ||
| 119 | } | ||
| 120 | |||
| 79 | #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | 121 | #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM |
| 80 | #define OFF(field) offsetof(AACDecContext, field) | 122 | #define OFF(field) offsetof(AACDecContext, field) |
| 81 | static const AVOption options[] = { | 123 | static const AVOption options[] = { |
| @@ -42,7 +42,6 @@ typedef int AAC_SIGNE; · 41 unmodified lines | |||
| 42 | #define Q23(a) (int)((a) * 8388608.0 + 0.5) | 42 | #define Q23(a) (int)((a) * 8388608.0 + 0.5) |
| 43 | #define Q30(x) (int)((x)*1073741824.0 + 0.5) | 43 | #define Q30(x) (int)((x)*1073741824.0 + 0.5) |
| 44 | #define Q31(x) (int)((x)*2147483648.0 + 0.5) | 44 | #define Q31(x) (int)((x)*2147483648.0 + 0.5) |
| 45 | #define TX_SCALE(x) ((x) * 128.0f) | ||
| 46 | #define GET_GAIN(x, y) (-(y) * (1 << (x))) + 1024 | 45 | #define GET_GAIN(x, y) (-(y) * (1 << (x))) + 1024 |
| 47 | #define AAC_MUL16(x, y) (int)(((int64_t)(x) * (y) + 0x8000) >> 16) | 46 | #define AAC_MUL16(x, y) (int)(((int64_t)(x) * (y) + 0x8000) >> 16) |
| 48 | #define AAC_MUL26(x, y) (int)(((int64_t)(x) * (y) + 0x2000000) >> 26) | 47 | #define AAC_MUL26(x, y) (int)(((int64_t)(x) * (y) + 0x2000000) >> 26) |
| @@ -110,7 +109,6 @@ typedef unsigned AAC_SIGNE; · 61 unmodified lines | |||
| 110 | #define Q23(x) ((float)(x)) | 109 | #define Q23(x) ((float)(x)) |
| 111 | #define Q30(x) ((float)(x)) | 110 | #define Q30(x) ((float)(x)) |
| 112 | #define Q31(x) ((float)(x)) | 111 | #define Q31(x) ((float)(x)) |
| 113 | #define TX_SCALE(x) ((x) / 32768.0f) | ||
| 114 | #define GET_GAIN(x, y) powf((x), -(y)) | 112 | #define GET_GAIN(x, y) powf((x), -(y)) |
| 115 | #define AAC_MUL16(x, y) ((x) * (y)) | 113 | #define AAC_MUL16(x, y) ((x) * (y)) |
| 116 | #define AAC_MUL26(x, y) ((x) * (y)) | 114 | #define AAC_MUL26(x, y) ((x) * (y)) |
| @@ -33,7 +33,6 @@ · 32 unmodified lines | |||
| 33 | */ | 33 | */ |
| 34 | 34 | ||
| 35 | #define USE_FIXED 0 | 35 | #define USE_FIXED 0 |
| 36 | #define TX_TYPE AV_TX_FLOAT_MDCT | ||
| 37 | 36 | ||
| 38 | #include "libavutil/float_dsp.h" | 37 | #include "libavutil/float_dsp.h" |
| 39 | #include "avcodec.h" | 38 | #include "avcodec.h" |
| @@ -306,6 +306,7 @@ typedef struct AACDecContext { · 305 unmodified lines | |||
| 306 | 306 | ||
| 307 | extern const struct AVClass ff_aac_decoder_class; | 307 | extern const struct AVClass ff_aac_decoder_class; |
| 308 | 308 | ||
| 309 | int ff_aac_decode_init_common(struct AVCodecContext *avctx); | ||
| 309 | int ff_aac_decode_close(struct AVCodecContext *avctx); | 310 | int ff_aac_decode_close(struct AVCodecContext *avctx); |
| 310 | 311 | ||
| 311 | void ff_aacdec_init_mips(AACDecContext *c); | 312 | void ff_aacdec_init_mips(AACDecContext *c); |
| @@ -59,7 +59,6 @@ · 58 unmodified lines | |||
| 59 | */ | 59 | */ |
| 60 | 60 | ||
| 61 | #define USE_FIXED 1 | 61 | #define USE_FIXED 1 |
| 62 | #define TX_TYPE AV_TX_INT32_MDCT | ||
| 63 | 62 | ||
| 64 | #include "libavutil/fixed_dsp.h" | 63 | #include "libavutil/fixed_dsp.h" |
| 65 | #include "avcodec.h" | 64 | #include "avcodec.h" |
| @@ -1145,7 +1145,6 @@ static AVOnce aac_table_init = AV_ONCE_INIT; · 1144 unmodified lines | |||
| 1145 | 1145 | ||
| 1146 | static av_cold int aac_decode_init(AVCodecContext *avctx) | 1146 | static av_cold int aac_decode_init(AVCodecContext *avctx) |
| 1147 | { | 1147 | { |
| 1148 | float scale; | ||
| 1149 | AACDecContext *ac = avctx->priv_data; | 1148 | AACDecContext *ac = avctx->priv_data; |
| 1150 | int ret; | 1149 | int ret; |
| 1151 | 1150 | ||
| @@ -1204,11 +1203,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) · 52 unmodified lines | |||
| 1204 | } | 1203 | } |
| 1205 | } | 1204 | } |
| 1206 | 1205 | ||
| 1207 | if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { | ||
| 1208 | av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); | ||
| 1209 | return AVERROR_INVALIDDATA; | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | #if USE_FIXED | 1206 | #if USE_FIXED |
| 1213 | ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT); | 1207 | ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT); |
| 1214 | #else | 1208 | #else |
| @@ -1218,29 +1212,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) · 3 unmodified lines | |||
| 1218 | return AVERROR(ENOMEM); | 1212 | return AVERROR(ENOMEM); |
| 1219 | } | 1213 | } |
| 1220 | 1214 | ||
| 1221 | ac->random_state = 0x1f2e3d4c; | 1215 | return ff_aac_decode_init_common(avctx); |
| 1222 | |||
| 1223 | #define MDCT_INIT(s, fn, len, sval) \ | ||
| 1224 | scale = sval; \ | ||
| 1225 | ret = av_tx_init(&s, &fn, TX_TYPE, 1, len, &scale, 0); \ | ||
| 1226 | if (ret < 0) \ | ||
| 1227 | return ret; | ||
| 1228 | |||
| 1229 | MDCT_INIT(ac->mdct120, ac->mdct120_fn, 120, TX_SCALE(1.0/120)) | ||
| 1230 | MDCT_INIT(ac->mdct128, ac->mdct128_fn, 128, TX_SCALE(1.0/128)) | ||
| 1231 | MDCT_INIT(ac->mdct480, ac->mdct480_fn, 480, TX_SCALE(1.0/480)) | ||
| 1232 | MDCT_INIT(ac->mdct512, ac->mdct512_fn, 512, TX_SCALE(1.0/512)) | ||
| 1233 | MDCT_INIT(ac->mdct960, ac->mdct960_fn, 960, TX_SCALE(1.0/960)) | ||
| 1234 | MDCT_INIT(ac->mdct1024, ac->mdct1024_fn, 1024, TX_SCALE(1.0/1024)) | ||
| 1235 | #undef MDCT_INIT | ||
| 1236 | |||
| 1237 | /* LTP forward MDCT */ | ||
| 1238 | scale = USE_FIXED ? -1.0 : -32786.0*2 + 36; | ||
| 1239 | ret = av_tx_init(&ac->mdct_ltp, &ac->mdct_ltp_fn, TX_TYPE, 0, 1024, &scale, 0); | ||
| 1240 | if (ret < 0) | ||
| 1241 | return ret; | ||
| 1242 | |||
| 1243 | return 0; | ||
| 1244 | } | 1216 | } |
| 1245 | 1217 | ||
| 1246 | /** | 1218 | /** |