OLD | NEW |
1 /* | 1 /* |
2 * Common bit i/o utils | 2 * Common bit i/o utils |
3 * Copyright (c) 2000, 2001 Fabrice Bellard | 3 * Copyright (c) 2000, 2001 Fabrice Bellard |
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | 4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
5 * | 5 * |
6 * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.a
t> | 6 * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.a
t> |
7 * | 7 * |
8 * This file is part of FFmpeg. | 8 * This file is part of FFmpeg. |
9 * | 9 * |
10 * FFmpeg is free software; you can redistribute it and/or | 10 * FFmpeg is free software; you can redistribute it and/or |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 continue; | 151 continue; |
152 if (!symbols) | 152 if (!symbols) |
153 symbol = i; | 153 symbol = i; |
154 else | 154 else |
155 GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); | 155 GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); |
156 #if defined(DEBUG_VLC) && 0 | 156 #if defined(DEBUG_VLC) && 0 |
157 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code); | 157 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code); |
158 #endif | 158 #endif |
159 /* if code matches the prefix, it is in the table */ | 159 /* if code matches the prefix, it is in the table */ |
160 n -= n_prefix; | 160 n -= n_prefix; |
161 if(flags & INIT_VLC_LE) | 161 if (n > 0) { |
162 code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1)
; | 162 if(flags & INIT_VLC_LE) |
163 else | 163 code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix
)-1); |
164 code_prefix2= code >> n; | 164 else |
165 if (n > 0 && code_prefix2 == code_prefix) { | 165 code_prefix2= code >> n; |
166 if (n <= table_nb_bits) { | 166 if (code_prefix2 == code_prefix) { |
167 /* no need to add another table */ | 167 if (n <= table_nb_bits) { |
168 j = (code << (table_nb_bits - n)) & (table_size - 1); | 168 /* no need to add another table */ |
169 nb = 1 << (table_nb_bits - n); | 169 j = (code << (table_nb_bits - n)) & (table_size - 1); |
170 for(k=0;k<nb;k++) { | 170 nb = 1 << (table_nb_bits - n); |
171 if(flags & INIT_VLC_LE) | 171 for(k=0;k<nb;k++) { |
172 j = (code >> n_prefix) + (k<<n); | 172 if(flags & INIT_VLC_LE) |
| 173 j = (code >> n_prefix) + (k<<n); |
173 #ifdef DEBUG_VLC | 174 #ifdef DEBUG_VLC |
174 av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", | 175 av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", |
175 j, i, n); | 176 j, i, n); |
176 #endif | 177 #endif |
177 if (table[j][1] /*bits*/ != 0) { | 178 if (table[j][1] /*bits*/ != 0) { |
178 av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); | 179 av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); |
179 return -1; | 180 return -1; |
| 181 } |
| 182 table[j][1] = n; //bits |
| 183 table[j][0] = symbol; |
| 184 j++; |
180 } | 185 } |
181 table[j][1] = n; //bits | 186 } else { |
182 table[j][0] = symbol; | 187 n -= table_nb_bits; |
183 j++; | 188 j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 <
< table_nb_bits) - 1); |
| 189 #ifdef DEBUG_VLC |
| 190 av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", |
| 191 j, n); |
| 192 #endif |
| 193 /* compute table size */ |
| 194 n1 = -table[j][1]; //bits |
| 195 if (n > n1) |
| 196 n1 = n; |
| 197 table[j][1] = -n1; //bits |
184 } | 198 } |
185 } else { | |
186 n -= table_nb_bits; | |
187 j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << ta
ble_nb_bits) - 1); | |
188 #ifdef DEBUG_VLC | |
189 av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", | |
190 j, n); | |
191 #endif | |
192 /* compute table size */ | |
193 n1 = -table[j][1]; //bits | |
194 if (n > n1) | |
195 n1 = n; | |
196 table[j][1] = -n1; //bits | |
197 } | 199 } |
198 } | 200 } |
199 } | 201 } |
200 | 202 |
201 /* second pass : fill auxillary tables recursively */ | 203 /* second pass : fill auxillary tables recursively */ |
202 for(i=0;i<table_size;i++) { | 204 for(i=0;i<table_size;i++) { |
203 n = table[i][1]; //bits | 205 n = table[i][1]; //bits |
204 if (n < 0) { | 206 if (n < 0) { |
205 n = -n; | 207 n = -n; |
206 if (n > table_nb_bits) { | 208 if (n > table_nb_bits) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->t
able_allocated); | 287 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->t
able_allocated); |
286 return 0; | 288 return 0; |
287 } | 289 } |
288 | 290 |
289 | 291 |
290 void free_vlc(VLC *vlc) | 292 void free_vlc(VLC *vlc) |
291 { | 293 { |
292 av_freep(&vlc->table); | 294 av_freep(&vlc->table); |
293 } | 295 } |
294 | 296 |
OLD | NEW |