00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "parser.h"
00024 #include "aac_ac3_parser.h"
00025 #include "aac_parser.h"
00026 #include "bitstream.h"
00027 #include "mpeg4audio.h"
00028
00029 #define AAC_HEADER_SIZE 7
00030
00031 int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
00032 {
00033 int size, rdb, ch, sr;
00034 int aot, crc_abs;
00035
00036 if(get_bits(gbc, 12) != 0xfff)
00037 return AAC_AC3_PARSE_ERROR_SYNC;
00038
00039 skip_bits1(gbc);
00040 skip_bits(gbc, 2);
00041 crc_abs = get_bits1(gbc);
00042 aot = get_bits(gbc, 2);
00043 sr = get_bits(gbc, 4);
00044 if(!ff_mpeg4audio_sample_rates[sr])
00045 return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
00046 skip_bits1(gbc);
00047 ch = get_bits(gbc, 3);
00048
00049 if(!ff_mpeg4audio_channels[ch])
00050 return AAC_AC3_PARSE_ERROR_CHANNEL_CFG;
00051
00052 skip_bits1(gbc);
00053 skip_bits1(gbc);
00054
00055
00056 skip_bits1(gbc);
00057 skip_bits1(gbc);
00058 size = get_bits(gbc, 13);
00059 if(size < AAC_HEADER_SIZE)
00060 return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
00061
00062 skip_bits(gbc, 11);
00063 rdb = get_bits(gbc, 2);
00064
00065 hdr->object_type = aot + 1;
00066 hdr->chan_config = ch;
00067 hdr->crc_absent = crc_abs;
00068 hdr->num_aac_frames = rdb + 1;
00069 hdr->sampling_index = sr;
00070 hdr->sample_rate = ff_mpeg4audio_sample_rates[sr];
00071 hdr->samples = (rdb + 1) * 1024;
00072 hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples;
00073
00074 return size;
00075 }
00076
00077 static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
00078 int *need_next_header, int *new_frame_start)
00079 {
00080 GetBitContext bits;
00081 AACADTSHeaderInfo hdr;
00082 int size;
00083 union {
00084 uint64_t u64;
00085 uint8_t u8[8];
00086 } tmp;
00087
00088 tmp.u64 = be2me_64(state);
00089 init_get_bits(&bits, tmp.u8+8-AAC_HEADER_SIZE, AAC_HEADER_SIZE * 8);
00090
00091 if ((size = ff_aac_parse_header(&bits, &hdr)) < 0)
00092 return 0;
00093 *need_next_header = 0;
00094 *new_frame_start = 1;
00095 hdr_info->sample_rate = hdr.sample_rate;
00096 hdr_info->channels = ff_mpeg4audio_channels[hdr.chan_config];
00097 hdr_info->samples = hdr.samples;
00098 hdr_info->bit_rate = hdr.bit_rate;
00099 return size;
00100 }
00101
00102 static av_cold int aac_parse_init(AVCodecParserContext *s1)
00103 {
00104 AACAC3ParseContext *s = s1->priv_data;
00105 s->header_size = AAC_HEADER_SIZE;
00106 s->sync = aac_sync;
00107 return 0;
00108 }
00109
00110
00111 AVCodecParser aac_parser = {
00112 { CODEC_ID_AAC },
00113 sizeof(AACAC3ParseContext),
00114 aac_parse_init,
00115 ff_aac_ac3_parse,
00116 ff_parse_close,
00117 };