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 "config_components.h"
24 #include "libavutil/avassert.h"
25 #include "libavutil/crc.h"
26 #include "libavcodec/ac3_parser.h"
31 static int ac3_eac3_probe(const AVProbeData
*p
, enum AVCodecID expected_codec_id
)
33 int max_frames
, first_frames
= 0, frames
;
34 const uint8_t *buf
, *buf2
, *end
;
35 enum AVCodecID codec_id
= AV_CODEC_ID_AC3
;
39 end
= buf
+ p
->buf_size
;
41 for(; buf
< end
; buf
++) {
42 if(buf
> p
->buf
&& !(buf
[0] == 0x0B && buf
[1] == 0x77)
43 && !(buf
[0] == 0x77 && buf
[1] == 0x0B) )
47 for(frames
= 0; buf2
< end
; frames
++) {
53 if(!memcmp(buf2
, "\x1\x10", 2)) {
58 if (buf
[0] == 0x77 && buf
[1] == 0x0B) {
63 ret
= av_ac3_parse_header(buf3
, 8, &bitstream_id
,
66 ret
= av_ac3_parse_header(buf2
, end
- buf2
, &bitstream_id
,
70 if(buf2
+ frame_size
> end
)
72 if (buf
[0] == 0x77 && buf
[1] == 0x0B) {
73 av_assert0(frame_size
<= sizeof(buf3
));
74 for(i
= 8; i
< frame_size
; i
+= 2) {
78 if (av_crc(av_crc_get_table(AV_CRC_16_ANSI
), 0, buf3
+ 2, frame_size
- 2))
81 if (av_crc(av_crc_get_table(AV_CRC_16_ANSI
), 0, buf2
+ 2, frame_size
- 2))
84 if (bitstream_id
> 10)
85 codec_id
= AV_CODEC_ID_EAC3
;
88 max_frames
= FFMAX(max_frames
, frames
);
90 first_frames
= frames
;
92 if(codec_id
!= expected_codec_id
) return 0;
93 // keep this in sync with mp3 probe, both need to avoid
94 // issues with MPEG-files!
95 if (first_frames
>=7) return AVPROBE_SCORE_EXTENSION
+ 1;
96 else if(max_frames
>200)return AVPROBE_SCORE_EXTENSION
;
97 else if(max_frames
>=4) return AVPROBE_SCORE_EXTENSION
/2;
98 else if(max_frames
>=1) return 1;
102 #if CONFIG_AC3_DEMUXER
103 static int ac3_probe(const AVProbeData
*p
)
105 return ac3_eac3_probe(p
, AV_CODEC_ID_AC3
);
108 const FFInputFormat ff_ac3_demuxer
= {
110 .p
.long_name
= NULL_IF_CONFIG_SMALL("raw AC-3"),
111 .p
.flags
= AVFMT_GENERIC_INDEX
,
112 .p
.extensions
= "ac3",
113 .p
.priv_class
= &ff_raw_demuxer_class
,
114 .read_probe
= ac3_probe
,
115 .read_header
= ff_raw_audio_read_header
,
116 .read_packet
= ff_raw_read_partial_packet
,
117 .raw_codec_id
= AV_CODEC_ID_AC3
,
118 .priv_data_size
= sizeof(FFRawDemuxerContext
),
122 #if CONFIG_EAC3_DEMUXER
123 static int eac3_probe(const AVProbeData
*p
)
125 return ac3_eac3_probe(p
, AV_CODEC_ID_EAC3
);
128 const FFInputFormat ff_eac3_demuxer
= {
130 .p
.long_name
= NULL_IF_CONFIG_SMALL("raw E-AC-3"),
131 .p
.flags
= AVFMT_GENERIC_INDEX
,
132 .p
.extensions
= "eac3,ec3",
133 .p
.priv_class
= &ff_raw_demuxer_class
,
134 .read_probe
= eac3_probe
,
135 .read_header
= ff_raw_audio_read_header
,
136 .read_packet
= ff_raw_read_partial_packet
,
137 .raw_codec_id
= AV_CODEC_ID_EAC3
,
138 .priv_data_size
= sizeof(FFRawDemuxerContext
),