Changeset 384 for libmpc/trunk/libmpcdec/mpc_demux.c
- Timestamp:
- 03/25/08 16:31:41 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/trunk/libmpcdec/mpc_demux.c
r377 r384 258 258 mpc_uint64_t ptr; 259 259 mpc_block b; 260 int st_head_size; 260 261 261 262 cur = mpc_demux_pos(d); 262 263 mpc_bits_get_size(&d->bits_reader, &ptr); 263 264 mpc_demux_seek(d, (ptr - size) * 8 + cur, 11); 264 mpc_bits_get_block(&d->bits_reader, &b);265 st_head_size = mpc_bits_get_block(&d->bits_reader, &b); 265 266 if (memcmp(b.key, "ST", 2) == 0) { 267 d->chap_pos = (ptr - size + b.size + st_head_size) * 8 + cur; 268 d->chap_nb = -1; 266 269 mpc_demux_fill(d, (mpc_uint32_t) b.size, 0); 267 270 mpc_demux_ST(d); … … 270 273 } 271 274 275 static void mpc_demux_chap_find(mpc_demux * d) 276 { 277 if (d->chap_pos == 0) { 278 // FIXME : find chapters from end of file 279 } 280 mpc_block b; 281 int tag_size = 0, chap_size = 0, size, i = 0; 282 d->chap_nb = 0; 283 mpc_demux_seek(d, d->chap_pos, 20); 284 size = mpc_bits_get_block(&d->bits_reader, &b); 285 while (memcmp(b.key, "CT", 2) == 0) { 286 mpc_uint64_t chap_sample; 287 d->chap_nb++; 288 chap_size += size; 289 size = mpc_bits_get_size(&d->bits_reader, &chap_sample); 290 chap_size += size; 291 tag_size += b.size - size; 292 mpc_demux_seek(d, d->chap_pos + (chap_size + tag_size) * 8, 20); 293 size = mpc_bits_get_block(&d->bits_reader, &b); 294 } 295 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++; 310 size = mpc_bits_get_block(&d->bits_reader, &b); 311 } 312 313 d->bits_reader.buff -= size; 314 } 315 316 mpc_int_t mpc_demux_chap_nb(mpc_demux * d) 317 { 318 if (d->chap_nb == -1) 319 mpc_demux_chap_find(d); 320 return d->chap_nb; 321 } 322 323 mpc_uint64_t mpc_demux_chap(mpc_demux * d, int chap_nb, char ** tag, mpc_uint_t * tag_size) 324 { 325 if (d->chap_nb == -1) 326 mpc_demux_chap_find(d); 327 if (chap_nb >= d->chap_nb) 328 return 0; 329 if (tag != 0 && tag_size != 0) { 330 *tag = d->chap[chap_nb].tag; 331 *tag_size = d->chap[chap_nb].tag_size; 332 } 333 return d->chap[chap_nb].sample; 334 } 335 272 336 static mpc_status mpc_demux_header(mpc_demux * d) 273 337 { … … 339 403 memset(p_tmp, 0, sizeof(mpc_demux)); 340 404 p_tmp->r = p_reader; 405 p_tmp->chap_nb = -1; 341 406 mpc_demux_clear_buff(p_tmp); 342 407 if (mpc_demux_header(p_tmp) == MPC_STATUS_OK && … … 358 423 mpc_decoder_exit(d->d); 359 424 free(d->seek_table); 425 free(d->chap); 360 426 free(d); 361 427 }
Note: See TracChangeset
for help on using the changeset viewer.