comparison parser.c @ 3455:cc4b4ea83e29 libavcodec

--enable/disable parsers. Warning: some combinations are broken.
author mru
date Sun, 09 Jul 2006 12:02:15 +0000
parents ab49baf4adad
children fa0b285144f0
comparison
equal deleted inserted replaced
3454:de0ed6497a13 3455:cc4b4ea83e29
296 // random, just to avoid segfault !never encode these 296 // random, just to avoid segfault !never encode these
297 25025, 297 25025,
298 25025, 298 25025,
299 }; 299 };
300 300
301 #ifdef CONFIG_MPEGVIDEO_PARSER
301 //FIXME move into mpeg12.c 302 //FIXME move into mpeg12.c
302 static void mpegvideo_extract_headers(AVCodecParserContext *s, 303 static void mpegvideo_extract_headers(AVCodecParserContext *s,
303 AVCodecContext *avctx, 304 AVCodecContext *avctx,
304 const uint8_t *buf, int buf_size) 305 const uint8_t *buf, int buf_size)
305 { 306 {
448 if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100) 449 if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100)
449 return i-3; 450 return i-3;
450 } 451 }
451 return 0; 452 return 0;
452 } 453 }
454 #endif /* CONFIG_MPEGVIDEO_PARSER */
453 455
454 void ff_parse_close(AVCodecParserContext *s) 456 void ff_parse_close(AVCodecParserContext *s)
455 { 457 {
456 ParseContext *pc = s->priv_data; 458 ParseContext *pc = s->priv_data;
457 459
466 av_free(pc1->enc); 468 av_free(pc1->enc);
467 } 469 }
468 470
469 /*************************/ 471 /*************************/
470 472
473 #ifdef CONFIG_MPEG4VIDEO_PARSER
471 /* used by parser */ 474 /* used by parser */
472 /* XXX: make it use less memory */ 475 /* XXX: make it use less memory */
473 static int av_mpeg4_decode_header(AVCodecParserContext *s1, 476 static int av_mpeg4_decode_header(AVCodecParserContext *s1,
474 AVCodecContext *avctx, 477 AVCodecContext *avctx,
475 const uint8_t *buf, int buf_size) 478 const uint8_t *buf, int buf_size)
531 534
532 *poutbuf = (uint8_t *)buf; 535 *poutbuf = (uint8_t *)buf;
533 *poutbuf_size = buf_size; 536 *poutbuf_size = buf_size;
534 return next; 537 return next;
535 } 538 }
536 539 #endif
537 #ifdef CONFIG_CAVS_DECODER 540
541 #ifdef CONFIG_CAVSVIDEO_PARSER
538 static int cavsvideo_parse(AVCodecParserContext *s, 542 static int cavsvideo_parse(AVCodecParserContext *s,
539 AVCodecContext *avctx, 543 AVCodecContext *avctx,
540 uint8_t **poutbuf, int *poutbuf_size, 544 uint8_t **poutbuf, int *poutbuf_size,
541 const uint8_t *buf, int buf_size) 545 const uint8_t *buf, int buf_size)
542 { 546 {
556 } 560 }
557 *poutbuf = (uint8_t *)buf; 561 *poutbuf = (uint8_t *)buf;
558 *poutbuf_size = buf_size; 562 *poutbuf_size = buf_size;
559 return next; 563 return next;
560 } 564 }
561 #endif /* CONFIG_CAVS_DECODER */ 565 #endif /* CONFIG_CAVSVIDEO_PARSER */
562 566
563 static int mpeg4video_split(AVCodecContext *avctx, 567 static int mpeg4video_split(AVCodecContext *avctx,
564 const uint8_t *buf, int buf_size) 568 const uint8_t *buf, int buf_size)
565 { 569 {
566 int i; 570 int i;
574 return 0; 578 return 0;
575 } 579 }
576 580
577 /*************************/ 581 /*************************/
578 582
583 #ifdef CONFIG_MPEGAUDIO_PARSER
579 typedef struct MpegAudioParseContext { 584 typedef struct MpegAudioParseContext {
580 uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ 585 uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */
581 uint8_t *inbuf_ptr; 586 uint8_t *inbuf_ptr;
582 int frame_size; 587 int frame_size;
583 int free_format_frame_size; 588 int free_format_frame_size;
751 break; 756 break;
752 } 757 }
753 } 758 }
754 return buf_ptr - buf; 759 return buf_ptr - buf;
755 } 760 }
756 761 #endif /* CONFIG_MPEGAUDIO_PARSER */
762
763 #if defined(CONFIG_AC3_PARSER) || defined(CONFIG_AAC_PARSER)
757 /* also used for ADTS AAC */ 764 /* also used for ADTS AAC */
758 typedef struct AC3ParseContext { 765 typedef struct AC3ParseContext {
759 uint8_t *inbuf_ptr; 766 uint8_t *inbuf_ptr;
760 int frame_size; 767 int frame_size;
761 int header_size; 768 int header_size;
765 } AC3ParseContext; 772 } AC3ParseContext;
766 773
767 #define AC3_HEADER_SIZE 7 774 #define AC3_HEADER_SIZE 7
768 #define AAC_HEADER_SIZE 7 775 #define AAC_HEADER_SIZE 7
769 776
777 #ifdef CONFIG_AC3_PARSER
770 static const int ac3_sample_rates[4] = { 778 static const int ac3_sample_rates[4] = {
771 48000, 44100, 32000, 0 779 48000, 44100, 32000, 0
772 }; 780 };
773 781
774 static const int ac3_frame_sizes[64][3] = { 782 static const int ac3_frame_sizes[64][3] = {
819 }; 827 };
820 828
821 static const int ac3_channels[8] = { 829 static const int ac3_channels[8] = {
822 2, 1, 2, 3, 3, 4, 4, 5 830 2, 1, 2, 3, 3, 4, 4, 5
823 }; 831 };
824 832 #endif /* CONFIG_AC3_PARSER */
833
834 #ifdef CONFIG_AAC_PARSER
825 static int aac_sample_rates[16] = { 835 static int aac_sample_rates[16] = {
826 96000, 88200, 64000, 48000, 44100, 32000, 836 96000, 88200, 64000, 48000, 44100, 32000,
827 24000, 22050, 16000, 12000, 11025, 8000, 7350 837 24000, 22050, 16000, 12000, 11025, 8000, 7350
828 }; 838 };
829 839
830 static int aac_channels[8] = { 840 static int aac_channels[8] = {
831 0, 1, 2, 3, 4, 5, 6, 8 841 0, 1, 2, 3, 4, 5, 6, 8
832 }; 842 };
833 843 #endif
844
845 #ifdef CONFIG_AC3_PARSER
834 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, 846 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
835 int *bit_rate, int *samples) 847 int *bit_rate, int *samples)
836 { 848 {
837 unsigned int fscod, frmsizecod, acmod, bsid, lfeon; 849 unsigned int fscod, frmsizecod, acmod, bsid, lfeon;
838 GetBitContext bits; 850 GetBitContext bits;
867 *channels = ac3_channels[acmod] + lfeon; 879 *channels = ac3_channels[acmod] + lfeon;
868 *samples = 6 * 256; 880 *samples = 6 * 256;
869 881
870 return ac3_frame_sizes[frmsizecod][fscod] * 2; 882 return ac3_frame_sizes[frmsizecod][fscod] * 2;
871 } 883 }
872 884 #endif /* CONFIG_AC3_PARSER */
885
886 #ifdef CONFIG_AAC_PARSER
873 static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate, 887 static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
874 int *bit_rate, int *samples) 888 int *bit_rate, int *samples)
875 { 889 {
876 GetBitContext bits; 890 GetBitContext bits;
877 int size, rdb, ch, sr; 891 int size, rdb, ch, sr;
907 *samples = (rdb + 1) * 1024; 921 *samples = (rdb + 1) * 1024;
908 *bit_rate = size * 8 * *sample_rate / *samples; 922 *bit_rate = size * 8 * *sample_rate / *samples;
909 923
910 return size; 924 return size;
911 } 925 }
912 926 #endif /* CONFIG_AAC_PARSER */
927
928 #ifdef CONFIG_AC3_PARSER
913 static int ac3_parse_init(AVCodecParserContext *s1) 929 static int ac3_parse_init(AVCodecParserContext *s1)
914 { 930 {
915 AC3ParseContext *s = s1->priv_data; 931 AC3ParseContext *s = s1->priv_data;
916 s->inbuf_ptr = s->inbuf; 932 s->inbuf_ptr = s->inbuf;
917 s->header_size = AC3_HEADER_SIZE; 933 s->header_size = AC3_HEADER_SIZE;
918 s->sync = ac3_sync; 934 s->sync = ac3_sync;
919 return 0; 935 return 0;
920 } 936 }
921 937 #endif
938
939 #ifdef CONFIG_AAC_PARSER
922 static int aac_parse_init(AVCodecParserContext *s1) 940 static int aac_parse_init(AVCodecParserContext *s1)
923 { 941 {
924 AC3ParseContext *s = s1->priv_data; 942 AC3ParseContext *s = s1->priv_data;
925 s->inbuf_ptr = s->inbuf; 943 s->inbuf_ptr = s->inbuf;
926 s->header_size = AAC_HEADER_SIZE; 944 s->header_size = AAC_HEADER_SIZE;
927 s->sync = aac_sync; 945 s->sync = aac_sync;
928 return 0; 946 return 0;
929 } 947 }
948 #endif
930 949
931 /* also used for ADTS AAC */ 950 /* also used for ADTS AAC */
932 static int ac3_parse(AVCodecParserContext *s1, 951 static int ac3_parse(AVCodecParserContext *s1,
933 AVCodecContext *avctx, 952 AVCodecContext *avctx,
934 uint8_t **poutbuf, int *poutbuf_size, 953 uint8_t **poutbuf, int *poutbuf_size,
993 } 1012 }
994 } 1013 }
995 } 1014 }
996 return buf_ptr - buf; 1015 return buf_ptr - buf;
997 } 1016 }
998 1017 #endif /* CONFIG_AC3_PARSER || CONFIG_AAC_PARSER */
1018
1019 #ifdef CONFIG_MPEGVIDEO_PARSER
999 AVCodecParser mpegvideo_parser = { 1020 AVCodecParser mpegvideo_parser = {
1000 { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, 1021 { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO },
1001 sizeof(ParseContext1), 1022 sizeof(ParseContext1),
1002 NULL, 1023 NULL,
1003 mpegvideo_parse, 1024 mpegvideo_parse,
1004 parse1_close, 1025 parse1_close,
1005 mpegvideo_split, 1026 mpegvideo_split,
1006 }; 1027 };
1007 1028 #endif
1029 #ifdef CONFIG_MPEG4VIDEO_PARSER
1008 AVCodecParser mpeg4video_parser = { 1030 AVCodecParser mpeg4video_parser = {
1009 { CODEC_ID_MPEG4 }, 1031 { CODEC_ID_MPEG4 },
1010 sizeof(ParseContext1), 1032 sizeof(ParseContext1),
1011 mpeg4video_parse_init, 1033 mpeg4video_parse_init,
1012 mpeg4video_parse, 1034 mpeg4video_parse,
1013 parse1_close, 1035 parse1_close,
1014 mpeg4video_split, 1036 mpeg4video_split,
1015 }; 1037 };
1016 1038 #endif
1017 #ifdef CONFIG_CAVS_DECODER 1039 #ifdef CONFIG_CAVSVIDEO_PARSER
1018 AVCodecParser cavsvideo_parser = { 1040 AVCodecParser cavsvideo_parser = {
1019 { CODEC_ID_CAVS }, 1041 { CODEC_ID_CAVS },
1020 sizeof(ParseContext1), 1042 sizeof(ParseContext1),
1021 NULL, 1043 NULL,
1022 cavsvideo_parse, 1044 cavsvideo_parse,
1023 parse1_close, 1045 parse1_close,
1024 mpeg4video_split, 1046 mpeg4video_split,
1025 }; 1047 };
1026 #endif 1048 #endif
1027 1049 #ifdef CONFIG_MPEGAUDIO_PARSER
1028 AVCodecParser mpegaudio_parser = { 1050 AVCodecParser mpegaudio_parser = {
1029 { CODEC_ID_MP2, CODEC_ID_MP3 }, 1051 { CODEC_ID_MP2, CODEC_ID_MP3 },
1030 sizeof(MpegAudioParseContext), 1052 sizeof(MpegAudioParseContext),
1031 mpegaudio_parse_init, 1053 mpegaudio_parse_init,
1032 mpegaudio_parse, 1054 mpegaudio_parse,
1033 NULL, 1055 NULL,
1034 }; 1056 };
1035 1057 #endif
1058 #ifdef CONFIG_AC3_PARSER
1036 AVCodecParser ac3_parser = { 1059 AVCodecParser ac3_parser = {
1037 { CODEC_ID_AC3 }, 1060 { CODEC_ID_AC3 },
1038 sizeof(AC3ParseContext), 1061 sizeof(AC3ParseContext),
1039 ac3_parse_init, 1062 ac3_parse_init,
1040 ac3_parse, 1063 ac3_parse,
1041 NULL, 1064 NULL,
1042 }; 1065 };
1043 1066 #endif
1067 #ifdef CONFIG_AAC_PARSER
1044 AVCodecParser aac_parser = { 1068 AVCodecParser aac_parser = {
1045 { CODEC_ID_AAC }, 1069 { CODEC_ID_AAC },
1046 sizeof(AC3ParseContext), 1070 sizeof(AC3ParseContext),
1047 aac_parse_init, 1071 aac_parse_init,
1048 ac3_parse, 1072 ac3_parse,
1049 NULL, 1073 NULL,
1050 }; 1074 };
1075 #endif