00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/crc.h"
00023 #include "libavcodec/ac3_parser.h"
00024 #include "avformat.h"
00025 #include "rawdec.h"
00026
00027 static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID expected_codec_id)
00028 {
00029 int max_frames, first_frames = 0, frames;
00030 uint8_t *buf, *buf2, *end;
00031 AC3HeaderInfo hdr;
00032 GetBitContext gbc;
00033 enum AVCodecID codec_id = AV_CODEC_ID_AC3;
00034
00035 max_frames = 0;
00036 buf = p->buf;
00037 end = buf + p->buf_size;
00038
00039 for(; buf < end; buf++) {
00040 if(buf > p->buf && !(buf[0] == 0x0B && buf[1] == 0x77)
00041 && !(buf[0] == 0x77 && buf[1] == 0x0B) )
00042 continue;
00043 buf2 = buf;
00044
00045 for(frames = 0; buf2 < end; frames++) {
00046 uint8_t buf3[4096];
00047 int i;
00048 if(!memcmp(buf2, "\x1\x10\0\0\0\0\0\0", 8))
00049 buf2+=16;
00050 if (buf[0] == 0x77 && buf[1] == 0x0B) {
00051 for(i=0; i<8; i+=2) {
00052 buf3[i ] = buf[i+1];
00053 buf3[i+1] = buf[i ];
00054 }
00055 init_get_bits(&gbc, buf3, 54);
00056 }else
00057 init_get_bits(&gbc, buf2, 54);
00058 if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)
00059 break;
00060 if(buf2 + hdr.frame_size > end)
00061 break;
00062 if (buf[0] == 0x77 && buf[1] == 0x0B) {
00063 av_assert0(hdr.frame_size <= sizeof(buf3));
00064 for(i=8; i<hdr.frame_size; i+=2) {
00065 buf3[i ] = buf[i+1];
00066 buf3[i+1] = buf[i ];
00067 }
00068 }
00069 if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, gbc.buffer + 2, hdr.frame_size - 2))
00070 break;
00071 if (hdr.bitstream_id > 10)
00072 codec_id = AV_CODEC_ID_EAC3;
00073 buf2 += hdr.frame_size;
00074 }
00075 max_frames = FFMAX(max_frames, frames);
00076 if(buf == p->buf)
00077 first_frames = frames;
00078 }
00079 if(codec_id != expected_codec_id) return 0;
00080
00081
00082 if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
00083 else if(max_frames>200)return AVPROBE_SCORE_MAX/2;
00084 else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
00085 else if(max_frames>=1) return 1;
00086 else return 0;
00087 }
00088
00089 #if CONFIG_AC3_DEMUXER
00090 static int ac3_probe(AVProbeData *p)
00091 {
00092 return ac3_eac3_probe(p, AV_CODEC_ID_AC3);
00093 }
00094
00095 AVInputFormat ff_ac3_demuxer = {
00096 .name = "ac3",
00097 .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"),
00098 .read_probe = ac3_probe,
00099 .read_header = ff_raw_audio_read_header,
00100 .read_packet = ff_raw_read_partial_packet,
00101 .flags= AVFMT_GENERIC_INDEX,
00102 .extensions = "ac3",
00103 .raw_codec_id = AV_CODEC_ID_AC3,
00104 };
00105 #endif
00106
00107 #if CONFIG_EAC3_DEMUXER
00108 static int eac3_probe(AVProbeData *p)
00109 {
00110 return ac3_eac3_probe(p, AV_CODEC_ID_EAC3);
00111 }
00112
00113 AVInputFormat ff_eac3_demuxer = {
00114 .name = "eac3",
00115 .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
00116 .read_probe = eac3_probe,
00117 .read_header = ff_raw_audio_read_header,
00118 .read_packet = ff_raw_read_partial_packet,
00119 .flags = AVFMT_GENERIC_INDEX,
00120 .extensions = "eac3",
00121 .raw_codec_id = AV_CODEC_ID_EAC3,
00122 };
00123 #endif