Mercurial > libavcodec.hg
comparison parser.c @ 2470:06aafb585f69 libavcodec
require a few valid and equal mp3 headers for resync
| author | michael |
|---|---|
| date | Sat, 29 Jan 2005 23:59:32 +0000 |
| parents | 429c1eedeee9 |
| children | 5252700f61df |
comparison
equal
deleted
inserted
replaced
| 2469:df02930c138b | 2470:06aafb585f69 |
|---|---|
| 492 uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ | 492 uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ |
| 493 uint8_t *inbuf_ptr; | 493 uint8_t *inbuf_ptr; |
| 494 int frame_size; | 494 int frame_size; |
| 495 int free_format_frame_size; | 495 int free_format_frame_size; |
| 496 int free_format_next_header; | 496 int free_format_next_header; |
| 497 uint32_t header; | |
| 498 int header_count; | |
| 497 } MpegAudioParseContext; | 499 } MpegAudioParseContext; |
| 498 | 500 |
| 499 #define MPA_HEADER_SIZE 4 | 501 #define MPA_HEADER_SIZE 4 |
| 500 | 502 |
| 501 /* header + layer + bitrate + freq + lsf/mpeg25 */ | 503 /* header + layer + bitrate + freq + lsf/mpeg25 */ |
| 513 AVCodecContext *avctx, | 515 AVCodecContext *avctx, |
| 514 uint8_t **poutbuf, int *poutbuf_size, | 516 uint8_t **poutbuf, int *poutbuf_size, |
| 515 const uint8_t *buf, int buf_size) | 517 const uint8_t *buf, int buf_size) |
| 516 { | 518 { |
| 517 MpegAudioParseContext *s = s1->priv_data; | 519 MpegAudioParseContext *s = s1->priv_data; |
| 518 int len, ret; | 520 int len, ret, sr; |
| 519 uint32_t header; | 521 uint32_t header; |
| 520 const uint8_t *buf_ptr; | 522 const uint8_t *buf_ptr; |
| 521 | 523 |
| 522 *poutbuf = NULL; | 524 *poutbuf = NULL; |
| 523 *poutbuf_size = 0; | 525 *poutbuf_size = 0; |
| 547 buf_size -= len; | 549 buf_size -= len; |
| 548 s->inbuf_ptr += len; | 550 s->inbuf_ptr += len; |
| 549 } | 551 } |
| 550 if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { | 552 if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { |
| 551 got_header: | 553 got_header: |
| 554 sr= avctx->sample_rate; | |
| 552 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | | 555 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | |
| 553 (s->inbuf[2] << 8) | s->inbuf[3]; | 556 (s->inbuf[2] << 8) | s->inbuf[3]; |
| 554 | 557 |
| 555 ret = mpa_decode_header(avctx, header); | 558 ret = mpa_decode_header(avctx, header); |
| 556 if (ret < 0) { | 559 if (ret < 0) { |
| 560 s->header_count= -2; | |
| 557 /* no sync found : move by one byte (inefficient, but simple!) */ | 561 /* no sync found : move by one byte (inefficient, but simple!) */ |
| 558 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); | 562 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); |
| 559 s->inbuf_ptr--; | 563 s->inbuf_ptr--; |
| 560 dprintf("skip %x\n", header); | 564 dprintf("skip %x\n", header); |
| 561 /* reset free format frame size to give a chance | 565 /* reset free format frame size to give a chance |
| 562 to get a new bitrate */ | 566 to get a new bitrate */ |
| 563 s->free_format_frame_size = 0; | 567 s->free_format_frame_size = 0; |
| 564 } else { | 568 } else { |
| 569 if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) | |
| 570 s->header_count= -3; | |
| 571 s->header= header; | |
| 572 s->header_count++; | |
| 565 s->frame_size = ret; | 573 s->frame_size = ret; |
| 574 | |
| 566 #if 0 | 575 #if 0 |
| 567 /* free format: prepare to compute frame size */ | 576 /* free format: prepare to compute frame size */ |
| 568 if (decode_header(s, header) == 1) { | 577 if (decode_header(s, header) == 1) { |
| 569 s->frame_size = -1; | 578 s->frame_size = -1; |
| 570 } | 579 } |
| 571 #endif | 580 #endif |
| 572 } | 581 } |
| 582 if(s->header_count <= 0) | |
| 583 avctx->sample_rate= sr; //FIXME ugly | |
| 573 } | 584 } |
| 574 } else | 585 } else |
| 575 #if 0 | 586 #if 0 |
| 576 if (s->frame_size == -1) { | 587 if (s->frame_size == -1) { |
| 577 /* free format : find next sync to compute frame size */ | 588 /* free format : find next sync to compute frame size */ |
| 640 buf_size -= len; | 651 buf_size -= len; |
| 641 } | 652 } |
| 642 // next_data: | 653 // next_data: |
| 643 if (s->frame_size > 0 && | 654 if (s->frame_size > 0 && |
| 644 (s->inbuf_ptr - s->inbuf) >= s->frame_size) { | 655 (s->inbuf_ptr - s->inbuf) >= s->frame_size) { |
| 645 *poutbuf = s->inbuf; | 656 if(s->header_count > 0){ |
| 646 *poutbuf_size = s->inbuf_ptr - s->inbuf; | 657 *poutbuf = s->inbuf; |
| 658 *poutbuf_size = s->inbuf_ptr - s->inbuf; | |
| 659 } | |
| 647 s->inbuf_ptr = s->inbuf; | 660 s->inbuf_ptr = s->inbuf; |
| 648 s->frame_size = 0; | 661 s->frame_size = 0; |
| 649 break; | 662 break; |
| 650 } | 663 } |
| 651 } | 664 } |
