Mercurial > libavcodec.hg
comparison parser.c @ 2979:bfabfdf9ce55 libavcodec
COSMETICS: tabs --> spaces, some prettyprinting
author | diego |
---|---|
date | Thu, 22 Dec 2005 01:10:11 +0000 |
parents | ef2149182f1c |
children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
2978:403183bbb505 | 2979:bfabfdf9ce55 |
---|---|
189 | 189 |
190 /*****************************************************/ | 190 /*****************************************************/ |
191 | 191 |
192 //#define END_NOT_FOUND (-100) | 192 //#define END_NOT_FOUND (-100) |
193 | 193 |
194 #define PICTURE_START_CODE 0x00000100 | 194 #define PICTURE_START_CODE 0x00000100 |
195 #define SEQ_START_CODE 0x000001b3 | 195 #define SEQ_START_CODE 0x000001b3 |
196 #define EXT_START_CODE 0x000001b5 | 196 #define EXT_START_CODE 0x000001b5 |
197 #define SLICE_MIN_START_CODE 0x00000101 | 197 #define SLICE_MIN_START_CODE 0x00000101 |
198 #define SLICE_MAX_START_CODE 0x000001af | 198 #define SLICE_MAX_START_CODE 0x000001af |
199 | 199 |
200 typedef struct ParseContext1{ | 200 typedef struct ParseContext1{ |
201 ParseContext pc; | 201 ParseContext pc; |
202 /* XXX/FIXME PC1 vs. PC */ | 202 /* XXX/FIXME PC1 vs. PC */ |
203 /* MPEG2 specific */ | 203 /* MPEG2 specific */ |
569 } | 569 } |
570 | 570 |
571 /*************************/ | 571 /*************************/ |
572 | 572 |
573 typedef struct MpegAudioParseContext { | 573 typedef struct MpegAudioParseContext { |
574 uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ | 574 uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ |
575 uint8_t *inbuf_ptr; | 575 uint8_t *inbuf_ptr; |
576 int frame_size; | 576 int frame_size; |
577 int free_format_frame_size; | 577 int free_format_frame_size; |
578 int free_format_next_header; | 578 int free_format_next_header; |
579 uint32_t header; | 579 uint32_t header; |
606 | 606 |
607 *poutbuf = NULL; | 607 *poutbuf = NULL; |
608 *poutbuf_size = 0; | 608 *poutbuf_size = 0; |
609 buf_ptr = buf; | 609 buf_ptr = buf; |
610 while (buf_size > 0) { | 610 while (buf_size > 0) { |
611 len = s->inbuf_ptr - s->inbuf; | 611 len = s->inbuf_ptr - s->inbuf; |
612 if (s->frame_size == 0) { | 612 if (s->frame_size == 0) { |
613 /* special case for next header for first frame in free | 613 /* special case for next header for first frame in free |
614 format case (XXX: find a simpler method) */ | 614 format case (XXX: find a simpler method) */ |
615 if (s->free_format_next_header != 0) { | 615 if (s->free_format_next_header != 0) { |
616 s->inbuf[0] = s->free_format_next_header >> 24; | 616 s->inbuf[0] = s->free_format_next_header >> 24; |
617 s->inbuf[1] = s->free_format_next_header >> 16; | 617 s->inbuf[1] = s->free_format_next_header >> 16; |
619 s->inbuf[3] = s->free_format_next_header; | 619 s->inbuf[3] = s->free_format_next_header; |
620 s->inbuf_ptr = s->inbuf + 4; | 620 s->inbuf_ptr = s->inbuf + 4; |
621 s->free_format_next_header = 0; | 621 s->free_format_next_header = 0; |
622 goto got_header; | 622 goto got_header; |
623 } | 623 } |
624 /* no header seen : find one. We need at least MPA_HEADER_SIZE | 624 /* no header seen : find one. We need at least MPA_HEADER_SIZE |
625 bytes to parse it */ | 625 bytes to parse it */ |
626 len = MPA_HEADER_SIZE - len; | 626 len = MPA_HEADER_SIZE - len; |
627 if (len > buf_size) | 627 if (len > buf_size) |
628 len = buf_size; | 628 len = buf_size; |
629 if (len > 0) { | 629 if (len > 0) { |
630 memcpy(s->inbuf_ptr, buf_ptr, len); | 630 memcpy(s->inbuf_ptr, buf_ptr, len); |
631 buf_ptr += len; | 631 buf_ptr += len; |
632 buf_size -= len; | 632 buf_size -= len; |
633 s->inbuf_ptr += len; | 633 s->inbuf_ptr += len; |
634 } | 634 } |
635 if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { | 635 if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { |
636 got_header: | 636 got_header: |
637 sr= avctx->sample_rate; | 637 sr= avctx->sample_rate; |
638 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | | 638 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | |
639 (s->inbuf[2] << 8) | s->inbuf[3]; | 639 (s->inbuf[2] << 8) | s->inbuf[3]; |
640 | 640 |
641 ret = mpa_decode_header(avctx, header); | 641 ret = mpa_decode_header(avctx, header); |
642 if (ret < 0) { | 642 if (ret < 0) { |
643 s->header_count= -2; | 643 s->header_count= -2; |
644 /* no sync found : move by one byte (inefficient, but simple!) */ | 644 /* no sync found : move by one byte (inefficient, but simple!) */ |
645 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); | 645 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); |
646 s->inbuf_ptr--; | 646 s->inbuf_ptr--; |
647 dprintf("skip %x\n", header); | 647 dprintf("skip %x\n", header); |
648 /* reset free format frame size to give a chance | 648 /* reset free format frame size to give a chance |
649 to get a new bitrate */ | 649 to get a new bitrate */ |
650 s->free_format_frame_size = 0; | 650 s->free_format_frame_size = 0; |
651 } else { | 651 } else { |
652 if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) | 652 if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) |
653 s->header_count= -3; | 653 s->header_count= -3; |
654 s->header= header; | 654 s->header= header; |
655 s->header_count++; | 655 s->header_count++; |
656 s->frame_size = ret; | 656 s->frame_size = ret; |
657 | 657 |
658 #if 0 | 658 #if 0 |
659 /* free format: prepare to compute frame size */ | 659 /* free format: prepare to compute frame size */ |
660 if (decode_header(s, header) == 1) { | 660 if (decode_header(s, header) == 1) { |
661 s->frame_size = -1; | 661 s->frame_size = -1; |
662 } | 662 } |
663 #endif | 663 #endif |
664 } | 664 } |
665 if(s->header_count <= 0) | 665 if(s->header_count <= 0) |
666 avctx->sample_rate= sr; //FIXME ugly | 666 avctx->sample_rate= sr; //FIXME ugly |
667 } | 667 } |
668 } else | 668 } else |
669 #if 0 | 669 #if 0 |
670 if (s->frame_size == -1) { | 670 if (s->frame_size == -1) { |
671 /* free format : find next sync to compute frame size */ | 671 /* free format : find next sync to compute frame size */ |
672 len = MPA_MAX_CODED_FRAME_SIZE - len; | 672 len = MPA_MAX_CODED_FRAME_SIZE - len; |
673 if (len > buf_size) | 673 if (len > buf_size) |
674 len = buf_size; | 674 len = buf_size; |
675 if (len == 0) { | 675 if (len == 0) { |
676 /* frame too long: resync */ | 676 /* frame too long: resync */ |
677 s->frame_size = 0; | 677 s->frame_size = 0; |
678 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); | 678 memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); |
679 s->inbuf_ptr--; | 679 s->inbuf_ptr--; |
680 } else { | 680 } else { |
681 uint8_t *p, *pend; | 681 uint8_t *p, *pend; |
682 uint32_t header1; | 682 uint32_t header1; |
683 int padding; | 683 int padding; |
684 | 684 |
718 /* not found: simply increase pointers */ | 718 /* not found: simply increase pointers */ |
719 buf_ptr += len; | 719 buf_ptr += len; |
720 s->inbuf_ptr += len; | 720 s->inbuf_ptr += len; |
721 buf_size -= len; | 721 buf_size -= len; |
722 } | 722 } |
723 } else | 723 } else |
724 #endif | 724 #endif |
725 if (len < s->frame_size) { | 725 if (len < s->frame_size) { |
726 if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) | 726 if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) |
727 s->frame_size = MPA_MAX_CODED_FRAME_SIZE; | 727 s->frame_size = MPA_MAX_CODED_FRAME_SIZE; |
728 len = s->frame_size - len; | 728 len = s->frame_size - len; |
729 if (len > buf_size) | 729 if (len > buf_size) |
730 len = buf_size; | 730 len = buf_size; |
731 memcpy(s->inbuf_ptr, buf_ptr, len); | 731 memcpy(s->inbuf_ptr, buf_ptr, len); |
732 buf_ptr += len; | 732 buf_ptr += len; |
733 s->inbuf_ptr += len; | 733 s->inbuf_ptr += len; |
734 buf_size -= len; | 734 buf_size -= len; |
735 } | 735 } |
736 // next_data: | 736 // next_data: |
737 if (s->frame_size > 0 && | 737 if (s->frame_size > 0 && |
738 (s->inbuf_ptr - s->inbuf) >= s->frame_size) { | 738 (s->inbuf_ptr - s->inbuf) >= s->frame_size) { |
739 if(s->header_count > 0){ | 739 if(s->header_count > 0){ |
740 *poutbuf = s->inbuf; | 740 *poutbuf = s->inbuf; |
741 *poutbuf_size = s->inbuf_ptr - s->inbuf; | 741 *poutbuf_size = s->inbuf_ptr - s->inbuf; |
742 } | 742 } |
743 s->inbuf_ptr = s->inbuf; | 743 s->inbuf_ptr = s->inbuf; |
744 s->frame_size = 0; | 744 s->frame_size = 0; |
745 break; | 745 break; |
746 } | 746 } |
747 } | 747 } |
748 return buf_ptr - buf; | 748 return buf_ptr - buf; |
749 } | 749 } |
750 | 750 |
751 #ifdef CONFIG_AC3 | 751 #ifdef CONFIG_AC3 |
781 { | 781 { |
782 AC3ParseContext *s = s1->priv_data; | 782 AC3ParseContext *s = s1->priv_data; |
783 const uint8_t *buf_ptr; | 783 const uint8_t *buf_ptr; |
784 int len, sample_rate, bit_rate; | 784 int len, sample_rate, bit_rate; |
785 static const int ac3_channels[8] = { | 785 static const int ac3_channels[8] = { |
786 2, 1, 2, 3, 3, 4, 4, 5 | 786 2, 1, 2, 3, 3, 4, 4, 5 |
787 }; | 787 }; |
788 | 788 |
789 *poutbuf = NULL; | 789 *poutbuf = NULL; |
790 *poutbuf_size = 0; | 790 *poutbuf_size = 0; |
791 | 791 |
810 if (len == 0) { | 810 if (len == 0) { |
811 /* no sync found : move by one byte (inefficient, but simple!) */ | 811 /* no sync found : move by one byte (inefficient, but simple!) */ |
812 memmove(s->inbuf, s->inbuf + 1, AC3_HEADER_SIZE - 1); | 812 memmove(s->inbuf, s->inbuf + 1, AC3_HEADER_SIZE - 1); |
813 s->inbuf_ptr--; | 813 s->inbuf_ptr--; |
814 } else { | 814 } else { |
815 s->frame_size = len; | 815 s->frame_size = len; |
816 /* update codec info */ | 816 /* update codec info */ |
817 avctx->sample_rate = sample_rate; | 817 avctx->sample_rate = sample_rate; |
818 /* set channels,except if the user explicitly requests 1 or 2 channels, XXX/FIXME this is a bit ugly */ | 818 /* set channels,except if the user explicitly requests 1 or 2 channels, XXX/FIXME this is a bit ugly */ |
819 if(avctx->channels!=1 && avctx->channels!=2){ | 819 if(avctx->channels!=1 && avctx->channels!=2){ |
820 avctx->channels = ac3_channels[s->flags & 7]; | 820 avctx->channels = ac3_channels[s->flags & 7]; |
821 if (s->flags & A52_LFE) | 821 if (s->flags & A52_LFE) |
822 avctx->channels++; | 822 avctx->channels++; |
823 } | 823 } |
824 avctx->bit_rate = bit_rate; | 824 avctx->bit_rate = bit_rate; |
825 avctx->frame_size = 6 * 256; | 825 avctx->frame_size = 6 * 256; |
826 } | 826 } |
827 } | 827 } |
828 } else if (len < s->frame_size) { | 828 } else if (len < s->frame_size) { |
829 len = s->frame_size - len; | 829 len = s->frame_size - len; |