Commit 445fdc01 authored by Michael Niedermayer's avatar Michael Niedermayer

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: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 55ce3c67 52fd16a2
...@@ -10,7 +10,6 @@ PROGS-$(CONFIG_FFPROBE) += ffprobe ...@@ -10,7 +10,6 @@ PROGS-$(CONFIG_FFPROBE) += ffprobe
PROGS-$(CONFIG_FFSERVER) += ffserver PROGS-$(CONFIG_FFSERVER) += ffserver
PROGS := $(PROGS-yes:%=%$(EXESUF)) PROGS := $(PROGS-yes:%=%$(EXESUF))
PROGS_G = $(PROGS-yes:%=%_g$(EXESUF))
OBJS = $(PROGS-yes:%=%.o) cmdutils.o OBJS = $(PROGS-yes:%=%.o) cmdutils.o
MANPAGES = $(PROGS-yes:%=doc/%.1) MANPAGES = $(PROGS-yes:%=doc/%.1)
PODPAGES = $(PROGS-yes:%=doc/%.pod) PODPAGES = $(PROGS-yes:%=doc/%.pod)
...@@ -21,7 +20,6 @@ HOSTPROGS := $(TESTTOOLS:%=tests/%) ...@@ -21,7 +20,6 @@ HOSTPROGS := $(TESTTOOLS:%=tests/%)
BASENAMES = ffmpeg ffplay ffprobe ffserver BASENAMES = ffmpeg ffplay ffprobe ffserver
ALLPROGS = $(BASENAMES:%=%$(EXESUF)) ALLPROGS = $(BASENAMES:%=%$(EXESUF))
ALLPROGS_G = $(BASENAMES:%=%_g$(EXESUF))
ALLMANPAGES = $(BASENAMES:%=%.1) ALLMANPAGES = $(BASENAMES:%=%.1)
FFLIBS-$(CONFIG_AVDEVICE) += avdevice FFLIBS-$(CONFIG_AVDEVICE) += avdevice
...@@ -53,10 +51,6 @@ INSTALL_PROGS_TARGETS-$(CONFIG_SHARED) = install-libs ...@@ -53,10 +51,6 @@ INSTALL_PROGS_TARGETS-$(CONFIG_SHARED) = install-libs
all: $(FF_DEP_LIBS) $(PROGS) $(ALL_TARGETS-yes) all: $(FF_DEP_LIBS) $(PROGS) $(ALL_TARGETS-yes)
$(PROGS): %$(EXESUF): %_g$(EXESUF)
$(CP) $< $@
$(STRIP) $@
config.h: .config config.h: .config
.config: $(wildcard $(FFLIBS:%=$(SRC_DIR)/lib%/all*.c)) .config: $(wildcard $(FFLIBS:%=$(SRC_DIR)/lib%/all*.c))
@-tput bold 2>/dev/null @-tput bold 2>/dev/null
...@@ -80,10 +74,10 @@ endef ...@@ -80,10 +74,10 @@ endef
$(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D)))) $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
ffplay_g$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS) ffplay$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
ffserver_g$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS) ffserver$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS)
%_g$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS) %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
$(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS) $(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
tools/%$(EXESUF): tools/%.o tools/%$(EXESUF): tools/%.o
...@@ -165,7 +159,7 @@ testclean: ...@@ -165,7 +159,7 @@ testclean:
$(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF)) $(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF))
clean:: testclean clean:: testclean
$(RM) $(ALLPROGS) $(ALLPROGS_G) $(RM) $(ALLPROGS)
$(RM) $(CLEANSUFFIXES) $(RM) $(CLEANSUFFIXES)
$(RM) doc/*.html doc/*.pod doc/*.1 $(RM) doc/*.html doc/*.pod doc/*.1
$(RM) $(TOOLS) $(RM) $(TOOLS)
......
...@@ -21,7 +21,7 @@ endif ...@@ -21,7 +21,7 @@ endif
ifndef V ifndef V
Q = @ Q = @
ECHO = printf "$(1)\t%s\n" $(2) ECHO = printf "$(1)\t%s\n" $(2)
BRIEF = CC AS YASM AR LD HOSTCC STRIP CP BRIEF = CC AS YASM AR LD HOSTCC
SILENT = DEPCC YASMDEP RM RANLIB SILENT = DEPCC YASMDEP RM RANLIB
MSG = $@ MSG = $@
M = @$(call ECHO,$(TAG),$@); M = @$(call ECHO,$(TAG),$@);
......
...@@ -243,7 +243,6 @@ Developer options (useful when working on FFmpeg itself): ...@@ -243,7 +243,6 @@ Developer options (useful when working on FFmpeg itself):
--enable-debug=LEVEL set the debug level [$debuglevel] --enable-debug=LEVEL set the debug level [$debuglevel]
--disable-optimizations disable compiler optimizations --disable-optimizations disable compiler optimizations
--enable-extra-warnings enable more compiler warnings --enable-extra-warnings enable more compiler warnings
--disable-stripping disable stripping of executables and shared libraries
--samples=PATH location of test samples for FATE, if not set use --samples=PATH location of test samples for FATE, if not set use
\$FATE_SAMPLES at make invocation time. \$FATE_SAMPLES at make invocation time.
...@@ -1146,7 +1145,6 @@ CMDLINE_SELECT=" ...@@ -1146,7 +1145,6 @@ CMDLINE_SELECT="
extra_warnings extra_warnings
logging logging
optimizations optimizations
stripping
symver symver
yasm yasm
" "
...@@ -1184,7 +1182,6 @@ CMDLINE_SET=" ...@@ -1184,7 +1182,6 @@ CMDLINE_SET="
pkg_config pkg_config
samples samples
source_path source_path
strip
sysinclude sysinclude
sysroot sysroot
target_exec target_exec
...@@ -1242,7 +1239,7 @@ rdft_select="fft" ...@@ -1242,7 +1239,7 @@ rdft_select="fft"
aac_decoder_select="mdct rdft sinewin" aac_decoder_select="mdct rdft sinewin"
aac_encoder_select="mdct sinewin" aac_encoder_select="mdct sinewin"
aac_latm_decoder_select="aac_decoder aac_latm_parser" aac_latm_decoder_select="aac_decoder aac_latm_parser"
ac3_decoder_select="mdct ac3_parser" ac3_decoder_select="mdct ac3dsp ac3_parser"
ac3_encoder_select="mdct ac3dsp" ac3_encoder_select="mdct ac3dsp"
ac3_fixed_encoder_select="ac3dsp" ac3_fixed_encoder_select="ac3dsp"
alac_encoder_select="lpc" alac_encoder_select="lpc"
...@@ -1624,7 +1621,6 @@ nm_default="nm" ...@@ -1624,7 +1621,6 @@ nm_default="nm"
objformat="elf" objformat="elf"
pkg_config_default=pkg-config pkg_config_default=pkg-config
ranlib="ranlib" ranlib="ranlib"
strip_default="strip"
yasmexe="yasm" yasmexe="yasm"
nogas=":" nogas=":"
...@@ -1657,7 +1653,6 @@ enable network ...@@ -1657,7 +1653,6 @@ enable network
enable optimizations enable optimizations
enable protocols enable protocols
enable static enable static
enable stripping
enable swscale enable swscale
enable swscale_alpha enable swscale_alpha
...@@ -1834,11 +1829,10 @@ cc_default="${cross_prefix}${cc_default}" ...@@ -1834,11 +1829,10 @@ cc_default="${cross_prefix}${cc_default}"
nm_default="${cross_prefix}${nm_default}" nm_default="${cross_prefix}${nm_default}"
pkg_config_default="${cross_prefix}${pkg_config_default}" pkg_config_default="${cross_prefix}${pkg_config_default}"
ranlib="${cross_prefix}${ranlib}" ranlib="${cross_prefix}${ranlib}"
strip_default="${cross_prefix}${strip_default}"
sysinclude_default="${sysroot}/usr/include" sysinclude_default="${sysroot}/usr/include"
set_default cc nm pkg_config strip sysinclude set_default cc nm pkg_config sysinclude
enabled cross_compile || host_cc_default=$cc enabled cross_compile || host_cc_default=$cc
set_default host_cc set_default host_cc
...@@ -2397,7 +2391,6 @@ case $target_os in ...@@ -2397,7 +2391,6 @@ case $target_os in
;; ;;
bsd/os) bsd/os)
add_extralibs -lpoll -lgnugetopt add_extralibs -lpoll -lgnugetopt
strip="strip -d"
;; ;;
darwin) darwin)
enable malloc_aligned enable malloc_aligned
...@@ -2405,7 +2398,6 @@ case $target_os in ...@@ -2405,7 +2398,6 @@ case $target_os in
enabled ppc && add_asflags -force_cpusubtype_ALL enabled ppc && add_asflags -force_cpusubtype_ALL
SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)' SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
strip="${strip} -x"
add_ldflags -Wl,-dynamic,-search_paths_first add_ldflags -Wl,-dynamic,-search_paths_first
SLIBSUF=".dylib" SLIBSUF=".dylib"
SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)' SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
...@@ -2475,7 +2467,6 @@ case $target_os in ...@@ -2475,7 +2467,6 @@ case $target_os in
ranlib="echo ignoring ranlib" ranlib="echo ignoring ranlib"
;; ;;
os/2*) os/2*)
strip="lxlite -CS"
ln_s="cp -f" ln_s="cp -f"
add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap
SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf' SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
...@@ -3130,7 +3121,6 @@ if enabled sparc; then ...@@ -3130,7 +3121,6 @@ if enabled sparc; then
echo "VIS enabled ${vis-no}" echo "VIS enabled ${vis-no}"
fi fi
echo "debug symbols ${debug-no}" echo "debug symbols ${debug-no}"
echo "strip symbols ${stripping-no}"
echo "optimizations ${optimizations-no}" echo "optimizations ${optimizations-no}"
echo "static ${static-no}" echo "static ${static-no}"
echo "shared ${shared-no}" echo "shared ${shared-no}"
...@@ -3226,8 +3216,6 @@ if enabled source_path_used; then ...@@ -3226,8 +3216,6 @@ if enabled source_path_used; then
map 'test -f "$source_path/$v" && $ln_s "$source_path/$v" $v' $FILES map 'test -f "$source_path/$v" && $ln_s "$source_path/$v" $v' $FILES
fi fi
enabled stripping || strip="echo skipping strip"
config_files="$TMPH config.mak" config_files="$TMPH config.mak"
cat > config.mak <<EOF cat > config.mak <<EOF
...@@ -3255,9 +3243,7 @@ YASM=$yasmexe ...@@ -3255,9 +3243,7 @@ YASM=$yasmexe
YASMDEP=$yasmexe YASMDEP=$yasmexe
AR=$ar AR=$ar
RANLIB=$ranlib RANLIB=$ranlib
CP=cp -p
LN_S=$ln_s LN_S=$ln_s
STRIP=$strip
CPPFLAGS=$CPPFLAGS CPPFLAGS=$CPPFLAGS
CFLAGS=$CFLAGS CFLAGS=$CFLAGS
ASFLAGS=$ASFLAGS ASFLAGS=$ASFLAGS
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
/** /**
* Starting frequency coefficient bin for each critical band. * Starting frequency coefficient bin for each critical band.
*/ */
static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = { const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 31, 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,7 +44,7 @@ static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = {
/** /**
* Map each frequency coefficient bin to the critical band that contains it. * Map each frequency coefficient bin to the critical band that contains it.
*/ */
static const uint8_t bin_to_band_tab[253] = { const uint8_t ff_ac3_bin_to_band_tab[253] = {
0, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 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,7 +70,7 @@ static const uint8_t bin_to_band_tab[253] = {
}; };
#else /* CONFIG_HARDCODED_TABLES */ #else /* CONFIG_HARDCODED_TABLES */
static uint8_t bin_to_band_tab[253]; uint8_t ff_ac3_bin_to_band_tab[253];
#endif #endif
static inline int calc_lowcomp1(int a, int b0, int b1, int c) 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,10 +106,10 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
/* PSD integration */ /* PSD integration */
bin = start; bin = start;
band = bin_to_band_tab[start]; band = ff_ac3_bin_to_band_tab[start];
do { do {
int v = psd[bin++]; int v = psd[bin++];
int band_end = FFMIN(band_start_tab[band+1], end); int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end);
for (; bin < band_end; bin++) { for (; bin < band_end; bin++) {
int max = FFMAX(v, psd[bin]); int max = FFMAX(v, psd[bin]);
/* logadd */ /* logadd */
...@@ -117,7 +117,7 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, ...@@ -117,7 +117,7 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
v = max + ff_ac3_log_add_tab[adr]; v = max + ff_ac3_log_add_tab[adr];
} }
band_psd[band++] = v; band_psd[band++] = v;
} while (end > band_start_tab[band]); } while (end > ff_ac3_band_start_tab[band]);
} }
int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, 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,8 +132,8 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
int lowcomp, fastleak, slowleak; int lowcomp, fastleak, slowleak;
/* excitation function */ /* excitation function */
band_start = bin_to_band_tab[start]; band_start = ff_ac3_bin_to_band_tab[start];
band_end = bin_to_band_tab[end-1] + 1; band_end = ff_ac3_bin_to_band_tab[end-1] + 1;
if (band_start == 0) { if (band_start == 0) {
lowcomp = 0; lowcomp = 0;
...@@ -212,30 +212,6 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, ...@@ -212,30 +212,6 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
return 0; return 0;
} }
void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
int snr_offset, int floor,
const uint8_t *bap_tab, uint8_t *bap)
{
int bin, band;
/* special case, if snr offset is -960, set all bap's to zero */
if (snr_offset == -960) {
memset(bap, 0, AC3_MAX_COEFS);
return;
}
bin = start;
band = bin_to_band_tab[start];
do {
int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
int band_end = FFMIN(band_start_tab[band+1], end);
for (; bin < band_end; bin++) {
int address = av_clip((psd[bin] - m) >> 5, 0, 63);
bap[bin] = bap_tab[address];
}
} while (end > band_start_tab[band++]);
}
/** /**
* Initialize some tables. * Initialize some tables.
* note: This function must remain thread safe because it is called by the * 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,12 +220,12 @@ void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
av_cold void ff_ac3_common_init(void) av_cold void ff_ac3_common_init(void)
{ {
#if !CONFIG_HARDCODED_TABLES #if !CONFIG_HARDCODED_TABLES
/* compute bin_to_band_tab from band_start_tab */ /* compute ff_ac3_bin_to_band_tab from ff_ac3_band_start_tab */
int bin = 0, band; int bin = 0, band;
for (band = 0; band < AC3_CRITICAL_BANDS; band++) { for (band = 0; band < AC3_CRITICAL_BANDS; band++) {
int band_end = band_start_tab[band+1]; int band_end = ff_ac3_band_start_tab[band+1];
while (bin < band_end) while (bin < band_end)
bin_to_band_tab[bin++] = band; ff_ac3_bin_to_band_tab[bin++] = band;
} }
#endif /* !CONFIG_HARDCODED_TABLES */ #endif /* !CONFIG_HARDCODED_TABLES */
} }
...@@ -175,23 +175,4 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, ...@@ -175,23 +175,4 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
uint8_t *dba_lengths, uint8_t *dba_values, uint8_t *dba_lengths, uint8_t *dba_values,
int16_t *mask); int16_t *mask);
/**
* Calculate bit allocation pointers.
* The SNR is the difference between the masking curve and the signal. AC-3
* uses this value for each frequency bin to allocate bits. The snroffset
* parameter is a global adjustment to the SNR for all bins.
*
* @param[in] mask masking curve
* @param[in] psd signal power for each frequency bin
* @param[in] start starting bin location
* @param[in] end ending bin location
* @param[in] snr_offset SNR adjustment
* @param[in] floor noise floor
* @param[in] bap_tab look-up table for bit allocation pointers
* @param[out] bap bit allocation pointers
*/
void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
int snr_offset, int floor,
const uint8_t *bap_tab, uint8_t *bap);
#endif /* AVCODEC_AC3_H */ #endif /* AVCODEC_AC3_H */
...@@ -184,6 +184,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) ...@@ -184,6 +184,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
ff_mdct_init(&s->imdct_512, 9, 1, 1.0); ff_mdct_init(&s->imdct_512, 9, 1, 1.0);
ff_kbd_window_init(s->window, 5.0, 256); ff_kbd_window_init(s->window, 5.0, 256);
dsputil_init(&s->dsp, avctx); dsputil_init(&s->dsp, avctx);
ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
ff_fmt_convert_init(&s->fmt_conv, avctx); ff_fmt_convert_init(&s->fmt_conv, avctx);
av_lfg_init(&s->dith_state, 0); av_lfg_init(&s->dith_state, 0);
...@@ -1213,7 +1214,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) ...@@ -1213,7 +1214,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
/* Compute bit allocation */ /* Compute bit allocation */
const uint8_t *bap_tab = s->channel_uses_aht[ch] ? const uint8_t *bap_tab = s->channel_uses_aht[ch] ?
ff_eac3_hebap_tab : ff_ac3_bap_tab; ff_eac3_hebap_tab : ff_ac3_bap_tab;
ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], s->ac3dsp.bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
s->start_freq[ch], s->end_freq[ch], s->start_freq[ch], s->end_freq[ch],
s->snr_offset[ch], s->snr_offset[ch],
s->bit_alloc_params.floor, s->bit_alloc_params.floor,
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "libavutil/lfg.h" #include "libavutil/lfg.h"
#include "ac3.h" #include "ac3.h"
#include "ac3dsp.h"
#include "get_bits.h" #include "get_bits.h"
#include "dsputil.h" #include "dsputil.h"
#include "fft.h" #include "fft.h"
...@@ -192,6 +193,7 @@ typedef struct { ...@@ -192,6 +193,7 @@ typedef struct {
///@defgroup opt optimization ///@defgroup opt optimization
DSPContext dsp; ///< for optimization DSPContext dsp; ///< for optimization
AC3DSPContext ac3dsp;
FmtConvertContext fmt_conv; ///< optimized conversion functions FmtConvertContext fmt_conv; ///< optimized conversion functions
float mul_bias; ///< scaling for float_to_int16 conversion float mul_bias; ///< scaling for float_to_int16 conversion
///@} ///@}
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
*/ */
#include "avcodec.h" #include "avcodec.h"
#include "ac3.h"
#include "ac3dsp.h" #include "ac3dsp.h"
static void ac3_exponent_min_c(uint8_t *exp, int num_reuse_blocks, int nb_coefs) 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,6 +102,53 @@ static void float_to_fixed24_c(int32_t *dst, const float *src, unsigned int len)
} while (len > 0); } while (len > 0);
} }
static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd,
int start, int end,
int snr_offset, int floor,
const uint8_t *bap_tab, uint8_t *bap)
{
int bin, band;
/* special case, if snr offset is -960, set all bap's to zero */
if (snr_offset == -960) {
memset(bap, 0, AC3_MAX_COEFS);
return;
}
bin = start;
band = ff_ac3_bin_to_band_tab[start];
do {
int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end);
for (; bin < band_end; bin++) {
int address = av_clip((psd[bin] - m) >> 5, 0, 63);
bap[bin] = bap_tab[address];
}
} while (end > ff_ac3_band_start_tab[band++]);
}
static int ac3_compute_mantissa_size_c(int mant_cnt[5], uint8_t *bap,
int nb_coefs)
{
int bits, b, i;
bits = 0;
for (i = 0; i < nb_coefs; i++) {
b = bap[i];
if (b <= 4) {
// bap=1 to bap=4 will be counted in compute_mantissa_size_final
mant_cnt[b]++;
} else if (b <= 13) {
// bap=5 to bap=13 use (bap-1) bits
bits += b - 1;
} else {
// bap=14 uses 14 bits and bap=15 uses 16 bits
bits += (b == 14) ? 14 : 16;
}
}
return bits;
}
av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
{ {
c->ac3_exponent_min = ac3_exponent_min_c; c->ac3_exponent_min = ac3_exponent_min_c;
...@@ -108,6 +156,8 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) ...@@ -108,6 +156,8 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
c->ac3_lshift_int16 = ac3_lshift_int16_c; c->ac3_lshift_int16 = ac3_lshift_int16_c;
c->ac3_rshift_int32 = ac3_rshift_int32_c; c->ac3_rshift_int32 = ac3_rshift_int32_c;
c->float_to_fixed24 = float_to_fixed24_c; c->float_to_fixed24 = float_to_fixed24_c;
c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c;
c->compute_mantissa_size = ac3_compute_mantissa_size_c;
if (ARCH_ARM) if (ARCH_ARM)
ff_ac3dsp_init_arm(c, bit_exact); ff_ac3dsp_init_arm(c, bit_exact);
......
...@@ -81,6 +81,30 @@ typedef struct AC3DSPContext { ...@@ -81,6 +81,30 @@ typedef struct AC3DSPContext {
* constraints: multiple of 32 greater than zero * constraints: multiple of 32 greater than zero
*/ */
void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len); void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len);
/**
* Calculate bit allocation pointers.
* The SNR is the difference between the masking curve and the signal. AC-3
* uses this value for each frequency bin to allocate bits. The snroffset
* parameter is a global adjustment to the SNR for all bins.
*
* @param[in] mask masking curve
* @param[in] psd signal power for each frequency bin
* @param[in] start starting bin location
* @param[in] end ending bin location
* @param[in] snr_offset SNR adjustment
* @param[in] floor noise floor
* @param[in] bap_tab look-up table for bit allocation pointers
* @param[out] bap bit allocation pointers
*/
void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end,
int snr_offset, int floor,
const uint8_t *bap_tab, uint8_t *bap);
/**
* Calculate the number of bits needed to encode a set of mantissas.
*/
int (*compute_mantissa_size)(int mant_cnt[5], uint8_t *bap, int nb_coefs);
} AC3DSPContext; } AC3DSPContext;
void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact);
......
...@@ -178,10 +178,6 @@ typedef struct AC3EncodeContext { ...@@ -178,10 +178,6 @@ typedef struct AC3EncodeContext {
int frame_bits; ///< all frame bits except exponents and mantissas int frame_bits; ///< all frame bits except exponents and mantissas
int exponent_bits; ///< number of bits used for exponents int exponent_bits; ///< number of bits used for exponents
/* mantissa encoding */
int mant1_cnt, mant2_cnt, mant4_cnt; ///< mantissa counts for bap=1,2,4
uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4
SampleType **planar_samples; SampleType **planar_samples;
uint8_t *bap_buffer; uint8_t *bap_buffer;
uint8_t *bap1_buffer; uint8_t *bap1_buffer;
...@@ -199,6 +195,10 @@ typedef struct AC3EncodeContext { ...@@ -199,6 +195,10 @@ typedef struct AC3EncodeContext {
DECLARE_ALIGNED(16, SampleType, windowed_samples)[AC3_WINDOW_SIZE]; DECLARE_ALIGNED(16, SampleType, windowed_samples)[AC3_WINDOW_SIZE];
} AC3EncodeContext; } AC3EncodeContext;
typedef struct AC3Mant {
uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4
int mant1_cnt, mant2_cnt, mant4_cnt; ///< mantissa counts for bap=1,2,4
} AC3Mant;
#define CMIXLEV_NUM_OPTIONS 3 #define CMIXLEV_NUM_OPTIONS 3
static const float cmixlev_options[CMIXLEV_NUM_OPTIONS] = { static const float cmixlev_options[CMIXLEV_NUM_OPTIONS] = {
...@@ -927,31 +927,6 @@ static void count_frame_bits(AC3EncodeContext *s) ...@@ -927,31 +927,6 @@ static void count_frame_bits(AC3EncodeContext *s)
} }
/**
* Calculate the number of bits needed to encode a set of mantissas.
*/
static int compute_mantissa_size(int mant_cnt[5], uint8_t *bap, int nb_coefs)
{
int bits, b, i;
bits = 0;
for (i = 0; i < nb_coefs; i++) {
b = bap[i];
if (b <= 4) {
// bap=1 to bap=4 will be counted in compute_mantissa_size_final
mant_cnt[b]++;
} else if (b <= 13) {
// bap=5 to bap=13 use (bap-1) bits
bits += b - 1;
} else {
// bap=14 uses 14 bits and bap=15 uses 16 bits
bits += (b == 14) ? 14 : 16;
}
}
return bits;
}
/** /**
* Finalize the mantissa bit count by adding in the grouped mantissas. * Finalize the mantissa bit count by adding in the grouped mantissas.
*/ */
...@@ -1047,12 +1022,12 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) ...@@ -1047,12 +1022,12 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset)
whenever we reuse exponents. */ whenever we reuse exponents. */
block = s->blocks[blk].exp_ref_block[ch]; block = s->blocks[blk].exp_ref_block[ch];
if (s->exp_strategy[ch][blk] != EXP_REUSE) { if (s->exp_strategy[ch][blk] != EXP_REUSE) {
ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0, s->ac3dsp.bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
s->nb_coefs[ch], snr_offset, s->nb_coefs[ch], snr_offset,
s->bit_alloc.floor, ff_ac3_bap_tab, s->bit_alloc.floor, ff_ac3_bap_tab,
block->bap[ch]); block->bap[ch]);
} }
mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]); mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]);
} }
mantissa_bits += compute_mantissa_size_final(mant_cnt); mantissa_bits += compute_mantissa_size_final(mant_cnt);
} }
...@@ -1248,7 +1223,7 @@ static inline int asym_quant(int c, int e, int qbits) ...@@ -1248,7 +1223,7 @@ static inline int asym_quant(int c, int e, int qbits)
/** /**
* Quantize a set of mantissas for a single channel in a single block. * Quantize a set of mantissas for a single channel in a single block.
*/ */
static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef, static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef,
uint8_t *exp, uint8_t *exp,
uint8_t *bap, uint16_t *qmant, int n) uint8_t *bap, uint16_t *qmant, int n)
{ {
...@@ -1350,12 +1325,11 @@ static void quantize_mantissas(AC3EncodeContext *s) ...@@ -1350,12 +1325,11 @@ static void quantize_mantissas(AC3EncodeContext *s)
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
AC3Block *block = &s->blocks[blk]; AC3Block *block = &s->blocks[blk];
AC3Block *ref_block; AC3Block *ref_block;
s->mant1_cnt = s->mant2_cnt = s->mant4_cnt = 0; AC3Mant m = { 0 };
s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL;
for (ch = 0; ch < s->channels; ch++) { for (ch = 0; ch < s->channels; ch++) {
ref_block = block->exp_ref_block[ch]; ref_block = block->exp_ref_block[ch];
quantize_mantissas_blk_ch(s, block->fixed_coef[ch], quantize_mantissas_blk_ch(&m, block->fixed_coef[ch],
ref_block->exp[ch], ref_block->bap[ch], ref_block->exp[ch], ref_block->bap[ch],
block->qmant[ch], s->nb_coefs[ch]); block->qmant[ch], s->nb_coefs[ch]);
} }
......
...@@ -25,6 +25,12 @@ ...@@ -25,6 +25,12 @@
#include "libavutil/common.h" #include "libavutil/common.h"
#include "ac3.h" #include "ac3.h"
#if CONFIG_HARDCODED_TABLES
# define HCONST const
#else
# define HCONST
#endif
extern const uint16_t ff_ac3_frame_size_tab[38][3]; extern const uint16_t ff_ac3_frame_size_tab[38][3];
extern const uint8_t ff_ac3_channels_tab[8]; extern const uint8_t ff_ac3_channels_tab[8];
extern const uint16_t ff_ac3_channel_layout_tab[8]; 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,6 +50,8 @@ extern const uint16_t ff_ac3_db_per_bit_tab[4];
extern const int16_t ff_ac3_floor_tab[8]; extern const int16_t ff_ac3_floor_tab[8];
extern const uint16_t ff_ac3_fast_gain_tab[8]; extern const uint16_t ff_ac3_fast_gain_tab[8];
extern const uint16_t ff_eac3_default_chmap[8]; extern const uint16_t ff_eac3_default_chmap[8];
extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];
extern HCONST uint8_t ff_ac3_bin_to_band_tab[253];
/** Custom channel map locations bitmask /** Custom channel map locations bitmask
* Other channels described in documentation: * 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,6 +27,7 @@ void ff_ac3_exponent_min_neon(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
int ff_ac3_max_msb_abs_int16_neon(const int16_t *src, int len); int ff_ac3_max_msb_abs_int16_neon(const int16_t *src, int len);
void ff_ac3_lshift_int16_neon(int16_t *src, unsigned len, unsigned shift); void ff_ac3_lshift_int16_neon(int16_t *src, unsigned len, unsigned shift);
void ff_ac3_rshift_int32_neon(int32_t *src, unsigned len, unsigned shift); void ff_ac3_rshift_int32_neon(int32_t *src, unsigned len, unsigned shift);
void ff_float_to_fixed24_neon(int32_t *dst, const float *src, unsigned int len);
av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact) av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
{ {
...@@ -35,5 +36,6 @@ av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact) ...@@ -35,5 +36,6 @@ av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_neon; c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_neon;
c->ac3_lshift_int16 = ff_ac3_lshift_int16_neon; c->ac3_lshift_int16 = ff_ac3_lshift_int16_neon;
c->ac3_rshift_int32 = ff_ac3_rshift_int32_neon; c->ac3_rshift_int32 = ff_ac3_rshift_int32_neon;
c->float_to_fixed24 = ff_float_to_fixed24_neon;
} }
} }
...@@ -78,3 +78,17 @@ function ff_ac3_rshift_int32_neon, export=1 ...@@ -78,3 +78,17 @@ function ff_ac3_rshift_int32_neon, export=1
bgt 1b bgt 1b
bx lr bx lr
endfunc endfunc
function ff_float_to_fixed24_neon, export=1
1: vld1.32 {q0-q1}, [r1,:128]!
vcvt.s32.f32 q0, q0, #24
vld1.32 {q2-q3}, [r1,:128]!
vcvt.s32.f32 q1, q1, #24
vcvt.s32.f32 q2, q2, #24
vst1.32 {q0-q1}, [r0,:128]!
vcvt.s32.f32 q3, q3, #24
vst1.32 {q2-q3}, [r0,:128]!
subs r2, r2, #16
bgt 1b
bx lr
endfunc
...@@ -81,7 +81,7 @@ static int decode_tsw1(uint8_t *frame, int width, int height, ...@@ -81,7 +81,7 @@ static int decode_tsw1(uint8_t *frame, int width, int height,
v = bytestream_get_le16(&src); v = bytestream_get_le16(&src);
offset = (v & 0x1FFF) << 1; offset = (v & 0x1FFF) << 1;
count = ((v >> 13) + 2) << 1; count = ((v >> 13) + 2) << 1;
if (frame - offset < frame_start || frame_end - frame < count) if (frame - frame_start < offset || frame_end - frame < count)
return -1; return -1;
av_memcpy_backptr(frame, offset, count); av_memcpy_backptr(frame, offset, count);
frame += count; frame += count;
...@@ -117,7 +117,7 @@ static int decode_dsw1(uint8_t *frame, int width, int height, ...@@ -117,7 +117,7 @@ static int decode_dsw1(uint8_t *frame, int width, int height,
v = bytestream_get_le16(&src); v = bytestream_get_le16(&src);
offset = (v & 0x1FFF) << 1; offset = (v & 0x1FFF) << 1;
count = ((v >> 13) + 2) << 1; count = ((v >> 13) + 2) << 1;
if (frame - offset < frame_start || frame_end - frame < count) if (frame - frame_start < offset || frame_end - frame < count)
return -1; return -1;
// can't use av_memcpy_backptr() since it can overwrite following pixels // can't use av_memcpy_backptr() since it can overwrite following pixels
for (v = 0; v < count; v++) for (v = 0; v < count; v++)
...@@ -157,7 +157,7 @@ static int decode_dds1(uint8_t *frame, int width, int height, ...@@ -157,7 +157,7 @@ static int decode_dds1(uint8_t *frame, int width, int height,
v = bytestream_get_le16(&src); v = bytestream_get_le16(&src);
offset = (v & 0x1FFF) << 2; offset = (v & 0x1FFF) << 2;
count = ((v >> 13) + 2) << 1; count = ((v >> 13) + 2) << 1;
if (frame - offset < frame_start || frame_end - frame < count*2 + width) if (frame - frame_start < offset || frame_end - frame < count*2 + width)
return -1; return -1;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
frame[0] = frame[1] = frame[0] = frame[1] =
......
...@@ -60,7 +60,6 @@ distclean:: clean ...@@ -60,7 +60,6 @@ distclean:: clean
install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME) install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
$(Q)mkdir -p "$(SHLIBDIR)" $(Q)mkdir -p "$(SHLIBDIR)"
$$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)" $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
$$(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
$(Q)cd "$(SHLIBDIR)" && \ $(Q)cd "$(SHLIBDIR)" && \
$(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR) $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
$(Q)cd "$(SHLIBDIR)" && \ $(Q)cd "$(SHLIBDIR)" && \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment