From d63abfc7eb7db5eb36b325198fbb6ceaf8778685 Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Wed, 14 Jul 2010 19:37:52 +0000 Subject: Add WMA Pro to the main build. WMA Pro now plays on target and decodes in 151% realtime in a 320kbps sample on a sansa e200. Lots of cleanup still need to be done, and optimisations should start soon too. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27417 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/SOURCES | 1 + apps/codecs/codecs.make | 4 +- apps/codecs/libwmapro/SOURCES | 2 - apps/codecs/libwmapro/bitstream.c | 26 ++++---- apps/codecs/libwmapro/get_bits.h | 6 -- apps/codecs/libwmapro/libavutil/avutil.h | 2 +- apps/codecs/libwmapro/libavutil/bswap.h | 13 +--- apps/codecs/libwmapro/libavutil/internal.h | 19 +++--- apps/codecs/libwmapro/libavutil/intreadwrite.h | 18 +----- apps/codecs/libwmapro/libavutil/log.c | 9 ++- apps/codecs/libwmapro/libavutil/log.h | 2 +- apps/codecs/libwmapro/libavutil/mathematics.c | 4 +- apps/codecs/libwmapro/mathops.h | 14 ---- apps/codecs/libwmapro/put_bits.h | 2 +- apps/codecs/libwmapro/wma.c | 3 +- apps/codecs/libwmapro/wma.h | 88 +------------------------- apps/codecs/libwmapro/wmapro_mdct.c | 1 + apps/codecs/libwmapro/wmaprodec.c | 71 ++++++++++----------- apps/codecs/wmapro.c | 2 +- 19 files changed, 81 insertions(+), 206 deletions(-) diff --git a/apps/codecs/SOURCES b/apps/codecs/SOURCES index ca50529aed..1c484c4dcc 100644 --- a/apps/codecs/SOURCES +++ b/apps/codecs/SOURCES @@ -16,6 +16,7 @@ atrac3_rm.c atrac3_oma.c mpc.c wma.c +wmapro.c sid.c ape.c nsf.c diff --git a/apps/codecs/codecs.make b/apps/codecs/codecs.make index c137426591..49407db6b8 100644 --- a/apps/codecs/codecs.make +++ b/apps/codecs/codecs.make @@ -37,6 +37,7 @@ include $(APPSDIR)/codecs/libspeex/libspeex.make include $(APPSDIR)/codecs/libtremor/libtremor.make include $(APPSDIR)/codecs/libwavpack/libwavpack.make include $(APPSDIR)/codecs/libwma/libwma.make +include $(APPSDIR)/codecs/libwmapro/libwmapro.make include $(APPSDIR)/codecs/libcook/libcook.make include $(APPSDIR)/codecs/librm/librm.make include $(APPSDIR)/codecs/libatrac/libatrac.make @@ -58,7 +59,7 @@ CODEC_CRT0 := $(CODECDIR)/codec_crt0.o CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \ $(FAADLIB) $(FFMPEGFLACLIB) $(M4ALIB) $(MADLIB) $(MUSEPACKLIB) \ $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) $(COOKLIB) \ - $(ATRACLIB) \ + $(ATRACLIB) $(WMAPROLIB) \ $(CODECLIB) $(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS) @@ -83,6 +84,7 @@ $(CODECDIR)/shorten.codec : $(CODECDIR)/libffmpegFLAC.a $(CODECDIR)/ape-pre.map : $(CODECDIR)/libdemac-pre.a $(CODECDIR)/ape.codec : $(CODECDIR)/libdemac.a $(CODECDIR)/wma.codec : $(CODECDIR)/libwma.a $(CODECDIR)/libasf.a +$(CODECDIR)/wmapro.codec : $(CODECDIR)/libwmapro.a $(CODECDIR)/libasf.a $(CODECDIR)/wavpack_enc.codec: $(CODECDIR)/libwavpack.a $(CODECDIR)/asap.codec : $(CODECDIR)/libasap.a $(CODECDIR)/cook.codec : $(CODECDIR)/libcook.a $(CODECDIR)/librm.a diff --git a/apps/codecs/libwmapro/SOURCES b/apps/codecs/libwmapro/SOURCES index 1d5909bf9a..cfb1a97d4c 100644 --- a/apps/codecs/libwmapro/SOURCES +++ b/apps/codecs/libwmapro/SOURCES @@ -3,6 +3,4 @@ wma.c mdct_tables.c bitstream.c wmapro_mdct.c -libavutil/log.c -libavutil/mem.c libavutil/mathematics.c diff --git a/apps/codecs/libwmapro/bitstream.c b/apps/codecs/libwmapro/bitstream.c index deb1d631e2..4ae9727ac0 100644 --- a/apps/codecs/libwmapro/bitstream.c +++ b/apps/codecs/libwmapro/bitstream.c @@ -32,6 +32,8 @@ #include "get_bits.h" #include "put_bits.h" +#define av_log(...) + const uint8_t ff_log2_run[32]={ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, @@ -108,10 +110,10 @@ static int alloc_table(VLC *vlc, int size, int use_static) vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { if(use_static) - abort(); //cant do anything, init_vlc() is used with too little memory + return -1; //cant do anything, init_vlc() is used with too little memory vlc->table_allocated += (1 << vlc->bits); - vlc->table = av_realloc(vlc->table, - sizeof(VLC_TYPE) * 2 * vlc->table_allocated); + //vlc->table = av_realloc(vlc->table, + // sizeof(VLC_TYPE) * 2 * vlc->table_allocated); if (!vlc->table) return -1; } @@ -218,14 +220,14 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, if (n <= 0) break; code = codes[k].code; - if (code >> (32 - table_nb_bits) != code_prefix) + if (code >> (32 - table_nb_bits) != (unsigned)code_prefix) break; codes[k].bits = n; codes[k].code = code << table_nb_bits; subtable_bits = FFMAX(subtable_bits, n); } subtable_bits = FFMIN(subtable_bits, table_nb_bits); - j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix; + j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : (unsigned)code_prefix; table[j][1] = -subtable_bits; #ifdef DEBUG_VLC av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", @@ -284,7 +286,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, if(vlc->table_size && vlc->table_size == vlc->table_allocated){ return 0; }else if(vlc->table_size){ - abort(); // fatal error, we are called on a partially initialized table + return -1; // fatal error, we are called on a partially initialized table } }else { vlc->table = NULL; @@ -321,17 +323,11 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, nb_codes = j; if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) { - av_freep(&vlc->table); + //av_freep(&vlc->table); return -1; } - if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated) - av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); + //if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated) + // av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); return 0; } - -void free_vlc(VLC *vlc) -{ - av_freep(&vlc->table); -} - diff --git a/apps/codecs/libwmapro/get_bits.h b/apps/codecs/libwmapro/get_bits.h index a21d05210f..ecbfc6967b 100644 --- a/apps/codecs/libwmapro/get_bits.h +++ b/apps/codecs/libwmapro/get_bits.h @@ -40,13 +40,7 @@ #endif #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) -# if ARCH_ARM && !HAVE_FAST_UNALIGNED -# define A32_BITSTREAM_READER -# else # define ALT_BITSTREAM_READER -//#define LIBMPEG2_BITSTREAM_READER -//#define A32_BITSTREAM_READER -# endif #endif /* bit input */ diff --git a/apps/codecs/libwmapro/libavutil/avutil.h b/apps/codecs/libwmapro/libavutil/avutil.h index 1b858f1fe6..fd6e313b59 100644 --- a/apps/codecs/libwmapro/libavutil/avutil.h +++ b/apps/codecs/libwmapro/libavutil/avutil.h @@ -79,7 +79,7 @@ enum AVMediaType { }; #include "common.h" -#include "error.h" +//#include "error.h" #include "mathematics.h" //#include "rational.h" //#include "intfloat_readwrite.h" diff --git a/apps/codecs/libwmapro/libavutil/bswap.h b/apps/codecs/libwmapro/libavutil/bswap.h index 5743e126b8..e15501778b 100644 --- a/apps/codecs/libwmapro/libavutil/bswap.h +++ b/apps/codecs/libwmapro/libavutil/bswap.h @@ -30,18 +30,6 @@ //#include "config.h" #include "attributes.h" -#if ARCH_ARM -# include "arm/bswap.h" -#elif ARCH_AVR32 -# include "avr32/bswap.h" -#elif ARCH_BFIN -# include "bfin/bswap.h" -#elif ARCH_SH4 -# include "sh4/bswap.h" -#elif ARCH_X86 -# include "x86/bswap.h" -#endif - #ifndef bswap_16 static av_always_inline av_const uint16_t bswap_16(uint16_t x) { @@ -82,6 +70,7 @@ static inline uint64_t av_const bswap_64(uint64_t x) // be2me ... big-endian to machine-endian // le2me ... little-endian to machine-endian +#define HAVE_BIGENDIAN 0 #if HAVE_BIGENDIAN #define be2me_16(x) (x) #define be2me_32(x) (x) diff --git a/apps/codecs/libwmapro/libavutil/internal.h b/apps/codecs/libwmapro/libavutil/internal.h index 97087e462a..87a4d3ec10 100644 --- a/apps/codecs/libwmapro/libavutil/internal.h +++ b/apps/codecs/libwmapro/libavutil/internal.h @@ -55,7 +55,8 @@ #endif #ifndef av_alias -#if HAVE_ATTRIBUTE_MAY_ALIAS && (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(3,3) +//#if HAVE_ATTRIBUTE_MAY_ALIAS && (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(3,3) +#if 0 # define av_alias __attribute__((may_alias)) #else # define av_alias @@ -106,7 +107,8 @@ #define LABEL_MANGLE(a) EXTERN_PREFIX #a // Use rip-relative addressing if compiling PIC code on x86-64. -#if ARCH_X86_64 && defined(PIC) +//#if ARCH_X86_64 && defined(PIC) +#if 0 # define LOCAL_MANGLE(a) #a "(%%rip)" #else # define LOCAL_MANGLE(a) #a @@ -127,7 +129,8 @@ /* math */ -#if ARCH_X86 +//#if ARCH_X86 +#if 0 #define MASK_ABS(mask, level)\ __asm__ volatile(\ "cltd \n\t"\ @@ -198,10 +201,10 @@ * without modification. Used to disable the definition of strings * (for example AVCodec long_names). */ -#if CONFIG_SMALL -# define NULL_IF_CONFIG_SMALL(x) NULL -#else -# define NULL_IF_CONFIG_SMALL(x) x -#endif +//#if CONFIG_SMALL +//# define NULL_IF_CONFIG_SMALL(x) NULL +//#else +//# define NULL_IF_CONFIG_SMALL(x) x +//#endif #endif /* AVUTIL_INTERNAL_H */ diff --git a/apps/codecs/libwmapro/libavutil/intreadwrite.h b/apps/codecs/libwmapro/libavutil/intreadwrite.h index 87098d707d..a88ffa80f6 100644 --- a/apps/codecs/libwmapro/libavutil/intreadwrite.h +++ b/apps/codecs/libwmapro/libavutil/intreadwrite.h @@ -52,24 +52,10 @@ typedef union { * as inline functions. */ -#if ARCH_ARM -# include "arm/intreadwrite.h" -#elif ARCH_AVR32 -# include "avr32/intreadwrite.h" -#elif ARCH_MIPS -# include "mips/intreadwrite.h" -#elif ARCH_PPC -# include "ppc/intreadwrite.h" -#elif ARCH_TOMI -# include "tomi/intreadwrite.h" -#elif ARCH_X86 -# include "x86/intreadwrite.h" -#endif - /* * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers. */ - +#define HAVE_BIGENDIAN 0 #if HAVE_BIGENDIAN # if defined(AV_RN16) && !defined(AV_RB16) @@ -172,6 +158,8 @@ typedef union { #endif /* !HAVE_BIGENDIAN */ +#define HAVE_ATTRIBUTE_PACKED 0 +#define HAVE_FAST_UNALIGNED 0 /* * Define AV_[RW]N helper macros to simplify definitions not provided * by per-arch headers. diff --git a/apps/codecs/libwmapro/libavutil/log.c b/apps/codecs/libwmapro/libavutil/log.c index 6cbe0da8b8..f93a0d6677 100644 --- a/apps/codecs/libwmapro/libavutil/log.c +++ b/apps/codecs/libwmapro/libavutil/log.c @@ -26,13 +26,16 @@ #include "avutil.h" #include "log.h" +/* disable sprintf functions */ +#define snprintf(...) +#define vsnprintf snprintf #if LIBAVUTIL_VERSION_MAJOR > 50 static #endif int av_log_level = AV_LOG_INFO; -void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) +void av_log_default_callback(void* ptr, int level) { static int print_prefix=1; static int count; @@ -61,9 +64,9 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) strcpy(prev, line); } -static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; +static void (*av_log_callback)(void*, int = av_log_default_callback; -void av_log(void* avcl, int level, const char *fmt, ...) +void av_log(void* avcl, int level) { va_list vl; va_start(vl, fmt); diff --git a/apps/codecs/libwmapro/libavutil/log.h b/apps/codecs/libwmapro/libavutil/log.h index b0a1493607..43228e4985 100644 --- a/apps/codecs/libwmapro/libavutil/log.h +++ b/apps/codecs/libwmapro/libavutil/log.h @@ -110,6 +110,6 @@ void av_vlog(void*, int level, const char *fmt, va_list); int av_log_get_level(void); void av_log_set_level(int); void av_log_set_callback(void (*)(void*, int, const char*, va_list)); -void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl); +void av_log_default_callback(void* ptr, int level); #endif /* AVUTIL_LOG_H */ diff --git a/apps/codecs/libwmapro/libavutil/mathematics.c b/apps/codecs/libwmapro/libavutil/mathematics.c index 7af0104516..f607d68b6e 100644 --- a/apps/codecs/libwmapro/libavutil/mathematics.c +++ b/apps/codecs/libwmapro/libavutil/mathematics.c @@ -103,13 +103,13 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){ a0 = a0*b0 + t1a; a1 = a1*b1 + (t1>>32) + (a0=0; i--){ // int o= a1 & 0x8000000000000000ULL; a1+= a1 + ((a0>>i)&1); t1+=t1; - if(/*o || */c <= a1){ + if(/*o || */(unsigned)c <= a1){ a1 -= c; t1++; } diff --git a/apps/codecs/libwmapro/mathops.h b/apps/codecs/libwmapro/mathops.h index 149910bb1d..f6555dda21 100644 --- a/apps/codecs/libwmapro/mathops.h +++ b/apps/codecs/libwmapro/mathops.h @@ -24,20 +24,6 @@ #include "libavutil/common.h" -#if ARCH_ARM -# include "arm/mathops.h" -#elif ARCH_AVR32 -# include "avr32/mathops.h" -#elif ARCH_BFIN -# include "bfin/mathops.h" -#elif ARCH_MIPS -# include "mips/mathops.h" -#elif ARCH_PPC -# include "ppc/mathops.h" -#elif ARCH_X86 -# include "x86/mathops.h" -#endif - /* generic implementation */ #ifndef MULL diff --git a/apps/codecs/libwmapro/put_bits.h b/apps/codecs/libwmapro/put_bits.h index 9f66256b79..91401ff3fa 100644 --- a/apps/codecs/libwmapro/put_bits.h +++ b/apps/codecs/libwmapro/put_bits.h @@ -37,7 +37,7 @@ //#define ALT_BITSTREAM_WRITER //#define ALIGNED_BITSTREAM_WRITER - +#define HAVE_FAST_UNALIGNED 0 /* buf and buf_end must be present and used by every alternative writer. */ typedef struct PutBitContext { #ifdef ALT_BITSTREAM_WRITER diff --git a/apps/codecs/libwmapro/wma.c b/apps/codecs/libwmapro/wma.c index b606f59dbf..30fb9e022a 100644 --- a/apps/codecs/libwmapro/wma.c +++ b/apps/codecs/libwmapro/wma.c @@ -467,7 +467,8 @@ unsigned int ff_wma_get_large_val(GetBitContext* gb) * @param coef_nb_bits number of bits for escaped level codes * @return 0 on success, -1 otherwise */ -int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb, +#define av_log(...) +int ff_wma_run_level_decode(GetBitContext* gb, VLC *vlc, const int32_t *level_table, const uint16_t *run_table, int version, int32_t *ptr, int offset, diff --git a/apps/codecs/libwmapro/wma.h b/apps/codecs/libwmapro/wma.h index d23b7ea02f..e4a1601515 100644 --- a/apps/codecs/libwmapro/wma.h +++ b/apps/codecs/libwmapro/wma.h @@ -24,8 +24,6 @@ #include "get_bits.h" #include "put_bits.h" -#include "dsputil.h" -#include "fft.h" /* size of blocks */ #define BLOCK_MIN_BITS 7 @@ -62,90 +60,6 @@ typedef struct CoefVLCTable { const uint16_t *levels; ///< table to build run/level tables } CoefVLCTable; -typedef struct WMACodecContext { - AVCodecContext* avctx; - GetBitContext gb; - PutBitContext pb; - int sample_rate; - int nb_channels; - int bit_rate; - int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) - int block_align; - int use_bit_reservoir; - int use_variable_block_len; - int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta - int use_noise_coding; ///< true if perceptual noise is added - int byte_offset_bits; - VLC exp_vlc; - int exponent_sizes[BLOCK_NB_SIZES]; - uint16_t exponent_bands[BLOCK_NB_SIZES][25]; - int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band - int coefs_start; ///< first coded coef - int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients - int exponent_high_sizes[BLOCK_NB_SIZES]; - int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]; - VLC hgain_vlc; - - /* coded values in high bands */ - int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; - int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; - - /* there are two possible tables for spectral coefficients */ -//FIXME the following 3 tables should be shared between decoders - VLC coef_vlc[2]; - uint16_t *run_table[2]; - float *level_table[2]; - uint16_t *int_table[2]; - const CoefVLCTable *coef_vlcs[2]; - /* frame info */ - int frame_len; ///< frame length in samples - int frame_len_bits; ///< frame_len = 1 << frame_len_bits - int nb_block_sizes; ///< number of block sizes - /* block info */ - int reset_block_lengths; - int block_len_bits; ///< log2 of current block length - int next_block_len_bits; ///< log2 of next block length - int prev_block_len_bits; ///< log2 of prev block length - int block_len; ///< block length in samples - int block_num; ///< block number in current frame - int block_pos; ///< current position in frame - uint8_t ms_stereo; ///< true if mid/side stereo mode - uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded - int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length - DECLARE_ALIGNED(16, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE]; - float max_exponent[MAX_CHANNELS]; - WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; - DECLARE_ALIGNED(16, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE]; - DECLARE_ALIGNED(16, FFTSample, output)[BLOCK_MAX_SIZE * 2]; - FFTContext mdct_ctx[BLOCK_NB_SIZES]; - float *windows[BLOCK_NB_SIZES]; - /* output buffer for one frame and the last for IMDCT windowing */ - DECLARE_ALIGNED(16, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]; - /* last frame info */ - uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */ - int last_bitoffset; - int last_superframe_len; - float noise_table[NOISE_TAB_SIZE]; - int noise_index; - float noise_mult; /* XXX: suppress that and integrate it in the noise array */ - /* lsp_to_curve tables */ - float lsp_cos_table[BLOCK_MAX_SIZE]; - float lsp_pow_e_table[256]; - float lsp_pow_m_table1[(1 << LSP_POW_BITS)]; - float lsp_pow_m_table2[(1 << LSP_POW_BITS)]; - DSPContext dsp; - -#ifdef TRACE - int frame_count; -#endif -} WMACodecContext; - -extern const uint16_t ff_wma_critical_freqs[25]; -extern const uint16_t ff_wma_hgain_huffcodes[37]; -extern const uint8_t ff_wma_hgain_huffbits[37]; -extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]; -extern const uint32_t ff_aac_scalefactor_code[121]; -extern const uint8_t ff_aac_scalefactor_bits[121]; int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version, unsigned int decode_flags); @@ -153,7 +67,7 @@ int ff_wma_init(AVCodecContext * avctx, int flags2); int ff_wma_total_gain_to_bits(int total_gain); int ff_wma_end(AVCodecContext *avctx); unsigned int ff_wma_get_large_val(GetBitContext* gb); -int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb, +int ff_wma_run_level_decode(GetBitContext* gb, VLC *vlc, const int32_t *level_table, const uint16_t *run_table, int version, int32_t *ptr, int offset, diff --git a/apps/codecs/libwmapro/wmapro_mdct.c b/apps/codecs/libwmapro/wmapro_mdct.c index aaa95dccdf..8f651d224a 100644 --- a/apps/codecs/libwmapro/wmapro_mdct.c +++ b/apps/codecs/libwmapro/wmapro_mdct.c @@ -4,6 +4,7 @@ #include "../lib/mdct_lookup.h" /* for revtab */ #include "../lib/fft.h" /* for FFT data structures */ #include "codeclib.h" +#define ROCKBOX_BIG_ENDIAN 0 #include "../lib/codeclib_misc.h" /* for XNPROD31 */ #include "wmapro_math.h" diff --git a/apps/codecs/libwmapro/wmaprodec.c b/apps/codecs/libwmapro/wmaprodec.c index 8a8171aeb6..2dd2a6a1e4 100644 --- a/apps/codecs/libwmapro/wmaprodec.c +++ b/apps/codecs/libwmapro/wmaprodec.c @@ -103,6 +103,13 @@ /* Uncomment the following line to enable some debug output */ //#define WMAPRO_DUMP_CTX_EN +#undef DEBUGF +#ifdef WMAPRO_DUMP_CTX_EN +# define DEBUGF printf +#else +# define DEBUGF(...) +#endif + /* Some defines to make it compile */ #define AVERROR_INVALIDDATA -1 #define AVERROR_PATCHWELCOME -2 @@ -177,7 +184,6 @@ typedef struct { typedef struct WMAProDecodeCtx { /* generic decoder variables */ AVCodecContext* avctx; ///< codec context for av_log - DSPContext dsp; ///< accelerated DSP functions uint8_t frame_data[MAX_FRAMESIZE + FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data PutBitContext pb; ///< context for filling the frame_data buffer @@ -236,6 +242,8 @@ typedef struct WMAProDecodeCtx { WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data } WMAProDecodeCtx; +/* static decode context, to avoid malloc */ +static WMAProDecodeCtx globWMAProDecCtx; /** *@brief helper function to print the most important members of the context @@ -264,7 +272,7 @@ static void av_cold dump_context(WMAProDecodeCtx *s) */ av_cold int decode_init(AVCodecContext *avctx) { - avctx->priv_data = malloc(sizeof(WMAProDecodeCtx)); + avctx->priv_data = &globWMAProDecCtx; memset(avctx->priv_data, 0, sizeof(WMAProDecodeCtx)); WMAProDecodeCtx *s = avctx->priv_data; uint8_t *edata_ptr = avctx->extradata; @@ -276,8 +284,6 @@ av_cold int decode_init(AVCodecContext *avctx) s->avctx = avctx; init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); - avctx->sample_fmt = SAMPLE_FMT_FLT; - if (avctx->extradata_size >= 18) { s->decode_flags = AV_RL16(edata_ptr+14); channel_mask = AV_RL32(edata_ptr+2); @@ -288,7 +294,7 @@ av_cold int decode_init(AVCodecContext *avctx) dprintf(avctx, "\n"); } else { - av_log_ask_for_sample(avctx, "Unknown extradata size\n"); + DEBUGF("Unknown extradata size\n"); return AVERROR_INVALIDDATA; } @@ -301,7 +307,7 @@ av_cold int decode_init(AVCodecContext *avctx) s->len_prefix = (s->decode_flags & 0x40); if (!s->len_prefix) { - av_log_ask_for_sample(avctx, "no length prefix\n"); + DEBUGF("no length prefix\n"); return AVERROR_INVALIDDATA; } @@ -325,7 +331,7 @@ av_cold int decode_init(AVCodecContext *avctx) s->dynamic_range_compression = (s->decode_flags & 0x80); if (s->max_num_subframes > MAX_SUBFRAMES) { - av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n", + DEBUGF("invalid number of subframes %i\n", s->max_num_subframes); return AVERROR_INVALIDDATA; } @@ -344,10 +350,10 @@ av_cold int decode_init(AVCodecContext *avctx) } if (s->num_channels < 0) { - av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels); + DEBUGF("invalid number of channels %d\n", s->num_channels); return AVERROR_INVALIDDATA; } else if (s->num_channels > WMAPRO_MAX_CHANNELS) { - av_log_ask_for_sample(avctx, "unsupported number of channels\n"); + DEBUGF("unsupported number of channels\n"); return AVERROR_PATCHWELCOME; } @@ -437,8 +443,6 @@ av_cold int decode_init(AVCodecContext *avctx) #ifdef WMAPRO_DUMP_CTX_EN dump_context(s); #endif - - avctx->channel_layout = channel_mask; return 0; } @@ -469,7 +473,7 @@ static int decode_subframe_length(WMAProDecodeCtx *s, int offset) /** sanity check the length */ if (subframe_len < s->min_samples_per_subframe || subframe_len > s->samples_per_frame) { - av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n", + DEBUGF("broken frame: subframe_len %i\n", subframe_len); return AVERROR_INVALIDDATA; } @@ -546,16 +550,15 @@ static int decode_tilehdr(WMAProDecodeCtx *s) WMAProChannelCtx* chan = &s->channel[c]; if (contains_subframe[c]) { - if (chan->num_subframes >= MAX_SUBFRAMES) { - av_log(s->avctx, AV_LOG_ERROR, - "broken frame: num subframes > 31\n"); + if (chan->num_subframes >= MAX_SUBFRAMES) { + DEBUGF("broken frame: num subframes > 31\n"); return AVERROR_INVALIDDATA; } chan->subframe_len[chan->num_subframes] = subframe_len; num_samples[c] += subframe_len; ++chan->num_subframes; if (num_samples[c] > s->samples_per_frame) { - av_log(s->avctx, AV_LOG_ERROR, "broken frame: " + DEBUGF("broken frame: " "channel len > samples_per_frame\n"); return AVERROR_INVALIDDATA; } @@ -674,8 +677,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s) int remaining_channels = s->channels_for_cur_subframe; if (get_bits1(&s->gb)) { - av_log_ask_for_sample(s->avctx, - "unsupported channel transform bit\n"); + DEBUGF("unsupported channel transform bit\n"); return AVERROR_INVALIDDATA; } @@ -711,8 +713,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s) if (chgroup->num_channels == 2) { if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) { - av_log_ask_for_sample(s->avctx, - "unsupported channel transform type\n"); + DEBUGF("unsupported channel transform type\n"); } } else { chgroup->transform = 1; @@ -730,7 +731,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s) } } } else if (chgroup->num_channels > 2) { - LOGF("in wmaprodec.c: Multichannel streams still not supported\n"); + DEBUGF("in wmaprodec.c: Multichannel streams still not supported\n"); return -1; #if 0 if (get_bits1(&s->gb)) { @@ -857,7 +858,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c) memset(&ci->coeffs[cur_coeff], 0, sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff)); - if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc, + if (ff_wma_run_level_decode(&s->gb, vlc, level, run, 1, ci->coeffs, cur_coeff, s->subframe_len, s->subframe_len, s->esc_len, 0)) @@ -937,8 +938,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s) i += skip; if (i >= s->num_bands) { - av_log(s->avctx, AV_LOG_ERROR, - "invalid scale factor coding\n"); + DEBUGF("invalid scale factor coding\n"); return AVERROR_INVALIDDATA; } s->channel[c].scale_factors[i] += (val ^ sign) - sign; @@ -1137,7 +1137,7 @@ static int decode_subframe(WMAProDecodeCtx *s) if (num_fill_bits >= 0) { if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) { - av_log(s->avctx, AV_LOG_ERROR, "invalid number of fill bits\n"); + DEBUGF("invalid number of fill bits\n"); return AVERROR_INVALIDDATA; } @@ -1147,7 +1147,7 @@ static int decode_subframe(WMAProDecodeCtx *s) /** no idea for what the following bit is used */ if (get_bits1(&s->gb)) { - av_log_ask_for_sample(s->avctx, "reserved bit set\n"); + DEBUGF("reserved bit set\n"); return AVERROR_INVALIDDATA; } @@ -1165,7 +1165,7 @@ static int decode_subframe(WMAProDecodeCtx *s) int quant_step = 90 * s->bits_per_sample >> 4; if ((get_bits1(&s->gb))) { /** FIXME: might change run level mode decision */ - av_log_ask_for_sample(s->avctx, "unsupported quant step coding\n"); + DEBUGF("unsupported quant step coding\n"); return AVERROR_INVALIDDATA; } /** decode quantization step */ @@ -1181,7 +1181,7 @@ static int decode_subframe(WMAProDecodeCtx *s) quant_step += ((quant + step) ^ sign) - sign; } if (quant_step < 0) { - av_log(s->avctx, AV_LOG_DEBUG, "negative quant step\n"); + DEBUGF("negative quant step\n"); } /** decode quantization step modifiers for every channel */ @@ -1245,7 +1245,7 @@ static int decode_subframe(WMAProDecodeCtx *s) s->channel[c].scale_factor_step; if(exp < EXP_MIN || exp > EXP_MAX) { - LOGF("in wmaprodec.c : unhandled value for exp, please report sample.\n"); + DEBUGF("in wmaprodec.c : unhandled value for exp, please report sample.\n"); return -1; } const FIXED quant = QUANT(exp); @@ -1272,7 +1272,7 @@ static int decode_subframe(WMAProDecodeCtx *s) for (i = 0; i < s->channels_for_cur_subframe; i++) { int c = s->channel_indexes_for_cur_subframe[i]; if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) { - av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n"); + DEBUGF("broken subframe\n"); return AVERROR_INVALIDDATA; } ++s->channel[c].cur_subframe; @@ -1297,8 +1297,7 @@ static int decode_frame(WMAProDecodeCtx *s) /** check for potential output buffer overflow */ if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) { /** return an error if no frame could be decoded at all */ - av_log(s->avctx, AV_LOG_ERROR, - "not enough space for the output samples\n"); + DEBUGF("not enough space for the output samples\n"); s->packet_loss = 1; return 0; } @@ -1317,7 +1316,7 @@ static int decode_frame(WMAProDecodeCtx *s) /** read postproc transform */ if (s->num_channels > 1 && get_bits1(gb)) { - av_log_ask_for_sample(s->avctx, "Unsupported postproc transform found\n"); + DEBUGF("Unsupported postproc transform found\n"); s->packet_loss = 1; return 0; } @@ -1391,7 +1390,7 @@ static int decode_frame(WMAProDecodeCtx *s) if (len != (get_bits_count(gb) - s->frame_offset) + 2) { /** FIXME: not sure if this is always an error */ - av_log(s->avctx, AV_LOG_ERROR, "frame[%i] would have to skip %i bits\n", + DEBUGF("frame[%i] would have to skip %i bits\n", (int)s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1); s->packet_loss = 1; return 0; @@ -1443,7 +1442,7 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len, buflen = (s->num_saved_bits + len + 8) >> 3; if (len <= 0 || buflen > MAX_FRAMESIZE) { - av_log_ask_for_sample(s->avctx, "input buffer too small\n"); + DEBUGF("input buffer too small\n"); s->packet_loss = 1; return; } @@ -1516,7 +1515,7 @@ int decode_packet(AVCodecContext *avctx, if (!s->packet_loss && ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) { s->packet_loss = 1; - av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n", + DEBUGF("Packet loss detected! seq %x vs %x\n", s->packet_sequence_number, packet_sequence_number); } s->packet_sequence_number = packet_sequence_number; diff --git a/apps/codecs/wmapro.c b/apps/codecs/wmapro.c index a31e63d79f..ba19e2925c 100644 --- a/apps/codecs/wmapro.c +++ b/apps/codecs/wmapro.c @@ -28,7 +28,7 @@ CODEC_HEADER #define MAXSAMPLES (1L << 12) /* Max number of samples in a wma pro subframe */ #define MAXCHANNELS 8 #define BUFSIZE MAXCHANNELS * MAXSAMPLES -static int32_t decoded[BUFSIZE] IBSS_ATTR; +int32_t decoded[BUFSIZE]; AVCodecContext avctx; AVPacket avpkt; -- cgit v1.2.3