Mercurial > libavformat.hg
comparison avidec.c @ 519:d59dc270e1f5 libavformat
various fixes for the main chunk demux loop
author | michael |
---|---|
date | Wed, 15 Sep 2004 01:35:09 +0000 |
parents | 133287132e1d |
children | 5d96fe8f6560 |
comparison
equal
deleted
inserted
replaced
518:5f933fac3d3f | 519:d59dc270e1f5 |
---|---|
40 int sample_size; /* audio only data */ | 40 int sample_size; /* audio only data */ |
41 int start; | 41 int start; |
42 | 42 |
43 int new_frame_offset; /* temporary storage (used during seek) */ | 43 int new_frame_offset; /* temporary storage (used during seek) */ |
44 int cum_len; /* temporary storage (used during seek) */ | 44 int cum_len; /* temporary storage (used during seek) */ |
45 | |
46 int prefix; ///< normally 'd'<<8 + 'c' or 'w'<<8 + 'b' | |
47 int prefix_count; | |
45 } AVIStream; | 48 } AVIStream; |
46 | 49 |
47 typedef struct { | 50 typedef struct { |
48 int64_t riff_end; | 51 int64_t riff_end; |
49 int64_t movi_end; | 52 int64_t movi_end; |
395 d[j]= d[j+1]; | 398 d[j]= d[j+1]; |
396 d[7]= get_byte(pb); | 399 d[7]= get_byte(pb); |
397 | 400 |
398 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24); | 401 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24); |
399 | 402 |
403 if( d[2] >= '0' && d[2] <= '9' | |
404 && d[3] >= '0' && d[3] <= '9'){ | |
405 n= (d[2] - '0') * 10 + (d[3] - '0'); | |
406 }else{ | |
407 n= 100; //invalid stream id | |
408 } | |
409 //av_log(NULL, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %lld %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n); | |
410 if(i + size > avi->movi_end || d[0]<0) | |
411 continue; | |
412 | |
400 //parse ix## | 413 //parse ix## |
401 n= (d[2] - '0') * 10 + (d[3] - '0'); | 414 if( (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) |
402 if( d[2] >= '0' && d[2] <= '9' | 415 //parse JUNK |
403 && d[3] >= '0' && d[3] <= '9' | 416 ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')){ |
404 && d[0] == 'i' && d[1] == 'x' | |
405 && n < s->nb_streams | |
406 && i + size <= avi->movi_end){ | |
407 | |
408 url_fskip(pb, size); | 417 url_fskip(pb, size); |
409 } | 418 i+= size; |
410 | 419 memset(d, -1, sizeof(int)*8); |
411 //parse JUNK | 420 //av_log(NULL, AV_LOG_DEBUG, "SKIP\n"); |
412 if(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K' && | 421 continue; |
413 i + size <= avi->movi_end) { | 422 } |
414 | 423 |
415 url_fskip(pb, size); | 424 if( d[0] >= '0' && d[0] <= '9' |
425 && d[1] >= '0' && d[1] <= '9'){ | |
426 n= (d[0] - '0') * 10 + (d[1] - '0'); | |
427 }else{ | |
428 n= 100; //invalid stream id | |
416 } | 429 } |
417 | 430 |
418 //parse ##dc/##wb | 431 //parse ##dc/##wb |
419 n= (d[0] - '0') * 10 + (d[1] - '0'); | 432 if(n < s->nb_streams){ |
420 if( d[0] >= '0' && d[0] <= '9' | 433 AVStream *st; |
421 && d[1] >= '0' && d[1] <= '9' | 434 AVIStream *ast; |
422 && ((d[2] == 'd' && d[3] == 'c') || | 435 st = s->streams[n]; |
423 (d[2] == 'w' && d[3] == 'b') || | 436 ast = st->priv_data; |
424 (d[2] == 'd' && d[3] == 'b') || | 437 |
425 (d[2] == '_' && d[3] == '_')) | 438 if( (ast->prefix_count<5 && d[2]<128 && d[3]<128) || |
426 && n < s->nb_streams | 439 d[2]*256+d[3] == ast->prefix /*|| |
427 && i + size <= avi->movi_end) { | 440 (d[2] == 'd' && d[3] == 'c') || |
428 | 441 (d[2] == 'w' && d[3] == 'b')*/) { |
442 | |
443 //av_log(NULL, AV_LOG_DEBUG, "OK\n"); | |
444 if(d[2]*256+d[3] == ast->prefix) | |
445 ast->prefix_count++; | |
446 else{ | |
447 ast->prefix= d[2]*256+d[3]; | |
448 ast->prefix_count= 0; | |
449 } | |
450 | |
429 av_new_packet(pkt, size); | 451 av_new_packet(pkt, size); |
430 get_buffer(pb, pkt->data, size); | 452 get_buffer(pb, pkt->data, size); |
431 if (size & 1) { | 453 if (size & 1) { |
432 get_byte(pb); | 454 get_byte(pb); |
433 size++; | 455 size++; |
438 size = dv_produce_packet(avi->dv_demux, pkt, | 460 size = dv_produce_packet(avi->dv_demux, pkt, |
439 pkt->data, pkt->size); | 461 pkt->data, pkt->size); |
440 pkt->destruct = dstr; | 462 pkt->destruct = dstr; |
441 pkt->flags |= PKT_FLAG_KEY; | 463 pkt->flags |= PKT_FLAG_KEY; |
442 } else { | 464 } else { |
443 AVStream *st; | |
444 AVIStream *ast; | |
445 st = s->streams[n]; | |
446 ast = st->priv_data; | |
447 | |
448 /* XXX: how to handle B frames in avi ? */ | 465 /* XXX: how to handle B frames in avi ? */ |
449 pkt->dts = ast->frame_offset; | 466 pkt->dts = ast->frame_offset; |
450 // pkt->dts += ast->start; | 467 // pkt->dts += ast->start; |
451 if(ast->sample_size) | 468 if(ast->sample_size) |
452 pkt->dts /= ast->sample_size; | 469 pkt->dts /= ast->sample_size; |
469 ast->frame_offset += pkt->size; | 486 ast->frame_offset += pkt->size; |
470 else | 487 else |
471 ast->frame_offset++; | 488 ast->frame_offset++; |
472 } | 489 } |
473 return size; | 490 return size; |
474 } | 491 } |
475 } | 492 } |
493 } | |
494 | |
476 return -1; | 495 return -1; |
477 } | 496 } |
478 | 497 |
479 /* XXX: we make the implicit supposition that the position are sorted | 498 /* XXX: we make the implicit supposition that the position are sorted |
480 for each stream */ | 499 for each stream */ |