forked from len0rd/rockbox
Add libwmapro to trunk.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25739 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f96406c5f3
commit
dda7fab1d6
30 changed files with 16068 additions and 0 deletions
11
apps/codecs/libwmapro/Makefile
Normal file
11
apps/codecs/libwmapro/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
STD = c99
|
||||
LINK = -lm
|
||||
CFLAGS = -Wall -std=$(STD)
|
||||
TARGET = test
|
||||
OBJS = wmaprodec.c wma.c dsputil.c mdct.c fft.c bitstream.c libavutil/log.c libavutil/mem.c libavutil/mathematics.c
|
||||
$(TARGET): $(OBJS)
|
||||
gcc $(CFLAGS) $(OBJS) $(LINK) -o $(TARGET)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) *~
|
||||
|
3481
apps/codecs/libwmapro/avcodec.h
Normal file
3481
apps/codecs/libwmapro/avcodec.h
Normal file
File diff suppressed because it is too large
Load diff
99
apps/codecs/libwmapro/avfft.h
Normal file
99
apps/codecs/libwmapro/avfft.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AVFFT_H
|
||||
#define AVCODEC_AVFFT_H
|
||||
|
||||
typedef float FFTSample;
|
||||
|
||||
typedef struct FFTComplex {
|
||||
FFTSample re, im;
|
||||
} FFTComplex;
|
||||
|
||||
typedef struct FFTContext FFTContext;
|
||||
|
||||
/**
|
||||
* Set up a complex FFT.
|
||||
* @param nbits log2 of the length of the input array
|
||||
* @param inverse if 0 perform the forward transform, if 1 perform the inverse
|
||||
*/
|
||||
FFTContext *av_fft_init(int nbits, int inverse);
|
||||
|
||||
/**
|
||||
* Do the permutation needed BEFORE calling ff_fft_calc().
|
||||
*/
|
||||
void av_fft_permute(FFTContext *s, FFTComplex *z);
|
||||
|
||||
/**
|
||||
* Do a complex FFT with the parameters defined in av_fft_init(). The
|
||||
* input data must be permuted before. No 1.0/sqrt(n) normalization is done.
|
||||
*/
|
||||
void av_fft_calc(FFTContext *s, FFTComplex *z);
|
||||
|
||||
void av_fft_end(FFTContext *s);
|
||||
|
||||
FFTContext *av_mdct_init(int nbits, int inverse, double scale);
|
||||
void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void av_mdct_end(FFTContext *s);
|
||||
|
||||
/* Real Discrete Fourier Transform */
|
||||
|
||||
enum RDFTransformType {
|
||||
DFT_R2C,
|
||||
IDFT_C2R,
|
||||
IDFT_R2C,
|
||||
DFT_C2R,
|
||||
};
|
||||
|
||||
typedef struct RDFTContext RDFTContext;
|
||||
|
||||
/**
|
||||
* Set up a real FFT.
|
||||
* @param nbits log2 of the length of the input array
|
||||
* @param trans the type of transform
|
||||
*/
|
||||
RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans);
|
||||
void av_rdft_calc(RDFTContext *s, FFTSample *data);
|
||||
void av_rdft_end(RDFTContext *s);
|
||||
|
||||
/* Discrete Cosine Transform */
|
||||
|
||||
typedef struct DCTContext DCTContext;
|
||||
|
||||
enum DCTTransformType {
|
||||
DCT_II = 0,
|
||||
DCT_III,
|
||||
DCT_I,
|
||||
DST_I,
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets up DCT.
|
||||
* @param nbits size of the input array:
|
||||
* (1 << nbits) for DCT-II, DCT-III and DST-I
|
||||
* (1 << nbits) + 1 for DCT-I
|
||||
*
|
||||
* @note the first element of the input of DST-I is ignored
|
||||
*/
|
||||
DCTContext *av_dct_init(int nbits, enum DCTTransformType type);
|
||||
void av_dct_calc(DCTContext *s, FFTSample *data);
|
||||
void av_dct_end (DCTContext *s);
|
||||
|
||||
#endif /* AVCODEC_AVFFT_H */
|
338
apps/codecs/libwmapro/bitstream.c
Normal file
338
apps/codecs/libwmapro/bitstream.c
Normal file
|
@ -0,0 +1,338 @@
|
|||
/*
|
||||
* Common bit i/o utils
|
||||
* Copyright (c) 2000, 2001 Fabrice Bellard
|
||||
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
* Copyright (c) 2010 Loren Merritt
|
||||
*
|
||||
* alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavcodec/bitstream.c
|
||||
* bitstream api.
|
||||
*/
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "get_bits.h"
|
||||
#include "put_bits.h"
|
||||
|
||||
#define CONFIG_SMALL 0 // added to make it compile
|
||||
|
||||
const uint8_t ff_log2_run[32]={
|
||||
0, 0, 0, 0, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 3, 3, 3, 3,
|
||||
4, 4, 5, 5, 6, 6, 7, 7,
|
||||
8, 9,10,11,12,13,14,15
|
||||
};
|
||||
|
||||
void align_put_bits(PutBitContext *s)
|
||||
{
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
put_bits(s,( - s->index) & 7,0);
|
||||
#else
|
||||
put_bits(s,s->bit_left & 7,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
|
||||
{
|
||||
while(*string){
|
||||
put_bits(pb, 8, *string);
|
||||
string++;
|
||||
}
|
||||
if(terminate_string)
|
||||
put_bits(pb, 8, 0);
|
||||
}
|
||||
|
||||
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
|
||||
{
|
||||
int words= length>>4;
|
||||
int bits= length&15;
|
||||
int i;
|
||||
|
||||
if(length==0) return;
|
||||
|
||||
if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
|
||||
for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i));
|
||||
}else{
|
||||
for(i=0; put_bits_count(pb)&31; i++)
|
||||
put_bits(pb, 8, src[i]);
|
||||
flush_put_bits(pb);
|
||||
memcpy(put_bits_ptr(pb), src+i, 2*words-i);
|
||||
skip_put_bytes(pb, 2*words-i);
|
||||
}
|
||||
|
||||
put_bits(pb, bits, AV_RB16(src + 2*words)>>(16-bits));
|
||||
}
|
||||
|
||||
/* VLC decoding */
|
||||
|
||||
//#define DEBUG_VLC
|
||||
|
||||
#define GET_DATA(v, table, i, wrap, size) \
|
||||
{\
|
||||
const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
|
||||
switch(size) {\
|
||||
case 1:\
|
||||
v = *(const uint8_t *)ptr;\
|
||||
break;\
|
||||
case 2:\
|
||||
v = *(const uint16_t *)ptr;\
|
||||
break;\
|
||||
default:\
|
||||
v = *(const uint32_t *)ptr;\
|
||||
break;\
|
||||
}\
|
||||
}
|
||||
|
||||
|
||||
static int alloc_table(VLC *vlc, int size, int use_static)
|
||||
{
|
||||
int index;
|
||||
index = vlc->table_size;
|
||||
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
|
||||
vlc->table_allocated += (1 << vlc->bits);
|
||||
vlc->table = av_realloc(vlc->table,
|
||||
sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
|
||||
if (!vlc->table)
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static av_always_inline uint32_t bitswap_32(uint32_t x) {
|
||||
return av_reverse[x&0xFF]<<24
|
||||
| av_reverse[(x>>8)&0xFF]<<16
|
||||
| av_reverse[(x>>16)&0xFF]<<8
|
||||
| av_reverse[x>>24];
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t bits;
|
||||
uint16_t symbol;
|
||||
/** codeword, with the first bit-to-be-read in the msb
|
||||
* (even if intended for a little-endian bitstream reader) */
|
||||
uint32_t code;
|
||||
} VLCcode;
|
||||
|
||||
static int compare_vlcspec(const void *a, const void *b)
|
||||
{
|
||||
const VLCcode *sa=a, *sb=b;
|
||||
return (sa->code >> 1) - (sb->code >> 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build VLC decoding tables suitable for use with get_vlc().
|
||||
*
|
||||
* @param vlc the context to be initted
|
||||
*
|
||||
* @param table_nb_bits max length of vlc codes to store directly in this table
|
||||
* (Longer codes are delegated to subtables.)
|
||||
*
|
||||
* @param nb_codes number of elements in codes[]
|
||||
*
|
||||
* @param codes descriptions of the vlc codes
|
||||
* These must be ordered such that codes going into the same subtable are contiguous.
|
||||
* Sorting by VLCcode.code is sufficient, though not necessary.
|
||||
*/
|
||||
static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
|
||||
VLCcode *codes, int flags)
|
||||
{
|
||||
int table_size, table_index, index, code_prefix, symbol, subtable_bits;
|
||||
int i, j, k, n, nb, inc;
|
||||
uint32_t code;
|
||||
VLC_TYPE (*table)[2];
|
||||
|
||||
table_size = 1 << table_nb_bits;
|
||||
table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);
|
||||
#ifdef DEBUG_VLC
|
||||
av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n",
|
||||
table_index, table_size);
|
||||
#endif
|
||||
if (table_index < 0)
|
||||
return -1;
|
||||
table = &vlc->table[table_index];
|
||||
|
||||
for (i = 0; i < table_size; i++) {
|
||||
table[i][1] = 0; //bits
|
||||
table[i][0] = -1; //codes
|
||||
}
|
||||
|
||||
/* first pass: map codes and compute auxillary table sizes */
|
||||
for (i = 0; i < nb_codes; i++) {
|
||||
n = codes[i].bits;
|
||||
code = codes[i].code;
|
||||
symbol = codes[i].symbol;
|
||||
#if defined(DEBUG_VLC) && 0
|
||||
av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
|
||||
#endif
|
||||
if (n <= table_nb_bits) {
|
||||
/* no need to add another table */
|
||||
j = code >> (32 - table_nb_bits);
|
||||
nb = 1 << (table_nb_bits - n);
|
||||
inc = 1;
|
||||
if (flags & INIT_VLC_LE) {
|
||||
j = bitswap_32(code);
|
||||
inc = 1 << n;
|
||||
}
|
||||
for (k = 0; k < nb; k++) {
|
||||
#ifdef DEBUG_VLC
|
||||
av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n",
|
||||
j, i, n);
|
||||
#endif
|
||||
if (table[j][1] /*bits*/ != 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
|
||||
return -1;
|
||||
}
|
||||
table[j][1] = n; //bits
|
||||
table[j][0] = symbol;
|
||||
j += inc;
|
||||
}
|
||||
} else {
|
||||
/* fill auxiliary table recursively */
|
||||
n -= table_nb_bits;
|
||||
code_prefix = code >> (32 - table_nb_bits);
|
||||
subtable_bits = n;
|
||||
codes[i].bits = n;
|
||||
codes[i].code = code << table_nb_bits;
|
||||
for (k = i+1; k < nb_codes; k++) {
|
||||
n = codes[k].bits - table_nb_bits;
|
||||
if (n <= 0)
|
||||
break;
|
||||
code = codes[k].code;
|
||||
if (code >> (32 - table_nb_bits) != 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;
|
||||
table[j][1] = -subtable_bits;
|
||||
#ifdef DEBUG_VLC
|
||||
av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n",
|
||||
j, codes[i].bits + table_nb_bits);
|
||||
#endif
|
||||
index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
|
||||
if (index < 0)
|
||||
return -1;
|
||||
/* note: realloc has been done, so reload tables */
|
||||
table = &vlc->table[table_index];
|
||||
table[j][0] = index; //code
|
||||
i = k-1;
|
||||
}
|
||||
}
|
||||
return table_index;
|
||||
}
|
||||
|
||||
|
||||
/* Build VLC decoding tables suitable for use with get_vlc().
|
||||
|
||||
'nb_bits' set thee decoding table size (2^nb_bits) entries. The
|
||||
bigger it is, the faster is the decoding. But it should not be too
|
||||
big to save memory and L1 cache. '9' is a good compromise.
|
||||
|
||||
'nb_codes' : number of vlcs codes
|
||||
|
||||
'bits' : table which gives the size (in bits) of each vlc code.
|
||||
|
||||
'codes' : table which gives the bit pattern of of each vlc code.
|
||||
|
||||
'symbols' : table which gives the values to be returned from get_vlc().
|
||||
|
||||
'xxx_wrap' : give the number of bytes between each entry of the
|
||||
'bits' or 'codes' tables.
|
||||
|
||||
'xxx_size' : gives the number of bytes of each entry of the 'bits'
|
||||
or 'codes' tables.
|
||||
|
||||
'wrap' and 'size' allows to use any memory configuration and types
|
||||
(byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
|
||||
|
||||
'use_static' should be set to 1 for tables, which should be freed
|
||||
with av_free_static(), 0 if free_vlc() will be used.
|
||||
*/
|
||||
int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
|
||||
const void *bits, int bits_wrap, int bits_size,
|
||||
const void *codes, int codes_wrap, int codes_size,
|
||||
const void *symbols, int symbols_wrap, int symbols_size,
|
||||
int flags)
|
||||
{
|
||||
VLCcode buf[nb_codes];
|
||||
int i, j;
|
||||
|
||||
vlc->bits = nb_bits;
|
||||
if(flags & INIT_VLC_USE_NEW_STATIC){
|
||||
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
|
||||
}
|
||||
}else {
|
||||
vlc->table = NULL;
|
||||
vlc->table_allocated = 0;
|
||||
vlc->table_size = 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_VLC
|
||||
av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
|
||||
#endif
|
||||
|
||||
assert(symbols_size <= 2 || !symbols);
|
||||
j = 0;
|
||||
#define COPY(condition)\
|
||||
for (i = 0; i < nb_codes; i++) {\
|
||||
GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\
|
||||
if (!(condition))\
|
||||
continue;\
|
||||
GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\
|
||||
if (flags & INIT_VLC_LE)\
|
||||
buf[j].code = bitswap_32(buf[j].code);\
|
||||
else\
|
||||
buf[j].code <<= 32 - buf[j].bits;\
|
||||
if (symbols)\
|
||||
GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\
|
||||
else\
|
||||
buf[j].symbol = i;\
|
||||
j++;\
|
||||
}
|
||||
COPY(buf[j].bits > nb_bits);
|
||||
// qsort is the slowest part of init_vlc, and could probably be improved or avoided
|
||||
qsort(buf, j, sizeof(VLCcode), compare_vlcspec);
|
||||
COPY(buf[j].bits && buf[j].bits <= nb_bits);
|
||||
nb_codes = j;
|
||||
|
||||
if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) {
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void free_vlc(VLC *vlc)
|
||||
{
|
||||
av_freep(&vlc->table);
|
||||
}
|
||||
|
4572
apps/codecs/libwmapro/dsputil.c
Normal file
4572
apps/codecs/libwmapro/dsputil.c
Normal file
File diff suppressed because it is too large
Load diff
808
apps/codecs/libwmapro/dsputil.h
Normal file
808
apps/codecs/libwmapro/dsputil.h
Normal file
|
@ -0,0 +1,808 @@
|
|||
/*
|
||||
* DSP utils
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavcodec/dsputil.h
|
||||
* DSP utils.
|
||||
* note, many functions in here may use MMX which trashes the FPU state, it is
|
||||
* absolutely necessary to call emms_c() between dsp & float/double code
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_DSPUTIL_H
|
||||
#define AVCODEC_DSPUTIL_H
|
||||
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "avcodec.h"
|
||||
|
||||
|
||||
//#define DEBUG
|
||||
/* dct code */
|
||||
typedef short DCTELEM;
|
||||
|
||||
void fdct_ifast (DCTELEM *data);
|
||||
void fdct_ifast248 (DCTELEM *data);
|
||||
void ff_jpeg_fdct_islow (DCTELEM *data);
|
||||
void ff_fdct248_islow (DCTELEM *data);
|
||||
|
||||
void j_rev_dct (DCTELEM *data);
|
||||
void j_rev_dct4 (DCTELEM *data);
|
||||
void j_rev_dct2 (DCTELEM *data);
|
||||
void j_rev_dct1 (DCTELEM *data);
|
||||
void ff_wmv2_idct_c(DCTELEM *data);
|
||||
|
||||
void ff_fdct_mmx(DCTELEM *block);
|
||||
void ff_fdct_mmx2(DCTELEM *block);
|
||||
void ff_fdct_sse2(DCTELEM *block);
|
||||
|
||||
void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
|
||||
void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
|
||||
void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
|
||||
void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride);
|
||||
void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
|
||||
void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
|
||||
void ff_h264_idct_add16_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
|
||||
void ff_h264_idct_add16intra_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
|
||||
void ff_h264_idct8_add4_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
|
||||
void ff_h264_idct_add8_c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);
|
||||
|
||||
void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1,
|
||||
const float *win, float add_bias, int len);
|
||||
void ff_float_to_int16_c(int16_t *dst, const float *src, long len);
|
||||
void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels);
|
||||
|
||||
/* encoding scans */
|
||||
extern const uint8_t ff_alternate_horizontal_scan[64];
|
||||
extern const uint8_t ff_alternate_vertical_scan[64];
|
||||
extern const uint8_t ff_zigzag_direct[64];
|
||||
extern const uint8_t ff_zigzag248_direct[64];
|
||||
|
||||
/* pixel operations */
|
||||
#define MAX_NEG_CROP 1024
|
||||
|
||||
/* temporary */
|
||||
extern uint32_t ff_squareTbl[512];
|
||||
extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP];
|
||||
|
||||
/* VP3 DSP functions */
|
||||
void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
|
||||
void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
|
||||
void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
|
||||
|
||||
void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
|
||||
void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
|
||||
|
||||
/* VP6 DSP functions */
|
||||
void ff_vp6_filter_diag4_c(uint8_t *dst, uint8_t *src, int stride,
|
||||
const int16_t *h_weights, const int16_t *v_weights);
|
||||
|
||||
/* Bink functions */
|
||||
void ff_bink_idct_c (DCTELEM *block);
|
||||
void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block);
|
||||
void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
|
||||
|
||||
/* CAVS functions */
|
||||
void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride);
|
||||
void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride);
|
||||
void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride);
|
||||
void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride);
|
||||
|
||||
/* VC1 functions */
|
||||
void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
|
||||
void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
|
||||
|
||||
/* EA functions */
|
||||
void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
|
||||
|
||||
/* 1/2^n downscaling functions from imgconvert.c */
|
||||
void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
|
||||
void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
|
||||
void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
|
||||
void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
|
||||
|
||||
void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
|
||||
int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
|
||||
|
||||
/* minimum alignment rules ;)
|
||||
If you notice errors in the align stuff, need more alignment for some ASM code
|
||||
for some CPU or need to use a function with less aligned data then send a mail
|
||||
to the ffmpeg-devel mailing list, ...
|
||||
|
||||
!warning These alignments might not match reality, (missing attribute((align))
|
||||
stuff somewhere possible).
|
||||
I (Michael) did not check them, these are just the alignments which I think
|
||||
could be reached easily ...
|
||||
|
||||
!future video codecs might need functions with less strict alignment
|
||||
*/
|
||||
|
||||
/*
|
||||
void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
|
||||
void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
|
||||
void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
|
||||
void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
|
||||
void clear_blocks_c(DCTELEM *blocks);
|
||||
*/
|
||||
|
||||
/* add and put pixel (decoding) */
|
||||
// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
|
||||
//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4
|
||||
typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
|
||||
typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h);
|
||||
typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
|
||||
typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
|
||||
|
||||
typedef void (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h);
|
||||
|
||||
#define DEF_OLD_QPEL(name)\
|
||||
void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
|
||||
void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
|
||||
void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
|
||||
|
||||
DEF_OLD_QPEL(qpel16_mc11_old_c)
|
||||
DEF_OLD_QPEL(qpel16_mc31_old_c)
|
||||
DEF_OLD_QPEL(qpel16_mc12_old_c)
|
||||
DEF_OLD_QPEL(qpel16_mc32_old_c)
|
||||
DEF_OLD_QPEL(qpel16_mc13_old_c)
|
||||
DEF_OLD_QPEL(qpel16_mc33_old_c)
|
||||
DEF_OLD_QPEL(qpel8_mc11_old_c)
|
||||
DEF_OLD_QPEL(qpel8_mc31_old_c)
|
||||
DEF_OLD_QPEL(qpel8_mc12_old_c)
|
||||
DEF_OLD_QPEL(qpel8_mc32_old_c)
|
||||
DEF_OLD_QPEL(qpel8_mc13_old_c)
|
||||
DEF_OLD_QPEL(qpel8_mc33_old_c)
|
||||
|
||||
#define CALL_2X_PIXELS(a, b, n)\
|
||||
static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
|
||||
b(block , pixels , line_size, h);\
|
||||
b(block+n, pixels+n, line_size, h);\
|
||||
}
|
||||
|
||||
/* motion estimation */
|
||||
// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2
|
||||
// although currently h<4 is not used as functions with width <8 are neither used nor implemented
|
||||
typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/;
|
||||
|
||||
/**
|
||||
* Scantable.
|
||||
*/
|
||||
typedef struct ScanTable{
|
||||
const uint8_t *scantable;
|
||||
uint8_t permutated[64];
|
||||
uint8_t raster_end[64];
|
||||
#if ARCH_PPC
|
||||
/** Used by dct_quantize_altivec to find last-non-zero */
|
||||
DECLARE_ALIGNED(16, uint8_t, inverse)[64];
|
||||
#endif
|
||||
} ScanTable;
|
||||
|
||||
void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
|
||||
|
||||
void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize,
|
||||
int block_w, int block_h,
|
||||
int src_x, int src_y, int w, int h);
|
||||
|
||||
/**
|
||||
* DSPContext.
|
||||
*/
|
||||
typedef struct DSPContext {
|
||||
/* pixel ops : interface with DCT */
|
||||
void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
|
||||
void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
|
||||
void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
|
||||
void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
|
||||
void (*put_pixels_nonclamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
|
||||
void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
|
||||
void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
|
||||
void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
|
||||
int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/);
|
||||
/**
|
||||
* translational global motion compensation.
|
||||
*/
|
||||
void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
|
||||
/**
|
||||
* global motion compensation.
|
||||
*/
|
||||
void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
|
||||
int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
|
||||
void (*clear_block)(DCTELEM *block/*align 16*/);
|
||||
void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
|
||||
int (*pix_sum)(uint8_t * pix, int line_size);
|
||||
int (*pix_norm1)(uint8_t * pix, int line_size);
|
||||
// 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4
|
||||
|
||||
me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
|
||||
me_cmp_func sse[6];
|
||||
me_cmp_func hadamard8_diff[6];
|
||||
me_cmp_func dct_sad[6];
|
||||
me_cmp_func quant_psnr[6];
|
||||
me_cmp_func bit[6];
|
||||
me_cmp_func rd[6];
|
||||
me_cmp_func vsad[6];
|
||||
me_cmp_func vsse[6];
|
||||
me_cmp_func nsse[6];
|
||||
me_cmp_func w53[6];
|
||||
me_cmp_func w97[6];
|
||||
me_cmp_func dct_max[6];
|
||||
me_cmp_func dct264_sad[6];
|
||||
|
||||
me_cmp_func me_pre_cmp[6];
|
||||
me_cmp_func me_cmp[6];
|
||||
me_cmp_func me_sub_cmp[6];
|
||||
me_cmp_func mb_cmp[6];
|
||||
me_cmp_func ildct_cmp[6]; //only width 16 used
|
||||
me_cmp_func frame_skip_cmp[6]; //only width 8 used
|
||||
|
||||
int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
|
||||
int size);
|
||||
|
||||
/**
|
||||
* Halfpel motion compensation with rounding (a+b+1)>>1.
|
||||
* this is an array[4][4] of motion compensation functions for 4
|
||||
* horizontal blocksizes (8,16) and the 4 halfpel positions<br>
|
||||
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
|
||||
* @param block destination where the result is stored
|
||||
* @param pixels source
|
||||
* @param line_size number of bytes in a horizontal line of block
|
||||
* @param h height
|
||||
*/
|
||||
op_pixels_func put_pixels_tab[4][4];
|
||||
|
||||
/**
|
||||
* Halfpel motion compensation with rounding (a+b+1)>>1.
|
||||
* This is an array[4][4] of motion compensation functions for 4
|
||||
* horizontal blocksizes (8,16) and the 4 halfpel positions<br>
|
||||
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
|
||||
* @param block destination into which the result is averaged (a+b+1)>>1
|
||||
* @param pixels source
|
||||
* @param line_size number of bytes in a horizontal line of block
|
||||
* @param h height
|
||||
*/
|
||||
op_pixels_func avg_pixels_tab[4][4];
|
||||
|
||||
/**
|
||||
* Halfpel motion compensation with no rounding (a+b)>>1.
|
||||
* this is an array[2][4] of motion compensation functions for 2
|
||||
* horizontal blocksizes (8,16) and the 4 halfpel positions<br>
|
||||
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
|
||||
* @param block destination where the result is stored
|
||||
* @param pixels source
|
||||
* @param line_size number of bytes in a horizontal line of block
|
||||
* @param h height
|
||||
*/
|
||||
op_pixels_func put_no_rnd_pixels_tab[4][4];
|
||||
|
||||
/**
|
||||
* Halfpel motion compensation with no rounding (a+b)>>1.
|
||||
* this is an array[2][4] of motion compensation functions for 2
|
||||
* horizontal blocksizes (8,16) and the 4 halfpel positions<br>
|
||||
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
|
||||
* @param block destination into which the result is averaged (a+b)>>1
|
||||
* @param pixels source
|
||||
* @param line_size number of bytes in a horizontal line of block
|
||||
* @param h height
|
||||
*/
|
||||
op_pixels_func avg_no_rnd_pixels_tab[4][4];
|
||||
|
||||
void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h);
|
||||
|
||||
/**
|
||||
* Thirdpel motion compensation with rounding (a+b+1)>>1.
|
||||
* this is an array[12] of motion compensation functions for the 9 thirdpe
|
||||
* positions<br>
|
||||
* *pixels_tab[ xthirdpel + 4*ythirdpel ]
|
||||
* @param block destination where the result is stored
|
||||
* @param pixels source
|
||||
* @param line_size number of bytes in a horizontal line of block
|
||||
* @param h height
|
||||
*/
|
||||
tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
|
||||
tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
|
||||
|
||||
qpel_mc_func put_qpel_pixels_tab[2][16];
|
||||
qpel_mc_func avg_qpel_pixels_tab[2][16];
|
||||
qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
|
||||
qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
|
||||
qpel_mc_func put_mspel_pixels_tab[8];
|
||||
|
||||
/**
|
||||
* h264 Chroma MC
|
||||
*/
|
||||
h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
|
||||
h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
|
||||
/* This is really one func used in VC-1 decoding */
|
||||
h264_chroma_mc_func put_no_rnd_vc1_chroma_pixels_tab[3];
|
||||
h264_chroma_mc_func avg_no_rnd_vc1_chroma_pixels_tab[3];
|
||||
|
||||
qpel_mc_func put_h264_qpel_pixels_tab[4][16];
|
||||
qpel_mc_func avg_h264_qpel_pixels_tab[4][16];
|
||||
|
||||
qpel_mc_func put_2tap_qpel_pixels_tab[4][16];
|
||||
qpel_mc_func avg_2tap_qpel_pixels_tab[4][16];
|
||||
|
||||
/* AVS specific */
|
||||
qpel_mc_func put_cavs_qpel_pixels_tab[2][16];
|
||||
qpel_mc_func avg_cavs_qpel_pixels_tab[2][16];
|
||||
void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
|
||||
void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
|
||||
void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
|
||||
void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2);
|
||||
void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
|
||||
|
||||
me_cmp_func pix_abs[2][4];
|
||||
|
||||
/* huffyuv specific */
|
||||
void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
|
||||
void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
|
||||
void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
|
||||
/**
|
||||
* subtract huffyuv's variant of median prediction
|
||||
* note, this might read from src1[-1], src2[-1]
|
||||
*/
|
||||
void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top);
|
||||
void (*add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top);
|
||||
int (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left);
|
||||
void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha);
|
||||
/* this might write to dst[w] */
|
||||
void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
|
||||
void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
|
||||
|
||||
void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
|
||||
void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
|
||||
|
||||
void (*h261_loop_filter)(uint8_t *src, int stride);
|
||||
|
||||
void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale);
|
||||
void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale);
|
||||
|
||||
void (*vp3_v_loop_filter)(uint8_t *src, int stride, int *bounding_values);
|
||||
void (*vp3_h_loop_filter)(uint8_t *src, int stride, int *bounding_values);
|
||||
|
||||
void (*vp6_filter_diag4)(uint8_t *dst, uint8_t *src, int stride,
|
||||
const int16_t *h_weights,const int16_t *v_weights);
|
||||
|
||||
/* assume len is a multiple of 4, and arrays are 16-byte aligned */
|
||||
void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize);
|
||||
void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len);
|
||||
/* no alignment needed */
|
||||
void (*lpc_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc);
|
||||
/* assume len is a multiple of 8, and arrays are 16-byte aligned */
|
||||
void (*vector_fmul)(float *dst, const float *src, int len);
|
||||
void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len);
|
||||
/* assume len is a multiple of 8, and src arrays are 16-byte aligned */
|
||||
void (*vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len);
|
||||
/* assume len is a multiple of 4, and arrays are 16-byte aligned */
|
||||
void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len);
|
||||
/* assume len is a multiple of 8, and arrays are 16-byte aligned */
|
||||
void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len);
|
||||
void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);
|
||||
/**
|
||||
* Multiply a vector of floats by a scalar float. Source and
|
||||
* destination vectors must overlap exactly or not at all.
|
||||
* @param dst result vector, 16-byte aligned
|
||||
* @param src input vector, 16-byte aligned
|
||||
* @param mul scalar value
|
||||
* @param len length of vector, multiple of 4
|
||||
*/
|
||||
void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
|
||||
int len);
|
||||
/**
|
||||
* Multiply a vector of floats by concatenated short vectors of
|
||||
* floats and by a scalar float. Source and destination vectors
|
||||
* must overlap exactly or not at all.
|
||||
* [0]: short vectors of length 2, 8-byte aligned
|
||||
* [1]: short vectors of length 4, 16-byte aligned
|
||||
* @param dst output vector, 16-byte aligned
|
||||
* @param src input vector, 16-byte aligned
|
||||
* @param sv array of pointers to short vectors
|
||||
* @param mul scalar value
|
||||
* @param len number of elements in src and dst, multiple of 4
|
||||
*/
|
||||
void (*vector_fmul_sv_scalar[2])(float *dst, const float *src,
|
||||
const float **sv, float mul, int len);
|
||||
/**
|
||||
* Multiply short vectors of floats by a scalar float, store
|
||||
* concatenated result.
|
||||
* [0]: short vectors of length 2, 8-byte aligned
|
||||
* [1]: short vectors of length 4, 16-byte aligned
|
||||
* @param dst output vector, 16-byte aligned
|
||||
* @param sv array of pointers to short vectors
|
||||
* @param mul scalar value
|
||||
* @param len number of output elements, multiple of 4
|
||||
*/
|
||||
void (*sv_fmul_scalar[2])(float *dst, const float **sv,
|
||||
float mul, int len);
|
||||
/**
|
||||
* Calculate the scalar product of two vectors of floats.
|
||||
* @param v1 first vector, 16-byte aligned
|
||||
* @param v2 second vector, 16-byte aligned
|
||||
* @param len length of vectors, multiple of 4
|
||||
*/
|
||||
float (*scalarproduct_float)(const float *v1, const float *v2, int len);
|
||||
/**
|
||||
* Calculate the sum and difference of two vectors of floats.
|
||||
* @param v1 first input vector, sum output, 16-byte aligned
|
||||
* @param v2 second input vector, difference output, 16-byte aligned
|
||||
* @param len length of vectors, multiple of 4
|
||||
*/
|
||||
void (*butterflies_float)(float *restrict v1, float *restrict v2, int len);
|
||||
|
||||
/* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
|
||||
* simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
|
||||
void (*float_to_int16)(int16_t *dst, const float *src, long len);
|
||||
void (*float_to_int16_interleave)(int16_t *dst, const float **src, long len, int channels);
|
||||
|
||||
/* (I)DCT */
|
||||
void (*fdct)(DCTELEM *block/* align 16*/);
|
||||
void (*fdct248)(DCTELEM *block/* align 16*/);
|
||||
|
||||
/* IDCT really*/
|
||||
void (*idct)(DCTELEM *block/* align 16*/);
|
||||
|
||||
/**
|
||||
* block -> idct -> clip to unsigned 8 bit -> dest.
|
||||
* (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
|
||||
* @param line_size size in bytes of a horizontal line of dest
|
||||
*/
|
||||
void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
|
||||
|
||||
/**
|
||||
* block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
|
||||
* @param line_size size in bytes of a horizontal line of dest
|
||||
*/
|
||||
void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
|
||||
|
||||
/**
|
||||
* idct input permutation.
|
||||
* several optimized IDCTs need a permutated input (relative to the normal order of the reference
|
||||
* IDCT)
|
||||
* this permutation must be performed before the idct_put/add, note, normally this can be merged
|
||||
* with the zigzag/alternate scan<br>
|
||||
* an example to avoid confusion:
|
||||
* - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
|
||||
* - (x -> referece dct -> reference idct -> x)
|
||||
* - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
|
||||
* - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
|
||||
*/
|
||||
uint8_t idct_permutation[64];
|
||||
int idct_permutation_type;
|
||||
#define FF_NO_IDCT_PERM 1
|
||||
#define FF_LIBMPEG2_IDCT_PERM 2
|
||||
#define FF_SIMPLE_IDCT_PERM 3
|
||||
#define FF_TRANSPOSE_IDCT_PERM 4
|
||||
#define FF_PARTTRANS_IDCT_PERM 5
|
||||
#define FF_SSE2_IDCT_PERM 6
|
||||
|
||||
int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale);
|
||||
void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
|
||||
#define BASIS_SHIFT 16
|
||||
#define RECON_SHIFT 6
|
||||
|
||||
void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
|
||||
#define EDGE_WIDTH 16
|
||||
|
||||
void (*prefetch)(void *mem, int stride, int h);
|
||||
|
||||
void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
|
||||
|
||||
/* mlp/truehd functions */
|
||||
void (*mlp_filter_channel)(int32_t *state, const int32_t *coeff,
|
||||
int firorder, int iirorder,
|
||||
unsigned int filter_shift, int32_t mask, int blocksize,
|
||||
int32_t *sample_buffer);
|
||||
|
||||
/* vc1 functions */
|
||||
void (*vc1_inv_trans_8x8)(DCTELEM *b);
|
||||
void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block);
|
||||
void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block);
|
||||
void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block);
|
||||
void (*vc1_inv_trans_8x8_dc)(uint8_t *dest, int line_size, DCTELEM *block);
|
||||
void (*vc1_inv_trans_8x4_dc)(uint8_t *dest, int line_size, DCTELEM *block);
|
||||
void (*vc1_inv_trans_4x8_dc)(uint8_t *dest, int line_size, DCTELEM *block);
|
||||
void (*vc1_inv_trans_4x4_dc)(uint8_t *dest, int line_size, DCTELEM *block);
|
||||
void (*vc1_v_overlap)(uint8_t* src, int stride);
|
||||
void (*vc1_h_overlap)(uint8_t* src, int stride);
|
||||
void (*vc1_v_loop_filter4)(uint8_t *src, int stride, int pq);
|
||||
void (*vc1_h_loop_filter4)(uint8_t *src, int stride, int pq);
|
||||
void (*vc1_v_loop_filter8)(uint8_t *src, int stride, int pq);
|
||||
void (*vc1_h_loop_filter8)(uint8_t *src, int stride, int pq);
|
||||
void (*vc1_v_loop_filter16)(uint8_t *src, int stride, int pq);
|
||||
void (*vc1_h_loop_filter16)(uint8_t *src, int stride, int pq);
|
||||
/* put 8x8 block with bicubic interpolation and quarterpel precision
|
||||
* last argument is actually round value instead of height
|
||||
*/
|
||||
op_pixels_func put_vc1_mspel_pixels_tab[16];
|
||||
op_pixels_func avg_vc1_mspel_pixels_tab[16];
|
||||
|
||||
/* intrax8 functions */
|
||||
void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize);
|
||||
void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize,
|
||||
int * range, int * sum, int edges);
|
||||
|
||||
/**
|
||||
* Calculate scalar product of two vectors.
|
||||
* @param len length of vectors, should be multiple of 16
|
||||
* @param shift number of bits to discard from product
|
||||
*/
|
||||
int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2/*align 16*/, int len, int shift);
|
||||
/* ape functions */
|
||||
/**
|
||||
* Calculate scalar product of v1 and v2,
|
||||
* and v1[i] += v3[i] * mul
|
||||
* @param len length of vectors, should be multiple of 16
|
||||
*/
|
||||
int32_t (*scalarproduct_and_madd_int16)(int16_t *v1/*align 16*/, int16_t *v2, int16_t *v3, int len, int mul);
|
||||
|
||||
/* rv30 functions */
|
||||
qpel_mc_func put_rv30_tpel_pixels_tab[4][16];
|
||||
qpel_mc_func avg_rv30_tpel_pixels_tab[4][16];
|
||||
|
||||
/* rv40 functions */
|
||||
qpel_mc_func put_rv40_qpel_pixels_tab[4][16];
|
||||
qpel_mc_func avg_rv40_qpel_pixels_tab[4][16];
|
||||
h264_chroma_mc_func put_rv40_chroma_pixels_tab[3];
|
||||
h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3];
|
||||
|
||||
/* bink functions */
|
||||
op_fill_func fill_block_tab[2];
|
||||
void (*scale_block)(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize);
|
||||
} DSPContext;
|
||||
|
||||
void dsputil_static_init(void);
|
||||
void dsputil_init(DSPContext* p, AVCodecContext *avctx);
|
||||
|
||||
int ff_check_alignment(void);
|
||||
|
||||
/**
|
||||
* permute block according to permuatation.
|
||||
* @param last last non zero element in scantable order
|
||||
*/
|
||||
void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
|
||||
|
||||
void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type);
|
||||
|
||||
#define BYTE_VEC32(c) ((c)*0x01010101UL)
|
||||
|
||||
static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
|
||||
{
|
||||
return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
|
||||
}
|
||||
|
||||
static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
|
||||
{
|
||||
return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
|
||||
}
|
||||
|
||||
static inline int get_penalty_factor(int lambda, int lambda2, int type){
|
||||
switch(type&0xFF){
|
||||
default:
|
||||
case FF_CMP_SAD:
|
||||
return lambda>>FF_LAMBDA_SHIFT;
|
||||
case FF_CMP_DCT:
|
||||
return (3*lambda)>>(FF_LAMBDA_SHIFT+1);
|
||||
case FF_CMP_W53:
|
||||
return (4*lambda)>>(FF_LAMBDA_SHIFT);
|
||||
case FF_CMP_W97:
|
||||
return (2*lambda)>>(FF_LAMBDA_SHIFT);
|
||||
case FF_CMP_SATD:
|
||||
case FF_CMP_DCT264:
|
||||
return (2*lambda)>>FF_LAMBDA_SHIFT;
|
||||
case FF_CMP_RD:
|
||||
case FF_CMP_PSNR:
|
||||
case FF_CMP_SSE:
|
||||
case FF_CMP_NSSE:
|
||||
return lambda2>>FF_LAMBDA_SHIFT;
|
||||
case FF_CMP_BIT:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty mmx state.
|
||||
* this must be called between any dsp function and float/double code.
|
||||
* for example sin(); dsp->idct_put(); emms_c(); cos()
|
||||
*/
|
||||
#define emms_c()
|
||||
|
||||
/* should be defined by architectures supporting
|
||||
one or more MultiMedia extension */
|
||||
int mm_support(void);
|
||||
extern int mm_flags;
|
||||
|
||||
void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
|
||||
void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
|
||||
|
||||
void ff_dsputil_init_dwt(DSPContext *c);
|
||||
void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
|
||||
void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx);
|
||||
void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx);
|
||||
void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
|
||||
void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx);
|
||||
void ff_mlp_init(DSPContext* c, AVCodecContext *avctx);
|
||||
void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx);
|
||||
|
||||
#if HAVE_MMX
|
||||
|
||||
#undef emms_c
|
||||
|
||||
static inline void emms(void)
|
||||
{
|
||||
__asm__ volatile ("emms;":::"memory");
|
||||
}
|
||||
|
||||
|
||||
#define emms_c() \
|
||||
{\
|
||||
if (mm_flags & FF_MM_MMX)\
|
||||
emms();\
|
||||
}
|
||||
|
||||
#elif ARCH_ARM
|
||||
|
||||
#if HAVE_NEON
|
||||
# define STRIDE_ALIGN 16
|
||||
#endif
|
||||
|
||||
#elif ARCH_PPC
|
||||
|
||||
#define STRIDE_ALIGN 16
|
||||
|
||||
#elif HAVE_MMI
|
||||
|
||||
#define STRIDE_ALIGN 16
|
||||
|
||||
#else
|
||||
|
||||
#define mm_flags 0
|
||||
#define mm_support() 0
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef STRIDE_ALIGN
|
||||
# define STRIDE_ALIGN 8
|
||||
#endif
|
||||
|
||||
#define LOCAL_ALIGNED(a, t, v, s, ...) \
|
||||
uint8_t la_##v[sizeof(t s __VA_ARGS__) + (a)]; \
|
||||
t (*v) __VA_ARGS__ = (void *)FFALIGN((uintptr_t)la_##v, a)
|
||||
|
||||
#if HAVE_LOCAL_ALIGNED_8
|
||||
# define LOCAL_ALIGNED_8(t, v, s, ...) DECLARE_ALIGNED(8, t, v) s __VA_ARGS__
|
||||
#else
|
||||
# define LOCAL_ALIGNED_8(t, v, s, ...) LOCAL_ALIGNED(8, t, v, s, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if HAVE_LOCAL_ALIGNED_16
|
||||
# define LOCAL_ALIGNED_16(t, v, s, ...) DECLARE_ALIGNED(16, t, v) s __VA_ARGS__
|
||||
#else
|
||||
# define LOCAL_ALIGNED_16(t, v, s, ...) LOCAL_ALIGNED(16, t, v, s, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/* PSNR */
|
||||
void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
|
||||
int orig_linesize[3], int coded_linesize,
|
||||
AVCodecContext *avctx);
|
||||
|
||||
#define WRAPPER8_16(name8, name16)\
|
||||
static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
|
||||
return name8(s, dst , src , stride, h)\
|
||||
+name8(s, dst+8 , src+8 , stride, h);\
|
||||
}
|
||||
|
||||
#define WRAPPER8_16_SQ(name8, name16)\
|
||||
static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\
|
||||
int score=0;\
|
||||
score +=name8(s, dst , src , stride, 8);\
|
||||
score +=name8(s, dst+8 , src+8 , stride, 8);\
|
||||
if(h==16){\
|
||||
dst += 8*stride;\
|
||||
src += 8*stride;\
|
||||
score +=name8(s, dst , src , stride, 8);\
|
||||
score +=name8(s, dst+8 , src+8 , stride, 8);\
|
||||
}\
|
||||
return score;\
|
||||
}
|
||||
|
||||
|
||||
static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_WN16(dst , AV_RN16(src ));
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_WN32(dst , AV_RN32(src ));
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_WN32(dst , AV_RN32(src ));
|
||||
AV_WN32(dst+4 , AV_RN32(src+4 ));
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_WN32(dst , AV_RN32(src ));
|
||||
AV_WN32(dst+4 , AV_RN32(src+4 ));
|
||||
dst[8]= src[8];
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_WN32(dst , AV_RN32(src ));
|
||||
AV_WN32(dst+4 , AV_RN32(src+4 ));
|
||||
AV_WN32(dst+8 , AV_RN32(src+8 ));
|
||||
AV_WN32(dst+12, AV_RN32(src+12));
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_WN32(dst , AV_RN32(src ));
|
||||
AV_WN32(dst+4 , AV_RN32(src+4 ));
|
||||
AV_WN32(dst+8 , AV_RN32(src+8 ));
|
||||
AV_WN32(dst+12, AV_RN32(src+12));
|
||||
dst[16]= src[16];
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_DSPUTIL_H */
|
385
apps/codecs/libwmapro/fft.c
Normal file
385
apps/codecs/libwmapro/fft.c
Normal file
|
@ -0,0 +1,385 @@
|
|||
/*
|
||||
* FFT/IFFT transforms
|
||||
* Copyright (c) 2008 Loren Merritt
|
||||
* Copyright (c) 2002 Fabrice Bellard
|
||||
* Partly based on libdjbfft by D. J. Bernstein
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavcodec/fft.c
|
||||
* FFT/IFFT transforms.
|
||||
*/
|
||||
|
||||
#include "dsputil.h"
|
||||
#include "fft.h"
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846 /* pi */
|
||||
#endif
|
||||
#ifndef M_SQRT1_2
|
||||
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||
#endif
|
||||
|
||||
/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_16[8]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_32[16]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_64[32]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_128[64]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_256[128]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_512[256]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_1024[512]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_2048[1024]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_4096[2048]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_8192[4096]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]);
|
||||
DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]);
|
||||
|
||||
FFTSample *ff_cos_tabs[] = {
|
||||
ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024,
|
||||
ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536,
|
||||
};
|
||||
|
||||
static int split_radix_permutation(int i, int n, int inverse)
|
||||
{
|
||||
int m;
|
||||
if(n <= 2) return i&1;
|
||||
m = n >> 1;
|
||||
if(!(i&m)) return split_radix_permutation(i, m, inverse)*2;
|
||||
m >>= 1;
|
||||
if(inverse == !(i&m)) return split_radix_permutation(i, m, inverse)*4 + 1;
|
||||
else return split_radix_permutation(i, m, inverse)*4 - 1;
|
||||
}
|
||||
|
||||
av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
|
||||
{
|
||||
int i, j, m, n;
|
||||
float alpha, c1, s1, s2;
|
||||
int split_radix = 1;
|
||||
int av_unused has_vectors;
|
||||
|
||||
if (nbits < 2 || nbits > 16)
|
||||
goto fail;
|
||||
s->nbits = nbits;
|
||||
n = 1 << nbits;
|
||||
|
||||
s->tmp_buf = NULL;
|
||||
s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
|
||||
if (!s->exptab)
|
||||
goto fail;
|
||||
s->revtab = av_malloc(n * sizeof(uint16_t));
|
||||
if (!s->revtab)
|
||||
goto fail;
|
||||
s->inverse = inverse;
|
||||
|
||||
s2 = inverse ? 1.0 : -1.0;
|
||||
|
||||
s->fft_permute = ff_fft_permute_c;
|
||||
s->fft_calc = ff_fft_calc_c;
|
||||
s->imdct_calc = ff_imdct_calc_c;
|
||||
s->imdct_half = ff_imdct_half_c;
|
||||
s->exptab1 = NULL;
|
||||
|
||||
#if HAVE_MMX && HAVE_YASM
|
||||
has_vectors = mm_support();
|
||||
if (has_vectors & FF_MM_SSE && HAVE_SSE) {
|
||||
/* SSE for P3/P4/K8 */
|
||||
s->imdct_calc = ff_imdct_calc_sse;
|
||||
s->imdct_half = ff_imdct_half_sse;
|
||||
s->fft_permute = ff_fft_permute_sse;
|
||||
s->fft_calc = ff_fft_calc_sse;
|
||||
} else if (has_vectors & FF_MM_3DNOWEXT && HAVE_AMD3DNOWEXT) {
|
||||
/* 3DNowEx for K7 */
|
||||
s->imdct_calc = ff_imdct_calc_3dn2;
|
||||
s->imdct_half = ff_imdct_half_3dn2;
|
||||
s->fft_calc = ff_fft_calc_3dn2;
|
||||
} else if (has_vectors & FF_MM_3DNOW && HAVE_AMD3DNOW) {
|
||||
/* 3DNow! for K6-2/3 */
|
||||
s->imdct_calc = ff_imdct_calc_3dn;
|
||||
s->imdct_half = ff_imdct_half_3dn;
|
||||
s->fft_calc = ff_fft_calc_3dn;
|
||||
}
|
||||
#elif HAVE_ALTIVEC
|
||||
has_vectors = mm_support();
|
||||
if (has_vectors & FF_MM_ALTIVEC) {
|
||||
s->fft_calc = ff_fft_calc_altivec;
|
||||
split_radix = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (split_radix) {
|
||||
for(j=4; j<=nbits; j++) {
|
||||
int m = 1<<j;
|
||||
double freq = 2*M_PI/m;
|
||||
FFTSample *tab = ff_cos_tabs[j-4];
|
||||
for(i=0; i<=m/4; i++)
|
||||
tab[i] = cos(i*freq);
|
||||
for(i=1; i<m/4; i++)
|
||||
tab[m/2-i] = tab[i];
|
||||
}
|
||||
for(i=0; i<n; i++)
|
||||
s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i;
|
||||
s->tmp_buf = av_malloc(n * sizeof(FFTComplex));
|
||||
} else {
|
||||
int np, nblocks, np2, l;
|
||||
FFTComplex *q;
|
||||
|
||||
for(i=0; i<(n/2); i++) {
|
||||
alpha = 2 * M_PI * (float)i / (float)n;
|
||||
c1 = cos(alpha);
|
||||
s1 = sin(alpha) * s2;
|
||||
s->exptab[i].re = c1;
|
||||
s->exptab[i].im = s1;
|
||||
}
|
||||
|
||||
np = 1 << nbits;
|
||||
nblocks = np >> 3;
|
||||
np2 = np >> 1;
|
||||
s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
|
||||
if (!s->exptab1)
|
||||
goto fail;
|
||||
q = s->exptab1;
|
||||
do {
|
||||
for(l = 0; l < np2; l += 2 * nblocks) {
|
||||
*q++ = s->exptab[l];
|
||||
*q++ = s->exptab[l + nblocks];
|
||||
|
||||
q->re = -s->exptab[l].im;
|
||||
q->im = s->exptab[l].re;
|
||||
q++;
|
||||
q->re = -s->exptab[l + nblocks].im;
|
||||
q->im = s->exptab[l + nblocks].re;
|
||||
q++;
|
||||
}
|
||||
nblocks = nblocks >> 1;
|
||||
} while (nblocks != 0);
|
||||
av_freep(&s->exptab);
|
||||
|
||||
/* compute bit reverse table */
|
||||
for(i=0;i<n;i++) {
|
||||
m=0;
|
||||
for(j=0;j<nbits;j++) {
|
||||
m |= ((i >> j) & 1) << (nbits-j-1);
|
||||
}
|
||||
s->revtab[i]=m;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
av_freep(&s->revtab);
|
||||
av_freep(&s->exptab);
|
||||
av_freep(&s->exptab1);
|
||||
av_freep(&s->tmp_buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ff_fft_permute_c(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
int j, k, np;
|
||||
FFTComplex tmp;
|
||||
const uint16_t *revtab = s->revtab;
|
||||
np = 1 << s->nbits;
|
||||
|
||||
if (s->tmp_buf) {
|
||||
/* TODO: handle split-radix permute in a more optimal way, probably in-place */
|
||||
for(j=0;j<np;j++) s->tmp_buf[revtab[j]] = z[j];
|
||||
memcpy(z, s->tmp_buf, np * sizeof(FFTComplex));
|
||||
return;
|
||||
}
|
||||
|
||||
/* reverse */
|
||||
for(j=0;j<np;j++) {
|
||||
k = revtab[j];
|
||||
if (k < j) {
|
||||
tmp = z[k];
|
||||
z[k] = z[j];
|
||||
z[j] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
av_cold void ff_fft_end(FFTContext *s)
|
||||
{
|
||||
av_freep(&s->revtab);
|
||||
av_freep(&s->exptab);
|
||||
av_freep(&s->exptab1);
|
||||
av_freep(&s->tmp_buf);
|
||||
}
|
||||
|
||||
#define sqrthalf (float)M_SQRT1_2
|
||||
|
||||
#define BF(x,y,a,b) {\
|
||||
x = a - b;\
|
||||
y = a + b;\
|
||||
}
|
||||
|
||||
#define BUTTERFLIES(a0,a1,a2,a3) {\
|
||||
BF(t3, t5, t5, t1);\
|
||||
BF(a2.re, a0.re, a0.re, t5);\
|
||||
BF(a3.im, a1.im, a1.im, t3);\
|
||||
BF(t4, t6, t2, t6);\
|
||||
BF(a3.re, a1.re, a1.re, t4);\
|
||||
BF(a2.im, a0.im, a0.im, t6);\
|
||||
}
|
||||
|
||||
// force loading all the inputs before storing any.
|
||||
// this is slightly slower for small data, but avoids store->load aliasing
|
||||
// for addresses separated by large powers of 2.
|
||||
#define BUTTERFLIES_BIG(a0,a1,a2,a3) {\
|
||||
FFTSample r0=a0.re, i0=a0.im, r1=a1.re, i1=a1.im;\
|
||||
BF(t3, t5, t5, t1);\
|
||||
BF(a2.re, a0.re, r0, t5);\
|
||||
BF(a3.im, a1.im, i1, t3);\
|
||||
BF(t4, t6, t2, t6);\
|
||||
BF(a3.re, a1.re, r1, t4);\
|
||||
BF(a2.im, a0.im, i0, t6);\
|
||||
}
|
||||
|
||||
#define TRANSFORM(a0,a1,a2,a3,wre,wim) {\
|
||||
t1 = a2.re * wre + a2.im * wim;\
|
||||
t2 = a2.im * wre - a2.re * wim;\
|
||||
t5 = a3.re * wre - a3.im * wim;\
|
||||
t6 = a3.im * wre + a3.re * wim;\
|
||||
BUTTERFLIES(a0,a1,a2,a3)\
|
||||
}
|
||||
|
||||
#define TRANSFORM_ZERO(a0,a1,a2,a3) {\
|
||||
t1 = a2.re;\
|
||||
t2 = a2.im;\
|
||||
t5 = a3.re;\
|
||||
t6 = a3.im;\
|
||||
BUTTERFLIES(a0,a1,a2,a3)\
|
||||
}
|
||||
|
||||
/* z[0...8n-1], w[1...2n-1] */
|
||||
#define PASS(name)\
|
||||
static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\
|
||||
{\
|
||||
FFTSample t1, t2, t3, t4, t5, t6;\
|
||||
int o1 = 2*n;\
|
||||
int o2 = 4*n;\
|
||||
int o3 = 6*n;\
|
||||
const FFTSample *wim = wre+o1;\
|
||||
n--;\
|
||||
\
|
||||
TRANSFORM_ZERO(z[0],z[o1],z[o2],z[o3]);\
|
||||
TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
|
||||
do {\
|
||||
z += 2;\
|
||||
wre += 2;\
|
||||
wim -= 2;\
|
||||
TRANSFORM(z[0],z[o1],z[o2],z[o3],wre[0],wim[0]);\
|
||||
TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
|
||||
} while(--n);\
|
||||
}
|
||||
|
||||
PASS(pass)
|
||||
#undef BUTTERFLIES
|
||||
#define BUTTERFLIES BUTTERFLIES_BIG
|
||||
PASS(pass_big)
|
||||
|
||||
#define DECL_FFT(n,n2,n4)\
|
||||
static void fft##n(FFTComplex *z)\
|
||||
{\
|
||||
fft##n2(z);\
|
||||
fft##n4(z+n4*2);\
|
||||
fft##n4(z+n4*3);\
|
||||
pass(z,ff_cos_##n,n4/2);\
|
||||
}
|
||||
|
||||
static void fft4(FFTComplex *z)
|
||||
{
|
||||
FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
|
||||
|
||||
BF(t3, t1, z[0].re, z[1].re);
|
||||
BF(t8, t6, z[3].re, z[2].re);
|
||||
BF(z[2].re, z[0].re, t1, t6);
|
||||
BF(t4, t2, z[0].im, z[1].im);
|
||||
BF(t7, t5, z[2].im, z[3].im);
|
||||
BF(z[3].im, z[1].im, t4, t8);
|
||||
BF(z[3].re, z[1].re, t3, t7);
|
||||
BF(z[2].im, z[0].im, t2, t5);
|
||||
}
|
||||
|
||||
static void fft8(FFTComplex *z)
|
||||
{
|
||||
FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
|
||||
|
||||
fft4(z);
|
||||
|
||||
BF(t1, z[5].re, z[4].re, -z[5].re);
|
||||
BF(t2, z[5].im, z[4].im, -z[5].im);
|
||||
BF(t3, z[7].re, z[6].re, -z[7].re);
|
||||
BF(t4, z[7].im, z[6].im, -z[7].im);
|
||||
BF(t8, t1, t3, t1);
|
||||
BF(t7, t2, t2, t4);
|
||||
BF(z[4].re, z[0].re, z[0].re, t1);
|
||||
BF(z[4].im, z[0].im, z[0].im, t2);
|
||||
BF(z[6].re, z[2].re, z[2].re, t7);
|
||||
BF(z[6].im, z[2].im, z[2].im, t8);
|
||||
|
||||
TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf);
|
||||
}
|
||||
|
||||
#if !CONFIG_SMALL
|
||||
static void fft16(FFTComplex *z)
|
||||
{
|
||||
FFTSample t1, t2, t3, t4, t5, t6;
|
||||
|
||||
fft8(z);
|
||||
fft4(z+8);
|
||||
fft4(z+12);
|
||||
|
||||
TRANSFORM_ZERO(z[0],z[4],z[8],z[12]);
|
||||
TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf);
|
||||
TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]);
|
||||
TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]);
|
||||
}
|
||||
#else
|
||||
DECL_FFT(16,8,4)
|
||||
#endif
|
||||
DECL_FFT(32,16,8)
|
||||
DECL_FFT(64,32,16)
|
||||
DECL_FFT(128,64,32)
|
||||
DECL_FFT(256,128,64)
|
||||
DECL_FFT(512,256,128)
|
||||
#if !CONFIG_SMALL
|
||||
#define pass pass_big
|
||||
#endif
|
||||
DECL_FFT(1024,512,256)
|
||||
DECL_FFT(2048,1024,512)
|
||||
DECL_FFT(4096,2048,1024)
|
||||
DECL_FFT(8192,4096,2048)
|
||||
DECL_FFT(16384,8192,4096)
|
||||
DECL_FFT(32768,16384,8192)
|
||||
DECL_FFT(65536,32768,16384)
|
||||
|
||||
static void (*fft_dispatch[])(FFTComplex*) = {
|
||||
fft4, fft8, fft16, fft32, fft64, fft128, fft256, fft512, fft1024,
|
||||
fft2048, fft4096, fft8192, fft16384, fft32768, fft65536,
|
||||
};
|
||||
|
||||
void ff_fft_calc_c(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
fft_dispatch[s->nbits-2](z);
|
||||
}
|
||||
|
244
apps/codecs/libwmapro/fft.h
Normal file
244
apps/codecs/libwmapro/fft.h
Normal file
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_FFT_H
|
||||
#define AVCODEC_FFT_H
|
||||
|
||||
#include <stdint.h>
|
||||
//#include "config.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "avfft.h"
|
||||
|
||||
/* DECLARE_ALIGNED - Taken from libavutil/internal.h */
|
||||
#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
|
||||
#define DECLARE_ALIGNED_16(t,v) DECLARE_ALIGNED(16,t,v)
|
||||
|
||||
/* FFT computation */
|
||||
|
||||
struct FFTContext {
|
||||
int nbits;
|
||||
int inverse;
|
||||
uint16_t *revtab;
|
||||
FFTComplex *exptab;
|
||||
FFTComplex *exptab1; /* only used by SSE code */
|
||||
FFTComplex *tmp_buf;
|
||||
int mdct_size; /* size of MDCT (i.e. number of input data * 2) */
|
||||
int mdct_bits; /* n = 2^nbits */
|
||||
/* pre/post rotation tables */
|
||||
FFTSample *tcos;
|
||||
FFTSample *tsin;
|
||||
void (*fft_permute)(struct FFTContext *s, FFTComplex *z);
|
||||
void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
|
||||
void (*imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void (*imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void (*mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
int split_radix;
|
||||
int permutation;
|
||||
#define FF_MDCT_PERM_NONE 0
|
||||
#define FF_MDCT_PERM_INTERLEAVE 1
|
||||
};
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#define COSTABLE_CONST const
|
||||
#define SINTABLE_CONST const
|
||||
#define SINETABLE_CONST const
|
||||
#else
|
||||
#define COSTABLE_CONST
|
||||
#define SINTABLE_CONST
|
||||
#define SINETABLE_CONST
|
||||
#endif
|
||||
|
||||
#define COSTABLE(size) \
|
||||
COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2]
|
||||
#define SINTABLE(size) \
|
||||
SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2]
|
||||
#define SINETABLE(size) \
|
||||
SINETABLE_CONST DECLARE_ALIGNED(16, float, ff_sine_##size)[size]
|
||||
extern COSTABLE(16);
|
||||
extern COSTABLE(32);
|
||||
extern COSTABLE(64);
|
||||
extern COSTABLE(128);
|
||||
extern COSTABLE(256);
|
||||
extern COSTABLE(512);
|
||||
extern COSTABLE(1024);
|
||||
extern COSTABLE(2048);
|
||||
extern COSTABLE(4096);
|
||||
extern COSTABLE(8192);
|
||||
extern COSTABLE(16384);
|
||||
extern COSTABLE(32768);
|
||||
extern COSTABLE(65536);
|
||||
//extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17];
|
||||
|
||||
/**
|
||||
* Initializes the cosine table in ff_cos_tabs[index]
|
||||
* \param index index in ff_cos_tabs array of the table to initialize
|
||||
*/
|
||||
void ff_init_ff_cos_tabs(int index);
|
||||
|
||||
extern SINTABLE(16);
|
||||
extern SINTABLE(32);
|
||||
extern SINTABLE(64);
|
||||
extern SINTABLE(128);
|
||||
extern SINTABLE(256);
|
||||
extern SINTABLE(512);
|
||||
extern SINTABLE(1024);
|
||||
extern SINTABLE(2048);
|
||||
extern SINTABLE(4096);
|
||||
extern SINTABLE(8192);
|
||||
extern SINTABLE(16384);
|
||||
extern SINTABLE(32768);
|
||||
extern SINTABLE(65536);
|
||||
|
||||
/**
|
||||
* Sets up a complex FFT.
|
||||
* @param nbits log2 of the length of the input array
|
||||
* @param inverse if 0 perform the forward transform, if 1 perform the inverse
|
||||
*/
|
||||
int ff_fft_init(FFTContext *s, int nbits, int inverse);
|
||||
void ff_fft_permute_c(FFTContext *s, FFTComplex *z);
|
||||
void ff_fft_calc_c(FFTContext *s, FFTComplex *z);
|
||||
|
||||
void ff_fft_init_altivec(FFTContext *s);
|
||||
void ff_fft_init_mmx(FFTContext *s);
|
||||
void ff_fft_init_arm(FFTContext *s);
|
||||
|
||||
/**
|
||||
* Do the permutation needed BEFORE calling ff_fft_calc().
|
||||
*/
|
||||
static inline void ff_fft_permute(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
s->fft_permute(s, z);
|
||||
}
|
||||
/**
|
||||
* Do a complex FFT with the parameters defined in ff_fft_init(). The
|
||||
* input data must be permuted before. No 1.0/sqrt(n) normalization is done.
|
||||
*/
|
||||
static inline void ff_fft_calc(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
s->fft_calc(s, z);
|
||||
}
|
||||
void ff_fft_end(FFTContext *s);
|
||||
|
||||
/* MDCT computation */
|
||||
|
||||
static inline void ff_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
s->imdct_calc(s, output, input);
|
||||
}
|
||||
static inline void ff_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
s->imdct_half(s, output, input);
|
||||
}
|
||||
|
||||
static inline void ff_mdct_calc(FFTContext *s, FFTSample *output,
|
||||
const FFTSample *input)
|
||||
{
|
||||
s->mdct_calc(s, output, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a Kaiser-Bessel Derived Window.
|
||||
* @param window pointer to half window
|
||||
* @param alpha determines window shape
|
||||
* @param n size of half window
|
||||
*/
|
||||
void ff_kbd_window_init(float *window, float alpha, int n);
|
||||
|
||||
/**
|
||||
* Generate a sine window.
|
||||
* @param window pointer to half window
|
||||
* @param n size of half window
|
||||
*/
|
||||
void ff_sine_window_init(float *window, int n);
|
||||
|
||||
/**
|
||||
* initialize the specified entry of ff_sine_windows
|
||||
*/
|
||||
void ff_init_ff_sine_windows(int index);
|
||||
extern SINETABLE( 32);
|
||||
extern SINETABLE( 64);
|
||||
extern SINETABLE( 128);
|
||||
extern SINETABLE( 256);
|
||||
extern SINETABLE( 512);
|
||||
extern SINETABLE(1024);
|
||||
extern SINETABLE(2048);
|
||||
extern SINETABLE(4096);
|
||||
extern SINETABLE_CONST float * const ff_sine_windows[13];
|
||||
|
||||
int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale);
|
||||
void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
|
||||
void ff_mdct_end(FFTContext *s);
|
||||
|
||||
/* Real Discrete Fourier Transform */
|
||||
|
||||
struct RDFTContext {
|
||||
int nbits;
|
||||
int inverse;
|
||||
int sign_convention;
|
||||
|
||||
/* pre/post rotation tables */
|
||||
const FFTSample *tcos;
|
||||
SINTABLE_CONST FFTSample *tsin;
|
||||
FFTContext fft;
|
||||
void (*rdft_calc)(struct RDFTContext *s, FFTSample *z);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets up a real FFT.
|
||||
* @param nbits log2 of the length of the input array
|
||||
* @param trans the type of transform
|
||||
*/
|
||||
int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
|
||||
void ff_rdft_end(RDFTContext *s);
|
||||
|
||||
void ff_rdft_init_arm(RDFTContext *s);
|
||||
|
||||
static av_always_inline void ff_rdft_calc(RDFTContext *s, FFTSample *data)
|
||||
{
|
||||
s->rdft_calc(s, data);
|
||||
}
|
||||
|
||||
/* Discrete Cosine Transform */
|
||||
|
||||
struct DCTContext {
|
||||
int nbits;
|
||||
int inverse;
|
||||
RDFTContext rdft;
|
||||
const float *costab;
|
||||
FFTSample *csc2;
|
||||
void (*dct_calc)(struct DCTContext *s, FFTSample *data);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets up DCT.
|
||||
* @param nbits size of the input array:
|
||||
* (1 << nbits) for DCT-II, DCT-III and DST-I
|
||||
* (1 << nbits) + 1 for DCT-I
|
||||
*
|
||||
* @note the first element of the input of DST-I is ignored
|
||||
*/
|
||||
int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type);
|
||||
void ff_dct_calc(DCTContext *s, FFTSample *data);
|
||||
void ff_dct_end (DCTContext *s);
|
||||
|
||||
#endif /* AVCODEC_FFT_H */
|
692
apps/codecs/libwmapro/get_bits.h
Normal file
692
apps/codecs/libwmapro/get_bits.h
Normal file
|
@ -0,0 +1,692 @@
|
|||
/*
|
||||
* copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavcodec/get_bits.h
|
||||
* bitstream reader API header.
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_GET_BITS_H
|
||||
#define AVCODEC_GET_BITS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "libavutil/bswap.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "libavutil/log.h"
|
||||
#include "mathops.h"
|
||||
|
||||
#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
|
||||
# define ALT_BITSTREAM_READER
|
||||
#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 */
|
||||
/* buffer, buffer_end and size_in_bits must be present and used by every reader */
|
||||
typedef struct GetBitContext {
|
||||
const uint8_t *buffer, *buffer_end;
|
||||
#ifdef ALT_BITSTREAM_READER
|
||||
int index;
|
||||
#elif defined LIBMPEG2_BITSTREAM_READER
|
||||
uint8_t *buffer_ptr;
|
||||
uint32_t cache;
|
||||
int bit_count;
|
||||
#elif defined A32_BITSTREAM_READER
|
||||
uint32_t *buffer_ptr;
|
||||
uint32_t cache0;
|
||||
uint32_t cache1;
|
||||
int bit_count;
|
||||
#endif
|
||||
int size_in_bits;
|
||||
} GetBitContext;
|
||||
|
||||
#define VLC_TYPE int16_t
|
||||
|
||||
typedef struct VLC {
|
||||
int bits;
|
||||
VLC_TYPE (*table)[2]; ///< code, bits
|
||||
int table_size, table_allocated;
|
||||
} VLC;
|
||||
|
||||
typedef struct RL_VLC_ELEM {
|
||||
int16_t level;
|
||||
int8_t len;
|
||||
uint8_t run;
|
||||
} RL_VLC_ELEM;
|
||||
|
||||
/* Bitstream reader API docs:
|
||||
name
|
||||
arbitrary name which is used as prefix for the internal variables
|
||||
|
||||
gb
|
||||
getbitcontext
|
||||
|
||||
OPEN_READER(name, gb)
|
||||
loads gb into local variables
|
||||
|
||||
CLOSE_READER(name, gb)
|
||||
stores local vars in gb
|
||||
|
||||
UPDATE_CACHE(name, gb)
|
||||
refills the internal cache from the bitstream
|
||||
after this call at least MIN_CACHE_BITS will be available,
|
||||
|
||||
GET_CACHE(name, gb)
|
||||
will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
|
||||
|
||||
SHOW_UBITS(name, gb, num)
|
||||
will return the next num bits
|
||||
|
||||
SHOW_SBITS(name, gb, num)
|
||||
will return the next num bits and do sign extension
|
||||
|
||||
SKIP_BITS(name, gb, num)
|
||||
will skip over the next num bits
|
||||
note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
|
||||
|
||||
SKIP_CACHE(name, gb, num)
|
||||
will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
|
||||
|
||||
SKIP_COUNTER(name, gb, num)
|
||||
will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
|
||||
|
||||
LAST_SKIP_CACHE(name, gb, num)
|
||||
will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
|
||||
|
||||
LAST_SKIP_BITS(name, gb, num)
|
||||
is equivalent to LAST_SKIP_CACHE; SKIP_COUNTER
|
||||
|
||||
for examples see get_bits, show_bits, skip_bits, get_vlc
|
||||
*/
|
||||
|
||||
#ifdef ALT_BITSTREAM_READER
|
||||
# define MIN_CACHE_BITS 25
|
||||
|
||||
# define OPEN_READER(name, gb)\
|
||||
unsigned int name##_index= (gb)->index;\
|
||||
int name##_cache= 0;\
|
||||
|
||||
# define CLOSE_READER(name, gb)\
|
||||
(gb)->index= name##_index;\
|
||||
|
||||
# ifdef ALT_BITSTREAM_READER_LE
|
||||
# define UPDATE_CACHE(name, gb)\
|
||||
name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
|
||||
|
||||
# define SKIP_CACHE(name, gb, num)\
|
||||
name##_cache >>= (num);
|
||||
# else
|
||||
# define UPDATE_CACHE(name, gb)\
|
||||
name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
|
||||
|
||||
# define SKIP_CACHE(name, gb, num)\
|
||||
name##_cache <<= (num);
|
||||
# endif
|
||||
|
||||
// FIXME name?
|
||||
# define SKIP_COUNTER(name, gb, num)\
|
||||
name##_index += (num);\
|
||||
|
||||
# define SKIP_BITS(name, gb, num)\
|
||||
{\
|
||||
SKIP_CACHE(name, gb, num)\
|
||||
SKIP_COUNTER(name, gb, num)\
|
||||
}\
|
||||
|
||||
# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
|
||||
# define LAST_SKIP_CACHE(name, gb, num) ;
|
||||
|
||||
# ifdef ALT_BITSTREAM_READER_LE
|
||||
# define SHOW_UBITS(name, gb, num)\
|
||||
zero_extend(name##_cache, num)
|
||||
|
||||
# define SHOW_SBITS(name, gb, num)\
|
||||
sign_extend(name##_cache, num)
|
||||
# else
|
||||
# define SHOW_UBITS(name, gb, num)\
|
||||
NEG_USR32(name##_cache, num)
|
||||
|
||||
# define SHOW_SBITS(name, gb, num)\
|
||||
NEG_SSR32(name##_cache, num)
|
||||
# endif
|
||||
|
||||
# define GET_CACHE(name, gb)\
|
||||
((uint32_t)name##_cache)
|
||||
|
||||
static inline int get_bits_count(const GetBitContext *s){
|
||||
return s->index;
|
||||
}
|
||||
|
||||
static inline void skip_bits_long(GetBitContext *s, int n){
|
||||
s->index += n;
|
||||
}
|
||||
|
||||
#elif defined LIBMPEG2_BITSTREAM_READER
|
||||
//libmpeg2 like reader
|
||||
|
||||
# define MIN_CACHE_BITS 17
|
||||
|
||||
# define OPEN_READER(name, gb)\
|
||||
int name##_bit_count=(gb)->bit_count;\
|
||||
int name##_cache= (gb)->cache;\
|
||||
uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
|
||||
|
||||
# define CLOSE_READER(name, gb)\
|
||||
(gb)->bit_count= name##_bit_count;\
|
||||
(gb)->cache= name##_cache;\
|
||||
(gb)->buffer_ptr= name##_buffer_ptr;\
|
||||
|
||||
# define UPDATE_CACHE(name, gb)\
|
||||
if(name##_bit_count >= 0){\
|
||||
name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \
|
||||
name##_buffer_ptr+=2;\
|
||||
name##_bit_count-= 16;\
|
||||
}\
|
||||
|
||||
# define SKIP_CACHE(name, gb, num)\
|
||||
name##_cache <<= (num);\
|
||||
|
||||
# define SKIP_COUNTER(name, gb, num)\
|
||||
name##_bit_count += (num);\
|
||||
|
||||
# define SKIP_BITS(name, gb, num)\
|
||||
{\
|
||||
SKIP_CACHE(name, gb, num)\
|
||||
SKIP_COUNTER(name, gb, num)\
|
||||
}\
|
||||
|
||||
# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
|
||||
# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
|
||||
|
||||
# define SHOW_UBITS(name, gb, num)\
|
||||
NEG_USR32(name##_cache, num)
|
||||
|
||||
# define SHOW_SBITS(name, gb, num)\
|
||||
NEG_SSR32(name##_cache, num)
|
||||
|
||||
# define GET_CACHE(name, gb)\
|
||||
((uint32_t)name##_cache)
|
||||
|
||||
static inline int get_bits_count(const GetBitContext *s){
|
||||
return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
|
||||
}
|
||||
|
||||
static inline void skip_bits_long(GetBitContext *s, int n){
|
||||
OPEN_READER(re, s)
|
||||
re_bit_count += n;
|
||||
re_buffer_ptr += 2*(re_bit_count>>4);
|
||||
re_bit_count &= 15;
|
||||
re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
|
||||
UPDATE_CACHE(re, s)
|
||||
CLOSE_READER(re, s)
|
||||
}
|
||||
|
||||
#elif defined A32_BITSTREAM_READER
|
||||
|
||||
# define MIN_CACHE_BITS 32
|
||||
|
||||
# define OPEN_READER(name, gb)\
|
||||
int name##_bit_count=(gb)->bit_count;\
|
||||
uint32_t name##_cache0= (gb)->cache0;\
|
||||
uint32_t name##_cache1= (gb)->cache1;\
|
||||
uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
|
||||
|
||||
# define CLOSE_READER(name, gb)\
|
||||
(gb)->bit_count= name##_bit_count;\
|
||||
(gb)->cache0= name##_cache0;\
|
||||
(gb)->cache1= name##_cache1;\
|
||||
(gb)->buffer_ptr= name##_buffer_ptr;\
|
||||
|
||||
# define UPDATE_CACHE(name, gb)\
|
||||
if(name##_bit_count > 0){\
|
||||
const uint32_t next= be2me_32( *name##_buffer_ptr );\
|
||||
name##_cache0 |= NEG_USR32(next,name##_bit_count);\
|
||||
name##_cache1 |= next<<name##_bit_count;\
|
||||
name##_buffer_ptr++;\
|
||||
name##_bit_count-= 32;\
|
||||
}\
|
||||
|
||||
#if ARCH_X86
|
||||
# define SKIP_CACHE(name, gb, num)\
|
||||
__asm__(\
|
||||
"shldl %2, %1, %0 \n\t"\
|
||||
"shll %2, %1 \n\t"\
|
||||
: "+r" (name##_cache0), "+r" (name##_cache1)\
|
||||
: "Ic" ((uint8_t)(num))\
|
||||
);
|
||||
#else
|
||||
# define SKIP_CACHE(name, gb, num)\
|
||||
name##_cache0 <<= (num);\
|
||||
name##_cache0 |= NEG_USR32(name##_cache1,num);\
|
||||
name##_cache1 <<= (num);
|
||||
#endif
|
||||
|
||||
# define SKIP_COUNTER(name, gb, num)\
|
||||
name##_bit_count += (num);\
|
||||
|
||||
# define SKIP_BITS(name, gb, num)\
|
||||
{\
|
||||
SKIP_CACHE(name, gb, num)\
|
||||
SKIP_COUNTER(name, gb, num)\
|
||||
}\
|
||||
|
||||
# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
|
||||
# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
|
||||
|
||||
# define SHOW_UBITS(name, gb, num)\
|
||||
NEG_USR32(name##_cache0, num)
|
||||
|
||||
# define SHOW_SBITS(name, gb, num)\
|
||||
NEG_SSR32(name##_cache0, num)
|
||||
|
||||
# define GET_CACHE(name, gb)\
|
||||
(name##_cache0)
|
||||
|
||||
static inline int get_bits_count(const GetBitContext *s){
|
||||
return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
|
||||
}
|
||||
|
||||
static inline void skip_bits_long(GetBitContext *s, int n){
|
||||
OPEN_READER(re, s)
|
||||
re_bit_count += n;
|
||||
re_buffer_ptr += re_bit_count>>5;
|
||||
re_bit_count &= 31;
|
||||
re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
|
||||
re_cache1 = 0;
|
||||
UPDATE_CACHE(re, s)
|
||||
CLOSE_READER(re, s)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
|
||||
* if MSB not set it is negative
|
||||
* @param n length in bits
|
||||
* @author BERO
|
||||
*/
|
||||
static inline int get_xbits(GetBitContext *s, int n){
|
||||
register int sign;
|
||||
register int32_t cache;
|
||||
OPEN_READER(re, s)
|
||||
UPDATE_CACHE(re, s)
|
||||
cache = GET_CACHE(re,s);
|
||||
sign=(~cache)>>31;
|
||||
LAST_SKIP_BITS(re, s, n)
|
||||
CLOSE_READER(re, s)
|
||||
return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
|
||||
}
|
||||
|
||||
static inline int get_sbits(GetBitContext *s, int n){
|
||||
register int tmp;
|
||||
OPEN_READER(re, s)
|
||||
UPDATE_CACHE(re, s)
|
||||
tmp= SHOW_SBITS(re, s, n);
|
||||
LAST_SKIP_BITS(re, s, n)
|
||||
CLOSE_READER(re, s)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads 1-17 bits.
|
||||
* Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
|
||||
*/
|
||||
static inline unsigned int get_bits(GetBitContext *s, int n){
|
||||
register int tmp;
|
||||
OPEN_READER(re, s)
|
||||
UPDATE_CACHE(re, s)
|
||||
tmp= SHOW_UBITS(re, s, n);
|
||||
LAST_SKIP_BITS(re, s, n)
|
||||
CLOSE_READER(re, s)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* shows 1-17 bits.
|
||||
* Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
|
||||
*/
|
||||
static inline unsigned int show_bits(GetBitContext *s, int n){
|
||||
register int tmp;
|
||||
OPEN_READER(re, s)
|
||||
UPDATE_CACHE(re, s)
|
||||
tmp= SHOW_UBITS(re, s, n);
|
||||
// CLOSE_READER(re, s)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static inline void skip_bits(GetBitContext *s, int n){
|
||||
//Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
|
||||
OPEN_READER(re, s)
|
||||
UPDATE_CACHE(re, s)
|
||||
LAST_SKIP_BITS(re, s, n)
|
||||
CLOSE_READER(re, s)
|
||||
}
|
||||
|
||||
static inline unsigned int get_bits1(GetBitContext *s){
|
||||
#ifdef ALT_BITSTREAM_READER
|
||||
unsigned int index= s->index;
|
||||
uint8_t result= s->buffer[ index>>3 ];
|
||||
#ifdef ALT_BITSTREAM_READER_LE
|
||||
result>>= (index&0x07);
|
||||
result&= 1;
|
||||
#else
|
||||
result<<= (index&0x07);
|
||||
result>>= 8 - 1;
|
||||
#endif
|
||||
index++;
|
||||
s->index= index;
|
||||
|
||||
return result;
|
||||
#else
|
||||
return get_bits(s, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline unsigned int show_bits1(GetBitContext *s){
|
||||
return show_bits(s, 1);
|
||||
}
|
||||
|
||||
static inline void skip_bits1(GetBitContext *s){
|
||||
skip_bits(s, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* reads 0-32 bits.
|
||||
*/
|
||||
static inline unsigned int get_bits_long(GetBitContext *s, int n){
|
||||
if(n<=MIN_CACHE_BITS) return get_bits(s, n);
|
||||
else{
|
||||
#ifdef ALT_BITSTREAM_READER_LE
|
||||
int ret= get_bits(s, 16);
|
||||
return ret | (get_bits(s, n-16) << 16);
|
||||
#else
|
||||
int ret= get_bits(s, 16) << (n-16);
|
||||
return ret | get_bits(s, n-16);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
/* mt : switched those off */
|
||||
/**
|
||||
* reads 0-32 bits as a signed integer.
|
||||
*/
|
||||
static inline int get_sbits_long(GetBitContext *s, int n) {
|
||||
return sign_extend(get_bits_long(s, n), n);
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* shows 0-32 bits.
|
||||
*/
|
||||
static inline unsigned int show_bits_long(GetBitContext *s, int n){
|
||||
if(n<=MIN_CACHE_BITS) return show_bits(s, n);
|
||||
else{
|
||||
GetBitContext gb= *s;
|
||||
return get_bits_long(&gb, n);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int check_marker(GetBitContext *s, const char *msg)
|
||||
{
|
||||
int bit= get_bits1(s);
|
||||
if(!bit)
|
||||
av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* init GetBitContext.
|
||||
* @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
|
||||
* because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
|
||||
* @param bit_size the size of the buffer in bits
|
||||
*
|
||||
* While GetBitContext stores the buffer size, for performance reasons you are
|
||||
* responsible for checking for the buffer end yourself (take advantage of the padding)!
|
||||
*/
|
||||
static inline void init_get_bits(GetBitContext *s,
|
||||
const uint8_t *buffer, int bit_size)
|
||||
{
|
||||
int buffer_size= (bit_size+7)>>3;
|
||||
if(buffer_size < 0 || bit_size < 0) {
|
||||
buffer_size = bit_size = 0;
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
s->buffer= buffer;
|
||||
s->size_in_bits= bit_size;
|
||||
s->buffer_end= buffer + buffer_size;
|
||||
#ifdef ALT_BITSTREAM_READER
|
||||
s->index=0;
|
||||
#elif defined LIBMPEG2_BITSTREAM_READER
|
||||
s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
|
||||
s->bit_count = 16 + 8*((intptr_t)buffer&1);
|
||||
skip_bits_long(s, 0);
|
||||
#elif defined A32_BITSTREAM_READER
|
||||
s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
|
||||
s->bit_count = 32 + 8*((intptr_t)buffer&3);
|
||||
skip_bits_long(s, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void align_get_bits(GetBitContext *s)
|
||||
{
|
||||
int n= (-get_bits_count(s)) & 7;
|
||||
if(n) skip_bits(s, n);
|
||||
}
|
||||
|
||||
#define init_vlc(vlc, nb_bits, nb_codes,\
|
||||
bits, bits_wrap, bits_size,\
|
||||
codes, codes_wrap, codes_size,\
|
||||
flags)\
|
||||
init_vlc_sparse(vlc, nb_bits, nb_codes,\
|
||||
bits, bits_wrap, bits_size,\
|
||||
codes, codes_wrap, codes_size,\
|
||||
NULL, 0, 0, flags)
|
||||
|
||||
int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
|
||||
const void *bits, int bits_wrap, int bits_size,
|
||||
const void *codes, int codes_wrap, int codes_size,
|
||||
const void *symbols, int symbols_wrap, int symbols_size,
|
||||
int flags);
|
||||
#define INIT_VLC_LE 2
|
||||
#define INIT_VLC_USE_NEW_STATIC 4
|
||||
void free_vlc(VLC *vlc);
|
||||
|
||||
#define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\
|
||||
{\
|
||||
static VLC_TYPE table[static_size][2];\
|
||||
(vlc)->table= table;\
|
||||
(vlc)->table_allocated= static_size;\
|
||||
init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* If the vlc code is invalid and max_depth=1, then no bits will be removed.
|
||||
* If the vlc code is invalid and max_depth>1, then the number of bits removed
|
||||
* is undefined.
|
||||
*/
|
||||
#define GET_VLC(code, name, gb, table, bits, max_depth)\
|
||||
{\
|
||||
int n, nb_bits;\
|
||||
unsigned int index;\
|
||||
\
|
||||
index= SHOW_UBITS(name, gb, bits);\
|
||||
code = table[index][0];\
|
||||
n = table[index][1];\
|
||||
\
|
||||
if(max_depth > 1 && n < 0){\
|
||||
LAST_SKIP_BITS(name, gb, bits)\
|
||||
UPDATE_CACHE(name, gb)\
|
||||
\
|
||||
nb_bits = -n;\
|
||||
\
|
||||
index= SHOW_UBITS(name, gb, nb_bits) + code;\
|
||||
code = table[index][0];\
|
||||
n = table[index][1];\
|
||||
if(max_depth > 2 && n < 0){\
|
||||
LAST_SKIP_BITS(name, gb, nb_bits)\
|
||||
UPDATE_CACHE(name, gb)\
|
||||
\
|
||||
nb_bits = -n;\
|
||||
\
|
||||
index= SHOW_UBITS(name, gb, nb_bits) + code;\
|
||||
code = table[index][0];\
|
||||
n = table[index][1];\
|
||||
}\
|
||||
}\
|
||||
SKIP_BITS(name, gb, n)\
|
||||
}
|
||||
|
||||
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
|
||||
{\
|
||||
int n, nb_bits;\
|
||||
unsigned int index;\
|
||||
\
|
||||
index= SHOW_UBITS(name, gb, bits);\
|
||||
level = table[index].level;\
|
||||
n = table[index].len;\
|
||||
\
|
||||
if(max_depth > 1 && n < 0){\
|
||||
SKIP_BITS(name, gb, bits)\
|
||||
if(need_update){\
|
||||
UPDATE_CACHE(name, gb)\
|
||||
}\
|
||||
\
|
||||
nb_bits = -n;\
|
||||
\
|
||||
index= SHOW_UBITS(name, gb, nb_bits) + level;\
|
||||
level = table[index].level;\
|
||||
n = table[index].len;\
|
||||
}\
|
||||
run= table[index].run;\
|
||||
SKIP_BITS(name, gb, n)\
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parses a vlc code, faster then get_vlc()
|
||||
* @param bits is the number of bits which will be read at once, must be
|
||||
* identical to nb_bits in init_vlc()
|
||||
* @param max_depth is the number of times bits bits must be read to completely
|
||||
* read the longest vlc code
|
||||
* = (max_vlc_length + bits - 1) / bits
|
||||
*/
|
||||
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
|
||||
int bits, int max_depth)
|
||||
{
|
||||
int code;
|
||||
|
||||
OPEN_READER(re, s)
|
||||
UPDATE_CACHE(re, s)
|
||||
|
||||
GET_VLC(code, re, s, table, bits, max_depth)
|
||||
|
||||
CLOSE_READER(re, s)
|
||||
return code;
|
||||
}
|
||||
|
||||
//#define TRACE
|
||||
|
||||
#ifdef TRACE
|
||||
static inline void print_bin(int bits, int n){
|
||||
int i;
|
||||
|
||||
for(i=n-1; i>=0; i--){
|
||||
av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
|
||||
}
|
||||
for(i=n; i<24; i++)
|
||||
av_log(NULL, AV_LOG_DEBUG, " ");
|
||||
}
|
||||
|
||||
static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
|
||||
int r= get_bits(s, n);
|
||||
|
||||
print_bin(r, n);
|
||||
av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
|
||||
return r;
|
||||
}
|
||||
static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
|
||||
int show= show_bits(s, 24);
|
||||
int pos= get_bits_count(s);
|
||||
int r= get_vlc2(s, table, bits, max_depth);
|
||||
int len= get_bits_count(s) - pos;
|
||||
int bits2= show>>(24-len);
|
||||
|
||||
print_bin(bits2, len);
|
||||
|
||||
av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
|
||||
return r;
|
||||
}
|
||||
static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
|
||||
int show= show_bits(s, n);
|
||||
int r= get_xbits(s, n);
|
||||
|
||||
print_bin(show, n);
|
||||
av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
|
||||
return r;
|
||||
}
|
||||
|
||||
#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
||||
#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
||||
#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
||||
#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
||||
#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
||||
|
||||
#define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__)
|
||||
|
||||
#else //TRACE
|
||||
#define tprintf(p, ...) {}
|
||||
#endif
|
||||
|
||||
static inline int decode012(GetBitContext *gb){
|
||||
int n;
|
||||
n = get_bits1(gb);
|
||||
if (n == 0)
|
||||
return 0;
|
||||
else
|
||||
return get_bits1(gb) + 1;
|
||||
}
|
||||
|
||||
static inline int decode210(GetBitContext *gb){
|
||||
if (get_bits1(gb))
|
||||
return 0;
|
||||
else
|
||||
return 2 - get_bits1(gb);
|
||||
}
|
||||
|
||||
static inline int get_bits_left(GetBitContext *gb)
|
||||
{
|
||||
return gb->size_in_bits - get_bits_count(gb);
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_GET_BITS_H */
|
51
apps/codecs/libwmapro/internal.h
Normal file
51
apps/codecs/libwmapro/internal.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavcodec/internal.h
|
||||
* common internal api header.
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_INTERNAL_H
|
||||
#define AVCODEC_INTERNAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "avcodec.h"
|
||||
|
||||
/**
|
||||
* Determines whether pix_fmt is a hardware accelerated format.
|
||||
*/
|
||||
//int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt);
|
||||
|
||||
/**
|
||||
* Returns the hardware accelerated codec for codec codec_id and
|
||||
* pixel format pix_fmt.
|
||||
*
|
||||
* @param codec_id the codec to match
|
||||
* @param pix_fmt the pixel format to match
|
||||
* @return the hardware accelerated codec, or NULL if none was found.
|
||||
*/
|
||||
//AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt);
|
||||
|
||||
/**
|
||||
* Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
|
||||
* If there is no such matching pair then size is returned.
|
||||
*/
|
||||
int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
|
||||
|
||||
#endif /* AVCODEC_INTERNAL_H */
|
113
apps/codecs/libwmapro/libavutil/attributes.h
Normal file
113
apps/codecs/libwmapro/libavutil/attributes.h
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/attributes.h
|
||||
* Macro definitions for various function/variable attributes
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_ATTRIBUTES_H
|
||||
#define AVUTIL_ATTRIBUTES_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
|
||||
#else
|
||||
# define AV_GCC_VERSION_AT_LEAST(x,y) 0
|
||||
#endif
|
||||
|
||||
#ifndef av_always_inline
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_always_inline __attribute__((always_inline)) inline
|
||||
#else
|
||||
# define av_always_inline inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_noinline
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_noinline __attribute__((noinline))
|
||||
#else
|
||||
# define av_noinline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_pure
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_pure __attribute__((pure))
|
||||
#else
|
||||
# define av_pure
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_const
|
||||
#if AV_GCC_VERSION_AT_LEAST(2,6)
|
||||
# define av_const __attribute__((const))
|
||||
#else
|
||||
# define av_const
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_cold
|
||||
#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3)
|
||||
# define av_cold __attribute__((cold))
|
||||
#else
|
||||
# define av_cold
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_flatten
|
||||
#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,1)
|
||||
# define av_flatten __attribute__((flatten))
|
||||
#else
|
||||
# define av_flatten
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef attribute_deprecated
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define attribute_deprecated __attribute__((deprecated))
|
||||
#else
|
||||
# define attribute_deprecated
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_unused
|
||||
#if defined(__GNUC__)
|
||||
# define av_unused __attribute__((unused))
|
||||
#else
|
||||
# define av_unused
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_uninit
|
||||
#if defined(__GNUC__) && !defined(__ICC)
|
||||
# define av_uninit(x) x=x
|
||||
#else
|
||||
# define av_uninit(x) x
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define av_builtin_constant_p __builtin_constant_p
|
||||
#else
|
||||
# define av_builtin_constant_p(x) 0
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_ATTRIBUTES_H */
|
63
apps/codecs/libwmapro/libavutil/avutil.h
Normal file
63
apps/codecs/libwmapro/libavutil/avutil.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_AVUTIL_H
|
||||
#define AVUTIL_AVUTIL_H
|
||||
|
||||
/**
|
||||
* @file libavutil/avutil.h
|
||||
* external API header
|
||||
*/
|
||||
|
||||
|
||||
#define AV_STRINGIFY(s) AV_TOSTRING(s)
|
||||
#define AV_TOSTRING(s) #s
|
||||
|
||||
#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
|
||||
#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c
|
||||
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
|
||||
|
||||
#define LIBAVUTIL_VERSION_MAJOR 50
|
||||
#define LIBAVUTIL_VERSION_MINOR 0
|
||||
#define LIBAVUTIL_VERSION_MICRO 0
|
||||
|
||||
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
|
||||
LIBAVUTIL_VERSION_MINOR, \
|
||||
LIBAVUTIL_VERSION_MICRO)
|
||||
#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \
|
||||
LIBAVUTIL_VERSION_MINOR, \
|
||||
LIBAVUTIL_VERSION_MICRO)
|
||||
#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
|
||||
|
||||
#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
|
||||
|
||||
/**
|
||||
* Returns the LIBAVUTIL_VERSION_INT constant.
|
||||
*/
|
||||
unsigned avutil_version(void);
|
||||
|
||||
#include "common.h"
|
||||
//#include "mathematics.h"
|
||||
//#include "rational.h"
|
||||
//#include "intfloat_readwrite.h"
|
||||
#include "log.h"
|
||||
//#include "pixfmt.h"
|
||||
|
||||
#endif /* AVUTIL_AVUTIL_H */
|
99
apps/codecs/libwmapro/libavutil/bswap.h
Normal file
99
apps/codecs/libwmapro/libavutil/bswap.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/bswap.h
|
||||
* byte swapping routines
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_BSWAP_H
|
||||
#define AVUTIL_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
//#include "ffmpeg_config.h"
|
||||
#include "common.h"
|
||||
|
||||
#if ARCH_ARM
|
||||
# include "arm/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)
|
||||
{
|
||||
x= (x>>8) | (x<<8);
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef bswap_32
|
||||
static av_always_inline av_const uint32_t bswap_32(uint32_t x)
|
||||
{
|
||||
x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
|
||||
x= (x>>16) | (x<<16);
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef bswap_64
|
||||
static inline uint64_t av_const bswap_64(uint64_t x)
|
||||
{
|
||||
#if 0
|
||||
x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
|
||||
x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
|
||||
return (x>>32) | (x<<32);
|
||||
#else
|
||||
union {
|
||||
uint64_t ll;
|
||||
uint32_t l[2];
|
||||
} w, r;
|
||||
w.ll = x;
|
||||
r.l[0] = bswap_32 (w.l[1]);
|
||||
r.l[1] = bswap_32 (w.l[0]);
|
||||
return r.ll;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// be2me ... big-endian to machine-endian
|
||||
// le2me ... little-endian to machine-endian
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define be2me_16(x) (x)
|
||||
#define be2me_32(x) (x)
|
||||
#define be2me_64(x) (x)
|
||||
#define le2me_16(x) bswap_16(x)
|
||||
#define le2me_32(x) bswap_32(x)
|
||||
#define le2me_64(x) bswap_64(x)
|
||||
#else
|
||||
#define be2me_16(x) bswap_16(x)
|
||||
#define be2me_32(x) bswap_32(x)
|
||||
#define be2me_64(x) bswap_64(x)
|
||||
#define le2me_16(x) (x)
|
||||
#define le2me_32(x) (x)
|
||||
#define le2me_64(x) (x)
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_BSWAP_H */
|
299
apps/codecs/libwmapro/libavutil/common.h
Normal file
299
apps/codecs/libwmapro/libavutil/common.h
Normal file
|
@ -0,0 +1,299 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/common.h
|
||||
* common internal and external API header
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_COMMON_H
|
||||
#define AVUTIL_COMMON_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "attributes.h"
|
||||
#include "internal.h"
|
||||
|
||||
//rounded division & shift
|
||||
#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
|
||||
/* assume b>0 */
|
||||
#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
|
||||
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
|
||||
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
|
||||
|
||||
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
|
||||
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
|
||||
|
||||
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
|
||||
#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
|
||||
|
||||
/* misc math functions */
|
||||
extern const uint8_t ff_log2_tab[256];
|
||||
|
||||
extern const uint8_t av_reverse[256];
|
||||
|
||||
static inline av_const int av_log2_c(unsigned int v)
|
||||
{
|
||||
int n = 0;
|
||||
if (v & 0xffff0000) {
|
||||
v >>= 16;
|
||||
n += 16;
|
||||
}
|
||||
if (v & 0xff00) {
|
||||
v >>= 8;
|
||||
n += 8;
|
||||
}
|
||||
n += ff_log2_tab[v];
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline av_const int av_log2_16bit_c(unsigned int v)
|
||||
{
|
||||
int n = 0;
|
||||
if (v & 0xff00) {
|
||||
v >>= 8;
|
||||
n += 8;
|
||||
}
|
||||
n += ff_log2_tab[v];
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
# include "config.h"
|
||||
# include "intmath.h"
|
||||
#endif
|
||||
|
||||
#ifndef av_log2
|
||||
# define av_log2 av_log2_c
|
||||
#endif
|
||||
#ifndef av_log2_16bit
|
||||
# define av_log2_16bit av_log2_16bit_c
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Clips a signed integer value into the amin-amax range.
|
||||
* @param a value to clip
|
||||
* @param amin minimum value of the clip range
|
||||
* @param amax maximum value of the clip range
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const int av_clip(int a, int amin, int amax)
|
||||
{
|
||||
if (a < amin) return amin;
|
||||
else if (a > amax) return amax;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clips a signed integer value into the 0-255 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const uint8_t av_clip_uint8(int a)
|
||||
{
|
||||
if (a&(~255)) return (-a)>>31;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clips a signed integer value into the 0-65535 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const uint16_t av_clip_uint16(int a)
|
||||
{
|
||||
if (a&(~65535)) return (-a)>>31;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clips a signed integer value into the -32768,32767 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const int16_t av_clip_int16(int a)
|
||||
{
|
||||
if ((a+32768) & ~65535) return (a>>31) ^ 32767;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clips a float value into the amin-amax range.
|
||||
* @param a value to clip
|
||||
* @param amin minimum value of the clip range
|
||||
* @param amax maximum value of the clip range
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const float av_clipf(float a, float amin, float amax)
|
||||
{
|
||||
if (a < amin) return amin;
|
||||
else if (a > amax) return amax;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/** Computes ceil(log2(x)).
|
||||
* @param x value used to compute ceil(log2(x))
|
||||
* @return computed ceiling of log2(x)
|
||||
*/
|
||||
static inline av_const int av_ceil_log2(int x)
|
||||
{
|
||||
return av_log2((x - 1) << 1);
|
||||
}
|
||||
|
||||
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
|
||||
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
|
||||
|
||||
/*!
|
||||
* \def GET_UTF8(val, GET_BYTE, ERROR)
|
||||
* Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
|
||||
* \param val is the output and should be of type uint32_t. It holds the converted
|
||||
* UCS-4 character and should be a left value.
|
||||
* \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
|
||||
* a function or a statement whose return value or evaluated value is of type
|
||||
* uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
|
||||
* and up to 7 times in the general case.
|
||||
* \param ERROR action that should be taken when an invalid UTF-8 byte is returned
|
||||
* from GET_BYTE. It should be a statement that jumps out of the macro,
|
||||
* like exit(), goto, return, break, or continue.
|
||||
*/
|
||||
#define GET_UTF8(val, GET_BYTE, ERROR)\
|
||||
val= GET_BYTE;\
|
||||
{\
|
||||
int ones= 7 - av_log2(val ^ 255);\
|
||||
if(ones==1)\
|
||||
ERROR\
|
||||
val&= 127>>ones;\
|
||||
while(--ones > 0){\
|
||||
int tmp= GET_BYTE - 128;\
|
||||
if(tmp>>6)\
|
||||
ERROR\
|
||||
val= (val<<6) + tmp;\
|
||||
}\
|
||||
}
|
||||
|
||||
/*!
|
||||
* \def GET_UTF16(val, GET_16BIT, ERROR)
|
||||
* Converts a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form
|
||||
* \param val is the output and should be of type uint32_t. It holds the converted
|
||||
* UCS-4 character and should be a left value.
|
||||
* \param GET_16BIT gets two bytes of UTF-16 encoded data converted to native endianness.
|
||||
* It can be a function or a statement whose return value or evaluated value is of type
|
||||
* uint16_t. It will be executed up to 2 times.
|
||||
* \param ERROR action that should be taken when an invalid UTF-16 surrogate is
|
||||
* returned from GET_BYTE. It should be a statement that jumps out of the macro,
|
||||
* like exit(), goto, return, break, or continue.
|
||||
*/
|
||||
#define GET_UTF16(val, GET_16BIT, ERROR)\
|
||||
val = GET_16BIT;\
|
||||
{\
|
||||
unsigned int hi = val - 0xD800;\
|
||||
if (hi < 0x800) {\
|
||||
val = GET_16BIT - 0xDC00;\
|
||||
if (val > 0x3FFU || hi > 0x3FFU)\
|
||||
ERROR\
|
||||
val += (hi<<10) + 0x10000;\
|
||||
}\
|
||||
}\
|
||||
|
||||
/*!
|
||||
* \def PUT_UTF8(val, tmp, PUT_BYTE)
|
||||
* Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
|
||||
* \param val is an input-only argument and should be of type uint32_t. It holds
|
||||
* a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
|
||||
* val is given as a function it is executed only once.
|
||||
* \param tmp is a temporary variable and should be of type uint8_t. It
|
||||
* represents an intermediate value during conversion that is to be
|
||||
* output by PUT_BYTE.
|
||||
* \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
|
||||
* It could be a function or a statement, and uses tmp as the input byte.
|
||||
* For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
|
||||
* executed up to 4 times for values in the valid UTF-8 range and up to
|
||||
* 7 times in the general case, depending on the length of the converted
|
||||
* Unicode character.
|
||||
*/
|
||||
#define PUT_UTF8(val, tmp, PUT_BYTE)\
|
||||
{\
|
||||
int bytes, shift;\
|
||||
uint32_t in = val;\
|
||||
if (in < 0x80) {\
|
||||
tmp = in;\
|
||||
PUT_BYTE\
|
||||
} else {\
|
||||
bytes = (av_log2(in) + 4) / 5;\
|
||||
shift = (bytes - 1) * 6;\
|
||||
tmp = (256 - (256 >> bytes)) | (in >> shift);\
|
||||
PUT_BYTE\
|
||||
while (shift >= 6) {\
|
||||
shift -= 6;\
|
||||
tmp = 0x80 | ((in >> shift) & 0x3f);\
|
||||
PUT_BYTE\
|
||||
}\
|
||||
}\
|
||||
}
|
||||
|
||||
/*!
|
||||
* \def PUT_UTF16(val, tmp, PUT_16BIT)
|
||||
* Converts a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
|
||||
* \param val is an input-only argument and should be of type uint32_t. It holds
|
||||
* a UCS-4 encoded Unicode character that is to be converted to UTF-16. If
|
||||
* val is given as a function it is executed only once.
|
||||
* \param tmp is a temporary variable and should be of type uint16_t. It
|
||||
* represents an intermediate value during conversion that is to be
|
||||
* output by PUT_16BIT.
|
||||
* \param PUT_16BIT writes the converted UTF-16 data to any proper destination
|
||||
* in desired endianness. It could be a function or a statement, and uses tmp
|
||||
* as the input byte. For example, PUT_BYTE could be "*output++ = tmp;"
|
||||
* PUT_BYTE will be executed 1 or 2 times depending on input character.
|
||||
*/
|
||||
#define PUT_UTF16(val, tmp, PUT_16BIT)\
|
||||
{\
|
||||
uint32_t in = val;\
|
||||
if (in < 0x10000) {\
|
||||
tmp = in;\
|
||||
PUT_16BIT\
|
||||
} else {\
|
||||
tmp = 0xD800 | ((in - 0x10000) >> 10);\
|
||||
PUT_16BIT\
|
||||
tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\
|
||||
PUT_16BIT\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
|
||||
#include "mem.h"
|
||||
|
||||
#if 0
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
# include "internal.h"
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
#endif
|
||||
#endif /* AVUTIL_COMMON_H */
|
207
apps/codecs/libwmapro/libavutil/internal.h
Normal file
207
apps/codecs/libwmapro/libavutil/internal.h
Normal file
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/internal.h
|
||||
* common internal API header
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_INTERNAL_H
|
||||
#define AVUTIL_INTERNAL_H
|
||||
|
||||
#if !defined(DEBUG) && !defined(NDEBUG)
|
||||
# define NDEBUG
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
//#include "config.h"
|
||||
#include "attributes.h"
|
||||
//#include "timer.h"
|
||||
|
||||
#ifndef attribute_align_arg
|
||||
#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,2)
|
||||
# define attribute_align_arg __attribute__((force_align_arg_pointer))
|
||||
#else
|
||||
# define attribute_align_arg
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef attribute_used
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define attribute_used __attribute__((used))
|
||||
#else
|
||||
# define attribute_used
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_alias
|
||||
#if HAVE_ATTRIBUTE_MAY_ALIAS && (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(3,3)
|
||||
# define av_alias __attribute__((may_alias))
|
||||
#else
|
||||
# define av_alias
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MIN
|
||||
#define INT16_MIN (-0x7fff - 1)
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
#define INT16_MAX 0x7fff
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MIN
|
||||
#define INT32_MIN (-0x7fffffff - 1)
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX 0x7fffffff
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifndef INT64_MIN
|
||||
#define INT64_MIN (-0x7fffffffffffffffLL - 1)
|
||||
#endif
|
||||
|
||||
#ifndef INT64_MAX
|
||||
#define INT64_MAX INT64_C(9223372036854775807)
|
||||
#endif
|
||||
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
|
||||
#ifndef INT_BIT
|
||||
# define INT_BIT (CHAR_BIT * sizeof(int))
|
||||
#endif
|
||||
|
||||
#ifndef offsetof
|
||||
# define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
|
||||
#endif
|
||||
|
||||
/* Use to export labels from asm. */
|
||||
#define LABEL_MANGLE(a) EXTERN_PREFIX #a
|
||||
|
||||
// Use rip-relative addressing if compiling PIC code on x86-64.
|
||||
#if ARCH_X86_64 && defined(PIC)
|
||||
# define LOCAL_MANGLE(a) #a "(%%rip)"
|
||||
#else
|
||||
# define LOCAL_MANGLE(a) #a
|
||||
#endif
|
||||
|
||||
#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
|
||||
|
||||
/* debug stuff */
|
||||
|
||||
/* dprintf macros */
|
||||
#ifdef DEBUG
|
||||
# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
|
||||
#else
|
||||
# define dprintf(pctx, ...)
|
||||
#endif
|
||||
|
||||
#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
|
||||
|
||||
/* math */
|
||||
|
||||
#if ARCH_X86
|
||||
#define MASK_ABS(mask, level)\
|
||||
__asm__ volatile(\
|
||||
"cltd \n\t"\
|
||||
"xorl %1, %0 \n\t"\
|
||||
"subl %1, %0 \n\t"\
|
||||
: "+a" (level), "=&d" (mask)\
|
||||
);
|
||||
#else
|
||||
#define MASK_ABS(mask, level)\
|
||||
mask = level >> 31;\
|
||||
level = (level ^ mask) - mask;
|
||||
#endif
|
||||
|
||||
/* avoid usage of dangerous/inappropriate system functions */
|
||||
#undef malloc
|
||||
#define malloc please_use_av_malloc
|
||||
#undef free
|
||||
#define free please_use_av_free
|
||||
#undef realloc
|
||||
#define realloc please_use_av_realloc
|
||||
#undef time
|
||||
#define time time_is_forbidden_due_to_security_issues
|
||||
#undef rand
|
||||
#define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
|
||||
#undef srand
|
||||
#define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
|
||||
#undef random
|
||||
#define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
|
||||
#undef sprintf
|
||||
#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
|
||||
#undef strcat
|
||||
#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
|
||||
#undef exit
|
||||
#define exit exit_is_forbidden
|
||||
#ifndef LIBAVFORMAT_BUILD
|
||||
#undef printf
|
||||
#define printf please_use_av_log_instead_of_printf
|
||||
#undef fprintf
|
||||
#define fprintf please_use_av_log_instead_of_fprintf
|
||||
#undef puts
|
||||
#define puts please_use_av_log_instead_of_puts
|
||||
#undef perror
|
||||
#define perror please_use_av_log_instead_of_perror
|
||||
#endif
|
||||
|
||||
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
|
||||
{\
|
||||
p = av_malloc(size);\
|
||||
if (p == NULL && (size) != 0) {\
|
||||
av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
|
||||
goto label;\
|
||||
}\
|
||||
}
|
||||
|
||||
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
|
||||
{\
|
||||
p = av_mallocz(size);\
|
||||
if (p == NULL && (size) != 0) {\
|
||||
av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
|
||||
goto label;\
|
||||
}\
|
||||
}
|
||||
|
||||
//#include "libm.h"
|
||||
|
||||
/**
|
||||
* Returns NULL if CONFIG_SMALL is true, otherwise the argument
|
||||
* 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
|
||||
|
||||
#endif /* AVUTIL_INTERNAL_H */
|
192
apps/codecs/libwmapro/libavutil/intreadwrite.h
Normal file
192
apps/codecs/libwmapro/libavutil/intreadwrite.h
Normal file
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_INTREADWRITE_H
|
||||
#define AVUTIL_INTREADWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
//#include "ffmpeg_config.h"
|
||||
#include "bswap.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
struct unaligned_64 { uint64_t l; } __attribute__((packed));
|
||||
struct unaligned_32 { uint32_t l; } __attribute__((packed));
|
||||
struct unaligned_16 { uint16_t l; } __attribute__((packed));
|
||||
|
||||
#define AV_RN16(a) (((const struct unaligned_16 *) (a))->l)
|
||||
#define AV_RN32(a) (((const struct unaligned_32 *) (a))->l)
|
||||
#define AV_RN64(a) (((const struct unaligned_64 *) (a))->l)
|
||||
|
||||
#define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
|
||||
#define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
|
||||
#define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b)
|
||||
|
||||
#elif defined(__DECC)
|
||||
|
||||
#define AV_RN16(a) (*((const __unaligned uint16_t*)(a)))
|
||||
#define AV_RN32(a) (*((const __unaligned uint32_t*)(a)))
|
||||
#define AV_RN64(a) (*((const __unaligned uint64_t*)(a)))
|
||||
|
||||
#define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b)
|
||||
#define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b)
|
||||
#define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b)
|
||||
|
||||
#else
|
||||
|
||||
#define AV_RN16(a) (*((const uint16_t*)(a)))
|
||||
#define AV_RN32(a) (*((const uint32_t*)(a)))
|
||||
#define AV_RN64(a) (*((const uint64_t*)(a)))
|
||||
|
||||
#define AV_WN16(a, b) *((uint16_t*)(a)) = (b)
|
||||
#define AV_WN32(a, b) *((uint32_t*)(a)) = (b)
|
||||
#define AV_WN64(a, b) *((uint64_t*)(a)) = (b)
|
||||
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
/* endian macros */
|
||||
#define AV_RB8(x) (((const uint8_t*)(x))[0])
|
||||
#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
|
||||
|
||||
#define AV_RL8(x) AV_RB8(x)
|
||||
#define AV_WL8(p, d) AV_WB8(p, d)
|
||||
|
||||
#if HAVE_FAST_UNALIGNED
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
# define AV_RB16(x) AV_RN16(x)
|
||||
# define AV_WB16(p, d) AV_WN16(p, d)
|
||||
|
||||
# define AV_RL16(x) bswap_16(AV_RN16(x))
|
||||
# define AV_WL16(p, d) AV_WN16(p, bswap_16(d))
|
||||
|
||||
# define AV_RB32(x) AV_RN32(x)
|
||||
# define AV_WB32(p, d) AV_WN32(p, d)
|
||||
|
||||
# define AV_RL32(x) bswap_32(AV_RN32(x))
|
||||
# define AV_WL32(p, d) AV_WN32(p, bswap_32(d))
|
||||
|
||||
# define AV_RB64(x) AV_RN64(x)
|
||||
# define AV_WB64(p, d) AV_WN64(p, d)
|
||||
|
||||
# define AV_RL64(x) bswap_64(AV_RN64(x))
|
||||
# define AV_WL64(p, d) AV_WN64(p, bswap_64(d))
|
||||
# else /* WORDS_BIGENDIAN */
|
||||
# define AV_RB16(x) bswap_16(AV_RN16(x))
|
||||
# define AV_WB16(p, d) AV_WN16(p, bswap_16(d))
|
||||
|
||||
# define AV_RL16(x) AV_RN16(x)
|
||||
# define AV_WL16(p, d) AV_WN16(p, d)
|
||||
|
||||
# define AV_RB32(x) bswap_32(AV_RN32(x))
|
||||
# define AV_WB32(p, d) AV_WN32(p, bswap_32(d))
|
||||
|
||||
# define AV_RL32(x) AV_RN32(x)
|
||||
# define AV_WL32(p, d) AV_WN32(p, d)
|
||||
|
||||
# define AV_RB64(x) bswap_64(AV_RN64(x))
|
||||
# define AV_WB64(p, d) AV_WN64(p, bswap_64(d))
|
||||
|
||||
# define AV_RL64(x) AV_RN64(x)
|
||||
# define AV_WL64(p, d) AV_WN64(p, d)
|
||||
# endif
|
||||
#else /* HAVE_FAST_UNALIGNED */
|
||||
#define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
|
||||
#define AV_WB16(p, d) do { \
|
||||
((uint8_t*)(p))[1] = (d); \
|
||||
((uint8_t*)(p))[0] = (d)>>8; } while(0)
|
||||
|
||||
#define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#define AV_WL16(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; } while(0)
|
||||
|
||||
#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
|
||||
(((const uint8_t*)(x))[1] << 16) | \
|
||||
(((const uint8_t*)(x))[2] << 8) | \
|
||||
((const uint8_t*)(x))[3])
|
||||
#define AV_WB32(p, d) do { \
|
||||
((uint8_t*)(p))[3] = (d); \
|
||||
((uint8_t*)(p))[2] = (d)>>8; \
|
||||
((uint8_t*)(p))[1] = (d)>>16; \
|
||||
((uint8_t*)(p))[0] = (d)>>24; } while(0)
|
||||
|
||||
#define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
|
||||
(((const uint8_t*)(x))[2] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#define AV_WL32(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[2] = (d)>>16; \
|
||||
((uint8_t*)(p))[3] = (d)>>24; } while(0)
|
||||
|
||||
#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
|
||||
((uint64_t)((const uint8_t*)(x))[1] << 48) | \
|
||||
((uint64_t)((const uint8_t*)(x))[2] << 40) | \
|
||||
((uint64_t)((const uint8_t*)(x))[3] << 32) | \
|
||||
((uint64_t)((const uint8_t*)(x))[4] << 24) | \
|
||||
((uint64_t)((const uint8_t*)(x))[5] << 16) | \
|
||||
((uint64_t)((const uint8_t*)(x))[6] << 8) | \
|
||||
(uint64_t)((const uint8_t*)(x))[7])
|
||||
#define AV_WB64(p, d) do { \
|
||||
((uint8_t*)(p))[7] = (d); \
|
||||
((uint8_t*)(p))[6] = (d)>>8; \
|
||||
((uint8_t*)(p))[5] = (d)>>16; \
|
||||
((uint8_t*)(p))[4] = (d)>>24; \
|
||||
((uint8_t*)(p))[3] = (d)>>32; \
|
||||
((uint8_t*)(p))[2] = (d)>>40; \
|
||||
((uint8_t*)(p))[1] = (d)>>48; \
|
||||
((uint8_t*)(p))[0] = (d)>>56; } while(0)
|
||||
|
||||
#define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
|
||||
((uint64_t)((const uint8_t*)(x))[6] << 48) | \
|
||||
((uint64_t)((const uint8_t*)(x))[5] << 40) | \
|
||||
((uint64_t)((const uint8_t*)(x))[4] << 32) | \
|
||||
((uint64_t)((const uint8_t*)(x))[3] << 24) | \
|
||||
((uint64_t)((const uint8_t*)(x))[2] << 16) | \
|
||||
((uint64_t)((const uint8_t*)(x))[1] << 8) | \
|
||||
(uint64_t)((const uint8_t*)(x))[0])
|
||||
#define AV_WL64(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[2] = (d)>>16; \
|
||||
((uint8_t*)(p))[3] = (d)>>24; \
|
||||
((uint8_t*)(p))[4] = (d)>>32; \
|
||||
((uint8_t*)(p))[5] = (d)>>40; \
|
||||
((uint8_t*)(p))[6] = (d)>>48; \
|
||||
((uint8_t*)(p))[7] = (d)>>56; } while(0)
|
||||
#endif /* HAVE_FAST_UNALIGNED */
|
||||
|
||||
#define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[2])
|
||||
#define AV_WB24(p, d) do { \
|
||||
((uint8_t*)(p))[2] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[0] = (d)>>16; } while(0)
|
||||
|
||||
#define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#define AV_WL24(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[2] = (d)>>16; } while(0)
|
||||
|
||||
#endif /* AVUTIL_INTREADWRITE_H */
|
89
apps/codecs/libwmapro/libavutil/log.c
Normal file
89
apps/codecs/libwmapro/libavutil/log.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* log functions
|
||||
* Copyright (c) 2003 Michel Bardiaux
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/log.c
|
||||
* logging functions
|
||||
*/
|
||||
|
||||
#include "avutil.h"
|
||||
#include "log.h"
|
||||
|
||||
int av_log_level = AV_LOG_INFO;
|
||||
|
||||
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||
{
|
||||
static int print_prefix=1;
|
||||
static int count;
|
||||
static char line[1024], prev[1024];
|
||||
AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
|
||||
if(level>av_log_level)
|
||||
return;
|
||||
#undef fprintf
|
||||
if(print_prefix && avc) {
|
||||
snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
|
||||
}else
|
||||
line[0]=0;
|
||||
|
||||
vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
|
||||
|
||||
print_prefix= line[strlen(line)-1] == '\n';
|
||||
if(print_prefix && !strcmp(line, prev)){
|
||||
count++;
|
||||
return;
|
||||
}
|
||||
if(count>0){
|
||||
fprintf(stderr, " Last message repeated %d times\n", count);
|
||||
count=0;
|
||||
}
|
||||
fputs(line, stderr);
|
||||
strcpy(prev, line);
|
||||
}
|
||||
|
||||
static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
|
||||
|
||||
void av_log(void* avcl, int level, const char *fmt, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
av_vlog(avcl, level, fmt, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
|
||||
{
|
||||
av_log_callback(avcl, level, fmt, vl);
|
||||
}
|
||||
|
||||
int av_log_get_level(void)
|
||||
{
|
||||
return av_log_level;
|
||||
}
|
||||
|
||||
void av_log_set_level(int level)
|
||||
{
|
||||
av_log_level = level;
|
||||
}
|
||||
|
||||
void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
|
||||
{
|
||||
av_log_callback = callback;
|
||||
}
|
116
apps/codecs/libwmapro/libavutil/log.h
Normal file
116
apps/codecs/libwmapro/libavutil/log.h
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_LOG_H
|
||||
#define AVUTIL_LOG_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "avutil.h"
|
||||
|
||||
/**
|
||||
* Describes the class of an AVClass context structure. That is an
|
||||
* arbitrary struct of which the first field is a pointer to an
|
||||
* AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
|
||||
*/
|
||||
typedef struct AVCLASS AVClass;
|
||||
struct AVCLASS {
|
||||
/**
|
||||
* The name of the class; usually it is the same name as the
|
||||
* context structure type to which the AVClass is associated.
|
||||
*/
|
||||
const char* class_name;
|
||||
|
||||
/**
|
||||
* A pointer to a function which returns the name of a context
|
||||
* instance \p ctx associated with the class.
|
||||
*/
|
||||
const char* (*item_name)(void* ctx);
|
||||
|
||||
/**
|
||||
* a pointer to the first option specified in the class if any or NULL
|
||||
*
|
||||
* @see av_set_default_options()
|
||||
*/
|
||||
const struct AVOption *option;
|
||||
};
|
||||
|
||||
/* av_log API */
|
||||
|
||||
#define AV_LOG_QUIET -8
|
||||
|
||||
/**
|
||||
* Something went really wrong and we will crash now.
|
||||
*/
|
||||
#define AV_LOG_PANIC 0
|
||||
|
||||
/**
|
||||
* Something went wrong and recovery is not possible.
|
||||
* For example, no header was found for a format which depends
|
||||
* on headers or an illegal combination of parameters is used.
|
||||
*/
|
||||
#define AV_LOG_FATAL 8
|
||||
|
||||
/**
|
||||
* Something went wrong and cannot losslessly be recovered.
|
||||
* However, not all future data is affected.
|
||||
*/
|
||||
#define AV_LOG_ERROR 16
|
||||
|
||||
/**
|
||||
* Something somehow does not look correct. This may or may not
|
||||
* lead to problems. An example would be the use of '-vstrict -2'.
|
||||
*/
|
||||
#define AV_LOG_WARNING 24
|
||||
|
||||
#define AV_LOG_INFO 32
|
||||
#define AV_LOG_VERBOSE 40
|
||||
|
||||
/**
|
||||
* Stuff which is only useful for libav* developers.
|
||||
*/
|
||||
#define AV_LOG_DEBUG 48
|
||||
|
||||
/**
|
||||
* Sends the specified message to the log if the level is less than or equal
|
||||
* to the current av_log_level. By default, all logging messages are sent to
|
||||
* stderr. This behavior can be altered by setting a different av_vlog callback
|
||||
* function.
|
||||
*
|
||||
* @param avcl A pointer to an arbitrary struct of which the first field is a
|
||||
* pointer to an AVClass struct.
|
||||
* @param level The importance level of the message, lower values signifying
|
||||
* higher importance.
|
||||
* @param fmt The format string (printf-compatible) that specifies how
|
||||
* subsequent arguments are converted to output.
|
||||
* @see av_vlog
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
#else
|
||||
void av_log(void*, int level, const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
#endif /* AVUTIL_LOG_H */
|
177
apps/codecs/libwmapro/libavutil/mathematics.c
Normal file
177
apps/codecs/libwmapro/libavutil/mathematics.c
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/mathematics.c
|
||||
* miscellaneous math routines and tables
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include "mathematics.h"
|
||||
|
||||
const uint8_t ff_sqrt_tab[256]={
|
||||
0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90,
|
||||
91, 92, 94, 95, 96, 98, 99,100,102,103,104,105,107,108,109,110,111,112,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,144,145,146,147,148,149,150,151,151,152,153,154,155,156,156,
|
||||
157,158,159,160,160,161,162,163,164,164,165,166,167,168,168,169,170,171,171,172,173,174,174,175,176,176,177,178,179,179,180,181,
|
||||
182,182,183,184,184,185,186,186,187,188,188,189,190,190,191,192,192,193,194,194,195,196,196,197,198,198,199,200,200,201,202,202,
|
||||
203,204,204,205,205,206,207,207,208,208,209,210,210,211,212,212,213,213,214,215,215,216,216,217,218,218,219,219,220,220,221,222,
|
||||
222,223,223,224,224,225,226,226,227,227,228,228,229,230,230,231,231,232,232,233,233,234,235,235,236,236,237,237,238,238,239,239,
|
||||
240,240,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,255,255
|
||||
};
|
||||
|
||||
const uint8_t ff_log2_tab[256]={
|
||||
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
||||
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
|
||||
};
|
||||
|
||||
const uint8_t av_reverse[256]={
|
||||
0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
|
||||
0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
|
||||
0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
|
||||
0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
|
||||
0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
|
||||
0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
|
||||
0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
|
||||
0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
|
||||
0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
|
||||
0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
|
||||
0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
|
||||
0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
|
||||
0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
|
||||
0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
|
||||
0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
|
||||
0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
|
||||
};
|
||||
|
||||
int64_t av_gcd(int64_t a, int64_t b){
|
||||
if(b) return av_gcd(b, a%b);
|
||||
else return a;
|
||||
}
|
||||
|
||||
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
|
||||
int64_t r=0;
|
||||
assert(c > 0);
|
||||
assert(b >=0);
|
||||
assert(rnd >=0 && rnd<=5 && rnd!=4);
|
||||
|
||||
if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1));
|
||||
|
||||
if(rnd==AV_ROUND_NEAR_INF) r= c/2;
|
||||
else if(rnd&1) r= c-1;
|
||||
|
||||
if(b<=INT_MAX && c<=INT_MAX){
|
||||
if(a<=INT_MAX)
|
||||
return (a * b + r)/c;
|
||||
else
|
||||
return a/c*b + (a%c*b + r)/c;
|
||||
}else{
|
||||
#if 1
|
||||
uint64_t a0= a&0xFFFFFFFF;
|
||||
uint64_t a1= a>>32;
|
||||
uint64_t b0= b&0xFFFFFFFF;
|
||||
uint64_t b1= b>>32;
|
||||
uint64_t t1= a0*b1 + a1*b0;
|
||||
uint64_t t1a= t1<<32;
|
||||
int i;
|
||||
|
||||
a0 = a0*b0 + t1a;
|
||||
a1 = a1*b1 + (t1>>32) + (a0<t1a);
|
||||
a0 += r;
|
||||
a1 += a0<r;
|
||||
|
||||
for(i=63; i>=0; i--){
|
||||
// int o= a1 & 0x8000000000000000ULL;
|
||||
a1+= a1 + ((a0>>i)&1);
|
||||
t1+=t1;
|
||||
if(/*o || */c <= a1){
|
||||
a1 -= c;
|
||||
t1++;
|
||||
}
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
#else
|
||||
AVInteger ai;
|
||||
ai= av_mul_i(av_int2i(a), av_int2i(b));
|
||||
ai= av_add_i(ai, av_int2i(r));
|
||||
|
||||
return av_i2int(av_div_i(ai, av_int2i(c)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t av_rescale(int64_t a, int64_t b, int64_t c){
|
||||
return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
|
||||
}
|
||||
|
||||
#if 0
|
||||
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
|
||||
int64_t b= bq.num * (int64_t)cq.den;
|
||||
int64_t c= cq.num * (int64_t)bq.den;
|
||||
return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
|
||||
}
|
||||
|
||||
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
|
||||
int64_t a= tb_a.num * (int64_t)tb_b.den;
|
||||
int64_t b= tb_b.num * (int64_t)tb_a.den;
|
||||
if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
|
||||
if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include "integer.h"
|
||||
#undef printf
|
||||
int main(void){
|
||||
int64_t a,b,c,d,e;
|
||||
|
||||
for(a=7; a<(1LL<<62); a+=a/3+1){
|
||||
for(b=3; b<(1LL<<62); b+=b/4+1){
|
||||
for(c=9; c<(1LL<<62); c+=(c*2)/5+3){
|
||||
int64_t r= c/2;
|
||||
AVInteger ai;
|
||||
ai= av_mul_i(av_int2i(a), av_int2i(b));
|
||||
ai= av_add_i(ai, av_int2i(r));
|
||||
|
||||
d= av_i2int(av_div_i(ai, av_int2i(c)));
|
||||
|
||||
e= av_rescale(a,b,c);
|
||||
|
||||
if((double)a * (double)b / (double)c > (1LL<<63))
|
||||
continue;
|
||||
|
||||
if(d!=e) printf("%"PRId64"*%"PRId64"/%"PRId64"= %"PRId64"=%"PRId64"\n", a, b, c, d, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* 0 */
|
98
apps/codecs/libwmapro/libavutil/mathematics.h
Normal file
98
apps/codecs/libwmapro/libavutil/mathematics.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_MATHEMATICS_H
|
||||
#define AVUTIL_MATHEMATICS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "attributes.h"
|
||||
//#include "rational.h"
|
||||
|
||||
#ifndef M_E
|
||||
#define M_E 2.7182818284590452354 /* e */
|
||||
#endif
|
||||
#ifndef M_LN2
|
||||
#define M_LN2 0.69314718055994530942 /* log_e 2 */
|
||||
#endif
|
||||
#ifndef M_LN10
|
||||
#define M_LN10 2.30258509299404568402 /* log_e 10 */
|
||||
#endif
|
||||
#ifndef M_LOG2_10
|
||||
#define M_LOG2_10 3.32192809488736234787 /* log_2 10 */
|
||||
#endif
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846 /* pi */
|
||||
#endif
|
||||
#ifndef M_SQRT1_2
|
||||
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||
#endif
|
||||
#ifndef NAN
|
||||
#define NAN (0.0/0.0)
|
||||
#endif
|
||||
#ifndef INFINITY
|
||||
#define INFINITY (1.0/0.0)
|
||||
#endif
|
||||
|
||||
enum AVRounding {
|
||||
AV_ROUND_ZERO = 0, ///< Round toward zero.
|
||||
AV_ROUND_INF = 1, ///< Round away from zero.
|
||||
AV_ROUND_DOWN = 2, ///< Round toward -infinity.
|
||||
AV_ROUND_UP = 3, ///< Round toward +infinity.
|
||||
AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the greatest common divisor of a and b.
|
||||
* If both a and b are 0 or either or both are <0 then behavior is
|
||||
* undefined.
|
||||
*/
|
||||
int64_t av_const av_gcd(int64_t a, int64_t b);
|
||||
|
||||
/**
|
||||
* Rescales a 64-bit integer with rounding to nearest.
|
||||
* A simple a*b/c isn't possible as it can overflow.
|
||||
*/
|
||||
int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const;
|
||||
|
||||
/**
|
||||
* Rescales a 64-bit integer with specified rounding.
|
||||
* A simple a*b/c isn't possible as it can overflow.
|
||||
*/
|
||||
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const;
|
||||
|
||||
/**
|
||||
* Rescales a 64-bit integer by 2 rational numbers.
|
||||
*/
|
||||
//int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
|
||||
|
||||
/**
|
||||
* Compares 2 timestamps each in its own timebases.
|
||||
* The result of the function is undefined if one of the timestamps
|
||||
* is outside the int64_t range when represented in the others timebase.
|
||||
* @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position
|
||||
*/
|
||||
//int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
|
||||
|
||||
|
||||
#endif /* AVUTIL_MATHEMATICS_H */
|
159
apps/codecs/libwmapro/libavutil/mem.c
Normal file
159
apps/codecs/libwmapro/libavutil/mem.c
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* default memory allocator for libavutil
|
||||
* Copyright (c) 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/mem.c
|
||||
* default memory allocator for libavutil
|
||||
*/
|
||||
|
||||
//#include "ffmpeg_config.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#include "mem.h"
|
||||
|
||||
/* here we can use OS-dependent allocation functions */
|
||||
#undef free
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
|
||||
/* You can redefine av_malloc and av_free in your project to use your
|
||||
memory allocator. You do not need to suppress this file because the
|
||||
linker will do it automatically. */
|
||||
|
||||
void *av_malloc(unsigned int size)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
long diff;
|
||||
#endif
|
||||
|
||||
/* let's disallow possible ambiguous cases */
|
||||
if(size > (INT_MAX-16) )
|
||||
return NULL;
|
||||
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
ptr = malloc(size+16);
|
||||
if(!ptr)
|
||||
return ptr;
|
||||
diff= ((-(long)ptr - 1)&15) + 1;
|
||||
ptr = (char*)ptr + diff;
|
||||
((char*)ptr)[-1]= diff;
|
||||
#elif HAVE_POSIX_MEMALIGN
|
||||
if (posix_memalign(&ptr,16,size))
|
||||
ptr = NULL;
|
||||
#elif HAVE_MEMALIGN
|
||||
ptr = memalign(16,size);
|
||||
/* Why 64?
|
||||
Indeed, we should align it:
|
||||
on 4 for 386
|
||||
on 16 for 486
|
||||
on 32 for 586, PPro - K6-III
|
||||
on 64 for K7 (maybe for P3 too).
|
||||
Because L1 and L2 caches are aligned on those values.
|
||||
But I don't want to code such logic here!
|
||||
*/
|
||||
/* Why 16?
|
||||
Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
|
||||
it will just trigger an exception and the unaligned load will be done in the
|
||||
exception handler or it will just segfault (SSE2 on P4).
|
||||
Why not larger? Because I did not see a difference in benchmarks ...
|
||||
*/
|
||||
/* benchmarks with P3
|
||||
memalign(64)+1 3071,3051,3032
|
||||
memalign(64)+2 3051,3032,3041
|
||||
memalign(64)+4 2911,2896,2915
|
||||
memalign(64)+8 2545,2554,2550
|
||||
memalign(64)+16 2543,2572,2563
|
||||
memalign(64)+32 2546,2545,2571
|
||||
memalign(64)+64 2570,2533,2558
|
||||
|
||||
BTW, malloc seems to do 8-byte alignment by default here.
|
||||
*/
|
||||
#else
|
||||
ptr = malloc(size);
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *av_realloc(void *ptr, unsigned int size)
|
||||
{
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
int diff;
|
||||
#endif
|
||||
|
||||
/* let's disallow possible ambiguous cases */
|
||||
if(size > (INT_MAX-16) )
|
||||
return NULL;
|
||||
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
//FIXME this isn't aligned correctly, though it probably isn't needed
|
||||
if(!ptr) return av_malloc(size);
|
||||
diff= ((char*)ptr)[-1];
|
||||
return (char*)realloc((char*)ptr - diff, size + diff) + diff;
|
||||
#else
|
||||
return realloc(ptr, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void av_free(void *ptr)
|
||||
{
|
||||
/* XXX: this test should not be needed on most libcs */
|
||||
if (ptr)
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
free((char*)ptr - ((char*)ptr)[-1]);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void av_freep(void *arg)
|
||||
{
|
||||
void **ptr= (void**)arg;
|
||||
av_free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
|
||||
void *av_mallocz(unsigned int size)
|
||||
{
|
||||
void *ptr = av_malloc(size);
|
||||
if (ptr)
|
||||
memset(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *av_strdup(const char *s)
|
||||
{
|
||||
char *ptr= NULL;
|
||||
if(s){
|
||||
int len = strlen(s) + 1;
|
||||
ptr = av_malloc(len);
|
||||
if (ptr)
|
||||
memcpy(ptr, s, len);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
104
apps/codecs/libwmapro/libavutil/mem.h
Normal file
104
apps/codecs/libwmapro/libavutil/mem.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavutil/mem.h
|
||||
* memory handling functions
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_MEM_H
|
||||
#define AVUTIL_MEM_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
#define av_malloc_attrib __attribute__((__malloc__))
|
||||
#else
|
||||
#define av_malloc_attrib
|
||||
#endif
|
||||
|
||||
#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
|
||||
#define av_alloc_size(n) __attribute__((alloc_size(n)))
|
||||
#else
|
||||
#define av_alloc_size(n)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allocates a block of \p size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU).
|
||||
* @param size Size in bytes for the memory block to be allocated.
|
||||
* @return Pointer to the allocated block, NULL if the block cannot
|
||||
* be allocated.
|
||||
* @see av_mallocz()
|
||||
*/
|
||||
void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Allocates or reallocates a block of memory.
|
||||
* If \p ptr is NULL and \p size > 0, allocates a new block. If \p
|
||||
* size is zero, frees the memory block pointed to by \p ptr.
|
||||
* @param size Size in bytes for the memory block to be allocated or
|
||||
* reallocated.
|
||||
* @param ptr Pointer to a memory block already allocated with
|
||||
* av_malloc(z)() or av_realloc() or NULL.
|
||||
* @return Pointer to a newly reallocated block or NULL if the block
|
||||
* cannot be reallocated or the function is used to free the memory block.
|
||||
* @see av_fast_realloc()
|
||||
*/
|
||||
void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
|
||||
|
||||
/**
|
||||
* Frees a memory block which has been allocated with av_malloc(z)() or
|
||||
* av_realloc().
|
||||
* @param ptr Pointer to the memory block which should be freed.
|
||||
* @note ptr = NULL is explicitly allowed.
|
||||
* @note It is recommended that you use av_freep() instead.
|
||||
* @see av_freep()
|
||||
*/
|
||||
void av_free(void *ptr);
|
||||
|
||||
/**
|
||||
* Allocates a block of \p size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU) and
|
||||
* zeroes all the bytes of the block.
|
||||
* @param size Size in bytes for the memory block to be allocated.
|
||||
* @return Pointer to the allocated block, NULL if it cannot be allocated.
|
||||
* @see av_malloc()
|
||||
*/
|
||||
void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Duplicates the string \p s.
|
||||
* @param s string to be duplicated
|
||||
* @return Pointer to a newly allocated string containing a
|
||||
* copy of \p s or NULL if the string cannot be allocated.
|
||||
*/
|
||||
char *av_strdup(const char *s) av_malloc_attrib;
|
||||
|
||||
/**
|
||||
* Frees a memory block which has been allocated with av_malloc(z)() or
|
||||
* av_realloc() and set the pointer pointing to it to NULL.
|
||||
* @param ptr Pointer to the pointer to the memory block which should
|
||||
* be freed.
|
||||
* @see av_free()
|
||||
*/
|
||||
void av_freep(void *ptr);
|
||||
|
||||
#endif /* AVUTIL_MEM_H */
|
150
apps/codecs/libwmapro/mathops.h
Normal file
150
apps/codecs/libwmapro/mathops.h
Normal file
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* simple math operations
|
||||
* Copyright (c) 2001, 2002 Fabrice Bellard
|
||||
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef AVCODEC_MATHOPS_H
|
||||
#define AVCODEC_MATHOPS_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 */
|
||||
|
||||
#ifndef MULL
|
||||
# define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
|
||||
#endif
|
||||
|
||||
#ifndef MULH
|
||||
//gcc 3.4 creates an incredibly bloated mess out of this
|
||||
//# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
|
||||
|
||||
static av_always_inline int MULH(int a, int b){
|
||||
return ((int64_t)(a) * (int64_t)(b))>>32;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef UMULH
|
||||
static av_always_inline unsigned UMULH(unsigned a, unsigned b){
|
||||
return ((uint64_t)(a) * (uint64_t)(b))>>32;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef MUL64
|
||||
# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
|
||||
#endif
|
||||
|
||||
#ifndef MAC64
|
||||
# define MAC64(d, a, b) ((d) += MUL64(a, b))
|
||||
#endif
|
||||
|
||||
#ifndef MLS64
|
||||
# define MLS64(d, a, b) ((d) -= MUL64(a, b))
|
||||
#endif
|
||||
|
||||
/* signed 16x16 -> 32 multiply add accumulate */
|
||||
#ifndef MAC16
|
||||
# define MAC16(rt, ra, rb) rt += (ra) * (rb)
|
||||
#endif
|
||||
|
||||
/* signed 16x16 -> 32 multiply */
|
||||
#ifndef MUL16
|
||||
# define MUL16(ra, rb) ((ra) * (rb))
|
||||
#endif
|
||||
|
||||
#ifndef MLS16
|
||||
# define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
|
||||
#endif
|
||||
|
||||
/* median of 3 */
|
||||
#ifndef mid_pred
|
||||
#define mid_pred mid_pred
|
||||
static inline av_const int mid_pred(int a, int b, int c)
|
||||
{
|
||||
#if 0
|
||||
int t= (a-b)&((a-b)>>31);
|
||||
a-=t;
|
||||
b+=t;
|
||||
b-= (b-c)&((b-c)>>31);
|
||||
b+= (a-b)&((a-b)>>31);
|
||||
|
||||
return b;
|
||||
#else
|
||||
if(a>b){
|
||||
if(c>b){
|
||||
if(c>a) b=a;
|
||||
else b=c;
|
||||
}
|
||||
}else{
|
||||
if(b>c){
|
||||
if(c>a) b=c;
|
||||
else b=a;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef sign_extend
|
||||
static inline av_const int sign_extend(int val, unsigned bits)
|
||||
{
|
||||
return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef zero_extend
|
||||
static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
|
||||
{
|
||||
return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef COPY3_IF_LT
|
||||
#define COPY3_IF_LT(x, y, a, b, c, d)\
|
||||
if ((y) < (x)) {\
|
||||
(x) = (y);\
|
||||
(a) = (b);\
|
||||
(c) = (d);\
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NEG_SSR32
|
||||
# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
|
||||
#endif
|
||||
|
||||
#ifndef NEG_USR32
|
||||
# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
|
||||
#endif
|
||||
|
||||
#endif /* AVCODEC_MATHOPS_H */
|
||||
|
232
apps/codecs/libwmapro/mdct.c
Normal file
232
apps/codecs/libwmapro/mdct.c
Normal file
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* MDCT/IMDCT transforms
|
||||
* Copyright (c) 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "fft.h"
|
||||
|
||||
/**
|
||||
* @file libavcodec/mdct.c
|
||||
* MDCT/IMDCT transforms.
|
||||
*/
|
||||
|
||||
// Generate a Kaiser-Bessel Derived Window.
|
||||
#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation
|
||||
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
|
||||
{
|
||||
int i, j;
|
||||
double sum = 0.0, bessel, tmp;
|
||||
double local_window[n];
|
||||
double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
tmp = i * (n - i) * alpha2;
|
||||
bessel = 1.0;
|
||||
for (j = BESSEL_I0_ITER; j > 0; j--)
|
||||
bessel = bessel * tmp / (j * j) + 1;
|
||||
sum += bessel;
|
||||
local_window[i] = sum;
|
||||
}
|
||||
|
||||
sum++;
|
||||
for (i = 0; i < n; i++)
|
||||
window[i] = sqrt(local_window[i] / sum);
|
||||
}
|
||||
|
||||
#include "mdct_tablegen.h"
|
||||
|
||||
/**
|
||||
* init MDCT or IMDCT computation.
|
||||
*/
|
||||
av_cold int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale)
|
||||
{
|
||||
int n, n4, i;
|
||||
double alpha, theta;
|
||||
int tstep;
|
||||
|
||||
memset(s, 0, sizeof(*s));
|
||||
n = 1 << nbits;
|
||||
s->mdct_bits = nbits;
|
||||
s->mdct_size = n;
|
||||
n4 = n >> 2;
|
||||
s->permutation = FF_MDCT_PERM_NONE;
|
||||
|
||||
if (ff_fft_init(s, s->mdct_bits - 2, inverse) < 0)
|
||||
goto fail;
|
||||
|
||||
s->tcos = av_malloc(n/2 * sizeof(FFTSample));
|
||||
if (!s->tcos)
|
||||
goto fail;
|
||||
|
||||
switch (s->permutation) {
|
||||
case FF_MDCT_PERM_NONE:
|
||||
s->tsin = s->tcos + n4;
|
||||
tstep = 1;
|
||||
break;
|
||||
case FF_MDCT_PERM_INTERLEAVE:
|
||||
s->tsin = s->tcos + 1;
|
||||
tstep = 2;
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0);
|
||||
scale = sqrt(fabs(scale));
|
||||
for(i=0;i<n4;i++) {
|
||||
alpha = 2 * M_PI * (i + theta) / n;
|
||||
s->tcos[i*tstep] = -cos(alpha) * scale;
|
||||
s->tsin[i*tstep] = -sin(alpha) * scale;
|
||||
}
|
||||
return 0;
|
||||
fail:
|
||||
ff_mdct_end(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* complex multiplication: p = a * b */
|
||||
#define CMUL(pre, pim, are, aim, bre, bim) \
|
||||
{\
|
||||
FFTSample _are = (are);\
|
||||
FFTSample _aim = (aim);\
|
||||
FFTSample _bre = (bre);\
|
||||
FFTSample _bim = (bim);\
|
||||
(pre) = _are * _bre - _aim * _bim;\
|
||||
(pim) = _are * _bim + _aim * _bre;\
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the middle half of the inverse MDCT of size N = 2^nbits,
|
||||
* thus excluding the parts that can be derived by symmetry
|
||||
* @param output N/2 samples
|
||||
* @param input N/2 samples
|
||||
*/
|
||||
void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
int k, n8, n4, n2, n, j;
|
||||
const uint16_t *revtab = s->revtab;
|
||||
const FFTSample *tcos = s->tcos;
|
||||
const FFTSample *tsin = s->tsin;
|
||||
const FFTSample *in1, *in2;
|
||||
FFTComplex *z = (FFTComplex *)output;
|
||||
|
||||
n = 1 << s->mdct_bits;
|
||||
n2 = n >> 1;
|
||||
n4 = n >> 2;
|
||||
n8 = n >> 3;
|
||||
|
||||
/* pre rotation */
|
||||
in1 = input;
|
||||
in2 = input + n2 - 1;
|
||||
for(k = 0; k < n4; k++) {
|
||||
j=revtab[k];
|
||||
CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]);
|
||||
in1 += 2;
|
||||
in2 -= 2;
|
||||
}
|
||||
ff_fft_calc(s, z);
|
||||
|
||||
/* post rotation + reordering */
|
||||
for(k = 0; k < n8; k++) {
|
||||
FFTSample r0, i0, r1, i1;
|
||||
CMUL(r0, i1, z[n8-k-1].im, z[n8-k-1].re, tsin[n8-k-1], tcos[n8-k-1]);
|
||||
CMUL(r1, i0, z[n8+k ].im, z[n8+k ].re, tsin[n8+k ], tcos[n8+k ]);
|
||||
z[n8-k-1].re = r0;
|
||||
z[n8-k-1].im = i0;
|
||||
z[n8+k ].re = r1;
|
||||
z[n8+k ].im = i1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute inverse MDCT of size N = 2^nbits
|
||||
* @param output N samples
|
||||
* @param input N/2 samples
|
||||
*/
|
||||
void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
int k;
|
||||
int n = 1 << s->mdct_bits;
|
||||
int n2 = n >> 1;
|
||||
int n4 = n >> 2;
|
||||
|
||||
ff_imdct_half_c(s, output+n4, input);
|
||||
|
||||
for(k = 0; k < n4; k++) {
|
||||
output[k] = -output[n2-k-1];
|
||||
output[n-k-1] = output[n2+k];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute MDCT of size N = 2^nbits
|
||||
* @param input N samples
|
||||
* @param out N/2 samples
|
||||
*/
|
||||
void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input)
|
||||
{
|
||||
int i, j, n, n8, n4, n2, n3;
|
||||
FFTSample re, im;
|
||||
const uint16_t *revtab = s->revtab;
|
||||
const FFTSample *tcos = s->tcos;
|
||||
const FFTSample *tsin = s->tsin;
|
||||
FFTComplex *x = (FFTComplex *)out;
|
||||
|
||||
n = 1 << s->mdct_bits;
|
||||
n2 = n >> 1;
|
||||
n4 = n >> 2;
|
||||
n8 = n >> 3;
|
||||
n3 = 3 * n4;
|
||||
|
||||
/* pre rotation */
|
||||
for(i=0;i<n8;i++) {
|
||||
re = -input[2*i+3*n4] - input[n3-1-2*i];
|
||||
im = -input[n4+2*i] + input[n4-1-2*i];
|
||||
j = revtab[i];
|
||||
CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]);
|
||||
|
||||
re = input[2*i] - input[n2-1-2*i];
|
||||
im = -(input[n2+2*i] + input[n-1-2*i]);
|
||||
j = revtab[n8 + i];
|
||||
CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]);
|
||||
}
|
||||
|
||||
ff_fft_calc(s, x);
|
||||
|
||||
/* post rotation */
|
||||
for(i=0;i<n8;i++) {
|
||||
FFTSample r0, i0, r1, i1;
|
||||
CMUL(i1, r0, x[n8-i-1].re, x[n8-i-1].im, -tsin[n8-i-1], -tcos[n8-i-1]);
|
||||
CMUL(i0, r1, x[n8+i ].re, x[n8+i ].im, -tsin[n8+i ], -tcos[n8+i ]);
|
||||
x[n8-i-1].re = r0;
|
||||
x[n8-i-1].im = i0;
|
||||
x[n8+i ].re = r1;
|
||||
x[n8+i ].im = i1;
|
||||
}
|
||||
}
|
||||
|
||||
av_cold void ff_mdct_end(FFTContext *s)
|
||||
{
|
||||
av_freep(&s->tcos);
|
||||
ff_fft_end(s);
|
||||
}
|
60
apps/codecs/libwmapro/mdct_tablegen.h
Normal file
60
apps/codecs/libwmapro/mdct_tablegen.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Header file for hardcoded MDCT tables
|
||||
*
|
||||
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
// do not use libavutil/mathematics.h since this is compiled both
|
||||
// for the host and the target and config.h is only valid for the target
|
||||
#include <math.h>
|
||||
//#include "../libavutil/attributes.h"
|
||||
|
||||
#if !CONFIG_HARDCODED_TABLES
|
||||
SINETABLE( 32);
|
||||
SINETABLE( 64);
|
||||
SINETABLE( 128);
|
||||
SINETABLE( 256);
|
||||
SINETABLE( 512);
|
||||
SINETABLE(1024);
|
||||
SINETABLE(2048);
|
||||
SINETABLE(4096);
|
||||
#else
|
||||
#include "libavcodec/mdct_tables.h"
|
||||
#endif
|
||||
|
||||
SINETABLE_CONST float * const ff_sine_windows[] = {
|
||||
NULL, NULL, NULL, NULL, NULL, // unused
|
||||
ff_sine_32 , ff_sine_64 ,
|
||||
ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
|
||||
};
|
||||
|
||||
// Generate a sine window.
|
||||
av_cold void ff_sine_window_init(float *window, int n) {
|
||||
int i;
|
||||
for(i = 0; i < n; i++)
|
||||
window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
|
||||
}
|
||||
|
||||
av_cold void ff_init_ff_sine_windows(int index) {
|
||||
assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows));
|
||||
#if !CONFIG_HARDCODED_TABLES
|
||||
ff_sine_window_init(ff_sine_windows[index], 1 << index);
|
||||
#endif
|
||||
}
|
343
apps/codecs/libwmapro/put_bits.h
Normal file
343
apps/codecs/libwmapro/put_bits.h
Normal file
|
@ -0,0 +1,343 @@
|
|||
/*
|
||||
* copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavcodec/put_bits.h
|
||||
* bitstream writer API
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_PUT_BITS_H
|
||||
#define AVCODEC_PUT_BITS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "libavutil/bswap.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "libavutil/log.h"
|
||||
#include "mathops.h"
|
||||
|
||||
//#define ALT_BITSTREAM_WRITER
|
||||
//#define ALIGNED_BITSTREAM_WRITER
|
||||
|
||||
/* buf and buf_end must be present and used by every alternative writer. */
|
||||
typedef struct PutBitContext {
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
uint8_t *buf, *buf_end;
|
||||
int index;
|
||||
#else
|
||||
uint32_t bit_buf;
|
||||
int bit_left;
|
||||
uint8_t *buf, *buf_ptr, *buf_end;
|
||||
#endif
|
||||
int size_in_bits;
|
||||
} PutBitContext;
|
||||
|
||||
/**
|
||||
* Initializes the PutBitContext s.
|
||||
*
|
||||
* @param buffer the buffer where to put bits
|
||||
* @param buffer_size the size in bytes of buffer
|
||||
*/
|
||||
static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
|
||||
{
|
||||
if(buffer_size < 0) {
|
||||
buffer_size = 0;
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
s->size_in_bits= 8*buffer_size;
|
||||
s->buf = buffer;
|
||||
s->buf_end = s->buf + buffer_size;
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
s->index=0;
|
||||
((uint32_t*)(s->buf))[0]=0;
|
||||
// memset(buffer, 0, buffer_size);
|
||||
#else
|
||||
s->buf_ptr = s->buf;
|
||||
s->bit_left=32;
|
||||
s->bit_buf=0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of bits written to the bitstream.
|
||||
*/
|
||||
static inline int put_bits_count(PutBitContext *s)
|
||||
{
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
return s->index;
|
||||
#else
|
||||
return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Pads the end of the output stream with zeros.
|
||||
*/
|
||||
static inline void flush_put_bits(PutBitContext *s)
|
||||
{
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
align_put_bits(s);
|
||||
#else
|
||||
#ifndef BITSTREAM_WRITER_LE
|
||||
s->bit_buf<<= s->bit_left;
|
||||
#endif
|
||||
while (s->bit_left < 32) {
|
||||
/* XXX: should test end of buffer */
|
||||
#ifdef BITSTREAM_WRITER_LE
|
||||
*s->buf_ptr++=s->bit_buf;
|
||||
s->bit_buf>>=8;
|
||||
#else
|
||||
*s->buf_ptr++=s->bit_buf >> 24;
|
||||
s->bit_buf<<=8;
|
||||
#endif
|
||||
s->bit_left+=8;
|
||||
}
|
||||
s->bit_left=32;
|
||||
s->bit_buf=0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(ALT_BITSTREAM_WRITER) || defined(BITSTREAM_WRITER_LE)
|
||||
#define align_put_bits align_put_bits_unsupported_here
|
||||
#define ff_put_string ff_put_string_unsupported_here
|
||||
#define ff_copy_bits ff_copy_bits_unsupported_here
|
||||
#else
|
||||
/**
|
||||
* Pads the bitstream with zeros up to the next byte boundary.
|
||||
*/
|
||||
void align_put_bits(PutBitContext *s);
|
||||
|
||||
/**
|
||||
* Puts the string string in the bitstream.
|
||||
*
|
||||
* @param terminate_string 0-terminates the written string if value is 1
|
||||
*/
|
||||
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string);
|
||||
|
||||
/**
|
||||
* Copies the content of src to the bitstream.
|
||||
*
|
||||
* @param length the number of bits of src to copy
|
||||
*/
|
||||
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Writes up to 31 bits into a bitstream.
|
||||
* Use put_bits32 to write 32 bits.
|
||||
*/
|
||||
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
|
||||
#ifndef ALT_BITSTREAM_WRITER
|
||||
{
|
||||
unsigned int bit_buf;
|
||||
int bit_left;
|
||||
|
||||
// printf("put_bits=%d %x\n", n, value);
|
||||
assert(n <= 31 && value < (1U << n));
|
||||
|
||||
bit_buf = s->bit_buf;
|
||||
bit_left = s->bit_left;
|
||||
|
||||
// printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
|
||||
/* XXX: optimize */
|
||||
#ifdef BITSTREAM_WRITER_LE
|
||||
bit_buf |= value << (32 - bit_left);
|
||||
if (n >= bit_left) {
|
||||
#if !HAVE_FAST_UNALIGNED
|
||||
if (3 & (intptr_t) s->buf_ptr) {
|
||||
AV_WL32(s->buf_ptr, bit_buf);
|
||||
} else
|
||||
#endif
|
||||
*(uint32_t *)s->buf_ptr = le2me_32(bit_buf);
|
||||
s->buf_ptr+=4;
|
||||
bit_buf = (bit_left==32)?0:value >> bit_left;
|
||||
bit_left+=32;
|
||||
}
|
||||
bit_left-=n;
|
||||
#else
|
||||
if (n < bit_left) {
|
||||
bit_buf = (bit_buf<<n) | value;
|
||||
bit_left-=n;
|
||||
} else {
|
||||
bit_buf<<=bit_left;
|
||||
bit_buf |= value >> (n - bit_left);
|
||||
#if !HAVE_FAST_UNALIGNED
|
||||
if (3 & (intptr_t) s->buf_ptr) {
|
||||
AV_WB32(s->buf_ptr, bit_buf);
|
||||
} else
|
||||
#endif
|
||||
*(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
|
||||
//printf("bitbuf = %08x\n", bit_buf);
|
||||
s->buf_ptr+=4;
|
||||
bit_left+=32 - n;
|
||||
bit_buf = value;
|
||||
}
|
||||
#endif
|
||||
|
||||
s->bit_buf = bit_buf;
|
||||
s->bit_left = bit_left;
|
||||
}
|
||||
#else /* ALT_BITSTREAM_WRITER defined */
|
||||
{
|
||||
# ifdef ALIGNED_BITSTREAM_WRITER
|
||||
# if ARCH_X86
|
||||
__asm__ volatile(
|
||||
"movl %0, %%ecx \n\t"
|
||||
"xorl %%eax, %%eax \n\t"
|
||||
"shrdl %%cl, %1, %%eax \n\t"
|
||||
"shrl %%cl, %1 \n\t"
|
||||
"movl %0, %%ecx \n\t"
|
||||
"shrl $3, %%ecx \n\t"
|
||||
"andl $0xFFFFFFFC, %%ecx \n\t"
|
||||
"bswapl %1 \n\t"
|
||||
"orl %1, (%2, %%ecx) \n\t"
|
||||
"bswapl %%eax \n\t"
|
||||
"addl %3, %0 \n\t"
|
||||
"movl %%eax, 4(%2, %%ecx) \n\t"
|
||||
: "=&r" (s->index), "=&r" (value)
|
||||
: "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
|
||||
: "%eax", "%ecx"
|
||||
);
|
||||
# else
|
||||
int index= s->index;
|
||||
uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
|
||||
|
||||
value<<= 32-n;
|
||||
|
||||
ptr[0] |= be2me_32(value>>(index&31));
|
||||
ptr[1] = be2me_32(value<<(32-(index&31)));
|
||||
//if(n>24) printf("%d %d\n", n, value);
|
||||
index+= n;
|
||||
s->index= index;
|
||||
# endif
|
||||
# else //ALIGNED_BITSTREAM_WRITER
|
||||
# if ARCH_X86
|
||||
__asm__ volatile(
|
||||
"movl $7, %%ecx \n\t"
|
||||
"andl %0, %%ecx \n\t"
|
||||
"addl %3, %%ecx \n\t"
|
||||
"negl %%ecx \n\t"
|
||||
"shll %%cl, %1 \n\t"
|
||||
"bswapl %1 \n\t"
|
||||
"movl %0, %%ecx \n\t"
|
||||
"shrl $3, %%ecx \n\t"
|
||||
"orl %1, (%%ecx, %2) \n\t"
|
||||
"addl %3, %0 \n\t"
|
||||
"movl $0, 4(%%ecx, %2) \n\t"
|
||||
: "=&r" (s->index), "=&r" (value)
|
||||
: "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
|
||||
: "%ecx"
|
||||
);
|
||||
# else
|
||||
int index= s->index;
|
||||
uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
|
||||
|
||||
ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
|
||||
ptr[1] = 0;
|
||||
//if(n>24) printf("%d %d\n", n, value);
|
||||
index+= n;
|
||||
s->index= index;
|
||||
# endif
|
||||
# endif //!ALIGNED_BITSTREAM_WRITER
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void put_sbits(PutBitContext *pb, int n, int32_t value)
|
||||
{
|
||||
assert(n >= 0 && n <= 31);
|
||||
|
||||
put_bits(pb, n, value & ((1<<n)-1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes exactly 32 bits into a bitstream.
|
||||
*/
|
||||
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
|
||||
{
|
||||
int lo = value & 0xffff;
|
||||
int hi = value >> 16;
|
||||
#ifdef BITSTREAM_WRITER_LE
|
||||
put_bits(s, 16, lo);
|
||||
put_bits(s, 16, hi);
|
||||
#else
|
||||
put_bits(s, 16, hi);
|
||||
put_bits(s, 16, lo);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pointer to the byte where the bitstream writer will put
|
||||
* the next bit.
|
||||
*/
|
||||
static inline uint8_t* put_bits_ptr(PutBitContext *s)
|
||||
{
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
return s->buf + (s->index>>3);
|
||||
#else
|
||||
return s->buf_ptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the given number of bytes.
|
||||
* PutBitContext must be flushed & aligned to a byte boundary before calling this.
|
||||
*/
|
||||
static inline void skip_put_bytes(PutBitContext *s, int n)
|
||||
{
|
||||
assert((put_bits_count(s)&7)==0);
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
FIXME may need some cleaning of the buffer
|
||||
s->index += n<<3;
|
||||
#else
|
||||
assert(s->bit_left==32);
|
||||
s->buf_ptr += n;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the given number of bits.
|
||||
* Must only be used if the actual values in the bitstream do not matter.
|
||||
* If n is 0 the behavior is undefined.
|
||||
*/
|
||||
static inline void skip_put_bits(PutBitContext *s, int n)
|
||||
{
|
||||
#ifdef ALT_BITSTREAM_WRITER
|
||||
s->index += n;
|
||||
#else
|
||||
s->bit_left -= n;
|
||||
s->buf_ptr-= 4*(s->bit_left>>5);
|
||||
s->bit_left &= 31;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the end of the buffer.
|
||||
*
|
||||
* @param size the new size in bytes of the buffer where to put bits
|
||||
*/
|
||||
static inline void set_put_bits_buffer_size(PutBitContext *s, int size)
|
||||
{
|
||||
s->buf_end= s->buf + size;
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_PUT_BITS_H */
|
525
apps/codecs/libwmapro/wma.c
Normal file
525
apps/codecs/libwmapro/wma.c
Normal file
|
@ -0,0 +1,525 @@
|
|||
/*
|
||||
* WMA compatible codec
|
||||
* Copyright (c) 2002-2007 The FFmpeg Project
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "wma.h"
|
||||
//#include "wmadata.h"
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#if 0
|
||||
/* XXX: use same run/length optimization as mpeg decoders */
|
||||
//FIXME maybe split decode / encode or pass flag
|
||||
static void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
|
||||
float **plevel_table, uint16_t **pint_table,
|
||||
const CoefVLCTable *vlc_table)
|
||||
{
|
||||
int n = vlc_table->n;
|
||||
const uint8_t *table_bits = vlc_table->huffbits;
|
||||
const uint32_t *table_codes = vlc_table->huffcodes;
|
||||
const uint16_t *levels_table = vlc_table->levels;
|
||||
uint16_t *run_table, *level_table, *int_table;
|
||||
float *flevel_table;
|
||||
int i, l, j, k, level;
|
||||
|
||||
init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0);
|
||||
|
||||
run_table = av_malloc(n * sizeof(uint16_t));
|
||||
level_table = av_malloc(n * sizeof(uint16_t));
|
||||
flevel_table= av_malloc(n * sizeof(*flevel_table));
|
||||
int_table = av_malloc(n * sizeof(uint16_t));
|
||||
i = 2;
|
||||
level = 1;
|
||||
k = 0;
|
||||
while (i < n) {
|
||||
int_table[k] = i;
|
||||
l = levels_table[k++];
|
||||
for (j = 0; j < l; j++) {
|
||||
run_table[i] = j;
|
||||
level_table[i] = level;
|
||||
flevel_table[i]= level;
|
||||
i++;
|
||||
}
|
||||
level++;
|
||||
}
|
||||
*prun_table = run_table;
|
||||
*plevel_table = flevel_table;
|
||||
*pint_table = int_table;
|
||||
av_free(level_table);
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
/**
|
||||
*@brief Get the samples per frame for this stream.
|
||||
*@param sample_rate output sample_rate
|
||||
*@param version wma version
|
||||
*@param decode_flags codec compression features
|
||||
*@return log2 of the number of output samples per frame
|
||||
*/
|
||||
int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
|
||||
unsigned int decode_flags)
|
||||
{
|
||||
|
||||
int frame_len_bits;
|
||||
|
||||
if (sample_rate <= 16000) {
|
||||
frame_len_bits = 9;
|
||||
} else if (sample_rate <= 22050 ||
|
||||
(sample_rate <= 32000 && version == 1)) {
|
||||
frame_len_bits = 10;
|
||||
} else if (sample_rate <= 48000) {
|
||||
frame_len_bits = 11;
|
||||
} else if (sample_rate <= 96000) {
|
||||
frame_len_bits = 12;
|
||||
} else {
|
||||
frame_len_bits = 13;
|
||||
}
|
||||
|
||||
if (version == 3) {
|
||||
int tmp = decode_flags & 0x6;
|
||||
if (tmp == 0x2) {
|
||||
++frame_len_bits;
|
||||
} else if (tmp == 0x4) {
|
||||
--frame_len_bits;
|
||||
} else if (tmp == 0x6) {
|
||||
frame_len_bits -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
return frame_len_bits;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int ff_wma_init(AVCodecContext *avctx, int flags2)
|
||||
{
|
||||
WMACodecContext *s = avctx->priv_data;
|
||||
int i;
|
||||
float bps1, high_freq;
|
||||
volatile float bps;
|
||||
int sample_rate1;
|
||||
int coef_vlc_table;
|
||||
|
||||
if ( avctx->sample_rate <= 0 || avctx->sample_rate > 50000
|
||||
|| avctx->channels <= 0 || avctx->channels > 8
|
||||
|| avctx->bit_rate <= 0)
|
||||
return -1;
|
||||
|
||||
s->sample_rate = avctx->sample_rate;
|
||||
s->nb_channels = avctx->channels;
|
||||
s->bit_rate = avctx->bit_rate;
|
||||
s->block_align = avctx->block_align;
|
||||
|
||||
dsputil_init(&s->dsp, avctx);
|
||||
|
||||
if (avctx->codec->id == CODEC_ID_WMAV1) {
|
||||
s->version = 1;
|
||||
} else {
|
||||
s->version = 2;
|
||||
}
|
||||
|
||||
/* compute MDCT block size */
|
||||
s->frame_len_bits = ff_wma_get_frame_len_bits(s->sample_rate, s->version, 0);
|
||||
|
||||
s->frame_len = 1 << s->frame_len_bits;
|
||||
if (s->use_variable_block_len) {
|
||||
int nb_max, nb;
|
||||
nb = ((flags2 >> 3) & 3) + 1;
|
||||
if ((s->bit_rate / s->nb_channels) >= 32000)
|
||||
nb += 2;
|
||||
nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
|
||||
if (nb > nb_max)
|
||||
nb = nb_max;
|
||||
s->nb_block_sizes = nb + 1;
|
||||
} else {
|
||||
s->nb_block_sizes = 1;
|
||||
}
|
||||
|
||||
/* init rate dependent parameters */
|
||||
s->use_noise_coding = 1;
|
||||
high_freq = s->sample_rate * 0.5;
|
||||
|
||||
/* if version 2, then the rates are normalized */
|
||||
sample_rate1 = s->sample_rate;
|
||||
if (s->version == 2) {
|
||||
if (sample_rate1 >= 44100) {
|
||||
sample_rate1 = 44100;
|
||||
} else if (sample_rate1 >= 22050) {
|
||||
sample_rate1 = 22050;
|
||||
} else if (sample_rate1 >= 16000) {
|
||||
sample_rate1 = 16000;
|
||||
} else if (sample_rate1 >= 11025) {
|
||||
sample_rate1 = 11025;
|
||||
} else if (sample_rate1 >= 8000) {
|
||||
sample_rate1 = 8000;
|
||||
}
|
||||
}
|
||||
|
||||
bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
|
||||
s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
|
||||
|
||||
/* compute high frequency value and choose if noise coding should
|
||||
be activated */
|
||||
bps1 = bps;
|
||||
if (s->nb_channels == 2)
|
||||
bps1 = bps * 1.6;
|
||||
if (sample_rate1 == 44100) {
|
||||
if (bps1 >= 0.61) {
|
||||
s->use_noise_coding = 0;
|
||||
} else {
|
||||
high_freq = high_freq * 0.4;
|
||||
}
|
||||
} else if (sample_rate1 == 22050) {
|
||||
if (bps1 >= 1.16) {
|
||||
s->use_noise_coding = 0;
|
||||
} else if (bps1 >= 0.72) {
|
||||
high_freq = high_freq * 0.7;
|
||||
} else {
|
||||
high_freq = high_freq * 0.6;
|
||||
}
|
||||
} else if (sample_rate1 == 16000) {
|
||||
if (bps > 0.5) {
|
||||
high_freq = high_freq * 0.5;
|
||||
} else {
|
||||
high_freq = high_freq * 0.3;
|
||||
}
|
||||
} else if (sample_rate1 == 11025) {
|
||||
high_freq = high_freq * 0.7;
|
||||
} else if (sample_rate1 == 8000) {
|
||||
if (bps <= 0.625) {
|
||||
high_freq = high_freq * 0.5;
|
||||
} else if (bps > 0.75) {
|
||||
s->use_noise_coding = 0;
|
||||
} else {
|
||||
high_freq = high_freq * 0.65;
|
||||
}
|
||||
} else {
|
||||
if (bps >= 0.8) {
|
||||
high_freq = high_freq * 0.75;
|
||||
} else if (bps >= 0.6) {
|
||||
high_freq = high_freq * 0.6;
|
||||
} else {
|
||||
high_freq = high_freq * 0.5;
|
||||
}
|
||||
}
|
||||
dprintf(s->avctx, "flags2=0x%x\n", flags2);
|
||||
dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
|
||||
s->version, s->nb_channels, s->sample_rate, s->bit_rate,
|
||||
s->block_align);
|
||||
dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
|
||||
bps, bps1, high_freq, s->byte_offset_bits);
|
||||
dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
|
||||
s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
|
||||
|
||||
/* compute the scale factor band sizes for each MDCT block size */
|
||||
{
|
||||
int a, b, pos, lpos, k, block_len, i, j, n;
|
||||
const uint8_t *table;
|
||||
|
||||
if (s->version == 1) {
|
||||
s->coefs_start = 3;
|
||||
} else {
|
||||
s->coefs_start = 0;
|
||||
}
|
||||
for (k = 0; k < s->nb_block_sizes; k++) {
|
||||
block_len = s->frame_len >> k;
|
||||
|
||||
if (s->version == 1) {
|
||||
lpos = 0;
|
||||
for (i = 0; i < 25; i++) {
|
||||
a = ff_wma_critical_freqs[i];
|
||||
b = s->sample_rate;
|
||||
pos = ((block_len * 2 * a) + (b >> 1)) / b;
|
||||
if (pos > block_len)
|
||||
pos = block_len;
|
||||
s->exponent_bands[0][i] = pos - lpos;
|
||||
if (pos >= block_len) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
lpos = pos;
|
||||
}
|
||||
s->exponent_sizes[0] = i;
|
||||
} else {
|
||||
/* hardcoded tables */
|
||||
table = NULL;
|
||||
a = s->frame_len_bits - BLOCK_MIN_BITS - k;
|
||||
if (a < 3) {
|
||||
if (s->sample_rate >= 44100) {
|
||||
table = exponent_band_44100[a];
|
||||
} else if (s->sample_rate >= 32000) {
|
||||
table = exponent_band_32000[a];
|
||||
} else if (s->sample_rate >= 22050) {
|
||||
table = exponent_band_22050[a];
|
||||
}
|
||||
}
|
||||
if (table) {
|
||||
n = *table++;
|
||||
for (i = 0; i < n; i++)
|
||||
s->exponent_bands[k][i] = table[i];
|
||||
s->exponent_sizes[k] = n;
|
||||
} else {
|
||||
j = 0;
|
||||
lpos = 0;
|
||||
for (i = 0; i < 25; i++) {
|
||||
a = ff_wma_critical_freqs[i];
|
||||
b = s->sample_rate;
|
||||
pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
|
||||
pos <<= 2;
|
||||
if (pos > block_len)
|
||||
pos = block_len;
|
||||
if (pos > lpos)
|
||||
s->exponent_bands[k][j++] = pos - lpos;
|
||||
if (pos >= block_len)
|
||||
break;
|
||||
lpos = pos;
|
||||
}
|
||||
s->exponent_sizes[k] = j;
|
||||
}
|
||||
}
|
||||
|
||||
/* max number of coefs */
|
||||
s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
|
||||
/* high freq computation */
|
||||
s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
|
||||
s->sample_rate + 0.5);
|
||||
n = s->exponent_sizes[k];
|
||||
j = 0;
|
||||
pos = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
int start, end;
|
||||
start = pos;
|
||||
pos += s->exponent_bands[k][i];
|
||||
end = pos;
|
||||
if (start < s->high_band_start[k])
|
||||
start = s->high_band_start[k];
|
||||
if (end > s->coefs_end[k])
|
||||
end = s->coefs_end[k];
|
||||
if (end > start)
|
||||
s->exponent_high_bands[k][j++] = end - start;
|
||||
}
|
||||
s->exponent_high_sizes[k] = j;
|
||||
#if 0
|
||||
tprintf(s->avctx, "%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
|
||||
s->frame_len >> k,
|
||||
s->coefs_end[k],
|
||||
s->high_band_start[k],
|
||||
s->exponent_high_sizes[k]);
|
||||
for (j = 0; j < s->exponent_high_sizes[k]; j++)
|
||||
tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]);
|
||||
tprintf(s->avctx, "\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TRACE
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < s->nb_block_sizes; i++) {
|
||||
tprintf(s->avctx, "%5d: n=%2d:",
|
||||
s->frame_len >> i,
|
||||
s->exponent_sizes[i]);
|
||||
for (j = 0; j < s->exponent_sizes[i]; j++)
|
||||
tprintf(s->avctx, " %d", s->exponent_bands[i][j]);
|
||||
tprintf(s->avctx, "\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* init MDCT windows : simple sinus window */
|
||||
for (i = 0; i < s->nb_block_sizes; i++) {
|
||||
ff_init_ff_sine_windows(s->frame_len_bits - i);
|
||||
s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
|
||||
}
|
||||
|
||||
s->reset_block_lengths = 1;
|
||||
|
||||
if (s->use_noise_coding) {
|
||||
|
||||
/* init the noise generator */
|
||||
if (s->use_exp_vlc) {
|
||||
s->noise_mult = 0.02;
|
||||
} else {
|
||||
s->noise_mult = 0.04;
|
||||
}
|
||||
|
||||
#ifdef TRACE
|
||||
for (i = 0; i < NOISE_TAB_SIZE; i++)
|
||||
s->noise_table[i] = 1.0 * s->noise_mult;
|
||||
#else
|
||||
{
|
||||
unsigned int seed;
|
||||
float norm;
|
||||
seed = 1;
|
||||
norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
|
||||
for (i = 0; i < NOISE_TAB_SIZE; i++) {
|
||||
seed = seed * 314159 + 1;
|
||||
s->noise_table[i] = (float)((int)seed) * norm;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* choose the VLC tables for the coefficients */
|
||||
coef_vlc_table = 2;
|
||||
if (s->sample_rate >= 32000) {
|
||||
if (bps1 < 0.72) {
|
||||
coef_vlc_table = 0;
|
||||
} else if (bps1 < 1.16) {
|
||||
coef_vlc_table = 1;
|
||||
}
|
||||
}
|
||||
s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ];
|
||||
s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1];
|
||||
init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0],
|
||||
s->coef_vlcs[0]);
|
||||
init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1],
|
||||
s->coef_vlcs[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ff_wma_total_gain_to_bits(int total_gain)
|
||||
{
|
||||
if (total_gain < 15) return 13;
|
||||
else if (total_gain < 32) return 12;
|
||||
else if (total_gain < 40) return 11;
|
||||
else if (total_gain < 45) return 10;
|
||||
else return 9;
|
||||
}
|
||||
|
||||
int ff_wma_end(AVCodecContext *avctx)
|
||||
{
|
||||
WMACodecContext *s = avctx->priv_data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < s->nb_block_sizes; i++)
|
||||
ff_mdct_end(&s->mdct_ctx[i]);
|
||||
|
||||
if (s->use_exp_vlc) {
|
||||
free_vlc(&s->exp_vlc);
|
||||
}
|
||||
if (s->use_noise_coding) {
|
||||
free_vlc(&s->hgain_vlc);
|
||||
}
|
||||
for (i = 0; i < 2; i++) {
|
||||
free_vlc(&s->coef_vlc[i]);
|
||||
av_free(s->run_table[i]);
|
||||
av_free(s->level_table[i]);
|
||||
av_free(s->int_table[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* 0 */
|
||||
/**
|
||||
* Decode an uncompressed coefficient.
|
||||
* @param s codec context
|
||||
* @return the decoded coefficient
|
||||
*/
|
||||
unsigned int ff_wma_get_large_val(GetBitContext* gb)
|
||||
{
|
||||
/** consumes up to 34 bits */
|
||||
int n_bits = 8;
|
||||
/** decode length */
|
||||
if (get_bits1(gb)) {
|
||||
n_bits += 8;
|
||||
if (get_bits1(gb)) {
|
||||
n_bits += 8;
|
||||
if (get_bits1(gb)) {
|
||||
n_bits += 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
return get_bits_long(gb, n_bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode run level compressed coefficients.
|
||||
* @param avctx codec context
|
||||
* @param gb bitstream reader context
|
||||
* @param vlc vlc table for get_vlc2
|
||||
* @param level_table level codes
|
||||
* @param run_table run codes
|
||||
* @param version 0 for wma1,2 1 for wmapro
|
||||
* @param ptr output buffer
|
||||
* @param offset offset in the output buffer
|
||||
* @param num_coefs number of input coefficents
|
||||
* @param block_len input buffer length (2^n)
|
||||
* @param frame_len_bits number of bits for escaped run codes
|
||||
* @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,
|
||||
VLC *vlc,
|
||||
const float *level_table, const uint16_t *run_table,
|
||||
int version, WMACoef *ptr, int offset,
|
||||
int num_coefs, int block_len, int frame_len_bits,
|
||||
int coef_nb_bits)
|
||||
{
|
||||
int code, level, sign;
|
||||
const uint32_t *ilvl = (const uint32_t*)level_table;
|
||||
uint32_t *iptr = (uint32_t*)ptr;
|
||||
const unsigned int coef_mask = block_len - 1;
|
||||
for (; offset < num_coefs; offset++) {
|
||||
code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
|
||||
if (code > 1) {
|
||||
/** normal code */
|
||||
offset += run_table[code];
|
||||
sign = get_bits1(gb) - 1;
|
||||
iptr[offset & coef_mask] = ilvl[code] ^ sign<<31;
|
||||
} else if (code == 1) {
|
||||
/** EOB */
|
||||
break;
|
||||
} else {
|
||||
/** escape */
|
||||
if (!version) {
|
||||
level = get_bits(gb, coef_nb_bits);
|
||||
/** NOTE: this is rather suboptimal. reading
|
||||
block_len_bits would be better */
|
||||
offset += get_bits(gb, frame_len_bits);
|
||||
} else {
|
||||
level = ff_wma_get_large_val(gb);
|
||||
/** escape decode */
|
||||
if (get_bits1(gb)) {
|
||||
if (get_bits1(gb)) {
|
||||
if (get_bits1(gb)) {
|
||||
av_log(avctx,AV_LOG_ERROR,
|
||||
"broken escape sequence\n");
|
||||
return -1;
|
||||
} else
|
||||
offset += get_bits(gb, frame_len_bits) + 4;
|
||||
} else
|
||||
offset += get_bits(gb, 2) + 1;
|
||||
}
|
||||
}
|
||||
sign = get_bits1(gb) - 1;
|
||||
ptr[offset & coef_mask] = (level^sign) - sign;
|
||||
}
|
||||
}
|
||||
/** NOTE: EOB can be omitted */
|
||||
if (offset > num_coefs) {
|
||||
av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
163
apps/codecs/libwmapro/wma.h
Normal file
163
apps/codecs/libwmapro/wma.h
Normal file
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* WMA compatible codec
|
||||
* Copyright (c) 2002-2007 The FFmpeg Project
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_WMA_H
|
||||
#define AVCODEC_WMA_H
|
||||
|
||||
#include "get_bits.h"
|
||||
#include "put_bits.h"
|
||||
#include "dsputil.h"
|
||||
#include "fft.h"
|
||||
|
||||
/* size of blocks */
|
||||
#define BLOCK_MIN_BITS 7
|
||||
#define BLOCK_MAX_BITS 11
|
||||
#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
|
||||
|
||||
#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
|
||||
|
||||
/* XXX: find exact max size */
|
||||
#define HIGH_BAND_MAX_SIZE 16
|
||||
|
||||
#define NB_LSP_COEFS 10
|
||||
|
||||
/* XXX: is it a suitable value ? */
|
||||
#define MAX_CODED_SUPERFRAME_SIZE 16384
|
||||
|
||||
#define MAX_CHANNELS 2
|
||||
|
||||
#define NOISE_TAB_SIZE 8192
|
||||
|
||||
#define LSP_POW_BITS 7
|
||||
|
||||
//FIXME should be in wmadec
|
||||
#define VLCBITS 9
|
||||
#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
|
||||
|
||||
typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
|
||||
|
||||
typedef struct CoefVLCTable {
|
||||
int n; ///< total number of codes
|
||||
int max_level;
|
||||
const uint32_t *huffcodes; ///< VLC bit values
|
||||
const uint8_t *huffbits; ///< VLC bit size
|
||||
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);
|
||||
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,
|
||||
VLC *vlc,
|
||||
const float *level_table, const uint16_t *run_table,
|
||||
int version, WMACoef *ptr, int offset,
|
||||
int num_coefs, int block_len, int frame_len_bits,
|
||||
int coef_nb_bits);
|
||||
|
||||
#endif /* AVCODEC_WMA_H */
|
604
apps/codecs/libwmapro/wmaprodata.h
Normal file
604
apps/codecs/libwmapro/wmaprodata.h
Normal file
|
@ -0,0 +1,604 @@
|
|||
/*
|
||||
* WMA 9/3/PRO compatible decoder
|
||||
* Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
|
||||
* Copyright (c) 2008 - 2009 Sascha Sommer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file libavcodec/wmaprodata.h
|
||||
* @brief tables for wmapro decoding
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_WMAPRODATA_H
|
||||
#define AVCODEC_WMAPRODATA_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief frequencies to divide the frequency spectrum into scale factor bands
|
||||
*/
|
||||
static const uint16_t critical_freq[] = {
|
||||
100, 200, 300, 400, 510, 630, 770,
|
||||
920, 1080, 1270, 1480, 1720, 2000, 2320,
|
||||
2700, 3150, 3700, 4400, 5300, 6400, 7700,
|
||||
9500, 12000, 15500, 20675, 28575, 41375, 63875,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @name Huffman tables for DPCM-coded scale factors
|
||||
* @{
|
||||
*/
|
||||
#define HUFF_SCALE_SIZE 121
|
||||
#define HUFF_SCALE_MAXBITS 19
|
||||
static const uint16_t scale_huffcodes[HUFF_SCALE_SIZE] = {
|
||||
0xE639, 0xE6C2, 0xE6C1, 0xE6C0, 0xE63F, 0xE63E, 0xE63D, 0xE63C,
|
||||
0xE63B, 0xE63A, 0xE638, 0xE637, 0xE636, 0xE635, 0xE634, 0xE632,
|
||||
0xE633, 0xE620, 0x737B, 0xE610, 0xE611, 0xE612, 0xE613, 0xE614,
|
||||
0xE615, 0xE616, 0xE617, 0xE618, 0xE619, 0xE61A, 0xE61B, 0xE61C,
|
||||
0xE61D, 0xE61E, 0xE61F, 0xE6C3, 0xE621, 0xE622, 0xE623, 0xE624,
|
||||
0xE625, 0xE626, 0xE627, 0xE628, 0xE629, 0xE62A, 0xE62B, 0xE62C,
|
||||
0xE62D, 0xE62E, 0xE62F, 0xE630, 0xE631, 0x1CDF, 0x0E60, 0x0399,
|
||||
0x00E7, 0x001D, 0x0000, 0x0001, 0x0001, 0x0001, 0x0002, 0x0006,
|
||||
0x0002, 0x0007, 0x0006, 0x000F, 0x0038, 0x0072, 0x039A, 0xE6C4,
|
||||
0xE6C5, 0xE6C6, 0xE6C7, 0xE6C8, 0xE6C9, 0xE6CA, 0xE6CB, 0xE6CC,
|
||||
0xE6CD, 0xE6CE, 0xE6CF, 0xE6D0, 0xE6D1, 0xE6D2, 0xE6D3, 0xE6D4,
|
||||
0xE6D5, 0xE6D6, 0xE6D7, 0xE6D8, 0xE6D9, 0xE6DA, 0xE6DB, 0xE6DC,
|
||||
0xE6DD, 0xE6DE, 0xE6DF, 0xE6E0, 0xE6E1, 0xE6E2, 0xE6E3, 0xE6E4,
|
||||
0xE6E5, 0xE6E6, 0xE6E7, 0xE6E8, 0xE6E9, 0xE6EA, 0xE6EB, 0xE6EC,
|
||||
0xE6ED, 0xE6EE, 0xE6EF, 0xE6F0, 0xE6F1, 0xE6F2, 0xE6F3, 0xE6F4,
|
||||
0xE6F5,
|
||||
};
|
||||
|
||||
static const uint8_t scale_huffbits[HUFF_SCALE_SIZE] = {
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 18, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 16, 15, 13,
|
||||
11, 8, 5, 2, 1, 3, 5, 6,
|
||||
6, 7, 7, 7, 9, 10, 13, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19,
|
||||
};
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @name Huffman, run and level tables for runlevel-coded scale factors
|
||||
* @{
|
||||
*/
|
||||
#define HUFF_SCALE_RL_SIZE 120
|
||||
#define HUFF_SCALE_RL_MAXBITS 21
|
||||
static const uint32_t scale_rl_huffcodes[HUFF_SCALE_RL_SIZE] = {
|
||||
0x00010C, 0x000001, 0x10FE2A, 0x000003, 0x000003, 0x000001, 0x000013,
|
||||
0x000020, 0x000029, 0x000014, 0x000016, 0x000045, 0x000049, 0x00002F,
|
||||
0x000042, 0x00008E, 0x00008F, 0x000129, 0x000009, 0x00000D, 0x0004AC,
|
||||
0x00002C, 0x000561, 0x0002E6, 0x00087C, 0x0002E2, 0x00095C, 0x000018,
|
||||
0x000001, 0x000016, 0x000044, 0x00002A, 0x000007, 0x000159, 0x000143,
|
||||
0x000128, 0x00015A, 0x00012D, 0x00002B, 0x0000A0, 0x000142, 0x00012A,
|
||||
0x0002EF, 0x0004AF, 0x00087D, 0x004AE9, 0x0043F9, 0x000067, 0x000199,
|
||||
0x002B05, 0x001583, 0x0021FE, 0x10FE2C, 0x000004, 0x00002E, 0x00010D,
|
||||
0x00000A, 0x000244, 0x000017, 0x000245, 0x000011, 0x00010E, 0x00012C,
|
||||
0x00002A, 0x00002F, 0x000121, 0x000046, 0x00087E, 0x0000BA, 0x000032,
|
||||
0x0087F0, 0x0056DC, 0x0002EC, 0x0043FA, 0x002B6F, 0x004AE8, 0x0002B7,
|
||||
0x10FE2B, 0x000001, 0x000051, 0x000010, 0x0002EE, 0x000B9C, 0x002576,
|
||||
0x000198, 0x0056DD, 0x0000CD, 0x000AC0, 0x000170, 0x004AEF, 0x00002D,
|
||||
0x0004AD, 0x0021FF, 0x0005CF, 0x002B04, 0x10FE29, 0x10FE28, 0x0002ED,
|
||||
0x002E74, 0x021FC4, 0x004AEE, 0x010FE3, 0x087F17, 0x000000, 0x000097,
|
||||
0x0002E3, 0x000ADA, 0x002575, 0x00173B, 0x0043FB, 0x002E75, 0x10FE2D,
|
||||
0x0015B6, 0x00056C, 0x000057, 0x000123, 0x000120, 0x00021E, 0x000172,
|
||||
0x0002B1,
|
||||
};
|
||||
|
||||
static const uint8_t scale_rl_huffbits[HUFF_SCALE_RL_SIZE] = {
|
||||
9, 2, 21, 2, 4, 5, 5,
|
||||
6, 6, 7, 7, 7, 7, 6,
|
||||
7, 8, 8, 9, 10, 10, 11,
|
||||
12, 11, 12, 12, 12, 12, 11,
|
||||
4, 5, 7, 8, 9, 9, 9,
|
||||
9, 9, 9, 8, 8, 9, 9,
|
||||
12, 11, 12, 15, 15, 13, 15,
|
||||
14, 13, 14, 21, 5, 6, 9,
|
||||
10, 10, 11, 10, 11, 9, 9,
|
||||
6, 8, 9, 7, 12, 10, 12,
|
||||
16, 15, 12, 15, 14, 15, 10,
|
||||
21, 6, 7, 11, 12, 14, 14,
|
||||
15, 15, 14, 12, 11, 15, 12,
|
||||
11, 14, 13, 14, 21, 21, 12,
|
||||
16, 18, 15, 17, 20, 7, 8,
|
||||
12, 12, 14, 15, 15, 16, 21,
|
||||
13, 11, 7, 9, 9, 10, 11,
|
||||
10,
|
||||
};
|
||||
|
||||
|
||||
static const uint8_t scale_rl_run[HUFF_SCALE_RL_SIZE] = {
|
||||
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3,
|
||||
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
|
||||
23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||
0, 1, 0, 1, 0, 1,
|
||||
};
|
||||
|
||||
static const uint8_t scale_rl_level[HUFF_SCALE_RL_SIZE] = {
|
||||
0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
7, 7, 8, 8, 9, 9,
|
||||
};
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @name Huffman, run and level codes for runlevel-coded coefficients
|
||||
* @{
|
||||
*/
|
||||
#define HUFF_COEF0_SIZE 272
|
||||
#define HUFF_COEF0_MAXBITS 21
|
||||
static const uint32_t coef0_huffcodes[HUFF_COEF0_SIZE] = {
|
||||
0x00004A, 0x00002B, 0x000000, 0x000003, 0x000006, 0x000009, 0x00000F,
|
||||
0x000010, 0x000016, 0x000011, 0x000016, 0x000028, 0x00002F, 0x000026,
|
||||
0x000029, 0x000045, 0x000055, 0x00005D, 0x000042, 0x00004E, 0x000051,
|
||||
0x00005E, 0x00008D, 0x0000A8, 0x0000AD, 0x000080, 0x000096, 0x00009F,
|
||||
0x0000AA, 0x0000BE, 0x00011C, 0x000153, 0x000158, 0x000170, 0x000104,
|
||||
0x00010D, 0x000105, 0x000103, 0x00012F, 0x000177, 0x000175, 0x000157,
|
||||
0x000174, 0x000225, 0x00023B, 0x00020D, 0x00021F, 0x000281, 0x00027B,
|
||||
0x000282, 0x0002AC, 0x0002FD, 0x00044F, 0x000478, 0x00044D, 0x0002EC,
|
||||
0x00044E, 0x000564, 0x000409, 0x00040B, 0x000501, 0x000545, 0x0004F3,
|
||||
0x000541, 0x00043B, 0x0004F1, 0x0004F4, 0x0008FD, 0x000A94, 0x000811,
|
||||
0x000B88, 0x000B91, 0x000B93, 0x0008EA, 0x000899, 0x000B8A, 0x000972,
|
||||
0x0009E5, 0x000A8F, 0x000A84, 0x000A8E, 0x000A00, 0x000830, 0x0008E8,
|
||||
0x000B95, 0x000871, 0x00083A, 0x000814, 0x000873, 0x000BFE, 0x001728,
|
||||
0x001595, 0x001712, 0x00102A, 0x001021, 0x001729, 0x00152E, 0x0013C3,
|
||||
0x001721, 0x001597, 0x00151B, 0x0010F2, 0x001403, 0x001703, 0x001503,
|
||||
0x001708, 0x0013C1, 0x00170E, 0x00170C, 0x0010E1, 0x0011EA, 0x001020,
|
||||
0x001500, 0x0017FA, 0x001704, 0x001705, 0x0017F0, 0x0017FB, 0x0021E6,
|
||||
0x002B2D, 0x0020C6, 0x002B29, 0x002E4A, 0x0023AC, 0x001519, 0x0023F3,
|
||||
0x002B2C, 0x0021C0, 0x0017FE, 0x0023D7, 0x0017F9, 0x0012E7, 0x0013C0,
|
||||
0x002261, 0x0023D3, 0x002057, 0x002056, 0x0021D2, 0x0020C7, 0x0023D2,
|
||||
0x0020EC, 0x0044C0, 0x002FE2, 0x00475B, 0x002A03, 0x002FE3, 0x0021E2,
|
||||
0x0021D0, 0x002A31, 0x002E13, 0x002E05, 0x0047E5, 0x00000E, 0x000024,
|
||||
0x000088, 0x0000B9, 0x00010C, 0x000224, 0x0002B3, 0x000283, 0x0002ED,
|
||||
0x00047B, 0x00041E, 0x00043D, 0x0004F5, 0x0005FD, 0x000A92, 0x000B96,
|
||||
0x000838, 0x000971, 0x000B83, 0x000B80, 0x000BF9, 0x0011D3, 0x0011E8,
|
||||
0x0011D7, 0x001527, 0x0011F8, 0x001073, 0x0010F0, 0x0010E4, 0x0017F8,
|
||||
0x001062, 0x001402, 0x0017E3, 0x00151A, 0x001077, 0x00152B, 0x00170D,
|
||||
0x0021D3, 0x002E41, 0x0013C2, 0x000029, 0x0000A9, 0x00025D, 0x000419,
|
||||
0x000544, 0x000B8B, 0x0009E4, 0x0011D2, 0x001526, 0x001724, 0x0012E6,
|
||||
0x00150B, 0x0017FF, 0x002E26, 0x002E4B, 0x002B28, 0x0021E3, 0x002A14,
|
||||
0x00475A, 0x002E12, 0x000057, 0x00023E, 0x000A90, 0x000BF0, 0x001072,
|
||||
0x001502, 0x0023D6, 0x0020ED, 0x002A30, 0x0044C7, 0x00008C, 0x00047F,
|
||||
0x00152A, 0x002262, 0x002E04, 0x0000A1, 0x0005F9, 0x000173, 0x000875,
|
||||
0x000171, 0x00152D, 0x0002E3, 0x0017E2, 0x0002AD, 0x0021C1, 0x000479,
|
||||
0x0021E7, 0x00041F, 0x005C4E, 0x000543, 0x005C4F, 0x000A91, 0x00898D,
|
||||
0x000B97, 0x008746, 0x000970, 0x008745, 0x000B85, 0x00A856, 0x00152F,
|
||||
0x010E8E, 0x0010E5, 0x00A857, 0x00170F, 0x021D11, 0x002A58, 0x010E8F,
|
||||
0x002E40, 0x021D13, 0x002A59, 0x043A25, 0x002A02, 0x043A21, 0x0044C1,
|
||||
0x087448, 0x0047E4, 0x043A20, 0x00542A, 0x087449, 0x00898C,
|
||||
};
|
||||
|
||||
static const uint8_t coef0_huffbits[HUFF_COEF0_SIZE] = {
|
||||
8, 7, 2, 3, 3, 4, 4,
|
||||
5, 5, 6, 6, 6, 6, 7,
|
||||
7, 7, 7, 7, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 10,
|
||||
10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 13,
|
||||
12, 12, 12, 12, 12, 12, 13,
|
||||
13, 13, 13, 13, 13, 13, 12,
|
||||
12, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 14, 14, 13, 13, 14,
|
||||
13, 13, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 13, 14,
|
||||
14, 14, 14, 14, 14, 14, 15,
|
||||
14, 15, 14, 14, 14, 14, 14,
|
||||
14, 15, 14, 14, 14, 14, 14,
|
||||
14, 14, 15, 15, 15, 15, 14,
|
||||
15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 4, 7,
|
||||
8, 9, 10, 10, 10, 11, 11,
|
||||
11, 12, 12, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 13, 14,
|
||||
15, 14, 14, 6, 9, 11, 12,
|
||||
12, 12, 13, 13, 13, 13, 14,
|
||||
14, 14, 14, 14, 14, 15, 15,
|
||||
15, 15, 7, 10, 12, 13, 14,
|
||||
14, 14, 15, 15, 15, 8, 11,
|
||||
13, 14, 15, 9, 12, 9, 13,
|
||||
10, 13, 10, 14, 11, 15, 11,
|
||||
15, 12, 15, 12, 15, 12, 16,
|
||||
12, 17, 13, 17, 13, 17, 13,
|
||||
18, 14, 17, 14, 19, 14, 18,
|
||||
14, 19, 14, 20, 15, 20, 15,
|
||||
21, 15, 20, 16, 21, 16,
|
||||
};
|
||||
|
||||
|
||||
#define HUFF_COEF1_SIZE 244
|
||||
#define HUFF_COEF1_MAXBITS 22
|
||||
static const uint32_t coef1_huffcodes[HUFF_COEF1_SIZE] = {
|
||||
0x0001E2, 0x00007F, 0x000000, 0x000002, 0x000008, 0x00000E, 0x000019,
|
||||
0x00002F, 0x000037, 0x000060, 0x00006C, 0x000095, 0x0000C6, 0x0000F0,
|
||||
0x00012E, 0x000189, 0x0001A5, 0x0001F8, 0x000253, 0x00030A, 0x000344,
|
||||
0x00034D, 0x0003F2, 0x0004BD, 0x0005D7, 0x00062A, 0x00068B, 0x000693,
|
||||
0x000797, 0x00097D, 0x000BAB, 0x000C52, 0x000C5E, 0x000D21, 0x000D20,
|
||||
0x000F1A, 0x000FCE, 0x000FD1, 0x0012F1, 0x001759, 0x0018AC, 0x0018A7,
|
||||
0x0018BF, 0x001A2B, 0x001E52, 0x001E50, 0x001E31, 0x001FB8, 0x0025E6,
|
||||
0x0025E7, 0x002EB4, 0x002EB7, 0x003169, 0x00315B, 0x00317C, 0x00316C,
|
||||
0x0034CA, 0x00348D, 0x003F40, 0x003CA2, 0x003F76, 0x004BC3, 0x004BE5,
|
||||
0x003F73, 0x004BF8, 0x004BF9, 0x006131, 0x00628B, 0x006289, 0x0062DA,
|
||||
0x00628A, 0x0062D4, 0x006997, 0x0062B4, 0x006918, 0x00794D, 0x007E7B,
|
||||
0x007E87, 0x007EEA, 0x00794E, 0x00699D, 0x007967, 0x00699F, 0x0062DB,
|
||||
0x007E7A, 0x007EEB, 0x00BAC0, 0x0097C9, 0x00C537, 0x00C5AB, 0x00D233,
|
||||
0x00D338, 0x00BAC1, 0x00D23D, 0x012F91, 0x00D339, 0x00FDC8, 0x00D23C,
|
||||
0x00FDDC, 0x00FDC9, 0x00FDDD, 0x00D33C, 0x000003, 0x000016, 0x00003E,
|
||||
0x0000C3, 0x0001A1, 0x000347, 0x00062E, 0x000BAA, 0x000F2D, 0x001A2A,
|
||||
0x001E58, 0x00309B, 0x003CA3, 0x005D6A, 0x00629A, 0x006996, 0x00794F,
|
||||
0x007EE5, 0x00BAD7, 0x00C5AA, 0x00C5F4, 0x00FDDF, 0x00FDDE, 0x018A20,
|
||||
0x018A6D, 0x01A67B, 0x01A464, 0x025F21, 0x01F9E2, 0x01F9E3, 0x00000A,
|
||||
0x00003D, 0x000128, 0x0003C7, 0x000C24, 0x0018A3, 0x002EB1, 0x003CB2,
|
||||
0x00691F, 0x007E79, 0x000013, 0x0000BB, 0x00034E, 0x000D14, 0x0025FD,
|
||||
0x004BE7, 0x000024, 0x000188, 0x0007EF, 0x000035, 0x000308, 0x0012F2,
|
||||
0x00005C, 0x0003F6, 0x0025E0, 0x00006D, 0x000698, 0x000096, 0x000C25,
|
||||
0x0000C7, 0x000F1B, 0x0000F3, 0x0012FF, 0x000174, 0x001A66, 0x0001A0,
|
||||
0x003099, 0x0001E4, 0x00316B, 0x000252, 0x003F31, 0x00030B, 0x004BE6,
|
||||
0x000346, 0x0062FB, 0x00034F, 0x007966, 0x0003F5, 0x007E86, 0x0005D4,
|
||||
0x00C511, 0x00062C, 0x00C5F5, 0x000692, 0x00F299, 0x000795, 0x00F298,
|
||||
0x0007E9, 0x018A21, 0x00097E, 0x0175AD, 0x000C27, 0x01A67A, 0x000C57,
|
||||
0x02EB59, 0x000D22, 0x0314D9, 0x000F19, 0x03F3C2, 0x000FCD, 0x0348CB,
|
||||
0x0012F8, 0x04BE41, 0x0018A0, 0x03F3C1, 0x0018A1, 0x04BE40, 0x0018B7,
|
||||
0x0629B0, 0x001A64, 0x0D2329, 0x001E30, 0x03F3C3, 0x001F9F, 0x0BAD62,
|
||||
0x001F99, 0x0FCF00, 0x00309A, 0x0629B1, 0x002EB6, 0x175AC3, 0x00314C,
|
||||
0x069195, 0x003168, 0x0BAD63, 0x00348E, 0x175AC1, 0x003F30, 0x07E781,
|
||||
0x003F41, 0x0D2328, 0x003F42, 0x1F9E03, 0x004BC2, 0x175AC2, 0x003F74,
|
||||
0x175AC0, 0x005D61, 0x3F3C05, 0x006130, 0x3F3C04, 0x0062B5,
|
||||
};
|
||||
|
||||
static const uint8_t coef1_huffbits[HUFF_COEF1_SIZE] = {
|
||||
9, 7, 2, 3, 4, 4, 5,
|
||||
6, 6, 7, 7, 8, 8, 8,
|
||||
9, 9, 9, 9, 10, 10, 10,
|
||||
10, 10, 11, 11, 11, 11, 11,
|
||||
11, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 14,
|
||||
14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 15, 15,
|
||||
14, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 17, 16, 16, 16,
|
||||
16, 16, 16, 16, 3, 5, 6,
|
||||
8, 9, 10, 11, 12, 12, 13,
|
||||
13, 14, 14, 15, 15, 15, 15,
|
||||
15, 16, 16, 16, 16, 16, 17,
|
||||
17, 17, 17, 18, 17, 17, 4,
|
||||
6, 9, 10, 12, 13, 14, 14,
|
||||
15, 15, 5, 8, 10, 12, 14,
|
||||
15, 6, 9, 11, 6, 10, 13,
|
||||
7, 10, 14, 7, 11, 8, 12,
|
||||
8, 12, 8, 13, 9, 13, 9,
|
||||
14, 9, 14, 10, 14, 10, 15,
|
||||
10, 15, 10, 15, 10, 15, 11,
|
||||
16, 11, 16, 11, 16, 11, 16,
|
||||
11, 17, 12, 17, 12, 17, 12,
|
||||
18, 12, 18, 12, 18, 12, 18,
|
||||
13, 19, 13, 18, 13, 19, 13,
|
||||
19, 13, 20, 13, 18, 13, 20,
|
||||
13, 20, 14, 19, 14, 21, 14,
|
||||
19, 14, 20, 14, 21, 14, 19,
|
||||
14, 20, 14, 21, 15, 21, 14,
|
||||
21, 15, 22, 15, 22, 15,
|
||||
};
|
||||
|
||||
|
||||
static const uint16_t coef0_run[HUFF_COEF0_SIZE] = {
|
||||
0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
|
||||
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
|
||||
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
|
||||
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
|
||||
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
|
||||
82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
|
||||
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
|
||||
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
|
||||
124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
|
||||
138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 0, 1,
|
||||
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
|
||||
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 1, 2, 3,
|
||||
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
|
||||
2, 3, 4, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0,
|
||||
};
|
||||
|
||||
static const float coef0_level[HUFF_COEF0_SIZE] = {
|
||||
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5,
|
||||
5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11,
|
||||
11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18,
|
||||
18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25,
|
||||
25, 26, 26, 27, 27, 28,
|
||||
};
|
||||
|
||||
|
||||
static const uint16_t coef1_run[HUFF_COEF1_SIZE] = {
|
||||
0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
|
||||
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
|
||||
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
|
||||
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5,
|
||||
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
|
||||
2, 3, 4, 5, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 0, 0,
|
||||
};
|
||||
|
||||
static const float coef1_level[HUFF_COEF1_SIZE] = {
|
||||
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4,
|
||||
4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10,
|
||||
10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19,
|
||||
19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28,
|
||||
28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37,
|
||||
37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46,
|
||||
46, 47, 47, 48, 48, 49, 49, 50, 51, 52,
|
||||
};
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @name Huffman and vector lookup tables for vector-coded coefficients
|
||||
* @{
|
||||
*/
|
||||
#define HUFF_VEC4_SIZE 127
|
||||
#define HUFF_VEC4_MAXBITS 14
|
||||
static const uint16_t vec4_huffcodes[HUFF_VEC4_SIZE] = {
|
||||
0x0019, 0x0027, 0x00F2, 0x03BA, 0x0930, 0x1267, 0x0031, 0x0030,
|
||||
0x0097, 0x0221, 0x058B, 0x0124, 0x00EB, 0x01D4, 0x03D8, 0x0584,
|
||||
0x0364, 0x045F, 0x0F66, 0x0931, 0x24CD, 0x002F, 0x0039, 0x00E8,
|
||||
0x02C3, 0x078A, 0x0037, 0x0029, 0x0084, 0x01B1, 0x00ED, 0x0086,
|
||||
0x00F9, 0x03AB, 0x01EB, 0x08BC, 0x011E, 0x00F3, 0x0220, 0x058A,
|
||||
0x00EC, 0x008E, 0x012B, 0x01EA, 0x0119, 0x04B0, 0x04B1, 0x03B8,
|
||||
0x0691, 0x0365, 0x01ED, 0x049A, 0x0EA9, 0x0EA8, 0x08BD, 0x24CC,
|
||||
0x0026, 0x0035, 0x00DB, 0x02C4, 0x07B2, 0x0038, 0x002B, 0x007F,
|
||||
0x01B3, 0x00F4, 0x0091, 0x0116, 0x03BB, 0x0215, 0x0932, 0x002D,
|
||||
0x002A, 0x008A, 0x01DE, 0x0028, 0x0020, 0x005C, 0x0090, 0x0068,
|
||||
0x01EE, 0x00E9, 0x008D, 0x012A, 0x0087, 0x005D, 0x0118, 0x0349,
|
||||
0x01EF, 0x01E3, 0x08B9, 0x00F0, 0x00D3, 0x0214, 0x049B, 0x00DA,
|
||||
0x0089, 0x0125, 0x0217, 0x012D, 0x0690, 0x0094, 0x007D, 0x011F,
|
||||
0x007E, 0x0059, 0x0127, 0x01A5, 0x0111, 0x00F8, 0x045D, 0x03B9,
|
||||
0x0259, 0x0580, 0x02C1, 0x01DF, 0x0585, 0x0216, 0x0163, 0x01B0,
|
||||
0x03C4, 0x08B8, 0x078B, 0x0755, 0x0581, 0x0F67, 0x0000,
|
||||
};
|
||||
|
||||
static const uint8_t vec4_huffbits[HUFF_VEC4_SIZE] = {
|
||||
5, 6, 8, 10, 12, 13, 6, 6,
|
||||
8, 10, 11, 9, 8, 9, 10, 11,
|
||||
10, 11, 12, 12, 14, 6, 6, 8,
|
||||
10, 11, 6, 6, 8, 9, 8, 8,
|
||||
8, 10, 9, 12, 9, 8, 10, 11,
|
||||
8, 8, 9, 9, 9, 11, 11, 10,
|
||||
11, 10, 9, 11, 12, 12, 12, 14,
|
||||
6, 6, 8, 10, 11, 6, 6, 7,
|
||||
9, 8, 8, 9, 10, 10, 12, 6,
|
||||
6, 8, 9, 6, 6, 7, 8, 7,
|
||||
9, 8, 8, 9, 8, 7, 9, 10,
|
||||
9, 9, 12, 8, 8, 10, 11, 8,
|
||||
8, 9, 10, 9, 11, 8, 7, 9,
|
||||
7, 7, 9, 9, 9, 8, 11, 10,
|
||||
10, 11, 10, 9, 11, 10, 9, 9,
|
||||
10, 12, 11, 11, 11, 12, 1,
|
||||
};
|
||||
|
||||
|
||||
#define HUFF_VEC2_SIZE 137
|
||||
#define HUFF_VEC2_MAXBITS 12
|
||||
static const uint16_t vec2_huffcodes[HUFF_VEC2_SIZE] = {
|
||||
0x055, 0x01C, 0x01A, 0x02B, 0x028, 0x067, 0x08B, 0x039,
|
||||
0x170, 0x10D, 0x2A5, 0x047, 0x464, 0x697, 0x523, 0x8CB,
|
||||
0x01B, 0x00E, 0x000, 0x010, 0x012, 0x036, 0x048, 0x04C,
|
||||
0x0C2, 0x09B, 0x171, 0x03B, 0x224, 0x34A, 0x2D6, 0x019,
|
||||
0x00F, 0x002, 0x014, 0x017, 0x006, 0x05D, 0x054, 0x0C7,
|
||||
0x0B4, 0x192, 0x10E, 0x233, 0x043, 0x02C, 0x00F, 0x013,
|
||||
0x006, 0x02F, 0x02C, 0x068, 0x077, 0x0DF, 0x111, 0x1A4,
|
||||
0x16A, 0x2A4, 0x027, 0x011, 0x018, 0x02D, 0x00F, 0x04A,
|
||||
0x040, 0x097, 0x01F, 0x11B, 0x022, 0x16D, 0x066, 0x035,
|
||||
0x005, 0x02B, 0x049, 0x009, 0x075, 0x0CB, 0x0AA, 0x187,
|
||||
0x106, 0x08A, 0x047, 0x060, 0x06E, 0x01D, 0x074, 0x0C4,
|
||||
0x01E, 0x118, 0x1A7, 0x038, 0x042, 0x053, 0x076, 0x0A8,
|
||||
0x0CA, 0x082, 0x110, 0x18D, 0x12D, 0x0B9, 0x0C8, 0x0DE,
|
||||
0x01C, 0x0AB, 0x113, 0x18C, 0x10F, 0x09A, 0x0A5, 0x0B7,
|
||||
0x11A, 0x186, 0x1A6, 0x259, 0x153, 0x18A, 0x193, 0x020,
|
||||
0x10C, 0x046, 0x03A, 0x107, 0x149, 0x16C, 0x2D7, 0x225,
|
||||
0x258, 0x316, 0x696, 0x317, 0x042, 0x522, 0x290, 0x8CA,
|
||||
0x001,
|
||||
};
|
||||
|
||||
static const uint8_t vec2_huffbits[HUFF_VEC2_SIZE] = {
|
||||
7, 6, 6, 6, 7, 7, 8, 9,
|
||||
9, 10, 10, 11, 11, 11, 12, 12,
|
||||
6, 4, 5, 5, 6, 6, 7, 8,
|
||||
8, 9, 9, 10, 10, 10, 11, 6,
|
||||
4, 5, 5, 6, 7, 7, 8, 8,
|
||||
9, 9, 10, 10, 11, 6, 5, 5,
|
||||
6, 6, 7, 7, 8, 8, 9, 9,
|
||||
10, 10, 7, 6, 6, 6, 7, 7,
|
||||
8, 8, 9, 9, 10, 10, 7, 6,
|
||||
7, 7, 7, 8, 8, 8, 9, 9,
|
||||
10, 8, 7, 7, 7, 8, 8, 8,
|
||||
9, 9, 9, 9, 8, 8, 8, 8,
|
||||
8, 9, 9, 9, 9, 8, 8, 8,
|
||||
9, 9, 9, 9, 10, 9, 9, 9,
|
||||
9, 9, 9, 10, 9, 9, 9, 10,
|
||||
10, 11, 10, 10, 10, 10, 11, 10,
|
||||
10, 10, 11, 10, 11, 12, 11, 12,
|
||||
3,
|
||||
};
|
||||
|
||||
|
||||
#define HUFF_VEC1_SIZE 101
|
||||
#define HUFF_VEC1_MAXBITS 11
|
||||
static const uint16_t vec1_huffcodes[HUFF_VEC1_SIZE] = {
|
||||
0x01A, 0x003, 0x017, 0x010, 0x00C, 0x009, 0x005, 0x000,
|
||||
0x00D, 0x00A, 0x009, 0x00C, 0x00F, 0x002, 0x004, 0x007,
|
||||
0x00B, 0x00F, 0x01C, 0x006, 0x010, 0x015, 0x01C, 0x022,
|
||||
0x03B, 0x00E, 0x019, 0x023, 0x034, 0x036, 0x03A, 0x047,
|
||||
0x008, 0x00A, 0x01E, 0x031, 0x037, 0x050, 0x053, 0x06B,
|
||||
0x06F, 0x08C, 0x0E8, 0x0EA, 0x0EB, 0x016, 0x03E, 0x03F,
|
||||
0x06C, 0x089, 0x08A, 0x0A3, 0x0A4, 0x0D4, 0x0DD, 0x0EC,
|
||||
0x0EE, 0x11A, 0x1D2, 0x024, 0x025, 0x02E, 0x027, 0x0C2,
|
||||
0x0C0, 0x0DA, 0x0DB, 0x111, 0x144, 0x116, 0x14A, 0x145,
|
||||
0x1B8, 0x1AB, 0x1DA, 0x1DE, 0x1DB, 0x1DF, 0x236, 0x237,
|
||||
0x3A6, 0x3A7, 0x04D, 0x04C, 0x05E, 0x05F, 0x183, 0x182,
|
||||
0x186, 0x221, 0x187, 0x220, 0x22E, 0x22F, 0x296, 0x354,
|
||||
0x297, 0x355, 0x372, 0x373, 0x016,
|
||||
};
|
||||
|
||||
static const uint8_t vec1_huffbits[HUFF_VEC1_SIZE] = {
|
||||
7, 6, 5, 5, 5, 5, 5, 5,
|
||||
4, 4, 4, 4, 4, 5, 5, 5,
|
||||
5, 5, 5, 6, 6, 6, 6, 6,
|
||||
6, 7, 7, 7, 7, 7, 7, 7,
|
||||
8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 5,
|
||||
};
|
||||
|
||||
|
||||
static const uint16_t symbol_to_vec4[HUFF_VEC4_SIZE] = {
|
||||
0, 1, 2, 3, 4, 5, 16, 17, 18, 19,
|
||||
20, 32, 33, 34, 35, 48, 49, 50, 64, 65,
|
||||
80, 256, 257, 258, 259, 260, 272, 273, 274, 275,
|
||||
288, 289, 290, 304, 305, 320, 512, 513, 514, 515,
|
||||
528, 529, 530, 544, 545, 560, 768, 769, 770, 784,
|
||||
785, 800, 1024, 1025, 1040, 1280, 4096, 4097, 4098, 4099,
|
||||
4100, 4112, 4113, 4114, 4115, 4128, 4129, 4130, 4144, 4145,
|
||||
4160, 4352, 4353, 4354, 4355, 4368, 4369, 4370, 4384, 4385,
|
||||
4400, 4608, 4609, 4610, 4624, 4625, 4640, 4864, 4865, 4880,
|
||||
5120, 8192, 8193, 8194, 8195, 8208, 8209, 8210, 8224, 8225,
|
||||
8240, 8448, 8449, 8450, 8464, 8465, 8480, 8704, 8705, 8720,
|
||||
8960, 12288, 12289, 12290, 12304, 12305, 12320, 12544, 12545, 12560,
|
||||
12800, 16384, 16385, 16400, 16640, 20480, 0,
|
||||
};
|
||||
|
||||
|
||||
static const uint8_t symbol_to_vec2[HUFF_VEC2_SIZE] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
|
||||
30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 64, 65,
|
||||
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 80, 81, 82, 83, 84,
|
||||
85, 86, 87, 88, 89, 90, 96, 97, 98, 99, 100, 101, 102, 103, 104,
|
||||
105, 112, 113, 114, 115, 116, 117, 118, 119, 120, 128, 129, 130, 131, 132,
|
||||
133, 134, 135, 144, 145, 146, 147, 148, 149, 150, 160, 161, 162, 163, 164,
|
||||
165, 176, 177, 178, 179, 180, 192, 193, 194, 195, 208, 209, 210, 224, 225,
|
||||
240, 0,
|
||||
};
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @brief decorrelation matrix for multichannel streams
|
||||
**/
|
||||
static const float default_decorrelation_matrices[] = {
|
||||
1.000000, 0.707031, -0.707031, 0.707031, 0.707031, 0.578125, 0.707031,
|
||||
0.410156, 0.578125, -0.707031, 0.410156, 0.578125, 0.000000, -0.816406,
|
||||
0.500000, 0.652344, 0.500000, 0.269531, 0.500000, 0.269531, -0.500000,
|
||||
-0.652344, 0.500000, -0.269531, -0.500000, 0.652344, 0.500000, -0.652344,
|
||||
0.500000, -0.269531, 0.445312, 0.601562, 0.511719, 0.371094, 0.195312,
|
||||
0.445312, 0.371094, -0.195312, -0.601562, -0.511719, 0.445312, 0.000000,
|
||||
-0.632812, 0.000000, 0.632812, 0.445312, -0.371094, -0.195312, 0.601562,
|
||||
-0.511719, 0.445312, -0.601562, 0.511719, -0.371094, 0.195312, 0.410156,
|
||||
0.558594, 0.500000, 0.410156, 0.289062, 0.148438, 0.410156, 0.410156,
|
||||
0.000000, -0.410156, -0.578125, -0.410156, 0.410156, 0.148438, -0.500000,
|
||||
-0.410156, 0.289062, 0.558594, 0.410156, -0.148438, -0.500000, 0.410156,
|
||||
0.289062, -0.558594, 0.410156, -0.410156, 0.000000, 0.410156, -0.578125,
|
||||
0.410156, 0.410156, -0.558594, 0.500000, -0.410156, 0.289062, -0.148438,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief default decorrelation matrix offsets
|
||||
*/
|
||||
static const float * const default_decorrelation[] = {
|
||||
NULL,
|
||||
&default_decorrelation_matrices[0],
|
||||
&default_decorrelation_matrices[1],
|
||||
&default_decorrelation_matrices[5],
|
||||
&default_decorrelation_matrices[14],
|
||||
&default_decorrelation_matrices[30],
|
||||
&default_decorrelation_matrices[55]
|
||||
};
|
||||
|
||||
#endif /* AVCODEC_WMAPRODATA_H */
|
1594
apps/codecs/libwmapro/wmaprodec.c
Normal file
1594
apps/codecs/libwmapro/wmaprodec.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue