static int aac_decode_frame(AVCodecContext *avccontext, void *data,

                            int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    AACContext *ac = avccontext->priv_data;

    ChannelElement *che = NULL, *che_prev = NULL;

    GetBitContext gb;

    enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;

    int err, elem_id, data_size_tmp;

    int buf_consumed;

    int samples = 1024, multiplier;

    int buf_offset;



    init_get_bits(&gb, buf, buf_size * 8);



    if (show_bits(&gb, 12) == 0xfff) {

        if (parse_adts_frame_header(ac, &gb) < 0) {

            av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n");

            return -1;

        }

        if (ac->m4ac.sampling_index > 12) {

            av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);

            return -1;

        }

    }




    // parse

    while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {

        elem_id = get_bits(&gb, 4);



        if (elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) {

            av_log(ac->avccontext, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id);

            return -1;

        }



        switch (elem_type) {



        case TYPE_SCE:

            err = decode_ics(ac, &che->ch[0], &gb, 0, 0);

            break;



        case TYPE_CPE:

            err = decode_cpe(ac, &gb, che);

            break;



        case TYPE_CCE:

            err = decode_cce(ac, &gb, che);

            break;



        case TYPE_LFE:

            err = decode_ics(ac, &che->ch[0], &gb, 0, 0);

            break;



        case TYPE_DSE:

            err = skip_data_stream_element(ac, &gb);

            break;



        case TYPE_PCE: {

            enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];

            memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));

            if ((err = decode_pce(ac, new_che_pos, &gb)))

                break;

            if (ac->output_configured > OC_TRIAL_PCE)

                av_log(avccontext, AV_LOG_ERROR,

                       "Not evaluating a further program_config_element as this construct is dubious at best.\n");

            else

                err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE);

            break;

        }



        case TYPE_FIL:

            if (elem_id == 15)

                elem_id += get_bits(&gb, 8) - 1;

            if (get_bits_left(&gb) < 8 * elem_id) {

                    av_log(avccontext, AV_LOG_ERROR, overread_err);

                    return -1;

            }

            while (elem_id > 0)

                elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev);

            err = 0; /* FIXME */

            break;



        default:

            err = -1; /* should not happen, but keeps compiler happy */

            break;

        }



        che_prev       = che;

        elem_type_prev = elem_type;



        if (err)

            return err;



        if (get_bits_left(&gb) < 3) {

            av_log(avccontext, AV_LOG_ERROR, overread_err);

            return -1;

        }

    }



    spectral_to_sample(ac);



    multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0;

    samples <<= multiplier;

    if (ac->output_configured < OC_LOCKED) {

        avccontext->sample_rate = ac->m4ac.sample_rate << multiplier;

        avccontext->frame_size = samples;

    }



    data_size_tmp = samples * avccontext->channels * sizeof(int16_t);

    if (*data_size < data_size_tmp) {

        av_log(avccontext, AV_LOG_ERROR,

               "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",

               *data_size, data_size_tmp);

        return -1;

    }

    *data_size = data_size_tmp;



    ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avccontext->channels);



    if (ac->output_configured)

        ac->output_configured = OC_LOCKED;



    buf_consumed = (get_bits_count(&gb) + 7) >> 3;

    for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)

        if (buf[buf_offset])

            break;



    return buf_size > buf_offset ? buf_consumed : buf_size;

}
static int aac_decode_frame(AVCodecContext *avccontext, void *data,

                            int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    AACContext *ac = avccontext->priv_data;

    ChannelElement *che = NULL, *che_prev = NULL;

    GetBitContext gb;

    enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;

    int err, elem_id, data_size_tmp;

    int buf_consumed;

    int samples = 1024, multiplier;

    int buf_offset;



    init_get_bits(&gb, buf, buf_size * 8);



    if (show_bits(&gb, 12) == 0xfff) {

        if (parse_adts_frame_header(ac, &gb) < 0) {

            av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n");

            return -1;

        }

        if (ac->m4ac.sampling_index > 12) {

            av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);

            return -1;

        }

    }




    

    while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {

        elem_id = get_bits(&gb, 4);



        if (elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) {

            av_log(ac->avccontext, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id);

            return -1;

        }



        switch (elem_type) {



        case TYPE_SCE:

            err = decode_ics(ac, &che->ch[0], &gb, 0, 0);

            break;



        case TYPE_CPE:

            err = decode_cpe(ac, &gb, che);

            break;



        case TYPE_CCE:

            err = decode_cce(ac, &gb, che);

            break;



        case TYPE_LFE:

            err = decode_ics(ac, &che->ch[0], &gb, 0, 0);

            break;



        case TYPE_DSE:

            err = skip_data_stream_element(ac, &gb);

            break;



        case TYPE_PCE: {

            enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];

            memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));

            if ((err = decode_pce(ac, new_che_pos, &gb)))

                break;

            if (ac->output_configured > OC_TRIAL_PCE)

                av_log(avccontext, AV_LOG_ERROR,

                       "Not evaluating a further program_config_element as this construct is dubious at best.\n");

            else

                err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE);

            break;

        }



        case TYPE_FIL:

            if (elem_id == 15)

                elem_id += get_bits(&gb, 8) - 1;

            if (get_bits_left(&gb) < 8 * elem_id) {

                    av_log(avccontext, AV_LOG_ERROR, overread_err);

                    return -1;

            }

            while (elem_id > 0)

                elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev);

            err = 0; 

            break;



        default:

            err = -1; 

            break;

        }



        che_prev       = che;

        elem_type_prev = elem_type;



        if (err)

            return err;



        if (get_bits_left(&gb) < 3) {

            av_log(avccontext, AV_LOG_ERROR, overread_err);

            return -1;

        }

    }



    spectral_to_sample(ac);



    multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0;

    samples <<= multiplier;

    if (ac->output_configured < OC_LOCKED) {

        avccontext->sample_rate = ac->m4ac.sample_rate << multiplier;

        avccontext->frame_size = samples;

    }



    data_size_tmp = samples * avccontext->channels * sizeof(int16_t);

    if (*data_size < data_size_tmp) {

        av_log(avccontext, AV_LOG_ERROR,

               "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",

               *data_size, data_size_tmp);

        return -1;

    }

    *data_size = data_size_tmp;



    ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avccontext->channels);



    if (ac->output_configured)

        ac->output_configured = OC_LOCKED;



    buf_consumed = (get_bits_count(&gb) + 7) >> 3;

    for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)

        if (buf[buf_offset])

            break;



    return buf_size > buf_offset ? buf_consumed : buf_size;

}
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                            int *VAR_2, AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5 = VAR_3->size;

    AACContext *ac = VAR_0->priv_data;

    ChannelElement *che = NULL, *che_prev = NULL;

    GetBitContext gb;

    enum RawDataBlockType VAR_6, VAR_7 = TYPE_END;

    int VAR_8, VAR_9, VAR_10;

    int VAR_11;

    int VAR_12 = 1024, VAR_13;

    int VAR_14;



    init_get_bits(&gb, VAR_4, VAR_5 * 8);



    if (show_bits(&gb, 12) == 0xfff) {

        if (parse_adts_frame_header(ac, &gb) < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Error decoding AAC frame header.\n");

            return -1;

        }

        if (ac->m4ac.sampling_index > 12) {

            av_log(ac->VAR_0, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);

            return -1;

        }

    }




    

    while ((VAR_6 = get_bits(&gb, 3)) != TYPE_END) {

        VAR_9 = get_bits(&gb, 4);



        if (VAR_6 < TYPE_DSE && !(che=get_che(ac, VAR_6, VAR_9))) {

            av_log(ac->VAR_0, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", VAR_6, VAR_9);

            return -1;

        }



        switch (VAR_6) {



        case TYPE_SCE:

            VAR_8 = decode_ics(ac, &che->ch[0], &gb, 0, 0);

            break;



        case TYPE_CPE:

            VAR_8 = decode_cpe(ac, &gb, che);

            break;



        case TYPE_CCE:

            VAR_8 = decode_cce(ac, &gb, che);

            break;



        case TYPE_LFE:

            VAR_8 = decode_ics(ac, &che->ch[0], &gb, 0, 0);

            break;



        case TYPE_DSE:

            VAR_8 = skip_data_stream_element(ac, &gb);

            break;



        case TYPE_PCE: {

            enum ChannelPosition VAR_15[4][MAX_ELEM_ID];

            memset(VAR_15, 0, 4 * MAX_ELEM_ID * sizeof(VAR_15[0][0]));

            if ((VAR_8 = decode_pce(ac, VAR_15, &gb)))

                break;

            if (ac->output_configured > OC_TRIAL_PCE)

                av_log(VAR_0, AV_LOG_ERROR,

                       "Not evaluating a further program_config_element as this construct is dubious at best.\n");

            else

                VAR_8 = output_configure(ac, ac->che_pos, VAR_15, 0, OC_TRIAL_PCE);

            break;

        }



        case TYPE_FIL:

            if (VAR_9 == 15)

                VAR_9 += get_bits(&gb, 8) - 1;

            if (get_bits_left(&gb) < 8 * VAR_9) {

                    av_log(VAR_0, AV_LOG_ERROR, overread_err);

                    return -1;

            }

            while (VAR_9 > 0)

                VAR_9 -= decode_extension_payload(ac, &gb, VAR_9, che_prev, VAR_7);

            VAR_8 = 0; 

            break;



        default:

            VAR_8 = -1; 

            break;

        }



        che_prev       = che;

        VAR_7 = VAR_6;



        if (VAR_8)

            return VAR_8;



        if (get_bits_left(&gb) < 3) {

            av_log(VAR_0, AV_LOG_ERROR, overread_err);

            return -1;

        }

    }



    spectral_to_sample(ac);



    VAR_13 = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0;

    VAR_12 <<= VAR_13;

    if (ac->output_configured < OC_LOCKED) {

        VAR_0->sample_rate = ac->m4ac.sample_rate << VAR_13;

        VAR_0->frame_size = VAR_12;

    }



    VAR_10 = VAR_12 * VAR_0->channels * sizeof(int16_t);

    if (*VAR_2 < VAR_10) {

        av_log(VAR_0, AV_LOG_ERROR,

               "Output buffer too small (%d) or trying to output too many VAR_12 (%d) for this frame.\n",

               *VAR_2, VAR_10);

        return -1;

    }

    *VAR_2 = VAR_10;



    ac->dsp.float_to_int16_interleave(VAR_1, (const float **)ac->output_data, VAR_12, VAR_0->channels);



    if (ac->output_configured)

        ac->output_configured = OC_LOCKED;



    VAR_11 = (get_bits_count(&gb) + 7) >> 3;

    for (VAR_14 = VAR_11; VAR_14 < VAR_5; VAR_14++)

        if (VAR_4[VAR_14])

            break;



    return VAR_5 > VAR_14 ? VAR_11 : VAR_5;

}
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5 = VAR_3->size; AACContext *ac = VAR_0->priv_data; ChannelElement *che = NULL, *che_prev = NULL; GetBitContext gb; enum RawDataBlockType VAR_6, VAR_7 = TYPE_END; int VAR_8, VAR_9, VAR_10; int VAR_11; int VAR_12 = 1024, VAR_13; int VAR_14; init_get_bits(&gb, VAR_4, VAR_5 * 8); if (show_bits(&gb, 12) == 0xfff) { if (parse_adts_frame_header(ac, &gb) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); return -1; } if (ac->m4ac.sampling_index > 12) { av_log(ac->VAR_0, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index); return -1; } } while ((VAR_6 = get_bits(&gb, 3)) != TYPE_END) { VAR_9 = get_bits(&gb, 4); if (VAR_6 < TYPE_DSE && !(che=get_che(ac, VAR_6, VAR_9))) { av_log(ac->VAR_0, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", VAR_6, VAR_9); return -1; } switch (VAR_6) { case TYPE_SCE:
VAR_8 = decode_ics(ac, &che->ch[0], &gb, 0, 0); break; case TYPE_CPE:
VAR_8 = decode_cpe(ac, &gb, che); break; case TYPE_CCE:
VAR_8 = decode_cce(ac, &gb, che); break; case TYPE_LFE:
VAR_8 = decode_ics(ac, &che->ch[0], &gb, 0, 0); break; case TYPE_DSE:
VAR_8 = skip_data_stream_element(ac, &gb); break; case TYPE_PCE: { enum ChannelPosition VAR_15[4][MAX_ELEM_ID]; memset(VAR_15, 0, 4 * MAX_ELEM_ID * sizeof(VAR_15[0][0])); if ((VAR_8 = decode_pce(ac, VAR_15, &gb)))
break; if (ac->output_configured > OC_TRIAL_PCE)
av_log(VAR_0, AV_LOG_ERROR,
"Not evaluating a further program_config_element as this construct is dubious at best.\n"); else
VAR_8 = output_configure(ac, ac->che_pos, VAR_15, 0, OC_TRIAL_PCE); break; } case TYPE_FIL:
if (VAR_9 == 15)
VAR_9 += get_bits(&gb, 8) - 1; if (get_bits_left(&gb) < 8 * VAR_9) { av_log(VAR_0, AV_LOG_ERROR, overread_err); return -1; } while (VAR_9 > 0)
VAR_9 -= decode_extension_payload(ac, &gb, VAR_9, che_prev, VAR_7); VAR_8 = 0; break; default:
VAR_8 = -1; break; } che_prev       = che; VAR_7 = VAR_6; if (VAR_8)
return VAR_8; if (get_bits_left(&gb) < 3) { av_log(VAR_0, AV_LOG_ERROR, overread_err); return -1; } } spectral_to_sample(ac); VAR_13 = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0; VAR_12 <<= VAR_13; if (ac->output_configured < OC_LOCKED) { VAR_0->sample_rate = ac->m4ac.sample_rate << VAR_13; VAR_0->frame_size = VAR_12; } VAR_10 = VAR_12 * VAR_0->channels * sizeof(int16_t); if (*VAR_2 < VAR_10) { av_log(VAR_0, AV_LOG_ERROR,
"Output buffer too small (%d) or trying to output too many VAR_12 (%d) for this frame.\n",
*VAR_2, VAR_10); return -1; } *VAR_2 = VAR_10; ac->dsp.float_to_int16_interleave(VAR_1, (const float **)ac->output_data, VAR_12, VAR_0->channels); if (ac->output_configured)
ac->output_configured = OC_LOCKED; VAR_11 = (get_bits_count(&gb) + 7) >> 3; for (VAR_14 = VAR_11; VAR_14 < VAR_5; VAR_14++) if (VAR_4[VAR_14])
break; return VAR_5 > VAR_14 ? VAR_11 : VAR_5; }