Changeset 389 for libmpc/trunk/libmpcdec/mpc_demux.c
- Timestamp:
- 04/02/08 17:22:31 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/trunk/libmpcdec/mpc_demux.c
r384 r389 275 275 static void mpc_demux_chap_find(mpc_demux * d) 276 276 { 277 if (d->chap_pos == 0) {278 // FIXME : find chapters from end of file279 }280 277 mpc_block b; 281 278 int tag_size = 0, chap_size = 0, size, i = 0; 279 280 if (d->si.stream_version < 8) 281 return; 282 283 if (d->chap_pos == 0) { 284 mpc_uint64_t cur_pos = (d->si.header_position + 4) * 8; 285 mpc_demux_seek(d, cur_pos, 11); // seek to the beginning of the stream 286 size = mpc_bits_get_block(&d->bits_reader, &b); 287 while (memcmp(b.key, "SE", 2) != 0) { 288 if (memcmp(b.key, "CT", 2) == 0) { 289 if (d->chap_pos == 0) d->chap_pos = cur_pos; 290 } else 291 d->chap_pos = 0; 292 cur_pos += (size + b.size) * 8; 293 mpc_demux_seek(d, cur_pos, 11); 294 size = mpc_bits_get_block(&d->bits_reader, &b); 295 } 296 if (d->chap_pos == 0) 297 d->chap_pos = cur_pos; 298 } 299 282 300 d->chap_nb = 0; 283 301 mpc_demux_seek(d, d->chap_pos, 20); … … 294 312 } 295 313 296 d->chap = malloc(sizeof(mpc_chap_t) * d->chap_nb + tag_size); 297 char * ptag = (char*)(d->chap + d->chap_nb); 298 299 mpc_demux_seek(d, d->chap_pos, 11); 300 size = mpc_bits_get_block(&d->bits_reader, &b); 301 while (memcmp(b.key, "CT", 2) == 0) { 302 mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0); 303 size = mpc_bits_get_size(&d->bits_reader, &d->chap[i].sample); 304 memcpy(ptag, d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3), b.size - size); 305 d->bits_reader.buff += b.size - size; 306 d->chap[i].tag_size = b.size - size; 307 d->chap[i].tag = ptag; 308 ptag += b.size - size; 309 i++; 314 if (d->chap_nb > 0) { 315 d->chap = malloc(sizeof(mpc_chap_t) * d->chap_nb + tag_size); 316 char * ptag = (char*)(d->chap + d->chap_nb); 317 318 mpc_demux_seek(d, d->chap_pos, 11); 310 319 size = mpc_bits_get_block(&d->bits_reader, &b); 320 while (memcmp(b.key, "CT", 2) == 0) { 321 mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0); 322 size = mpc_bits_get_size(&d->bits_reader, &d->chap[i].sample); 323 memcpy(ptag, d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3), b.size - size); 324 d->bits_reader.buff += b.size - size; 325 d->chap[i].tag_size = b.size - size; 326 d->chap[i].tag = ptag; 327 ptag += b.size - size; 328 i++; 329 size = mpc_bits_get_block(&d->bits_reader, &b); 330 } 311 331 } 312 332 … … 325 345 if (d->chap_nb == -1) 326 346 mpc_demux_chap_find(d); 327 if (chap_nb >= d->chap_nb )347 if (chap_nb >= d->chap_nb || chap_nb < 0) 328 348 return 0; 329 349 if (tag != 0 && tag_size != 0) {
Note: See TracChangeset
for help on using the changeset viewer.