Browse code

Split the ADTS header decoder off of the ADTS parser.

The AAC decoder and ADTS-to-ASC BSF both require the header decoder
but not full parsing capabilities.

Originally committed as revision 24217 to svn://svn.ffmpeg.org/ffmpeg/trunk

Alex Converse authored on 2010/07/13 03:52:03
Showing 9 changed files
... ...
@@ -1162,7 +1162,7 @@ mdct_select="fft"
1162 1162
 rdft_select="fft"
1163 1163
 
1164 1164
 # decoders / encoders / hardware accelerators
1165
-aac_decoder_select="mdct rdft aac_parser"
1165
+aac_decoder_select="mdct rdft"
1166 1166
 aac_encoder_select="mdct"
1167 1167
 ac3_decoder_select="mdct ac3_parser"
1168 1168
 alac_encoder_select="lpc"
... ...
@@ -1294,9 +1294,6 @@ vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1294 1294
 # parsers
1295 1295
 h264_parser_select="golomb h264dsp"
1296 1296
 
1297
-# bitstream_filters
1298
-aac_adtstoasc_bsf_select="aac_parser"
1299
-
1300 1297
 # external libraries
1301 1298
 libdirac_decoder_deps="libdirac !libschroedinger"
1302 1299
 libdirac_encoder_deps="libdirac"
... ...
@@ -42,7 +42,8 @@ OBJS-$(CONFIG_VAAPI)                   += vaapi.o
42 42
 OBJS-$(CONFIG_VDPAU)                   += vdpau.o
43 43
 
44 44
 # decoders/encoders/hardware accelerators
45
-OBJS-$(CONFIG_AAC_DECODER)             += aacdec.o aactab.o aacsbr.o aacps.o
45
+OBJS-$(CONFIG_AAC_DECODER)             += aacdec.o aactab.o aacsbr.o aacps.o \
46
+                                          aacadtsdec.o mpeg4audio.o
46 47
 OBJS-$(CONFIG_AAC_ENCODER)             += aacenc.o aaccoder.o    \
47 48
                                           aacpsy.o aactab.o      \
48 49
                                           psymodel.o iirfilter.o \
... ...
@@ -550,7 +551,7 @@ OBJS-$(CONFIG_LIBXVID)                    += libxvidff.o libxvid_rc.o
550 550
 
551 551
 # parsers
552 552
 OBJS-$(CONFIG_AAC_PARSER)              += aac_parser.o aac_ac3_parser.o \
553
-                                          mpeg4audio.o
553
+                                          aacadtsdec.o mpeg4audio.o
554 554
 OBJS-$(CONFIG_AC3_PARSER)              += ac3_parser.o ac3tab.o \
555 555
                                           aac_ac3_parser.o
556 556
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
... ...
@@ -586,7 +587,8 @@ OBJS-$(CONFIG_VP3_PARSER)              += vp3_parser.o
586 586
 OBJS-$(CONFIG_VP8_PARSER)              += vp8_parser.o
587 587
 
588 588
 # bitstream filters
589
-OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)          += aac_adtstoasc_bsf.o
589
+OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)          += aac_adtstoasc_bsf.o aacadtsdec.o \
590
+                                             mpeg4audio.o
590 591
 OBJS-$(CONFIG_CHOMP_BSF)                  += chomp_bsf.o
591 592
 OBJS-$(CONFIG_DUMP_EXTRADATA_BSF)         += dump_extradata_bsf.o
592 593
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)       += h264_mp4toannexb_bsf.o
... ...
@@ -20,7 +20,7 @@
20 20
  */
21 21
 
22 22
 #include "avcodec.h"
23
-#include "aac_parser.h"
23
+#include "aacadtsdec.h"
24 24
 #include "put_bits.h"
25 25
 #include "get_bits.h"
26 26
 #include "mpeg4audio.h"
... ...
@@ -22,53 +22,10 @@
22 22
 
23 23
 #include "parser.h"
24 24
 #include "aac_ac3_parser.h"
25
-#include "aac_parser.h"
25
+#include "aacadtsdec.h"
26 26
 #include "get_bits.h"
27 27
 #include "mpeg4audio.h"
28 28
 
29
-int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
30
-{
31
-    int size, rdb, ch, sr;
32
-    int aot, crc_abs;
33
-
34
-    if(get_bits(gbc, 12) != 0xfff)
35
-        return AAC_AC3_PARSE_ERROR_SYNC;
36
-
37
-    skip_bits1(gbc);             /* id */
38
-    skip_bits(gbc, 2);           /* layer */
39
-    crc_abs = get_bits1(gbc);    /* protection_absent */
40
-    aot     = get_bits(gbc, 2);  /* profile_objecttype */
41
-    sr      = get_bits(gbc, 4);  /* sample_frequency_index */
42
-    if(!ff_mpeg4audio_sample_rates[sr])
43
-        return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
44
-    skip_bits1(gbc);             /* private_bit */
45
-    ch      = get_bits(gbc, 3);  /* channel_configuration */
46
-
47
-    skip_bits1(gbc);             /* original/copy */
48
-    skip_bits1(gbc);             /* home */
49
-
50
-    /* adts_variable_header */
51
-    skip_bits1(gbc);             /* copyright_identification_bit */
52
-    skip_bits1(gbc);             /* copyright_identification_start */
53
-    size    = get_bits(gbc, 13); /* aac_frame_length */
54
-    if(size < AAC_ADTS_HEADER_SIZE)
55
-        return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
56
-
57
-    skip_bits(gbc, 11);          /* adts_buffer_fullness */
58
-    rdb = get_bits(gbc, 2);      /* number_of_raw_data_blocks_in_frame */
59
-
60
-    hdr->object_type    = aot + 1;
61
-    hdr->chan_config    = ch;
62
-    hdr->crc_absent     = crc_abs;
63
-    hdr->num_aac_frames = rdb + 1;
64
-    hdr->sampling_index = sr;
65
-    hdr->sample_rate    = ff_mpeg4audio_sample_rates[sr];
66
-    hdr->samples        = (rdb + 1) * 1024;
67
-    hdr->bit_rate       = size * 8 * hdr->sample_rate / hdr->samples;
68
-
69
-    return size;
70
-}
71
-
72 29
 static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
73 30
         int *need_next_header, int *new_frame_start)
74 31
 {
75 32
deleted file mode 100644
... ...
@@ -1,55 +0,0 @@
1
-/*
2
- * AAC parser prototypes
3
- * Copyright (c) 2003 Fabrice Bellard
4
- * Copyright (c) 2003 Michael Niedermayer
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-#ifndef AVCODEC_AAC_PARSER_H
24
-#define AVCODEC_AAC_PARSER_H
25
-
26
-#include <stdint.h>
27
-#include "aac_ac3_parser.h"
28
-#include "get_bits.h"
29
-
30
-#define AAC_ADTS_HEADER_SIZE 7
31
-
32
-typedef struct {
33
-    uint32_t sample_rate;
34
-    uint32_t samples;
35
-    uint32_t bit_rate;
36
-    uint8_t  crc_absent;
37
-    uint8_t  object_type;
38
-    uint8_t  sampling_index;
39
-    uint8_t  chan_config;
40
-    uint8_t  num_aac_frames;
41
-} AACADTSHeaderInfo;
42
-
43
-/**
44
- * Parse AAC frame header.
45
- * Parse the ADTS frame header to the end of the variable header, which is
46
- * the first 54 bits.
47
- * @param gbc BitContext containing the first 54 bits of the frame.
48
- * @param hdr Pointer to struct where header info is written.
49
- * @return Returns 0 on success, -1 if there is a sync word mismatch,
50
- * -2 if the version element is invalid, -3 if the sample rate
51
- * element is invalid, or -4 if the bit rate element is invalid.
52
- */
53
-int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
54
-
55
-#endif /* AVCODEC_AAC_PARSER_H */
56 1
new file mode 100644
... ...
@@ -0,0 +1,70 @@
0
+/*
1
+ * Audio and Video frame extraction
2
+ * Copyright (c) 2003 Fabrice Bellard
3
+ * Copyright (c) 2003 Michael Niedermayer
4
+ * Copyright (c) 2009 Alex Converse
5
+ *
6
+ * This file is part of FFmpeg.
7
+ *
8
+ * FFmpeg is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * FFmpeg is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with FFmpeg; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ */
22
+
23
+#include "aac_ac3_parser.h"
24
+#include "aacadtsdec.h"
25
+#include "get_bits.h"
26
+#include "mpeg4audio.h"
27
+
28
+int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
29
+{
30
+    int size, rdb, ch, sr;
31
+    int aot, crc_abs;
32
+
33
+    if(get_bits(gbc, 12) != 0xfff)
34
+        return AAC_AC3_PARSE_ERROR_SYNC;
35
+
36
+    skip_bits1(gbc);             /* id */
37
+    skip_bits(gbc, 2);           /* layer */
38
+    crc_abs = get_bits1(gbc);    /* protection_absent */
39
+    aot     = get_bits(gbc, 2);  /* profile_objecttype */
40
+    sr      = get_bits(gbc, 4);  /* sample_frequency_index */
41
+    if(!ff_mpeg4audio_sample_rates[sr])
42
+        return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
43
+    skip_bits1(gbc);             /* private_bit */
44
+    ch      = get_bits(gbc, 3);  /* channel_configuration */
45
+
46
+    skip_bits1(gbc);             /* original/copy */
47
+    skip_bits1(gbc);             /* home */
48
+
49
+    /* adts_variable_header */
50
+    skip_bits1(gbc);             /* copyright_identification_bit */
51
+    skip_bits1(gbc);             /* copyright_identification_start */
52
+    size    = get_bits(gbc, 13); /* aac_frame_length */
53
+    if(size < AAC_ADTS_HEADER_SIZE)
54
+        return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
55
+
56
+    skip_bits(gbc, 11);          /* adts_buffer_fullness */
57
+    rdb = get_bits(gbc, 2);      /* number_of_raw_data_blocks_in_frame */
58
+
59
+    hdr->object_type    = aot + 1;
60
+    hdr->chan_config    = ch;
61
+    hdr->crc_absent     = crc_abs;
62
+    hdr->num_aac_frames = rdb + 1;
63
+    hdr->sampling_index = sr;
64
+    hdr->sample_rate    = ff_mpeg4audio_sample_rates[sr];
65
+    hdr->samples        = (rdb + 1) * 1024;
66
+    hdr->bit_rate       = size * 8 * hdr->sample_rate / hdr->samples;
67
+
68
+    return size;
69
+}
0 70
new file mode 100644
... ...
@@ -0,0 +1,54 @@
0
+/*
1
+ * AAC ADTS header decoding prototypes and structures
2
+ * Copyright (c) 2003 Fabrice Bellard
3
+ * Copyright (c) 2003 Michael Niedermayer
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
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.
11
+ *
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.
16
+ *
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
20
+ */
21
+
22
+#ifndef AVCODEC_AACADTSDEC_H
23
+#define AVCODEC_AACADTSDEC_H
24
+
25
+#include <stdint.h>
26
+#include "get_bits.h"
27
+
28
+#define AAC_ADTS_HEADER_SIZE 7
29
+
30
+typedef struct {
31
+    uint32_t sample_rate;
32
+    uint32_t samples;
33
+    uint32_t bit_rate;
34
+    uint8_t  crc_absent;
35
+    uint8_t  object_type;
36
+    uint8_t  sampling_index;
37
+    uint8_t  chan_config;
38
+    uint8_t  num_aac_frames;
39
+} AACADTSHeaderInfo;
40
+
41
+/**
42
+ * Parse AAC frame header.
43
+ * Parse the ADTS frame header to the end of the variable header, which is
44
+ * the first 54 bits.
45
+ * @param gbc BitContext containing the first 54 bits of the frame.
46
+ * @param hdr Pointer to struct where header info is written.
47
+ * @return Returns 0 on success, -1 if there is a sync word mismatch,
48
+ * -2 if the version element is invalid, -3 if the sample rate
49
+ * element is invalid, or -4 if the bit rate element is invalid.
50
+ */
51
+int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
52
+
53
+#endif /* AVCODEC_AACADTSDEC_H */
... ...
@@ -90,7 +90,7 @@
90 90
 #include "sbr.h"
91 91
 #include "aacsbr.h"
92 92
 #include "mpeg4audio.h"
93
-#include "aac_parser.h"
93
+#include "aacadtsdec.h"
94 94
 
95 95
 #include <assert.h>
96 96
 #include <errno.h>
... ...
@@ -43,7 +43,7 @@
43 43
 #include "avformat.h"
44 44
 #include "libavcodec/ac3.h"
45 45
 #include "libavcodec/dca.h"
46
-#include "libavcodec/aac_parser.h"
46
+#include "libavcodec/aacadtsdec.h"
47 47
 
48 48
 #define SYNCWORD1 0xF872
49 49
 #define SYNCWORD2 0x4E1F