diff options
Diffstat (limited to 'apps/codecs/libcook/bitstream.c')
-rw-r--r-- | apps/codecs/libcook/bitstream.c | 85 |
1 files changed, 19 insertions, 66 deletions
diff --git a/apps/codecs/libcook/bitstream.c b/apps/codecs/libcook/bitstream.c index 4bc706ffb7..1375134b21 100644 --- a/apps/codecs/libcook/bitstream.c +++ b/apps/codecs/libcook/bitstream.c | |||
@@ -22,13 +22,13 @@ | |||
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | */ | 23 | */ |
24 | 24 | ||
25 | /** | ||
26 | * @file libavcodec/bitstream.c | ||
27 | * bitstream api. | ||
28 | */ | ||
29 | |||
30 | #include "bitstream.h" | 25 | #include "bitstream.h" |
31 | 26 | ||
27 | #ifdef ROCKBOX | ||
28 | #undef DEBUGF | ||
29 | #define DEBUGF(...) | ||
30 | #endif | ||
31 | |||
32 | const uint8_t ff_log2_run[32]={ | 32 | const uint8_t ff_log2_run[32]={ |
33 | 0, 0, 0, 0, 1, 1, 1, 1, | 33 | 0, 0, 0, 0, 1, 1, 1, 1, |
34 | 2, 2, 2, 2, 3, 3, 3, 3, | 34 | 2, 2, 2, 2, 3, 3, 3, 3, |
@@ -46,24 +46,6 @@ const uint8_t ff_log2_run[32]={ | |||
46 | * and should correctly use static arrays | 46 | * and should correctly use static arrays |
47 | */ | 47 | */ |
48 | 48 | ||
49 | #if 0 | ||
50 | attribute_deprecated av_alloc_size(2) | ||
51 | static void *ff_realloc_static(void *ptr, unsigned int size); | ||
52 | |||
53 | static void *ff_realloc_static(void *ptr, unsigned int size) | ||
54 | { | ||
55 | return av_realloc(ptr, size); | ||
56 | } | ||
57 | |||
58 | void align_put_bits(PutBitContext *s) | ||
59 | { | ||
60 | #ifdef ALT_BITSTREAM_WRITER | ||
61 | put_bits(s,( - s->index) & 7,0); | ||
62 | #else | ||
63 | put_bits(s,s->bit_left & 7,0); | ||
64 | #endif | ||
65 | } | ||
66 | #endif | ||
67 | 49 | ||
68 | void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) | 50 | void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) |
69 | { | 51 | { |
@@ -75,30 +57,6 @@ void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) | |||
75 | put_bits(pbc, 8, 0); | 57 | put_bits(pbc, 8, 0); |
76 | } | 58 | } |
77 | 59 | ||
78 | #if 0 | ||
79 | void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) | ||
80 | { | ||
81 | const uint16_t *srcw= (const uint16_t*)src; | ||
82 | int words= length>>4; | ||
83 | int bits= length&15; | ||
84 | int i; | ||
85 | |||
86 | if(length==0) return; | ||
87 | |||
88 | if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){ | ||
89 | for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(&srcw[i])); | ||
90 | }else{ | ||
91 | for(i=0; put_bits_count(pb)&31; i++) | ||
92 | put_bits(pb, 8, src[i]); | ||
93 | flush_put_bits(pb); | ||
94 | memcpy(pbBufPtr(pb), src+i, 2*words-i); | ||
95 | skip_put_bytes(pb, 2*words-i); | ||
96 | } | ||
97 | |||
98 | put_bits(pb, bits, AV_RB16(&srcw[words])>>(16-bits)); | ||
99 | } | ||
100 | #endif | ||
101 | |||
102 | /* VLC decoding */ | 60 | /* VLC decoding */ |
103 | 61 | ||
104 | //#define DEBUG_VLC | 62 | //#define DEBUG_VLC |
@@ -127,8 +85,7 @@ static int alloc_table(VLC *vlc, int size, int use_static) | |||
127 | vlc->table_size += size; | 85 | vlc->table_size += size; |
128 | if (vlc->table_size > vlc->table_allocated) { | 86 | if (vlc->table_size > vlc->table_allocated) { |
129 | if(use_static>1){ | 87 | if(use_static>1){ |
130 | printf("init_vlc() used with too little memory : table_size > allocated_memory\n"); | 88 | DEBUGF("init_vlc() used with too little memory : table_size > allocated_memory\n"); |
131 | abort(); //cant do anything, init_vlc() is used with too little memory | ||
132 | } | 89 | } |
133 | 90 | ||
134 | if (!vlc->table) | 91 | if (!vlc->table) |
@@ -151,7 +108,7 @@ static int build_table(VLC *vlc, int table_nb_bits, | |||
151 | table_size = 1 << table_nb_bits; | 108 | table_size = 1 << table_nb_bits; |
152 | table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); | 109 | table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); |
153 | #ifdef DEBUG_VLC | 110 | #ifdef DEBUG_VLC |
154 | printf("new table index=%d size=%d code_prefix=%x n=%d\n", | 111 | DEBUGF("new table index=%d size=%d code_prefix=%x n=%d\n", |
155 | table_index, table_size, code_prefix, n_prefix); | 112 | table_index, table_size, code_prefix, n_prefix); |
156 | #endif | 113 | #endif |
157 | if (table_index < 0) | 114 | if (table_index < 0) |
@@ -175,15 +132,15 @@ static int build_table(VLC *vlc, int table_nb_bits, | |||
175 | else | 132 | else |
176 | GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); | 133 | GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); |
177 | #if defined(DEBUG_VLC) && 0 | 134 | #if defined(DEBUG_VLC) && 0 |
178 | printf("i=%d n=%d code=0x%x\n", i, n, code); | 135 | DEBUGF("i=%d n=%d code=0x%x\n", i, n, code); |
179 | #endif | 136 | #endif |
180 | /* if code matches the prefix, it is in the table */ | 137 | /* if code matches the prefix, it is in the table */ |
181 | n -= n_prefix; | 138 | n -= n_prefix; |
182 | if(flags & INIT_VLC_LE) | 139 | if(flags & INIT_VLC_LE) |
183 | code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1); | 140 | code_prefix2= code & (n_prefix>=32 ? (int)0xffffffff : (1 << n_prefix)-1); |
184 | else | 141 | else |
185 | code_prefix2= code >> n; | 142 | code_prefix2= code >> n; |
186 | if (n > 0 && code_prefix2 == code_prefix) { | 143 | if (n > 0 && code_prefix2 == (int)code_prefix) { |
187 | if (n <= table_nb_bits) { | 144 | if (n <= table_nb_bits) { |
188 | /* no need to add another table */ | 145 | /* no need to add another table */ |
189 | j = (code << (table_nb_bits - n)) & (table_size - 1); | 146 | j = (code << (table_nb_bits - n)) & (table_size - 1); |
@@ -192,11 +149,11 @@ static int build_table(VLC *vlc, int table_nb_bits, | |||
192 | if(flags & INIT_VLC_LE) | 149 | if(flags & INIT_VLC_LE) |
193 | j = (code >> n_prefix) + (k<<n); | 150 | j = (code >> n_prefix) + (k<<n); |
194 | #ifdef DEBUG_VLC | 151 | #ifdef DEBUG_VLC |
195 | printf("%4x: code=%d n=%d\n", | 152 | DEBUGF("%4x: code=%d n=%d\n", |
196 | j, i, n); | 153 | j, i, n); |
197 | #endif | 154 | #endif |
198 | if (table[j][1] /*bits*/ != 0) { | 155 | if (table[j][1] /*bits*/ != 0) { |
199 | printf("incorrect codes\n"); | 156 | DEBUGF("incorrect codes\n"); |
200 | return -1; | 157 | return -1; |
201 | } | 158 | } |
202 | table[j][1] = n; //bits | 159 | table[j][1] = n; //bits |
@@ -207,7 +164,7 @@ static int build_table(VLC *vlc, int table_nb_bits, | |||
207 | n -= table_nb_bits; | 164 | n -= table_nb_bits; |
208 | j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); | 165 | j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); |
209 | #ifdef DEBUG_VLC | 166 | #ifdef DEBUG_VLC |
210 | printf("%4x: n=%d (subtable)\n", | 167 | DEBUGF("%4x: n=%d (subtable)\n", |
211 | j, n); | 168 | j, n); |
212 | #endif | 169 | #endif |
213 | /* compute table size */ | 170 | /* compute table size */ |
@@ -282,7 +239,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | |||
282 | if(vlc->table_size && vlc->table_size == vlc->table_allocated){ | 239 | if(vlc->table_size && vlc->table_size == vlc->table_allocated){ |
283 | return 0; | 240 | return 0; |
284 | }else if(vlc->table_size){ | 241 | }else if(vlc->table_size){ |
285 | abort(); // fatal error, we are called on a partially initialized table | 242 | return -1; // fatal error, we are called on a partially initialized table |
286 | } | 243 | } |
287 | }else if(!(flags & INIT_VLC_USE_STATIC)) { | 244 | }else if(!(flags & INIT_VLC_USE_STATIC)) { |
288 | vlc->table = NULL; | 245 | vlc->table = NULL; |
@@ -296,7 +253,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | |||
296 | } | 253 | } |
297 | 254 | ||
298 | #ifdef DEBUG_VLC | 255 | #ifdef DEBUG_VLC |
299 | printf("build table nb_codes=%d\n", nb_codes); | 256 | DEBUGF("build table nb_codes=%d\n", nb_codes); |
300 | #endif | 257 | #endif |
301 | 258 | ||
302 | if (build_table(vlc, nb_bits, nb_codes, | 259 | if (build_table(vlc, nb_bits, nb_codes, |
@@ -304,20 +261,16 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | |||
304 | codes, codes_wrap, codes_size, | 261 | codes, codes_wrap, codes_size, |
305 | symbols, symbols_wrap, symbols_size, | 262 | symbols, symbols_wrap, symbols_size, |
306 | 0, 0, flags) < 0) { | 263 | 0, 0, flags) < 0) { |
307 | free(&vlc->table); | 264 | //free(&vlc->table); |
308 | return -1; | 265 | return -1; |
309 | } | 266 | } |
310 | /* Changed the following condition to be true if table_size > table_allocated. * | 267 | /* Changed the following condition to be true if table_size > table_allocated. * |
311 | * This would be more sensible for static tables since we want warnings for * | 268 | * This would be more sensible for static tables since we want warnings for * |
312 | * memory shortages only. */ | 269 | * memory shortages only. */ |
270 | #ifdef TEST | ||
313 | if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated) | 271 | if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated) |
314 | printf("needed %d had %d\n", vlc->table_size, vlc->table_allocated); | 272 | DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated); |
273 | #endif | ||
315 | return 0; | 274 | return 0; |
316 | } | 275 | } |
317 | 276 | ||
318 | |||
319 | void free_vlc(VLC *vlc) | ||
320 | { | ||
321 | free(&vlc->table); | ||
322 | } | ||
323 | |||