3
3
* Copyright (c) 2000, 2001 Fabrice Bellard.
4
4
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6
* alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
6
8
* This file is part of FFmpeg.
8
10
* FFmpeg is free software; you can redistribute it and/or
18
20
* You should have received a copy of the GNU Lesser General Public
19
21
* License along with FFmpeg; if not, write to the Free Software
20
22
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
* alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
36
36
* @param[in] ptr The block of memory to reallocate.
37
37
* @param[in] size The requested size.
38
38
* @return Block of memory of requested size.
39
* @deprecated. Code which uses ff_realloc_static is broken/misdesigned
40
* and should correctly use static arrays
42
attribute_deprecated av_alloc_size(2)
40
43
void *ff_realloc_static(void *ptr, unsigned int size);
42
45
void align_put_bits(PutBitContext *s)
58
61
put_bits(pbc, 8, 0);
64
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
66
const uint16_t *srcw= (const uint16_t*)src;
73
if(ENABLE_SMALL || words < 16 || put_bits_count(pb)&7){
74
for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
76
for(i=0; put_bits_count(pb)&31; i++)
77
put_bits(pb, 8, src[i]);
79
memcpy(pbBufPtr(pb), src+i, 2*words-i);
80
skip_put_bytes(pb, 2*words-i);
83
put_bits(pb, bits, be2me_16(srcw[words])>>(16-bits));
63
88
//#define DEBUG_VLC
103
128
const void *bits, int bits_wrap, int bits_size,
104
129
const void *codes, int codes_wrap, int codes_size,
130
const void *symbols, int symbols_wrap, int symbols_size,
105
131
uint32_t code_prefix, int n_prefix, int flags)
107
int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2;
133
int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol;
109
135
VLC_TYPE (*table)[2];
111
137
table_size = 1 << table_nb_bits;
112
138
table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_STATIC);
114
printf("new table index=%d size=%d code_prefix=%x n=%d\n",
140
av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n",
115
141
table_index, table_size, code_prefix, n_prefix);
117
143
if (table_index < 0)
130
156
/* we accept tables with holes */
162
GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
133
163
#if defined(DEBUG_VLC) && 0
134
printf("i=%d n=%d code=0x%x\n", i, n, code);
164
av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
136
166
/* if code matches the prefix, it is in the table */
158
188
table[j][1] = n; //bits
159
table[j][0] = i; //code
189
table[j][0] = symbol;
163
193
n -= table_nb_bits;
164
194
j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
166
printf("%4x: n=%d (subtable)\n",
196
av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n",
169
199
/* compute table size */
187
217
index = build_table(vlc, n, nb_codes,
188
218
bits, bits_wrap, bits_size,
189
219
codes, codes_wrap, codes_size,
220
symbols, symbols_wrap, symbols_size,
190
221
(flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i),
191
222
n_prefix + table_nb_bits, flags);
213
244
'codes' : table which gives the bit pattern of of each vlc code.
246
'symbols' : table which gives the values to be returned from get_vlc().
215
248
'xxx_wrap' : give the number of bytes between each entry of the
216
249
'bits' or 'codes' tables.
219
252
or 'codes' tables.
221
254
'wrap' and 'size' allows to use any memory configuration and types
222
(byte/word/long) to store the 'bits' and 'codes' tables.
255
(byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
224
257
'use_static' should be set to 1 for tables, which should be freed
225
258
with av_free_static(), 0 if free_vlc() will be used.
227
int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
260
int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
228
261
const void *bits, int bits_wrap, int bits_size,
229
262
const void *codes, int codes_wrap, int codes_size,
263
const void *symbols, int symbols_wrap, int symbols_size,
232
266
vlc->bits = nb_bits;
267
if(!(flags & INIT_VLC_USE_STATIC)) {
234
268
vlc->table = NULL;
235
269
vlc->table_allocated = 0;
236
270
vlc->table_size = 0;
245
printf("build table nb_codes=%d\n", nb_codes);
279
av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
248
282
if (build_table(vlc, nb_bits, nb_codes,
249
283
bits, bits_wrap, bits_size,
250
284
codes, codes_wrap, codes_size,
251
0, 0, use_static) < 0) {
285
symbols, symbols_wrap, symbols_size,
287
av_freep(&vlc->table);