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
This commit is contained in:
Mohamed Tarek 2010-07-14 19:37:52 +00:00
parent 16284ae8ae
commit d63abfc7eb
19 changed files with 81 additions and 206 deletions

View file

@ -16,6 +16,7 @@ atrac3_rm.c
atrac3_oma.c atrac3_oma.c
mpc.c mpc.c
wma.c wma.c
wmapro.c
sid.c sid.c
ape.c ape.c
nsf.c nsf.c

View file

@ -37,6 +37,7 @@ include $(APPSDIR)/codecs/libspeex/libspeex.make
include $(APPSDIR)/codecs/libtremor/libtremor.make include $(APPSDIR)/codecs/libtremor/libtremor.make
include $(APPSDIR)/codecs/libwavpack/libwavpack.make include $(APPSDIR)/codecs/libwavpack/libwavpack.make
include $(APPSDIR)/codecs/libwma/libwma.make include $(APPSDIR)/codecs/libwma/libwma.make
include $(APPSDIR)/codecs/libwmapro/libwmapro.make
include $(APPSDIR)/codecs/libcook/libcook.make include $(APPSDIR)/codecs/libcook/libcook.make
include $(APPSDIR)/codecs/librm/librm.make include $(APPSDIR)/codecs/librm/librm.make
include $(APPSDIR)/codecs/libatrac/libatrac.make include $(APPSDIR)/codecs/libatrac/libatrac.make
@ -58,7 +59,7 @@ CODEC_CRT0 := $(CODECDIR)/codec_crt0.o
CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \ CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \
$(FAADLIB) $(FFMPEGFLACLIB) $(M4ALIB) $(MADLIB) $(MUSEPACKLIB) \ $(FAADLIB) $(FFMPEGFLACLIB) $(M4ALIB) $(MADLIB) $(MUSEPACKLIB) \
$(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) $(COOKLIB) \ $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) $(COOKLIB) \
$(ATRACLIB) \ $(ATRACLIB) $(WMAPROLIB) \
$(CODECLIB) $(CODECLIB)
$(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS) $(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-pre.map : $(CODECDIR)/libdemac-pre.a
$(CODECDIR)/ape.codec : $(CODECDIR)/libdemac.a $(CODECDIR)/ape.codec : $(CODECDIR)/libdemac.a
$(CODECDIR)/wma.codec : $(CODECDIR)/libwma.a $(CODECDIR)/libasf.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)/wavpack_enc.codec: $(CODECDIR)/libwavpack.a
$(CODECDIR)/asap.codec : $(CODECDIR)/libasap.a $(CODECDIR)/asap.codec : $(CODECDIR)/libasap.a
$(CODECDIR)/cook.codec : $(CODECDIR)/libcook.a $(CODECDIR)/librm.a $(CODECDIR)/cook.codec : $(CODECDIR)/libcook.a $(CODECDIR)/librm.a

View file

@ -3,6 +3,4 @@ wma.c
mdct_tables.c mdct_tables.c
bitstream.c bitstream.c
wmapro_mdct.c wmapro_mdct.c
libavutil/log.c
libavutil/mem.c
libavutil/mathematics.c libavutil/mathematics.c

View file

@ -32,6 +32,8 @@
#include "get_bits.h" #include "get_bits.h"
#include "put_bits.h" #include "put_bits.h"
#define av_log(...)
const uint8_t ff_log2_run[32]={ const uint8_t ff_log2_run[32]={
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
2, 2, 2, 2, 3, 3, 3, 3, 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; vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) { if (vlc->table_size > vlc->table_allocated) {
if(use_static) 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_allocated += (1 << vlc->bits);
vlc->table = av_realloc(vlc->table, //vlc->table = av_realloc(vlc->table,
sizeof(VLC_TYPE) * 2 * vlc->table_allocated); // sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
if (!vlc->table) if (!vlc->table)
return -1; return -1;
} }
@ -218,14 +220,14 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
if (n <= 0) if (n <= 0)
break; break;
code = codes[k].code; code = codes[k].code;
if (code >> (32 - table_nb_bits) != code_prefix) if (code >> (32 - table_nb_bits) != (unsigned)code_prefix)
break; break;
codes[k].bits = n; codes[k].bits = n;
codes[k].code = code << table_nb_bits; codes[k].code = code << table_nb_bits;
subtable_bits = FFMAX(subtable_bits, n); subtable_bits = FFMAX(subtable_bits, n);
} }
subtable_bits = FFMIN(subtable_bits, table_nb_bits); 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; table[j][1] = -subtable_bits;
#ifdef DEBUG_VLC #ifdef DEBUG_VLC
av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", 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){ if(vlc->table_size && vlc->table_size == vlc->table_allocated){
return 0; return 0;
}else if(vlc->table_size){ }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 { }else {
vlc->table = NULL; vlc->table = NULL;
@ -321,17 +323,11 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
nb_codes = j; nb_codes = j;
if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) { if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) {
av_freep(&vlc->table); //av_freep(&vlc->table);
return -1; return -1;
} }
if((flags & INIT_VLC_USE_NEW_STATIC) && 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); // av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
return 0; return 0;
} }
void free_vlc(VLC *vlc)
{
av_freep(&vlc->table);
}

View file

@ -40,13 +40,7 @@
#endif #endif
#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) #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 ALT_BITSTREAM_READER
//#define LIBMPEG2_BITSTREAM_READER
//#define A32_BITSTREAM_READER
# endif
#endif #endif
/* bit input */ /* bit input */

View file

@ -79,7 +79,7 @@ enum AVMediaType {
}; };
#include "common.h" #include "common.h"
#include "error.h" //#include "error.h"
#include "mathematics.h" #include "mathematics.h"
//#include "rational.h" //#include "rational.h"
//#include "intfloat_readwrite.h" //#include "intfloat_readwrite.h"

View file

@ -30,18 +30,6 @@
//#include "config.h" //#include "config.h"
#include "attributes.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 #ifndef bswap_16
static av_always_inline av_const uint16_t bswap_16(uint16_t x) 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 // be2me ... big-endian to machine-endian
// le2me ... little-endian to machine-endian // le2me ... little-endian to machine-endian
#define HAVE_BIGENDIAN 0
#if HAVE_BIGENDIAN #if HAVE_BIGENDIAN
#define be2me_16(x) (x) #define be2me_16(x) (x)
#define be2me_32(x) (x) #define be2me_32(x) (x)

View file

@ -55,7 +55,8 @@
#endif #endif
#ifndef av_alias #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)) # define av_alias __attribute__((may_alias))
#else #else
# define av_alias # define av_alias
@ -106,7 +107,8 @@
#define LABEL_MANGLE(a) EXTERN_PREFIX #a #define LABEL_MANGLE(a) EXTERN_PREFIX #a
// Use rip-relative addressing if compiling PIC code on x86-64. // 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)" # define LOCAL_MANGLE(a) #a "(%%rip)"
#else #else
# define LOCAL_MANGLE(a) #a # define LOCAL_MANGLE(a) #a
@ -127,7 +129,8 @@
/* math */ /* math */
#if ARCH_X86 //#if ARCH_X86
#if 0
#define MASK_ABS(mask, level)\ #define MASK_ABS(mask, level)\
__asm__ volatile(\ __asm__ volatile(\
"cltd \n\t"\ "cltd \n\t"\
@ -198,10 +201,10 @@
* without modification. Used to disable the definition of strings * without modification. Used to disable the definition of strings
* (for example AVCodec long_names). * (for example AVCodec long_names).
*/ */
#if CONFIG_SMALL //#if CONFIG_SMALL
# define NULL_IF_CONFIG_SMALL(x) NULL //# define NULL_IF_CONFIG_SMALL(x) NULL
#else //#else
# define NULL_IF_CONFIG_SMALL(x) x //# define NULL_IF_CONFIG_SMALL(x) x
#endif //#endif
#endif /* AVUTIL_INTERNAL_H */ #endif /* AVUTIL_INTERNAL_H */

View file

@ -52,24 +52,10 @@ typedef union {
* as inline functions. * 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. * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
*/ */
#define HAVE_BIGENDIAN 0
#if HAVE_BIGENDIAN #if HAVE_BIGENDIAN
# if defined(AV_RN16) && !defined(AV_RB16) # if defined(AV_RN16) && !defined(AV_RB16)
@ -172,6 +158,8 @@ typedef union {
#endif /* !HAVE_BIGENDIAN */ #endif /* !HAVE_BIGENDIAN */
#define HAVE_ATTRIBUTE_PACKED 0
#define HAVE_FAST_UNALIGNED 0
/* /*
* Define AV_[RW]N helper macros to simplify definitions not provided * Define AV_[RW]N helper macros to simplify definitions not provided
* by per-arch headers. * by per-arch headers.

View file

@ -26,13 +26,16 @@
#include "avutil.h" #include "avutil.h"
#include "log.h" #include "log.h"
/* disable sprintf functions */
#define snprintf(...)
#define vsnprintf snprintf
#if LIBAVUTIL_VERSION_MAJOR > 50 #if LIBAVUTIL_VERSION_MAJOR > 50
static static
#endif #endif
int av_log_level = AV_LOG_INFO; 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 print_prefix=1;
static int count; 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); 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_list vl;
va_start(vl, fmt); va_start(vl, fmt);

View file

@ -110,6 +110,6 @@ void av_vlog(void*, int level, const char *fmt, va_list);
int av_log_get_level(void); int av_log_get_level(void);
void av_log_set_level(int); void av_log_set_level(int);
void av_log_set_callback(void (*)(void*, int, const char*, va_list)); 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 */ #endif /* AVUTIL_LOG_H */

View file

@ -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; a0 = a0*b0 + t1a;
a1 = a1*b1 + (t1>>32) + (a0<t1a); a1 = a1*b1 + (t1>>32) + (a0<t1a);
a0 += r; a0 += r;
a1 += a0<r; a1 += a0<(unsigned)r;
for(i=63; i>=0; i--){ for(i=63; i>=0; i--){
// int o= a1 & 0x8000000000000000ULL; // int o= a1 & 0x8000000000000000ULL;
a1+= a1 + ((a0>>i)&1); a1+= a1 + ((a0>>i)&1);
t1+=t1; t1+=t1;
if(/*o || */c <= a1){ if(/*o || */(unsigned)c <= a1){
a1 -= c; a1 -= c;
t1++; t1++;
} }

View file

@ -24,20 +24,6 @@
#include "libavutil/common.h" #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 */ /* generic implementation */
#ifndef MULL #ifndef MULL

View file

@ -37,7 +37,7 @@
//#define ALT_BITSTREAM_WRITER //#define ALT_BITSTREAM_WRITER
//#define ALIGNED_BITSTREAM_WRITER //#define ALIGNED_BITSTREAM_WRITER
#define HAVE_FAST_UNALIGNED 0
/* buf and buf_end must be present and used by every alternative writer. */ /* buf and buf_end must be present and used by every alternative writer. */
typedef struct PutBitContext { typedef struct PutBitContext {
#ifdef ALT_BITSTREAM_WRITER #ifdef ALT_BITSTREAM_WRITER

View file

@ -467,7 +467,8 @@ unsigned int ff_wma_get_large_val(GetBitContext* gb)
* @param coef_nb_bits number of bits for escaped level codes * @param coef_nb_bits number of bits for escaped level codes
* @return 0 on success, -1 otherwise * @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, VLC *vlc,
const int32_t *level_table, const uint16_t *run_table, const int32_t *level_table, const uint16_t *run_table,
int version, int32_t *ptr, int offset, int version, int32_t *ptr, int offset,

View file

@ -24,8 +24,6 @@
#include "get_bits.h" #include "get_bits.h"
#include "put_bits.h" #include "put_bits.h"
#include "dsputil.h"
#include "fft.h"
/* size of blocks */ /* size of blocks */
#define BLOCK_MIN_BITS 7 #define BLOCK_MIN_BITS 7
@ -62,90 +60,6 @@ typedef struct CoefVLCTable {
const uint16_t *levels; ///< table to build run/level tables const uint16_t *levels; ///< table to build run/level tables
} CoefVLCTable; } 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, int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
unsigned int decode_flags); 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_total_gain_to_bits(int total_gain);
int ff_wma_end(AVCodecContext *avctx); int ff_wma_end(AVCodecContext *avctx);
unsigned int ff_wma_get_large_val(GetBitContext* gb); 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, VLC *vlc,
const int32_t *level_table, const uint16_t *run_table, const int32_t *level_table, const uint16_t *run_table,
int version, int32_t *ptr, int offset, int version, int32_t *ptr, int offset,

View file

@ -4,6 +4,7 @@
#include "../lib/mdct_lookup.h" /* for revtab */ #include "../lib/mdct_lookup.h" /* for revtab */
#include "../lib/fft.h" /* for FFT data structures */ #include "../lib/fft.h" /* for FFT data structures */
#include "codeclib.h" #include "codeclib.h"
#define ROCKBOX_BIG_ENDIAN 0
#include "../lib/codeclib_misc.h" /* for XNPROD31 */ #include "../lib/codeclib_misc.h" /* for XNPROD31 */
#include "wmapro_math.h" #include "wmapro_math.h"

View file

@ -103,6 +103,13 @@
/* Uncomment the following line to enable some debug output */ /* Uncomment the following line to enable some debug output */
//#define WMAPRO_DUMP_CTX_EN //#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 */ /* Some defines to make it compile */
#define AVERROR_INVALIDDATA -1 #define AVERROR_INVALIDDATA -1
#define AVERROR_PATCHWELCOME -2 #define AVERROR_PATCHWELCOME -2
@ -177,7 +184,6 @@ typedef struct {
typedef struct WMAProDecodeCtx { typedef struct WMAProDecodeCtx {
/* generic decoder variables */ /* generic decoder variables */
AVCodecContext* avctx; ///< codec context for av_log AVCodecContext* avctx; ///< codec context for av_log
DSPContext dsp; ///< accelerated DSP functions
uint8_t frame_data[MAX_FRAMESIZE + uint8_t frame_data[MAX_FRAMESIZE +
FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
PutBitContext pb; ///< context for filling the frame_data buffer PutBitContext pb; ///< context for filling the frame_data buffer
@ -236,6 +242,8 @@ typedef struct WMAProDecodeCtx {
WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data
} WMAProDecodeCtx; } WMAProDecodeCtx;
/* static decode context, to avoid malloc */
static WMAProDecodeCtx globWMAProDecCtx;
/** /**
*@brief helper function to print the most important members of the context *@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) av_cold int decode_init(AVCodecContext *avctx)
{ {
avctx->priv_data = malloc(sizeof(WMAProDecodeCtx)); avctx->priv_data = &globWMAProDecCtx;
memset(avctx->priv_data, 0, sizeof(WMAProDecodeCtx)); memset(avctx->priv_data, 0, sizeof(WMAProDecodeCtx));
WMAProDecodeCtx *s = avctx->priv_data; WMAProDecodeCtx *s = avctx->priv_data;
uint8_t *edata_ptr = avctx->extradata; uint8_t *edata_ptr = avctx->extradata;
@ -276,8 +284,6 @@ av_cold int decode_init(AVCodecContext *avctx)
s->avctx = avctx; s->avctx = avctx;
init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
avctx->sample_fmt = SAMPLE_FMT_FLT;
if (avctx->extradata_size >= 18) { if (avctx->extradata_size >= 18) {
s->decode_flags = AV_RL16(edata_ptr+14); s->decode_flags = AV_RL16(edata_ptr+14);
channel_mask = AV_RL32(edata_ptr+2); channel_mask = AV_RL32(edata_ptr+2);
@ -288,7 +294,7 @@ av_cold int decode_init(AVCodecContext *avctx)
dprintf(avctx, "\n"); dprintf(avctx, "\n");
} else { } else {
av_log_ask_for_sample(avctx, "Unknown extradata size\n"); DEBUGF("Unknown extradata size\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -301,7 +307,7 @@ av_cold int decode_init(AVCodecContext *avctx)
s->len_prefix = (s->decode_flags & 0x40); s->len_prefix = (s->decode_flags & 0x40);
if (!s->len_prefix) { if (!s->len_prefix) {
av_log_ask_for_sample(avctx, "no length prefix\n"); DEBUGF("no length prefix\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -325,7 +331,7 @@ av_cold int decode_init(AVCodecContext *avctx)
s->dynamic_range_compression = (s->decode_flags & 0x80); s->dynamic_range_compression = (s->decode_flags & 0x80);
if (s->max_num_subframes > MAX_SUBFRAMES) { 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); s->max_num_subframes);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -344,10 +350,10 @@ av_cold int decode_init(AVCodecContext *avctx)
} }
if (s->num_channels < 0) { 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; return AVERROR_INVALIDDATA;
} else if (s->num_channels > WMAPRO_MAX_CHANNELS) { } 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; return AVERROR_PATCHWELCOME;
} }
@ -437,8 +443,6 @@ av_cold int decode_init(AVCodecContext *avctx)
#ifdef WMAPRO_DUMP_CTX_EN #ifdef WMAPRO_DUMP_CTX_EN
dump_context(s); dump_context(s);
#endif #endif
avctx->channel_layout = channel_mask;
return 0; return 0;
} }
@ -469,7 +473,7 @@ static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
/** sanity check the length */ /** sanity check the length */
if (subframe_len < s->min_samples_per_subframe || if (subframe_len < s->min_samples_per_subframe ||
subframe_len > s->samples_per_frame) { 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); subframe_len);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -547,15 +551,14 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
if (contains_subframe[c]) { if (contains_subframe[c]) {
if (chan->num_subframes >= MAX_SUBFRAMES) { if (chan->num_subframes >= MAX_SUBFRAMES) {
av_log(s->avctx, AV_LOG_ERROR, DEBUGF("broken frame: num subframes > 31\n");
"broken frame: num subframes > 31\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
chan->subframe_len[chan->num_subframes] = subframe_len; chan->subframe_len[chan->num_subframes] = subframe_len;
num_samples[c] += subframe_len; num_samples[c] += subframe_len;
++chan->num_subframes; ++chan->num_subframes;
if (num_samples[c] > s->samples_per_frame) { 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"); "channel len > samples_per_frame\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -674,8 +677,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
int remaining_channels = s->channels_for_cur_subframe; int remaining_channels = s->channels_for_cur_subframe;
if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) {
av_log_ask_for_sample(s->avctx, DEBUGF("unsupported channel transform bit\n");
"unsupported channel transform bit\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -711,8 +713,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
if (chgroup->num_channels == 2) { if (chgroup->num_channels == 2) {
if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) {
if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) {
av_log_ask_for_sample(s->avctx, DEBUGF("unsupported channel transform type\n");
"unsupported channel transform type\n");
} }
} else { } else {
chgroup->transform = 1; chgroup->transform = 1;
@ -730,7 +731,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
} }
} }
} else if (chgroup->num_channels > 2) { } 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; return -1;
#if 0 #if 0
if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) {
@ -857,7 +858,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
memset(&ci->coeffs[cur_coeff], 0, memset(&ci->coeffs[cur_coeff], 0,
sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff)); 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, level, run, 1, ci->coeffs,
cur_coeff, s->subframe_len, cur_coeff, s->subframe_len,
s->subframe_len, s->esc_len, 0)) s->subframe_len, s->esc_len, 0))
@ -937,8 +938,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
i += skip; i += skip;
if (i >= s->num_bands) { if (i >= s->num_bands) {
av_log(s->avctx, AV_LOG_ERROR, DEBUGF("invalid scale factor coding\n");
"invalid scale factor coding\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
s->channel[c].scale_factors[i] += (val ^ sign) - sign; 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 (num_fill_bits >= 0) {
if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) { 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; return AVERROR_INVALIDDATA;
} }
@ -1147,7 +1147,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
/** no idea for what the following bit is used */ /** no idea for what the following bit is used */
if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) {
av_log_ask_for_sample(s->avctx, "reserved bit set\n"); DEBUGF("reserved bit set\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -1165,7 +1165,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
int quant_step = 90 * s->bits_per_sample >> 4; int quant_step = 90 * s->bits_per_sample >> 4;
if ((get_bits1(&s->gb))) { if ((get_bits1(&s->gb))) {
/** FIXME: might change run level mode decision */ /** 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; return AVERROR_INVALIDDATA;
} }
/** decode quantization step */ /** decode quantization step */
@ -1181,7 +1181,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
quant_step += ((quant + step) ^ sign) - sign; quant_step += ((quant + step) ^ sign) - sign;
} }
if (quant_step < 0) { 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 */ /** decode quantization step modifiers for every channel */
@ -1245,7 +1245,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
s->channel[c].scale_factor_step; s->channel[c].scale_factor_step;
if(exp < EXP_MIN || exp > EXP_MAX) { 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; return -1;
} }
const FIXED quant = QUANT(exp); 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++) { for (i = 0; i < s->channels_for_cur_subframe; i++) {
int c = s->channel_indexes_for_cur_subframe[i]; int c = s->channel_indexes_for_cur_subframe[i];
if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) { 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; return AVERROR_INVALIDDATA;
} }
++s->channel[c].cur_subframe; ++s->channel[c].cur_subframe;
@ -1297,8 +1297,7 @@ static int decode_frame(WMAProDecodeCtx *s)
/** check for potential output buffer overflow */ /** check for potential output buffer overflow */
if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) { if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) {
/** return an error if no frame could be decoded at all */ /** return an error if no frame could be decoded at all */
av_log(s->avctx, AV_LOG_ERROR, DEBUGF("not enough space for the output samples\n");
"not enough space for the output samples\n");
s->packet_loss = 1; s->packet_loss = 1;
return 0; return 0;
} }
@ -1317,7 +1316,7 @@ static int decode_frame(WMAProDecodeCtx *s)
/** read postproc transform */ /** read postproc transform */
if (s->num_channels > 1 && get_bits1(gb)) { 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; s->packet_loss = 1;
return 0; return 0;
} }
@ -1391,7 +1390,7 @@ static int decode_frame(WMAProDecodeCtx *s)
if (len != (get_bits_count(gb) - s->frame_offset) + 2) { if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
/** FIXME: not sure if this is always an error */ /** 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); (int)s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1);
s->packet_loss = 1; s->packet_loss = 1;
return 0; return 0;
@ -1443,7 +1442,7 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
buflen = (s->num_saved_bits + len + 8) >> 3; buflen = (s->num_saved_bits + len + 8) >> 3;
if (len <= 0 || buflen > MAX_FRAMESIZE) { 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; s->packet_loss = 1;
return; return;
} }
@ -1516,7 +1515,7 @@ int decode_packet(AVCodecContext *avctx,
if (!s->packet_loss && if (!s->packet_loss &&
((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) { ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
s->packet_loss = 1; 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);
} }
s->packet_sequence_number = packet_sequence_number; s->packet_sequence_number = packet_sequence_number;

View file

@ -28,7 +28,7 @@ CODEC_HEADER
#define MAXSAMPLES (1L << 12) /* Max number of samples in a wma pro subframe */ #define MAXSAMPLES (1L << 12) /* Max number of samples in a wma pro subframe */
#define MAXCHANNELS 8 #define MAXCHANNELS 8
#define BUFSIZE MAXCHANNELS * MAXSAMPLES #define BUFSIZE MAXCHANNELS * MAXSAMPLES
static int32_t decoded[BUFSIZE] IBSS_ATTR; int32_t decoded[BUFSIZE];
AVCodecContext avctx; AVCodecContext avctx;
AVPacket avpkt; AVPacket avpkt;