History

avcodec/aacdec_template: Deduplicate common part of aac_decode_init()

Andreas Rheinhardt committed 2 years ago

Commit 9de66fd1 parent 980a55f6 files · +44 −33Browse files

Showing the changes to libavcodec (6 of 6 files). Show all

Unified · Split

6 files
  1. libavcodec/aac/aacdec.c +42 −0
  2. libavcodec/aac_defines.h +0 −2
  3. libavcodec/aacdec.c +0 −1
  4. libavcodec/aacdec.h +1 −0
  5. libavcodec/aacdec_fixed.c +0 −1
  6. libavcodec/aacdec_template.c +1 −29
libavcodec/aac/aacdec.c+42−0
@@ -32,10 +32,12 @@ · 31 unmodified lines
3232 #include <limits.h>
3333 #include <stddef.h>
3434
35+#include "libavcodec/aac.h"
3536 #include "libavcodec/aacsbr.h"
3637 #include "libavcodec/aacdec.h"
3738 #include "libavcodec/avcodec.h"
3839 #include "libavutil/attributes.h"
40+#include "libavutil/error.h"
3941 #include "libavutil/log.h"
4042 #include "libavutil/macros.h"
4143 #include "libavutil/mem.h"
@@ -76,6 +78,46 @@ av_cold int ff_aac_decode_close(AVCodecContext *avctx) · 34 unmodified lines
7678 return 0;
7779 }
7880
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+
79121 #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
80122 #define OFF(field) offsetof(AACDecContext, field)
81123 static const AVOption options[] = {
libavcodec/aac_defines.h+0−2
@@ -42,7 +42,6 @@ typedef int AAC_SIGNE; · 41 unmodified lines
4242 #define Q23(a) (int)((a) * 8388608.0 + 0.5)
4343 #define Q30(x) (int)((x)*1073741824.0 + 0.5)
4444 #define Q31(x) (int)((x)*2147483648.0 + 0.5)
45−#define TX_SCALE(x) ((x) * 128.0f)
4645 #define GET_GAIN(x, y) (-(y) * (1 << (x))) + 1024
4746 #define AAC_MUL16(x, y) (int)(((int64_t)(x) * (y) + 0x8000) >> 16)
4847 #define AAC_MUL26(x, y) (int)(((int64_t)(x) * (y) + 0x2000000) >> 26)
@@ -110,7 +109,6 @@ typedef unsigned AAC_SIGNE; · 61 unmodified lines
110109 #define Q23(x) ((float)(x))
111110 #define Q30(x) ((float)(x))
112111 #define Q31(x) ((float)(x))
113−#define TX_SCALE(x) ((x) / 32768.0f)
114112 #define GET_GAIN(x, y) powf((x), -(y))
115113 #define AAC_MUL16(x, y) ((x) * (y))
116114 #define AAC_MUL26(x, y) ((x) * (y))
libavcodec/aacdec.c+0−1
@@ -33,7 +33,6 @@ · 32 unmodified lines
3333 */
3434
3535 #define USE_FIXED 0
36−#define TX_TYPE AV_TX_FLOAT_MDCT
3736
3837 #include "libavutil/float_dsp.h"
3938 #include "avcodec.h"
libavcodec/aacdec.h+1−0
@@ -306,6 +306,7 @@ typedef struct AACDecContext { · 305 unmodified lines
306306
307307 extern const struct AVClass ff_aac_decoder_class;
308308
309+int ff_aac_decode_init_common(struct AVCodecContext *avctx);
309310 int ff_aac_decode_close(struct AVCodecContext *avctx);
310311
311312 void ff_aacdec_init_mips(AACDecContext *c);
libavcodec/aacdec_fixed.c+0−1
@@ -59,7 +59,6 @@ · 58 unmodified lines
5959 */
6060
6161 #define USE_FIXED 1
62−#define TX_TYPE AV_TX_INT32_MDCT
6362
6463 #include "libavutil/fixed_dsp.h"
6564 #include "avcodec.h"
libavcodec/aacdec_template.c+1−29
@@ -1145,7 +1145,6 @@ static AVOnce aac_table_init = AV_ONCE_INIT; · 1144 unmodified lines
11451145
11461146 static av_cold int aac_decode_init(AVCodecContext *avctx)
11471147 {
1148− float scale;
11491148 AACDecContext *ac = avctx->priv_data;
11501149 int ret;
11511150
@@ -1204,11 +1203,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) · 52 unmodified lines
12041203 }
12051204 }
12061205
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−
12121206 #if USE_FIXED
12131207 ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT);
12141208 #else
@@ -1218,29 +1212,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) · 3 unmodified lines
12181212 return AVERROR(ENOMEM);
12191213 }
12201214
1221− ac->random_state = 0x1f2e3d4c;
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;
1215+ return ff_aac_decode_init_common(avctx);
12441216 }
12451217
12461218 /**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t