Commit 6d8629aa authored by Luca Barbato's avatar Luca Barbato

aac: K&R formatting cosmetics

parent 4f6b192e
...@@ -210,21 +210,32 @@ static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID], ...@@ -210,21 +210,32 @@ static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID],
{ {
if (layout_map[offset][0] == TYPE_CPE) { if (layout_map[offset][0] == TYPE_CPE) {
e2c_vec[offset] = (struct elem_to_channel) { e2c_vec[offset] = (struct elem_to_channel) {
.av_position = left | right, .syn_ele = TYPE_CPE, .av_position = left | right,
.elem_id = layout_map[offset ][1], .aac_position = pos }; .syn_ele = TYPE_CPE,
.elem_id = layout_map[offset][1],
.aac_position = pos
};
return 1; return 1;
} else { } else {
e2c_vec[offset] = (struct elem_to_channel) { e2c_vec[offset] = (struct elem_to_channel) {
.av_position = left, .syn_ele = TYPE_SCE, .av_position = left,
.elem_id = layout_map[offset ][1], .aac_position = pos }; .syn_ele = TYPE_SCE,
.elem_id = layout_map[offset][1],
.aac_position = pos
};
e2c_vec[offset + 1] = (struct elem_to_channel) { e2c_vec[offset + 1] = (struct elem_to_channel) {
.av_position = right, .syn_ele = TYPE_SCE, .av_position = right,
.elem_id = layout_map[offset + 1][1], .aac_position = pos }; .syn_ele = TYPE_SCE,
.elem_id = layout_map[offset + 1][1],
.aac_position = pos
};
return 2; return 2;
} }
} }
static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, int *current) { static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos,
int *current)
{
int num_pos_channels = 0; int num_pos_channels = 0;
int first_cpe = 0; int first_cpe = 0;
int sce_parity = 0; int sce_parity = 0;
...@@ -257,7 +268,7 @@ static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, in ...@@ -257,7 +268,7 @@ static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, in
static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
{ {
int i, n, total_non_cc_elements; int i, n, total_non_cc_elements;
struct elem_to_channel e2c_vec[4*MAX_ELEM_ID] = {{ 0 }}; struct elem_to_channel e2c_vec[4 * MAX_ELEM_ID] = { { 0 } };
int num_front_channels, num_side_channels, num_back_channels; int num_front_channels, num_side_channels, num_back_channels;
uint64_t layout; uint64_t layout;
...@@ -281,8 +292,11 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) ...@@ -281,8 +292,11 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
i = 0; i = 0;
if (num_front_channels & 1) { if (num_front_channels & 1) {
e2c_vec[i] = (struct elem_to_channel) { e2c_vec[i] = (struct elem_to_channel) {
.av_position = AV_CH_FRONT_CENTER, .syn_ele = TYPE_SCE, .av_position = AV_CH_FRONT_CENTER,
.elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_FRONT }; .syn_ele = TYPE_SCE,
.elem_id = layout_map[i][1],
.aac_position = AAC_CHANNEL_FRONT
};
i++; i++;
num_front_channels--; num_front_channels--;
} }
...@@ -339,22 +353,31 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) ...@@ -339,22 +353,31 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
} }
if (num_back_channels) { if (num_back_channels) {
e2c_vec[i] = (struct elem_to_channel) { e2c_vec[i] = (struct elem_to_channel) {
.av_position = AV_CH_BACK_CENTER, .syn_ele = TYPE_SCE, .av_position = AV_CH_BACK_CENTER,
.elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_BACK }; .syn_ele = TYPE_SCE,
.elem_id = layout_map[i][1],
.aac_position = AAC_CHANNEL_BACK
};
i++; i++;
num_back_channels--; num_back_channels--;
} }
if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) {
e2c_vec[i] = (struct elem_to_channel) { e2c_vec[i] = (struct elem_to_channel) {
.av_position = AV_CH_LOW_FREQUENCY, .syn_ele = TYPE_LFE, .av_position = AV_CH_LOW_FREQUENCY,
.elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE }; .syn_ele = TYPE_LFE,
.elem_id = layout_map[i][1],
.aac_position = AAC_CHANNEL_LFE
};
i++; i++;
} }
while (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { while (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) {
e2c_vec[i] = (struct elem_to_channel) { e2c_vec[i] = (struct elem_to_channel) {
.av_position = UINT64_MAX, .syn_ele = TYPE_LFE, .av_position = UINT64_MAX,
.elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE }; .syn_ele = TYPE_LFE,
.elem_id = layout_map[i][1],
.aac_position = AAC_CHANNEL_LFE
};
i++; i++;
} }
...@@ -362,12 +385,11 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) ...@@ -362,12 +385,11 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
total_non_cc_elements = n = i; total_non_cc_elements = n = i;
do { do {
int next_n = 0; int next_n = 0;
for (i = 1; i < n; i++) { for (i = 1; i < n; i++)
if (e2c_vec[i-1].av_position > e2c_vec[i].av_position) { if (e2c_vec[i - 1].av_position > e2c_vec[i].av_position) {
FFSWAP(struct elem_to_channel, e2c_vec[i-1], e2c_vec[i]); FFSWAP(struct elem_to_channel, e2c_vec[i - 1], e2c_vec[i]);
next_n = i; next_n = i;
} }
}
n = next_n; n = next_n;
} while (n > 0); } while (n > 0);
...@@ -407,12 +429,13 @@ static void pop_output_configuration(AACContext *ac) { ...@@ -407,12 +429,13 @@ static void pop_output_configuration(AACContext *ac) {
} }
/** /**
* Configure output channel order based on the current program configuration element. * Configure output channel order based on the current program
* configuration element.
* *
* @return Returns error status. 0 - OK, !0 - error * @return Returns error status. 0 - OK, !0 - error
*/ */
static int output_configure(AACContext *ac, static int output_configure(AACContext *ac,
uint8_t layout_map[MAX_ELEM_ID*4][3], int tags, uint8_t layout_map[MAX_ELEM_ID * 4][3], int tags,
enum OCStatus oc_type, int get_new_frame) enum OCStatus oc_type, int get_new_frame)
{ {
AVCodecContext *avctx = ac->avctx; AVCodecContext *avctx = ac->avctx;
...@@ -471,29 +494,33 @@ static int set_default_channel_config(AVCodecContext *avctx, ...@@ -471,29 +494,33 @@ static int set_default_channel_config(AVCodecContext *avctx,
int channel_config) int channel_config)
{ {
if (channel_config < 1 || channel_config > 7) { if (channel_config < 1 || channel_config > 7) {
av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n", av_log(avctx, AV_LOG_ERROR,
"invalid default channel configuration (%d)\n",
channel_config); channel_config);
return -1; return -1;
} }
*tags = tags_per_config[channel_config]; *tags = tags_per_config[channel_config];
memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map)); memcpy(layout_map, aac_channel_layout_map[channel_config - 1],
*tags * sizeof(*layout_map));
return 0; return 0;
} }
static ChannelElement *get_che(AACContext *ac, int type, int elem_id) static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
{ {
// For PCE based channel configurations map the channels solely based on tags. /* For PCE based channel configurations map the channels solely based
* on tags. */
if (!ac->oc[1].m4ac.chan_config) { if (!ac->oc[1].m4ac.chan_config) {
return ac->tag_che_map[type][elem_id]; return ac->tag_che_map[type][elem_id];
} }
// Allow single CPE stereo files to be signalled with mono configuration. // Allow single CPE stereo files to be signalled with mono configuration.
if (!ac->tags_mapped && type == TYPE_CPE && ac->oc[1].m4ac.chan_config == 1) { if (!ac->tags_mapped && type == TYPE_CPE &&
ac->oc[1].m4ac.chan_config == 1) {
uint8_t layout_map[MAX_ELEM_ID*4][3]; uint8_t layout_map[MAX_ELEM_ID*4][3];
int layout_map_tags; int layout_map_tags;
push_output_configuration(ac); push_output_configuration(ac);
if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags, if (set_default_channel_config(ac->avctx, layout_map,
2) < 0) &layout_map_tags, 2) < 0)
return NULL; return NULL;
if (output_configure(ac, layout_map, layout_map_tags, if (output_configure(ac, layout_map, layout_map_tags,
OC_TRIAL_FRAME, 1) < 0) OC_TRIAL_FRAME, 1) < 0)
...@@ -503,13 +530,14 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) ...@@ -503,13 +530,14 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
ac->oc[1].m4ac.ps = 0; ac->oc[1].m4ac.ps = 0;
} }
// And vice-versa // And vice-versa
if (!ac->tags_mapped && type == TYPE_SCE && ac->oc[1].m4ac.chan_config == 2) { if (!ac->tags_mapped && type == TYPE_SCE &&
uint8_t layout_map[MAX_ELEM_ID*4][3]; ac->oc[1].m4ac.chan_config == 2) {
uint8_t layout_map[MAX_ELEM_ID * 4][3];
int layout_map_tags; int layout_map_tags;
push_output_configuration(ac); push_output_configuration(ac);
if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags, if (set_default_channel_config(ac->avctx, layout_map,
1) < 0) &layout_map_tags, 1) < 0)
return NULL; return NULL;
if (output_configure(ac, layout_map, layout_map_tags, if (output_configure(ac, layout_map, layout_map_tags,
OC_TRIAL_FRAME, 1) < 0) OC_TRIAL_FRAME, 1) < 0)
...@@ -519,7 +547,8 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) ...@@ -519,7 +547,8 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
if (ac->oc[1].m4ac.sbr) if (ac->oc[1].m4ac.sbr)
ac->oc[1].m4ac.ps = -1; ac->oc[1].m4ac.ps = -1;
} }
// For indexed channel configurations map the channels solely based on position. /* For indexed channel configurations map the channels solely based
* on position. */
switch (ac->oc[1].m4ac.chan_config) { switch (ac->oc[1].m4ac.chan_config) {
case 7: case 7:
if (ac->tags_mapped == 3 && type == TYPE_CPE) { if (ac->tags_mapped == 3 && type == TYPE_CPE) {
...@@ -527,9 +556,12 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) ...@@ -527,9 +556,12 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2]; return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
} }
case 6: case 6:
/* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1] /* Some streams incorrectly code 5.1 audio as
instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have * SCE[0] CPE[0] CPE[1] SCE[1]
encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */ * instead of
* SCE[0] CPE[0] CPE[1] LFE[0].
* If we seem to have encountered such a stream, transfer
* the LFE[0] element to the SCE[1]'s mapping */
if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) { if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
ac->tags_mapped++; ac->tags_mapped++;
return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0]; return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
...@@ -540,13 +572,16 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) ...@@ -540,13 +572,16 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1]; return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
} }
case 4: case 4:
if (ac->tags_mapped == 2 && ac->oc[1].m4ac.chan_config == 4 && type == TYPE_SCE) { if (ac->tags_mapped == 2 &&
ac->oc[1].m4ac.chan_config == 4 &&
type == TYPE_SCE) {
ac->tags_mapped++; ac->tags_mapped++;
return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
} }
case 3: case 3:
case 2: case 2:
if (ac->tags_mapped == (ac->oc[1].m4ac.chan_config != 2) && type == TYPE_CPE) { if (ac->tags_mapped == (ac->oc[1].m4ac.chan_config != 2) &&
type == TYPE_CPE) {
ac->tags_mapped++; ac->tags_mapped++;
return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0]; return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
} else if (ac->oc[1].m4ac.chan_config == 2) { } else if (ac->oc[1].m4ac.chan_config == 2) {
...@@ -563,7 +598,8 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) ...@@ -563,7 +598,8 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
} }
/** /**
* Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit. * Decode an array of 4 bit element IDs, optionally interleaved with a
* stereo/mono switching bit.
* *
* @param type speaker type/position for these channels * @param type speaker type/position for these channels
*/ */
...@@ -603,7 +639,8 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, ...@@ -603,7 +639,8 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
uint8_t (*layout_map)[3], uint8_t (*layout_map)[3],
GetBitContext *gb) GetBitContext *gb)
{ {
int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index; int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
int sampling_index;
int comment_len; int comment_len;
int tags; int tags;
...@@ -611,7 +648,9 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, ...@@ -611,7 +648,9 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
sampling_index = get_bits(gb, 4); sampling_index = get_bits(gb, 4);
if (m4ac->sampling_index != sampling_index) if (m4ac->sampling_index != sampling_index)
av_log(avctx, AV_LOG_WARNING, "Sample rate index in program config element does not match the sample rate index configured by the container.\n"); av_log(avctx, AV_LOG_WARNING,
"Sample rate index in program config element does not "
"match the sample rate index configured by the container.\n");
num_front = get_bits(gb, 4); num_front = get_bits(gb, 4);
num_side = get_bits(gb, 4); num_side = get_bits(gb, 4);
...@@ -690,7 +729,8 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, ...@@ -690,7 +729,8 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
if (tags < 0) if (tags < 0)
return tags; return tags;
} else { } else {
if ((ret = set_default_channel_config(avctx, layout_map, &tags, channel_config))) if ((ret = set_default_channel_config(avctx, layout_map,
&tags, channel_config)))
return ret; return ret;
} }
...@@ -751,10 +791,13 @@ static int decode_audio_specific_config(AACContext *ac, ...@@ -751,10 +791,13 @@ static int decode_audio_specific_config(AACContext *ac,
init_get_bits(&gb, data, bit_size); init_get_bits(&gb, data, bit_size);
if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, sync_extension)) < 0) if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size,
sync_extension)) < 0)
return -1; return -1;
if (m4ac->sampling_index > 12) { if (m4ac->sampling_index > 12) {
av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index); av_log(avctx, AV_LOG_ERROR,
"invalid sampling rate index %d\n",
m4ac->sampling_index);
return -1; return -1;
} }
...@@ -768,14 +811,18 @@ static int decode_audio_specific_config(AACContext *ac, ...@@ -768,14 +811,18 @@ static int decode_audio_specific_config(AACContext *ac,
return -1; return -1;
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n", av_log(avctx, AV_LOG_ERROR,
m4ac->sbr == 1? "SBR+" : "", m4ac->object_type); "Audio object type %s%d is not supported.\n",
m4ac->sbr == 1 ? "SBR+" : "",
m4ac->object_type);
return -1; return -1;
} }
av_dlog(avctx, "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n", av_dlog(avctx,
"AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
m4ac->object_type, m4ac->chan_config, m4ac->sampling_index, m4ac->object_type, m4ac->chan_config, m4ac->sampling_index,
m4ac->sample_rate, m4ac->sbr, m4ac->ps); m4ac->sample_rate, m4ac->sbr,
m4ac->ps);
return get_bits_count(&gb); return get_bits_count(&gb);
} }
...@@ -835,8 +882,10 @@ static void reset_predictor_group(PredictorState *ps, int group_num) ...@@ -835,8 +882,10 @@ static void reset_predictor_group(PredictorState *ps, int group_num)
#define AAC_INIT_VLC_STATIC(num, size) \ #define AAC_INIT_VLC_STATIC(num, size) \
INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \ INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \
ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \ ff_aac_spectral_bits[num], sizeof(ff_aac_spectral_bits[num][0]), \
ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \ sizeof(ff_aac_spectral_bits[num][0]), \
ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), \
sizeof(ff_aac_spectral_codes[num][0]), \
size); size);
static av_cold int aac_decode_init(AVCodecContext *avctx) static av_cold int aac_decode_init(AVCodecContext *avctx)
...@@ -851,7 +900,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ...@@ -851,7 +900,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
if (avctx->extradata_size > 0) { if (avctx->extradata_size > 0) {
if (decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac, if (decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac,
avctx->extradata, avctx->extradata,
avctx->extradata_size*8, 1) < 0) avctx->extradata_size * 8, 1) < 0)
return -1; return -1;
} else { } else {
int sr, i; int sr, i;
...@@ -904,9 +953,14 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ...@@ -904,9 +953,14 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
ff_aac_tableinit(); ff_aac_tableinit();
INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code), INIT_VLC_STATIC(&vlc_scalefactors, 7,
ff_aac_scalefactor_bits, sizeof(ff_aac_scalefactor_bits[0]), sizeof(ff_aac_scalefactor_bits[0]), FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), ff_aac_scalefactor_bits,
sizeof(ff_aac_scalefactor_bits[0]),
sizeof(ff_aac_scalefactor_bits[0]),
ff_aac_scalefactor_code,
sizeof(ff_aac_scalefactor_code[0]),
sizeof(ff_aac_scalefactor_code[0]),
352); 352);
ff_mdct_init(&ac->mdct, 11, 1, 1.0 / (32768.0 * 1024.0)); ff_mdct_init(&ac->mdct, 11, 1, 1.0 / (32768.0 * 1024.0));
...@@ -949,8 +1003,10 @@ static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, ...@@ -949,8 +1003,10 @@ static int decode_prediction(AACContext *ac, IndividualChannelStream *ics,
int sfb; int sfb;
if (get_bits1(gb)) { if (get_bits1(gb)) {
ics->predictor_reset_group = get_bits(gb, 5); ics->predictor_reset_group = get_bits(gb, 5);
if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30) { if (ics->predictor_reset_group == 0 ||
av_log(ac->avctx, AV_LOG_ERROR, "Invalid Predictor Reset Group.\n"); ics->predictor_reset_group > 30) {
av_log(ac->avctx, AV_LOG_ERROR,
"Invalid Predictor Reset Group.\n");
return -1; return -1;
} }
} }
...@@ -1020,7 +1076,8 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, ...@@ -1020,7 +1076,8 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
} else if (ac->oc[1].m4ac.object_type == AOT_AAC_LC) { } else if (ac->oc[1].m4ac.object_type == AOT_AAC_LC) {
av_log(ac->avctx, AV_LOG_ERROR, "Prediction is not allowed in AAC-LC.\n"); av_log(ac->avctx, AV_LOG_ERROR,
"Prediction is not allowed in AAC-LC.\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} else { } else {
if ((ics->ltp.present = get_bits(gb, 1))) if ((ics->ltp.present = get_bits(gb, 1)))
...@@ -1031,7 +1088,8 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, ...@@ -1031,7 +1088,8 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
if (ics->max_sfb > ics->num_swb) { if (ics->max_sfb > ics->num_swb) {
av_log(ac->avctx, AV_LOG_ERROR, av_log(ac->avctx, AV_LOG_ERROR,
"Number of scalefactor bands in group (%d) exceeds limit (%d).\n", "Number of scalefactor bands in group (%d) "
"exceeds limit (%d).\n",
ics->max_sfb, ics->num_swb); ics->max_sfb, ics->num_swb);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -1112,7 +1170,8 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, ...@@ -1112,7 +1170,8 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
if (band_type[idx] == ZERO_BT) { if (band_type[idx] == ZERO_BT) {
for (; i < run_end; i++, idx++) for (; i < run_end; i++, idx++)
sf[idx] = 0.; sf[idx] = 0.;
} else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { } else if ((band_type[idx] == INTENSITY_BT) ||
(band_type[idx] == INTENSITY_BT2)) {
for (; i < run_end; i++, idx++) { for (; i < run_end; i++, idx++) {
offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
clipped_offset = av_clip(offset[2], -155, 100); clipped_offset = av_clip(offset[2], -155, 100);
...@@ -1200,7 +1259,8 @@ static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns, ...@@ -1200,7 +1259,8 @@ static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns,
tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); tns->length[w][filt] = get_bits(gb, 6 - 2 * is8);
if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) { if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
av_log(ac->avctx, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.\n", av_log(ac->avctx, AV_LOG_ERROR,
"TNS filter order %d is greater than maximum %d.\n",
tns->order[w][filt], tns_max_order); tns->order[w][filt], tns_max_order);
tns->order[w][filt] = 0; tns->order[w][filt] = 0;
return -1; return -1;
...@@ -1232,7 +1292,9 @@ static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, ...@@ -1232,7 +1292,9 @@ static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb,
{ {
int idx; int idx;
if (ms_present == 1) { if (ms_present == 1) {
for (idx = 0; idx < cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb; idx++) for (idx = 0;
idx < cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb;
idx++)
cpe->ms_mask[idx] = get_bits1(gb); cpe->ms_mask[idx] = get_bits1(gb);
} else if (ms_present == 2) { } else if (ms_present == 2) {
memset(cpe->ms_mask, 1, cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb * sizeof(cpe->ms_mask[0])); memset(cpe->ms_mask, 1, cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb * sizeof(cpe->ms_mask[0]));
...@@ -1331,7 +1393,8 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], ...@@ -1331,7 +1393,8 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
float *coef_base = coef; float *coef_base = coef;
for (g = 0; g < ics->num_windows; g++) for (g = 0; g < ics->num_windows; g++)
memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float) * (c - offsets[ics->max_sfb])); memset(coef + g * 128 + offsets[ics->max_sfb], 0,
sizeof(float) * (c - offsets[ics->max_sfb]));
for (g = 0; g < ics->num_window_groups; g++) { for (g = 0; g < ics->num_window_groups; g++) {
unsigned g_len = ics->group_len[g]; unsigned g_len = ics->group_len[g];
...@@ -1601,14 +1664,20 @@ static void apply_prediction(AACContext *ac, SingleChannelElement *sce) ...@@ -1601,14 +1664,20 @@ static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
} }
if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]; sfb++) { for (sfb = 0;
for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) { sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index];
sfb++) {
for (k = sce->ics.swb_offset[sfb];
k < sce->ics.swb_offset[sfb + 1];
k++) {
predict(&sce->predictor_state[k], &sce->coeffs[k], predict(&sce->predictor_state[k], &sce->coeffs[k],
sce->ics.predictor_present && sce->ics.prediction_used[sfb]); sce->ics.predictor_present &&
sce->ics.prediction_used[sfb]);
} }
} }
if (sce->ics.predictor_reset_group) if (sce->ics.predictor_reset_group)
reset_predictor_group(sce->predictor_state, sce->ics.predictor_reset_group); reset_predictor_group(sce->predictor_state,
sce->ics.predictor_reset_group);
} else } else
reset_all_predictors(sce->predictor_state); reset_all_predictors(sce->predictor_state);
} }
...@@ -1642,20 +1711,24 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, ...@@ -1642,20 +1711,24 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0) if (decode_band_types(ac, sce->band_type,
sce->band_type_run_end, gb, ics) < 0)
return -1; return -1;
if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, sce->band_type, sce->band_type_run_end) < 0) if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics,
sce->band_type, sce->band_type_run_end) < 0)
return -1; return -1;
pulse_present = 0; pulse_present = 0;
if (!scale_flag) { if (!scale_flag) {
if ((pulse_present = get_bits1(gb))) { if ((pulse_present = get_bits1(gb))) {
if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
av_log(ac->avctx, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n"); av_log(ac->avctx, AV_LOG_ERROR,
"Pulse tool not allowed in eight short sequence.\n");
return -1; return -1;
} }
if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) { if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) {
av_log(ac->avctx, AV_LOG_ERROR, "Pulse data corrupt or invalid.\n"); av_log(ac->avctx, AV_LOG_ERROR,
"Pulse data corrupt or invalid.\n");
return -1; return -1;
} }
} }
...@@ -1667,7 +1740,8 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, ...@@ -1667,7 +1740,8 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
} }
} }
if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0) if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present,
&pulse, ics, sce->band_type) < 0)
return -1; return -1;
if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window) if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window)
...@@ -1689,7 +1763,8 @@ static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe) ...@@ -1689,7 +1763,8 @@ static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe)
for (g = 0; g < ics->num_window_groups; g++) { for (g = 0; g < ics->num_window_groups; g++) {
for (i = 0; i < ics->max_sfb; i++, idx++) { for (i = 0; i < ics->max_sfb; i++, idx++) {
if (cpe->ms_mask[idx] && if (cpe->ms_mask[idx] &&
cpe->ch[0].band_type[idx] < NOISE_BT && cpe->ch[1].band_type[idx] < NOISE_BT) { cpe->ch[0].band_type[idx] < NOISE_BT &&
cpe->ch[1].band_type[idx] < NOISE_BT) {
for (group = 0; group < ics->group_len[g]; group++) { for (group = 0; group < ics->group_len[g]; group++) {
ac->fdsp.butterflies_float(ch0 + group * 128 + offsets[i], ac->fdsp.butterflies_float(ch0 + group * 128 + offsets[i],
ch1 + group * 128 + offsets[i], ch1 + group * 128 + offsets[i],
...@@ -1709,7 +1784,8 @@ static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe) ...@@ -1709,7 +1784,8 @@ static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe)
* [1] mask is decoded from bitstream; [2] mask is all 1s; * [1] mask is decoded from bitstream; [2] mask is all 1s;
* [3] reserved for scalable AAC * [3] reserved for scalable AAC
*/ */
static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present) static void apply_intensity_stereo(AACContext *ac,
ChannelElement *cpe, int ms_present)
{ {
const IndividualChannelStream *ics = &cpe->ch[1].ics; const IndividualChannelStream *ics = &cpe->ch[1].ics;
SingleChannelElement *sce1 = &cpe->ch[1]; SingleChannelElement *sce1 = &cpe->ch[1];
...@@ -1720,7 +1796,8 @@ static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_p ...@@ -1720,7 +1796,8 @@ static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_p
float scale; float scale;
for (g = 0; g < ics->num_window_groups; g++) { for (g = 0; g < ics->num_window_groups; g++) {
for (i = 0; i < ics->max_sfb;) { for (i = 0; i < ics->max_sfb;) {
if (sce1->band_type[idx] == INTENSITY_BT || sce1->band_type[idx] == INTENSITY_BT2) { if (sce1->band_type[idx] == INTENSITY_BT ||
sce1->band_type[idx] == INTENSITY_BT2) {
const int bt_run_end = sce1->band_type_run_end[idx]; const int bt_run_end = sce1->band_type_run_end[idx];
for (; i < bt_run_end; i++, idx++) { for (; i < bt_run_end; i++, idx++) {
c = -1 + 2 * (sce1->band_type[idx] - 14); c = -1 + 2 * (sce1->band_type[idx] - 14);
...@@ -1760,7 +1837,8 @@ static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) ...@@ -1760,7 +1837,8 @@ static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe)
i = cpe->ch[1].ics.use_kb_window[0]; i = cpe->ch[1].ics.use_kb_window[0];
cpe->ch[1].ics = cpe->ch[0].ics; cpe->ch[1].ics = cpe->ch[0].ics;
cpe->ch[1].ics.use_kb_window[1] = i; cpe->ch[1].ics.use_kb_window[1] = i;
if (cpe->ch[1].ics.predictor_present && (ac->oc[1].m4ac.object_type != AOT_AAC_MAIN)) if (cpe->ch[1].ics.predictor_present &&
(ac->oc[1].m4ac.object_type != AOT_AAC_MAIN))
if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1))) if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1)))
decode_ltp(&cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb); decode_ltp(&cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb);
ms_present = get_bits(gb, 2); ms_present = get_bits(gb, 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment