Browse code

Merge remote-tracking branch 'newdev/master'

* newdev/master:
ac3enc: move compute_mantissa_size() to ac3dsp
ac3enc: move mant*_cnt and qmant*_ptr out of AC3EncodeContext
Remove support for stripping executables
ac3enc: NEON optimised float_to_fixed24
ac3: move ff_ac3_bit_alloc_calc_bap to ac3dsp
dfa: protect pointer range checks against overflows.
Duplicate: mimic: implement multithreading.

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/03/30 10:01:41
Showing 15 changed files
... ...
@@ -10,7 +10,6 @@ PROGS-$(CONFIG_FFPROBE)  += ffprobe
10 10
 PROGS-$(CONFIG_FFSERVER) += ffserver
11 11
 
12 12
 PROGS      := $(PROGS-yes:%=%$(EXESUF))
13
-PROGS_G     = $(PROGS-yes:%=%_g$(EXESUF))
14 13
 OBJS        = $(PROGS-yes:%=%.o) cmdutils.o
15 14
 MANPAGES    = $(PROGS-yes:%=doc/%.1)
16 15
 PODPAGES    = $(PROGS-yes:%=doc/%.pod)
... ...
@@ -21,7 +20,6 @@ HOSTPROGS  := $(TESTTOOLS:%=tests/%)
21 21
 
22 22
 BASENAMES   = ffmpeg ffplay ffprobe ffserver
23 23
 ALLPROGS    = $(BASENAMES:%=%$(EXESUF))
24
-ALLPROGS_G  = $(BASENAMES:%=%_g$(EXESUF))
25 24
 ALLMANPAGES = $(BASENAMES:%=%.1)
26 25
 
27 26
 FFLIBS-$(CONFIG_AVDEVICE) += avdevice
... ...
@@ -53,10 +51,6 @@ INSTALL_PROGS_TARGETS-$(CONFIG_SHARED) = install-libs
53 53
 
54 54
 all: $(FF_DEP_LIBS) $(PROGS) $(ALL_TARGETS-yes)
55 55
 
56
-$(PROGS): %$(EXESUF): %_g$(EXESUF)
57
-	$(CP) $< $@
58
-	$(STRIP) $@
59
-
60 56
 config.h: .config
61 57
 .config: $(wildcard $(FFLIBS:%=$(SRC_DIR)/lib%/all*.c))
62 58
 	@-tput bold 2>/dev/null
... ...
@@ -80,10 +74,10 @@ endef
80 80
 
81 81
 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
82 82
 
83
-ffplay_g$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
84
-ffserver_g$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS)
83
+ffplay$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
84
+ffserver$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS)
85 85
 
86
-%_g$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
86
+%$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
87 87
 	$(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
88 88
 
89 89
 tools/%$(EXESUF): tools/%.o
... ...
@@ -165,7 +159,7 @@ testclean:
165 165
 	$(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF))
166 166
 
167 167
 clean:: testclean
168
-	$(RM) $(ALLPROGS) $(ALLPROGS_G)
168
+	$(RM) $(ALLPROGS)
169 169
 	$(RM) $(CLEANSUFFIXES)
170 170
 	$(RM) doc/*.html doc/*.pod doc/*.1
171 171
 	$(RM) $(TOOLS)
... ...
@@ -21,7 +21,7 @@ endif
21 21
 ifndef V
22 22
 Q      = @
23 23
 ECHO   = printf "$(1)\t%s\n" $(2)
24
-BRIEF  = CC AS YASM AR LD HOSTCC STRIP CP
24
+BRIEF  = CC AS YASM AR LD HOSTCC
25 25
 SILENT = DEPCC YASMDEP RM RANLIB
26 26
 MSG    = $@
27 27
 M      = @$(call ECHO,$(TAG),$@);
... ...
@@ -243,7 +243,6 @@ Developer options (useful when working on FFmpeg itself):
243 243
   --enable-debug=LEVEL     set the debug level [$debuglevel]
244 244
   --disable-optimizations  disable compiler optimizations
245 245
   --enable-extra-warnings  enable more compiler warnings
246
-  --disable-stripping      disable stripping of executables and shared libraries
247 246
   --samples=PATH           location of test samples for FATE, if not set use
248 247
                            \$FATE_SAMPLES at make invocation time.
249 248
 
... ...
@@ -1146,7 +1145,6 @@ CMDLINE_SELECT="
1146 1146
     extra_warnings
1147 1147
     logging
1148 1148
     optimizations
1149
-    stripping
1150 1149
     symver
1151 1150
     yasm
1152 1151
 "
... ...
@@ -1184,7 +1182,6 @@ CMDLINE_SET="
1184 1184
     pkg_config
1185 1185
     samples
1186 1186
     source_path
1187
-    strip
1188 1187
     sysinclude
1189 1188
     sysroot
1190 1189
     target_exec
... ...
@@ -1242,7 +1239,7 @@ rdft_select="fft"
1242 1242
 aac_decoder_select="mdct rdft sinewin"
1243 1243
 aac_encoder_select="mdct sinewin"
1244 1244
 aac_latm_decoder_select="aac_decoder aac_latm_parser"
1245
-ac3_decoder_select="mdct ac3_parser"
1245
+ac3_decoder_select="mdct ac3dsp ac3_parser"
1246 1246
 ac3_encoder_select="mdct ac3dsp"
1247 1247
 ac3_fixed_encoder_select="ac3dsp"
1248 1248
 alac_encoder_select="lpc"
... ...
@@ -1624,7 +1621,6 @@ nm_default="nm"
1624 1624
 objformat="elf"
1625 1625
 pkg_config_default=pkg-config
1626 1626
 ranlib="ranlib"
1627
-strip_default="strip"
1628 1627
 yasmexe="yasm"
1629 1628
 nogas=":"
1630 1629
 
... ...
@@ -1657,7 +1653,6 @@ enable network
1657 1657
 enable optimizations
1658 1658
 enable protocols
1659 1659
 enable static
1660
-enable stripping
1661 1660
 enable swscale
1662 1661
 enable swscale_alpha
1663 1662
 
... ...
@@ -1834,11 +1829,10 @@ cc_default="${cross_prefix}${cc_default}"
1834 1834
 nm_default="${cross_prefix}${nm_default}"
1835 1835
 pkg_config_default="${cross_prefix}${pkg_config_default}"
1836 1836
 ranlib="${cross_prefix}${ranlib}"
1837
-strip_default="${cross_prefix}${strip_default}"
1838 1837
 
1839 1838
 sysinclude_default="${sysroot}/usr/include"
1840 1839
 
1841
-set_default cc nm pkg_config strip sysinclude
1840
+set_default cc nm pkg_config sysinclude
1842 1841
 enabled cross_compile || host_cc_default=$cc
1843 1842
 set_default host_cc
1844 1843
 
... ...
@@ -2397,7 +2391,6 @@ case $target_os in
2397 2397
         ;;
2398 2398
     bsd/os)
2399 2399
         add_extralibs -lpoll -lgnugetopt
2400
-        strip="strip -d"
2401 2400
         ;;
2402 2401
     darwin)
2403 2402
         enable malloc_aligned
... ...
@@ -2405,7 +2398,6 @@ case $target_os in
2405 2405
         enabled ppc && add_asflags -force_cpusubtype_ALL
2406 2406
         SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
2407 2407
         enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
2408
-        strip="${strip} -x"
2409 2408
         add_ldflags -Wl,-dynamic,-search_paths_first
2410 2409
         SLIBSUF=".dylib"
2411 2410
         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
... ...
@@ -2475,7 +2467,6 @@ case $target_os in
2475 2475
         ranlib="echo ignoring ranlib"
2476 2476
         ;;
2477 2477
     os/2*)
2478
-        strip="lxlite -CS"
2479 2478
         ln_s="cp -f"
2480 2479
         add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap
2481 2480
         SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
... ...
@@ -3130,7 +3121,6 @@ if enabled sparc; then
3130 3130
     echo "VIS enabled               ${vis-no}"
3131 3131
 fi
3132 3132
 echo "debug symbols             ${debug-no}"
3133
-echo "strip symbols             ${stripping-no}"
3134 3133
 echo "optimizations             ${optimizations-no}"
3135 3134
 echo "static                    ${static-no}"
3136 3135
 echo "shared                    ${shared-no}"
... ...
@@ -3226,8 +3216,6 @@ if enabled source_path_used; then
3226 3226
     map 'test -f "$source_path/$v" && $ln_s "$source_path/$v" $v' $FILES
3227 3227
 fi
3228 3228
 
3229
-enabled stripping || strip="echo skipping strip"
3230
-
3231 3229
 config_files="$TMPH config.mak"
3232 3230
 
3233 3231
 cat > config.mak <<EOF
... ...
@@ -3255,9 +3243,7 @@ YASM=$yasmexe
3255 3255
 YASMDEP=$yasmexe
3256 3256
 AR=$ar
3257 3257
 RANLIB=$ranlib
3258
-CP=cp -p
3259 3258
 LN_S=$ln_s
3260
-STRIP=$strip
3261 3259
 CPPFLAGS=$CPPFLAGS
3262 3260
 CFLAGS=$CFLAGS
3263 3261
 ASFLAGS=$ASFLAGS
... ...
@@ -31,7 +31,7 @@
31 31
 /**
32 32
  * Starting frequency coefficient bin for each critical band.
33 33
  */
34
-static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = {
34
+const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1] = {
35 35
       0,  1,   2,   3,   4,   5,   6,   7,   8,   9,
36 36
      10,  11, 12,  13,  14,  15,  16,  17,  18,  19,
37 37
      20,  21, 22,  23,  24,  25,  26,  27,  28,  31,
... ...
@@ -44,7 +44,7 @@ static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = {
44 44
 /**
45 45
  * Map each frequency coefficient bin to the critical band that contains it.
46 46
  */
47
-static const uint8_t bin_to_band_tab[253] = {
47
+const uint8_t ff_ac3_bin_to_band_tab[253] = {
48 48
      0,
49 49
      1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12,
50 50
     13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
... ...
@@ -70,7 +70,7 @@ static const uint8_t bin_to_band_tab[253] = {
70 70
 };
71 71
 
72 72
 #else /* CONFIG_HARDCODED_TABLES */
73
-static uint8_t bin_to_band_tab[253];
73
+uint8_t ff_ac3_bin_to_band_tab[253];
74 74
 #endif
75 75
 
76 76
 static inline int calc_lowcomp1(int a, int b0, int b1, int c)
... ...
@@ -106,10 +106,10 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
106 106
 
107 107
     /* PSD integration */
108 108
     bin  = start;
109
-    band = bin_to_band_tab[start];
109
+    band = ff_ac3_bin_to_band_tab[start];
110 110
     do {
111 111
         int v = psd[bin++];
112
-        int band_end = FFMIN(band_start_tab[band+1], end);
112
+        int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end);
113 113
         for (; bin < band_end; bin++) {
114 114
             int max = FFMAX(v, psd[bin]);
115 115
             /* logadd */
... ...
@@ -117,7 +117,7 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
117 117
             v = max + ff_ac3_log_add_tab[adr];
118 118
         }
119 119
         band_psd[band++] = v;
120
-    } while (end > band_start_tab[band]);
120
+    } while (end > ff_ac3_band_start_tab[band]);
121 121
 }
122 122
 
123 123
 int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
... ...
@@ -132,8 +132,8 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
132 132
     int lowcomp, fastleak, slowleak;
133 133
 
134 134
     /* excitation function */
135
-    band_start = bin_to_band_tab[start];
136
-    band_end   = bin_to_band_tab[end-1] + 1;
135
+    band_start = ff_ac3_bin_to_band_tab[start];
136
+    band_end   = ff_ac3_bin_to_band_tab[end-1] + 1;
137 137
 
138 138
     if (band_start == 0) {
139 139
         lowcomp = 0;
... ...
@@ -212,30 +212,6 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
212 212
     return 0;
213 213
 }
214 214
 
215
-void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
216
-                               int snr_offset, int floor,
217
-                               const uint8_t *bap_tab, uint8_t *bap)
218
-{
219
-    int bin, band;
220
-
221
-    /* special case, if snr offset is -960, set all bap's to zero */
222
-    if (snr_offset == -960) {
223
-        memset(bap, 0, AC3_MAX_COEFS);
224
-        return;
225
-    }
226
-
227
-    bin  = start;
228
-    band = bin_to_band_tab[start];
229
-    do {
230
-        int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
231
-        int band_end = FFMIN(band_start_tab[band+1], end);
232
-        for (; bin < band_end; bin++) {
233
-            int address = av_clip((psd[bin] - m) >> 5, 0, 63);
234
-            bap[bin] = bap_tab[address];
235
-        }
236
-    } while (end > band_start_tab[band++]);
237
-}
238
-
239 215
 /**
240 216
  * Initialize some tables.
241 217
  * note: This function must remain thread safe because it is called by the
... ...
@@ -244,12 +220,12 @@ void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
244 244
 av_cold void ff_ac3_common_init(void)
245 245
 {
246 246
 #if !CONFIG_HARDCODED_TABLES
247
-    /* compute bin_to_band_tab from band_start_tab */
247
+    /* compute ff_ac3_bin_to_band_tab from ff_ac3_band_start_tab */
248 248
     int bin = 0, band;
249 249
     for (band = 0; band < AC3_CRITICAL_BANDS; band++) {
250
-        int band_end = band_start_tab[band+1];
250
+        int band_end = ff_ac3_band_start_tab[band+1];
251 251
         while (bin < band_end)
252
-            bin_to_band_tab[bin++] = band;
252
+            ff_ac3_bin_to_band_tab[bin++] = band;
253 253
     }
254 254
 #endif /* !CONFIG_HARDCODED_TABLES */
255 255
 }
... ...
@@ -175,23 +175,4 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
175 175
                                uint8_t *dba_lengths, uint8_t *dba_values,
176 176
                                int16_t *mask);
177 177
 
178
-/**
179
- * Calculate bit allocation pointers.
180
- * The SNR is the difference between the masking curve and the signal.  AC-3
181
- * uses this value for each frequency bin to allocate bits.  The snroffset
182
- * parameter is a global adjustment to the SNR for all bins.
183
- *
184
- * @param[in]  mask       masking curve
185
- * @param[in]  psd        signal power for each frequency bin
186
- * @param[in]  start      starting bin location
187
- * @param[in]  end        ending bin location
188
- * @param[in]  snr_offset SNR adjustment
189
- * @param[in]  floor      noise floor
190
- * @param[in]  bap_tab    look-up table for bit allocation pointers
191
- * @param[out] bap        bit allocation pointers
192
- */
193
-void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
194
-                               int snr_offset, int floor,
195
-                               const uint8_t *bap_tab, uint8_t *bap);
196
-
197 178
 #endif /* AVCODEC_AC3_H */
... ...
@@ -184,6 +184,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
184 184
     ff_mdct_init(&s->imdct_512, 9, 1, 1.0);
185 185
     ff_kbd_window_init(s->window, 5.0, 256);
186 186
     dsputil_init(&s->dsp, avctx);
187
+    ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
187 188
     ff_fmt_convert_init(&s->fmt_conv, avctx);
188 189
     av_lfg_init(&s->dith_state, 0);
189 190
 
... ...
@@ -1213,7 +1214,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
1213 1213
             /* Compute bit allocation */
1214 1214
             const uint8_t *bap_tab = s->channel_uses_aht[ch] ?
1215 1215
                                      ff_eac3_hebap_tab : ff_ac3_bap_tab;
1216
-            ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
1216
+            s->ac3dsp.bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
1217 1217
                                       s->start_freq[ch], s->end_freq[ch],
1218 1218
                                       s->snr_offset[ch],
1219 1219
                                       s->bit_alloc_params.floor,
... ...
@@ -52,6 +52,7 @@
52 52
 
53 53
 #include "libavutil/lfg.h"
54 54
 #include "ac3.h"
55
+#include "ac3dsp.h"
55 56
 #include "get_bits.h"
56 57
 #include "dsputil.h"
57 58
 #include "fft.h"
... ...
@@ -192,6 +193,7 @@ typedef struct {
192 192
 
193 193
 ///@defgroup opt optimization
194 194
     DSPContext dsp;                         ///< for optimization
195
+    AC3DSPContext ac3dsp;
195 196
     FmtConvertContext fmt_conv;             ///< optimized conversion functions
196 197
     float mul_bias;                         ///< scaling for float_to_int16 conversion
197 198
 ///@}
... ...
@@ -20,6 +20,7 @@
20 20
  */
21 21
 
22 22
 #include "avcodec.h"
23
+#include "ac3.h"
23 24
 #include "ac3dsp.h"
24 25
 
25 26
 static void ac3_exponent_min_c(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
... ...
@@ -101,6 +102,53 @@ static void float_to_fixed24_c(int32_t *dst, const float *src, unsigned int len)
101 101
     } while (len > 0);
102 102
 }
103 103
 
104
+static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd,
105
+                                     int start, int end,
106
+                                     int snr_offset, int floor,
107
+                                     const uint8_t *bap_tab, uint8_t *bap)
108
+{
109
+    int bin, band;
110
+
111
+    /* special case, if snr offset is -960, set all bap's to zero */
112
+    if (snr_offset == -960) {
113
+        memset(bap, 0, AC3_MAX_COEFS);
114
+        return;
115
+    }
116
+
117
+    bin  = start;
118
+    band = ff_ac3_bin_to_band_tab[start];
119
+    do {
120
+        int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
121
+        int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end);
122
+        for (; bin < band_end; bin++) {
123
+            int address = av_clip((psd[bin] - m) >> 5, 0, 63);
124
+            bap[bin] = bap_tab[address];
125
+        }
126
+    } while (end > ff_ac3_band_start_tab[band++]);
127
+}
128
+
129
+static int ac3_compute_mantissa_size_c(int mant_cnt[5], uint8_t *bap,
130
+                                       int nb_coefs)
131
+{
132
+    int bits, b, i;
133
+
134
+    bits = 0;
135
+    for (i = 0; i < nb_coefs; i++) {
136
+        b = bap[i];
137
+        if (b <= 4) {
138
+            // bap=1 to bap=4 will be counted in compute_mantissa_size_final
139
+            mant_cnt[b]++;
140
+        } else if (b <= 13) {
141
+            // bap=5 to bap=13 use (bap-1) bits
142
+            bits += b - 1;
143
+        } else {
144
+            // bap=14 uses 14 bits and bap=15 uses 16 bits
145
+            bits += (b == 14) ? 14 : 16;
146
+        }
147
+    }
148
+    return bits;
149
+}
150
+
104 151
 av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
105 152
 {
106 153
     c->ac3_exponent_min = ac3_exponent_min_c;
... ...
@@ -108,6 +156,8 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
108 108
     c->ac3_lshift_int16 = ac3_lshift_int16_c;
109 109
     c->ac3_rshift_int32 = ac3_rshift_int32_c;
110 110
     c->float_to_fixed24 = float_to_fixed24_c;
111
+    c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c;
112
+    c->compute_mantissa_size = ac3_compute_mantissa_size_c;
111 113
 
112 114
     if (ARCH_ARM)
113 115
         ff_ac3dsp_init_arm(c, bit_exact);
... ...
@@ -81,6 +81,30 @@ typedef struct AC3DSPContext {
81 81
      *            constraints: multiple of 32 greater than zero
82 82
      */
83 83
     void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len);
84
+
85
+    /**
86
+     * Calculate bit allocation pointers.
87
+     * The SNR is the difference between the masking curve and the signal.  AC-3
88
+     * uses this value for each frequency bin to allocate bits.  The snroffset
89
+     * parameter is a global adjustment to the SNR for all bins.
90
+     *
91
+     * @param[in]  mask       masking curve
92
+     * @param[in]  psd        signal power for each frequency bin
93
+     * @param[in]  start      starting bin location
94
+     * @param[in]  end        ending bin location
95
+     * @param[in]  snr_offset SNR adjustment
96
+     * @param[in]  floor      noise floor
97
+     * @param[in]  bap_tab    look-up table for bit allocation pointers
98
+     * @param[out] bap        bit allocation pointers
99
+     */
100
+    void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end,
101
+                               int snr_offset, int floor,
102
+                               const uint8_t *bap_tab, uint8_t *bap);
103
+
104
+    /**
105
+     * Calculate the number of bits needed to encode a set of mantissas.
106
+     */
107
+    int (*compute_mantissa_size)(int mant_cnt[5], uint8_t *bap, int nb_coefs);
84 108
 } AC3DSPContext;
85 109
 
86 110
 void ff_ac3dsp_init    (AC3DSPContext *c, int bit_exact);
... ...
@@ -178,10 +178,6 @@ typedef struct AC3EncodeContext {
178 178
     int frame_bits;                         ///< all frame bits except exponents and mantissas
179 179
     int exponent_bits;                      ///< number of bits used for exponents
180 180
 
181
-    /* mantissa encoding */
182
-    int mant1_cnt, mant2_cnt, mant4_cnt;    ///< mantissa counts for bap=1,2,4
183
-    uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4
184
-
185 181
     SampleType **planar_samples;
186 182
     uint8_t *bap_buffer;
187 183
     uint8_t *bap1_buffer;
... ...
@@ -199,6 +195,10 @@ typedef struct AC3EncodeContext {
199 199
     DECLARE_ALIGNED(16, SampleType, windowed_samples)[AC3_WINDOW_SIZE];
200 200
 } AC3EncodeContext;
201 201
 
202
+typedef struct AC3Mant {
203
+    uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4
204
+    int mant1_cnt, mant2_cnt, mant4_cnt;    ///< mantissa counts for bap=1,2,4
205
+} AC3Mant;
202 206
 
203 207
 #define CMIXLEV_NUM_OPTIONS 3
204 208
 static const float cmixlev_options[CMIXLEV_NUM_OPTIONS] = {
... ...
@@ -928,31 +928,6 @@ static void count_frame_bits(AC3EncodeContext *s)
928 928
 
929 929
 
930 930
 /**
931
- * Calculate the number of bits needed to encode a set of mantissas.
932
- */
933
-static int compute_mantissa_size(int mant_cnt[5], uint8_t *bap, int nb_coefs)
934
-{
935
-    int bits, b, i;
936
-
937
-    bits = 0;
938
-    for (i = 0; i < nb_coefs; i++) {
939
-        b = bap[i];
940
-        if (b <= 4) {
941
-            // bap=1 to bap=4 will be counted in compute_mantissa_size_final
942
-            mant_cnt[b]++;
943
-        } else if (b <= 13) {
944
-            // bap=5 to bap=13 use (bap-1) bits
945
-            bits += b - 1;
946
-        } else {
947
-            // bap=14 uses 14 bits and bap=15 uses 16 bits
948
-            bits += (b == 14) ? 14 : 16;
949
-        }
950
-    }
951
-    return bits;
952
-}
953
-
954
-
955
-/**
956 931
  * Finalize the mantissa bit count by adding in the grouped mantissas.
957 932
  */
958 933
 static int compute_mantissa_size_final(int mant_cnt[5])
... ...
@@ -1047,12 +1022,12 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset)
1047 1047
                whenever we reuse exponents. */
1048 1048
             block = s->blocks[blk].exp_ref_block[ch];
1049 1049
             if (s->exp_strategy[ch][blk] != EXP_REUSE) {
1050
-                ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
1050
+                s->ac3dsp.bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
1051 1051
                                           s->nb_coefs[ch], snr_offset,
1052 1052
                                           s->bit_alloc.floor, ff_ac3_bap_tab,
1053 1053
                                           block->bap[ch]);
1054 1054
             }
1055
-            mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]);
1055
+            mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]);
1056 1056
         }
1057 1057
         mantissa_bits += compute_mantissa_size_final(mant_cnt);
1058 1058
     }
... ...
@@ -1248,7 +1223,7 @@ static inline int asym_quant(int c, int e, int qbits)
1248 1248
 /**
1249 1249
  * Quantize a set of mantissas for a single channel in a single block.
1250 1250
  */
1251
-static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef,
1251
+static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef,
1252 1252
                                       uint8_t *exp,
1253 1253
                                       uint8_t *bap, uint16_t *qmant, int n)
1254 1254
 {
... ...
@@ -1350,12 +1325,11 @@ static void quantize_mantissas(AC3EncodeContext *s)
1350 1350
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1351 1351
         AC3Block *block = &s->blocks[blk];
1352 1352
         AC3Block *ref_block;
1353
-        s->mant1_cnt  = s->mant2_cnt  = s->mant4_cnt  = 0;
1354
-        s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL;
1353
+        AC3Mant m = { 0 };
1355 1354
 
1356 1355
         for (ch = 0; ch < s->channels; ch++) {
1357 1356
             ref_block = block->exp_ref_block[ch];
1358
-            quantize_mantissas_blk_ch(s, block->fixed_coef[ch],
1357
+            quantize_mantissas_blk_ch(&m, block->fixed_coef[ch],
1359 1358
                                       ref_block->exp[ch], ref_block->bap[ch],
1360 1359
                                       block->qmant[ch], s->nb_coefs[ch]);
1361 1360
         }
... ...
@@ -25,6 +25,12 @@
25 25
 #include "libavutil/common.h"
26 26
 #include "ac3.h"
27 27
 
28
+#if CONFIG_HARDCODED_TABLES
29
+#   define HCONST const
30
+#else
31
+#   define HCONST
32
+#endif
33
+
28 34
 extern const uint16_t ff_ac3_frame_size_tab[38][3];
29 35
 extern const uint8_t  ff_ac3_channels_tab[8];
30 36
 extern const uint16_t ff_ac3_channel_layout_tab[8];
... ...
@@ -44,6 +50,8 @@ extern const uint16_t ff_ac3_db_per_bit_tab[4];
44 44
 extern const int16_t  ff_ac3_floor_tab[8];
45 45
 extern const uint16_t ff_ac3_fast_gain_tab[8];
46 46
 extern const uint16_t ff_eac3_default_chmap[8];
47
+extern const uint8_t  ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];
48
+extern HCONST uint8_t ff_ac3_bin_to_band_tab[253];
47 49
 
48 50
 /** Custom channel map locations bitmask
49 51
  *  Other channels described in documentation:
... ...
@@ -27,6 +27,7 @@ void ff_ac3_exponent_min_neon(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
27 27
 int ff_ac3_max_msb_abs_int16_neon(const int16_t *src, int len);
28 28
 void ff_ac3_lshift_int16_neon(int16_t *src, unsigned len, unsigned shift);
29 29
 void ff_ac3_rshift_int32_neon(int32_t *src, unsigned len, unsigned shift);
30
+void ff_float_to_fixed24_neon(int32_t *dst, const float *src, unsigned int len);
30 31
 
31 32
 av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
32 33
 {
... ...
@@ -35,5 +36,6 @@ av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
35 35
         c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_neon;
36 36
         c->ac3_lshift_int16      = ff_ac3_lshift_int16_neon;
37 37
         c->ac3_rshift_int32      = ff_ac3_rshift_int32_neon;
38
+        c->float_to_fixed24      = ff_float_to_fixed24_neon;
38 39
     }
39 40
 }
... ...
@@ -78,3 +78,17 @@ function ff_ac3_rshift_int32_neon, export=1
78 78
         bgt             1b
79 79
         bx              lr
80 80
 endfunc
81
+
82
+function ff_float_to_fixed24_neon, export=1
83
+1:      vld1.32         {q0-q1},  [r1,:128]!
84
+        vcvt.s32.f32    q0,  q0,  #24
85
+        vld1.32         {q2-q3},  [r1,:128]!
86
+        vcvt.s32.f32    q1,  q1,  #24
87
+        vcvt.s32.f32    q2,  q2,  #24
88
+        vst1.32         {q0-q1},  [r0,:128]!
89
+        vcvt.s32.f32    q3,  q3,  #24
90
+        vst1.32         {q2-q3},  [r0,:128]!
91
+        subs            r2,  r2,  #16
92
+        bgt             1b
93
+        bx              lr
94
+endfunc
... ...
@@ -81,7 +81,7 @@ static int decode_tsw1(uint8_t *frame, int width, int height,
81 81
             v = bytestream_get_le16(&src);
82 82
             offset = (v & 0x1FFF) << 1;
83 83
             count = ((v >> 13) + 2) << 1;
84
-            if (frame - offset < frame_start || frame_end - frame < count)
84
+            if (frame - frame_start < offset || frame_end - frame < count)
85 85
                 return -1;
86 86
             av_memcpy_backptr(frame, offset, count);
87 87
             frame += count;
... ...
@@ -117,7 +117,7 @@ static int decode_dsw1(uint8_t *frame, int width, int height,
117 117
             v = bytestream_get_le16(&src);
118 118
             offset = (v & 0x1FFF) << 1;
119 119
             count = ((v >> 13) + 2) << 1;
120
-            if (frame - offset < frame_start || frame_end - frame < count)
120
+            if (frame - frame_start < offset || frame_end - frame < count)
121 121
                 return -1;
122 122
             // can't use av_memcpy_backptr() since it can overwrite following pixels
123 123
             for (v = 0; v < count; v++)
... ...
@@ -157,7 +157,7 @@ static int decode_dds1(uint8_t *frame, int width, int height,
157 157
             v = bytestream_get_le16(&src);
158 158
             offset = (v & 0x1FFF) << 2;
159 159
             count = ((v >> 13) + 2) << 1;
160
-            if (frame - offset < frame_start || frame_end - frame < count*2 + width)
160
+            if (frame - frame_start < offset || frame_end - frame < count*2 + width)
161 161
                 return -1;
162 162
             for (i = 0; i < count; i++) {
163 163
                 frame[0] = frame[1] =
... ...
@@ -60,7 +60,6 @@ distclean:: clean
60 60
 install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
61 61
 	$(Q)mkdir -p "$(SHLIBDIR)"
62 62
 	$$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
63
-	$$(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
64 63
 	$(Q)cd "$(SHLIBDIR)" && \
65 64
 		$(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
66 65
 	$(Q)cd "$(SHLIBDIR)" && \