2 * RAW AC-3 and E-AC-3 demuxer
3 * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/crc.h"
23 #include "libavcodec/ac3_parser.h"
27 static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
29 int max_frames, first_frames = 0, frames;
30 uint8_t *buf, *buf2, *end;
33 enum CodecID codec_id = CODEC_ID_AC3;
37 end = buf + p->buf_size;
39 for(; buf < end; buf++) {
42 for(frames = 0; buf2 < end; frames++) {
43 if(!memcmp(buf2, "\x1\x10\0\0\0\0\0\0", 8))
45 init_get_bits(&gbc, buf2, 54);
46 if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)
48 if(buf2 + hdr.frame_size > end ||
49 av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
51 if (hdr.bitstream_id > 10)
52 codec_id = CODEC_ID_EAC3;
53 buf2 += hdr.frame_size;
55 max_frames = FFMAX(max_frames, frames);
57 first_frames = frames;
59 if(codec_id != expected_codec_id) return 0;
60 // keep this in sync with mp3 probe, both need to avoid
61 // issues with MPEG-files!
62 if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
63 else if(max_frames>200)return AVPROBE_SCORE_MAX/2;
64 else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
65 else if(max_frames>=1) return 1;
69 #if CONFIG_AC3_DEMUXER
70 static int ac3_probe(AVProbeData *p)
72 return ac3_eac3_probe(p, CODEC_ID_AC3);
75 AVInputFormat ff_ac3_demuxer = {
77 .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"),
78 .read_probe = ac3_probe,
79 .read_header = ff_raw_audio_read_header,
80 .read_packet = ff_raw_read_partial_packet,
81 .flags= AVFMT_GENERIC_INDEX,
83 .raw_codec_id = CODEC_ID_AC3,
87 #if CONFIG_EAC3_DEMUXER
88 static int eac3_probe(AVProbeData *p)
90 return ac3_eac3_probe(p, CODEC_ID_EAC3);
93 AVInputFormat ff_eac3_demuxer = {
95 .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
96 .read_probe = eac3_probe,
97 .read_header = ff_raw_audio_read_header,
98 .read_packet = ff_raw_read_partial_packet,
99 .flags= AVFMT_GENERIC_INDEX,
100 .extensions = "eac3",
101 .raw_codec_id = CODEC_ID_EAC3,