00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "bitstream.h"
00023 #include "mpeg4audio.h"
00024
00025 const int ff_mpeg4audio_sample_rates[16] = {
00026 96000, 88200, 64000, 48000, 44100, 32000,
00027 24000, 22050, 16000, 12000, 11025, 8000, 7350
00028 };
00029
00030 const uint8_t ff_mpeg4audio_channels[8] = {
00031 0, 1, 2, 3, 4, 5, 6, 8
00032 };
00033
00034 static inline int get_object_type(GetBitContext *gb)
00035 {
00036 int object_type = get_bits(gb, 5);
00037 if (object_type == 31)
00038 object_type = 32 + get_bits(gb, 6);
00039 return object_type;
00040 }
00041
00042 static inline int get_sample_rate(GetBitContext *gb, int *index)
00043 {
00044 *index = get_bits(gb, 4);
00045 return *index == 0x0f ? get_bits(gb, 24) :
00046 ff_mpeg4audio_sample_rates[*index];
00047 }
00048
00049 int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size)
00050 {
00051 GetBitContext gb;
00052 int specific_config_bitindex;
00053
00054 init_get_bits(&gb, buf, buf_size*8);
00055 c->object_type = get_object_type(&gb);
00056 c->sample_rate = get_sample_rate(&gb, &c->sampling_index);
00057 c->chan_config = get_bits(&gb, 4);
00058 c->sbr = -1;
00059 if (c->object_type == 5) {
00060 c->ext_object_type = c->object_type;
00061 c->sbr = 1;
00062 c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);
00063 c->object_type = get_object_type(&gb);
00064 } else
00065 c->ext_object_type = 0;
00066
00067 specific_config_bitindex = get_bits_count(&gb);
00068
00069 if (c->ext_object_type != 5) {
00070 int bits_left = buf_size*8 - specific_config_bitindex;
00071 for (; bits_left > 15; bits_left--) {
00072 if (show_bits(&gb, 11) == 0x2b7) {
00073 get_bits(&gb, 11);
00074 c->ext_object_type = get_object_type(&gb);
00075 if (c->ext_object_type == 5 && (c->sbr = get_bits1(&gb)) == 1)
00076 c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);
00077 break;
00078 } else
00079 get_bits1(&gb);
00080 }
00081 }
00082 return specific_config_bitindex;
00083 }