Mercurial > libavcodec.hg
annotate wma.h @ 9592:05661d19f6d2 libavcodec
Check whether extra bits block has enough data.
Patch by Laurent Aimar "f\145nr\151r >at< vide\157lan <dot> o\162g"
author | kostya |
---|---|
date | Sun, 03 May 2009 05:42:51 +0000 |
parents | 0dce4fe6e6f3 |
children | 39bb2646fe00 |
rev | line source |
---|---|
4490 | 1 /* |
2 * WMA compatible codec | |
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
7760
diff
changeset
|
3 * Copyright (c) 2002-2007 The FFmpeg Project |
4490 | 4 * |
5 * This file is part of FFmpeg. | |
6 * | |
7 * FFmpeg is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2.1 of the License, or (at your option) any later version. | |
11 * | |
12 * FFmpeg is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with FFmpeg; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 */ | |
21 | |
7760 | 22 #ifndef AVCODEC_WMA_H |
23 #define AVCODEC_WMA_H | |
4490 | 24 |
9428 | 25 #include "get_bits.h" |
9411
4cb7c65fc775
Split bitstream.h, put the bitstream writer stuff in the new file
stefano
parents:
8629
diff
changeset
|
26 #include "put_bits.h" |
4490 | 27 #include "dsputil.h" |
28 | |
29 /* size of blocks */ | |
30 #define BLOCK_MIN_BITS 7 | |
31 #define BLOCK_MAX_BITS 11 | |
32 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS) | |
33 | |
34 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1) | |
35 | |
36 /* XXX: find exact max size */ | |
37 #define HIGH_BAND_MAX_SIZE 16 | |
38 | |
39 #define NB_LSP_COEFS 10 | |
40 | |
41 /* XXX: is it a suitable value ? */ | |
42 #define MAX_CODED_SUPERFRAME_SIZE 16384 | |
43 | |
44 #define MAX_CHANNELS 2 | |
45 | |
46 #define NOISE_TAB_SIZE 8192 | |
47 | |
48 #define LSP_POW_BITS 7 | |
49 | |
50 //FIXME should be in wmadec | |
51 #define VLCBITS 9 | |
52 #define VLCMAX ((22+VLCBITS-1)/VLCBITS) | |
53 | |
54 typedef struct CoefVLCTable { | |
4497 | 55 int n; ///< total number of codes |
4490 | 56 int max_level; |
4497 | 57 const uint32_t *huffcodes; ///< VLC bit values |
58 const uint8_t *huffbits; ///< VLC bit size | |
59 const uint16_t *levels; ///< table to build run/level tables | |
4490 | 60 } CoefVLCTable; |
61 | |
4601 | 62 typedef struct WMACodecContext { |
4600 | 63 AVCodecContext* avctx; |
4490 | 64 GetBitContext gb; |
65 PutBitContext pb; | |
66 int sample_rate; | |
67 int nb_channels; | |
68 int bit_rate; | |
4497 | 69 int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) |
4490 | 70 int block_align; |
71 int use_bit_reservoir; | |
72 int use_variable_block_len; | |
4497 | 73 int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta |
74 int use_noise_coding; ///< true if perceptual noise is added | |
4490 | 75 int byte_offset_bits; |
76 VLC exp_vlc; | |
77 int exponent_sizes[BLOCK_NB_SIZES]; | |
78 uint16_t exponent_bands[BLOCK_NB_SIZES][25]; | |
4497 | 79 int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band |
80 int coefs_start; ///< first coded coef | |
81 int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients | |
4490 | 82 int exponent_high_sizes[BLOCK_NB_SIZES]; |
83 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]; | |
84 VLC hgain_vlc; | |
85 | |
86 /* coded values in high bands */ | |
87 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; | |
88 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; | |
89 | |
90 /* there are two possible tables for spectral coefficients */ | |
91 //FIXME the following 3 tables should be shared between decoders | |
92 VLC coef_vlc[2]; | |
93 uint16_t *run_table[2]; | |
94 uint16_t *level_table[2]; | |
95 uint16_t *int_table[2]; | |
5258 | 96 const CoefVLCTable *coef_vlcs[2]; |
4490 | 97 /* frame info */ |
4497 | 98 int frame_len; ///< frame length in samples |
99 int frame_len_bits; ///< frame_len = 1 << frame_len_bits | |
100 int nb_block_sizes; ///< number of block sizes | |
4490 | 101 /* block info */ |
102 int reset_block_lengths; | |
4497 | 103 int block_len_bits; ///< log2 of current block length |
104 int next_block_len_bits; ///< log2 of next block length | |
105 int prev_block_len_bits; ///< log2 of prev block length | |
106 int block_len; ///< block length in samples | |
107 int block_num; ///< block number in current frame | |
108 int block_pos; ///< current position in frame | |
109 uint8_t ms_stereo; ///< true if mid/side stereo mode | |
110 uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded | |
4785
4ae9ab738aec
WMA decoder improvement, output closer to the dmo binary.
banan
parents:
4737
diff
changeset
|
111 int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length |
4490 | 112 DECLARE_ALIGNED_16(float, exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]); |
113 float max_exponent[MAX_CHANNELS]; | |
114 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; | |
115 DECLARE_ALIGNED_16(float, coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]); | |
116 DECLARE_ALIGNED_16(FFTSample, output[BLOCK_MAX_SIZE * 2]); | |
117 MDCTContext mdct_ctx[BLOCK_NB_SIZES]; | |
118 float *windows[BLOCK_NB_SIZES]; | |
119 /* output buffer for one frame and the last for IMDCT windowing */ | |
120 DECLARE_ALIGNED_16(float, frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]); | |
121 /* last frame info */ | |
122 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */ | |
123 int last_bitoffset; | |
124 int last_superframe_len; | |
125 float noise_table[NOISE_TAB_SIZE]; | |
126 int noise_index; | |
127 float noise_mult; /* XXX: suppress that and integrate it in the noise array */ | |
128 /* lsp_to_curve tables */ | |
129 float lsp_cos_table[BLOCK_MAX_SIZE]; | |
130 float lsp_pow_e_table[256]; | |
131 float lsp_pow_m_table1[(1 << LSP_POW_BITS)]; | |
132 float lsp_pow_m_table2[(1 << LSP_POW_BITS)]; | |
133 DSPContext dsp; | |
134 | |
135 #ifdef TRACE | |
136 int frame_count; | |
137 #endif | |
4601 | 138 } WMACodecContext; |
4490 | 139 |
140 extern const uint16_t ff_wma_hgain_huffcodes[37]; | |
141 extern const uint8_t ff_wma_hgain_huffbits[37]; | |
142 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]; | |
143 extern const uint32_t ff_wma_scale_huffcodes[121]; | |
144 extern const uint8_t ff_wma_scale_huffbits[121]; | |
145 | |
146 int ff_wma_init(AVCodecContext * avctx, int flags2); | |
147 int ff_wma_total_gain_to_bits(int total_gain); | |
148 int ff_wma_end(AVCodecContext *avctx); | |
149 | |
7760 | 150 #endif /* AVCODEC_WMA_H */ |