Changeset 407
- Timestamp:
- 06/02/08 16:23:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/trunk/libmpcdec/mpc_demux.c
r405 r407 42 42 #include "mpc_bits_reader.h" 43 43 44 /// maximum number of seek points in the table. The distance between points will 45 /// be adapted so this value is never exceeded. 46 #define MAX_SEEK_TABLE_SIZE 65536 47 44 48 // streaminfo.c 45 49 mpc_status streaminfo_read_header_sv8(mpc_streaminfo* si, … … 205 209 static mpc_status mpc_demux_seek_init(mpc_demux * d) 206 210 { 211 size_t seek_table_size; 207 212 if (d->seek_table != 0) 208 213 return MPC_STATUS_OK; … … 211 216 if (d->si.block_pwr > d->seek_pwr) 212 217 d->seek_pwr = d->si.block_pwr; 213 d->seek_table = malloc((size_t)(2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_seek_t)); 218 seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)); 219 while (seek_table_size > MAX_SEEK_TABLE_SIZE) { 220 d->seek_pwr++; 221 seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)); 222 } 223 d->seek_table = malloc((size_t)(seek_table_size * sizeof(mpc_seek_t))); 214 224 if (d->seek_table == 0) 215 225 return MPC_STATUS_FILE; … … 223 233 { 224 234 mpc_uint64_t tmp; 225 mpc_seek_t * table ;235 mpc_seek_t * table, last[2]; 226 236 mpc_bits_reader r = d->bits_reader; 227 mpc_uint_t i; 237 mpc_uint_t i, diff_pwr = 0, mask; 238 mpc_uint32_t file_table_size; 228 239 229 240 if (d->seek_table != 0) … … 231 242 232 243 mpc_bits_get_size(&r, &tmp); 233 d->seek_table_size = (mpc_seek_t) tmp;244 file_table_size = (mpc_seek_t) tmp; 234 245 d->seek_pwr = d->si.block_pwr + mpc_bits_read(&r, 4); 246 235 247 tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr); 236 if (tmp < d->seek_table_size) tmp = d->seek_table_size; 237 d->seek_table = malloc((size_t)(tmp * sizeof(mpc_seek_t))); 248 while (tmp > MAX_SEEK_TABLE_SIZE) { 249 d->seek_pwr++; 250 diff_pwr++; 251 tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr); 252 } 253 if ((file_table_size >> diff_pwr) > tmp) 254 file_table_size = tmp << diff_pwr; 255 d->seek_table = malloc((size_t) (tmp * sizeof(mpc_seek_t))); 256 d->seek_table_size = (file_table_size + ((1 << diff_pwr) - 1)) >> diff_pwr; 238 257 239 258 table = d->seek_table; 240 259 mpc_bits_get_size(&r, &tmp); 241 table[0] = (mpc_seek_t) (tmp + d->si.header_position) * 8;260 table[0] = last[0] = (mpc_seek_t) (tmp + d->si.header_position) * 8; 242 261 243 262 if (d->seek_table_size == 1) … … 245 264 246 265 mpc_bits_get_size(&r, &tmp); 247 table[1] = (mpc_seek_t) (tmp + d->si.header_position) * 8; 248 249 for (i = 2; i < d->seek_table_size; i++) { 266 last[1] = (mpc_seek_t) (tmp + d->si.header_position) * 8; 267 if (diff_pwr == 0) table[1] = last[1]; 268 269 mask = (1 << diff_pwr) - 1; 270 for (i = 2; i < file_table_size; i++) { 250 271 int code = mpc_bits_golomb_dec(&r, 12); 251 272 if (code & 1) 252 273 code = -(code & (-1 << 1)); 253 274 code <<= 2; 254 table[i] = code + 2 * table[i-1] - table[i-2]; 275 last[i & 1] = code + 2 * last[(i-1) & 1] - last[i & 1]; 276 if ((i & mask) == 0) 277 table[i >> diff_pwr] = last[i & 1]; 255 278 } 256 279 }
Note: See TracChangeset
for help on using the changeset viewer.