static int latm_decode_frame(AVCodecContext *avctx, void *out,

                             int *got_frame_ptr, AVPacket *avpkt)

{

    struct LATMContext *latmctx = avctx->priv_data;

    int                 muxlength, err;

    GetBitContext       gb;



    if ((err = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0)

        return err;



    // check for LOAS sync word

    if (get_bits(&gb, 11) != LOAS_SYNC_WORD)

        return AVERROR_INVALIDDATA;



    muxlength = get_bits(&gb, 13) + 3;

    // not enough data, the parser should have sorted this out

    if (muxlength > avpkt->size)

        return AVERROR_INVALIDDATA;



    if ((err = read_audio_mux_element(latmctx, &gb)) < 0)

        return err;



    if (!latmctx->initialized) {

        if (!avctx->extradata) {

            *got_frame_ptr = 0;

            return avpkt->size;

        } else {

            push_output_configuration(&latmctx->aac_ctx);

            if ((err = decode_audio_specific_config(

                    &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.oc[1].m4ac,

                    avctx->extradata, avctx->extradata_size*8, 1)) < 0) {

                pop_output_configuration(&latmctx->aac_ctx);

                return err;

            }

            latmctx->initialized = 1;

        }

    }



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

        av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR,

               "ADTS header detected, probably as result of configuration "

               "misparsing\n");

        return AVERROR_INVALIDDATA;

    }



    switch (latmctx->aac_ctx.oc[1].m4ac.object_type) {

    case AOT_ER_AAC_LC:

    case AOT_ER_AAC_LTP:

    case AOT_ER_AAC_LD:

    case AOT_ER_AAC_ELD:

        err = aac_decode_er_frame(avctx, out, got_frame_ptr, &gb);

        break;

    default:

        err = aac_decode_frame_int(avctx, out, got_frame_ptr, &gb, avpkt);

    }

    if (err < 0)

        return err;



    return muxlength;

}

static int latm_decode_frame(AVCodecContext *avctx, void *out,

                             int *got_frame_ptr, AVPacket *avpkt)

{

    struct LATMContext *latmctx = avctx->priv_data;

    int                 muxlength, err;

    GetBitContext       gb;



    if ((err = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0)

        return err;



    

    if (get_bits(&gb, 11) != LOAS_SYNC_WORD)

        return AVERROR_INVALIDDATA;



    muxlength = get_bits(&gb, 13) + 3;

    

    if (muxlength > avpkt->size)

        return AVERROR_INVALIDDATA;



    if ((err = read_audio_mux_element(latmctx, &gb)) < 0)

        return err;



    if (!latmctx->initialized) {

        if (!avctx->extradata) {

            *got_frame_ptr = 0;

            return avpkt->size;

        } else {

            push_output_configuration(&latmctx->aac_ctx);

            if ((err = decode_audio_specific_config(

                    &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.oc[1].m4ac,

                    avctx->extradata, avctx->extradata_size*8, 1)) < 0) {

                pop_output_configuration(&latmctx->aac_ctx);

                return err;

            }

            latmctx->initialized = 1;

        }

    }



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

        av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR,

               "ADTS header detected, probably as result of configuration "

               "misparsing\n");

        return AVERROR_INVALIDDATA;

    }



    switch (latmctx->aac_ctx.oc[1].m4ac.object_type) {

    case AOT_ER_AAC_LC:

    case AOT_ER_AAC_LTP:

    case AOT_ER_AAC_LD:

    case AOT_ER_AAC_ELD:

        err = aac_decode_er_frame(avctx, out, got_frame_ptr, &gb);

        break;

    default:

        err = aac_decode_frame_int(avctx, out, got_frame_ptr, &gb, avpkt);

    }

    if (err < 0)

        return err;



    return muxlength;

}

                    avctx->extradata, avctx->extradata_size*8, 1)) < 0) {
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                             int *VAR_2, AVPacket *VAR_3)

{

    struct LATMContext *VAR_4 = VAR_0->priv_data;

    int                 VAR_5, VAR_6;

    GetBitContext       gb;



    if ((VAR_6 = init_get_bits8(&gb, VAR_3->data, VAR_3->size)) < 0)

        return VAR_6;



    

    if (get_bits(&gb, 11) != LOAS_SYNC_WORD)

        return AVERROR_INVALIDDATA;



    VAR_5 = get_bits(&gb, 13) + 3;

    

    if (VAR_5 > VAR_3->size)

        return AVERROR_INVALIDDATA;



    if ((VAR_6 = read_audio_mux_element(VAR_4, &gb)) < 0)

        return VAR_6;



    if (!VAR_4->initialized) {

        if (!VAR_0->extradata) {

            *VAR_2 = 0;

            return VAR_3->size;

        } else {

            push_output_configuration(&VAR_4->aac_ctx);

            if ((VAR_6 = decode_audio_specific_config(

                    &VAR_4->aac_ctx, VAR_0, &VAR_4->aac_ctx.oc[1].m4ac,

                    VAR_0->extradata, VAR_0->extradata_size*8, 1)) < 0) {

                pop_output_configuration(&VAR_4->aac_ctx);

                return VAR_6;

            }

            VAR_4->initialized = 1;

        }

    }



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

        av_log(VAR_4->aac_ctx.VAR_0, AV_LOG_ERROR,

               "ADTS header detected, probably as result of configuration "

               "misparsing\n");

        return AVERROR_INVALIDDATA;

    }



    switch (VAR_4->aac_ctx.oc[1].m4ac.object_type) {

    case AOT_ER_AAC_LC:

    case AOT_ER_AAC_LTP:

    case AOT_ER_AAC_LD:

    case AOT_ER_AAC_ELD:

        VAR_6 = aac_decode_er_frame(VAR_0, VAR_1, VAR_2, &gb);

        break;

    default:

        VAR_6 = aac_decode_frame_int(VAR_0, VAR_1, VAR_2, &gb, VAR_3);

    }

    if (VAR_6 < 0)

        return VAR_6;



    return VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ struct LATMContext *VAR_4 = VAR_0->priv_data; int                 VAR_5, VAR_6; GetBitContext       gb; if ((VAR_6 = init_get_bits8(&gb, VAR_3->data, VAR_3->size)) < 0)
return VAR_6; if (get_bits(&gb, 11) != LOAS_SYNC_WORD)
return AVERROR_INVALIDDATA; VAR_5 = get_bits(&gb, 13) + 3; if (VAR_5 > VAR_3->size)
return AVERROR_INVALIDDATA; if ((VAR_6 = read_audio_mux_element(VAR_4, &gb)) < 0)
return VAR_6; if (!VAR_4->initialized) { if (!VAR_0->extradata) { *VAR_2 = 0; return VAR_3->size; } else { push_output_configuration(&VAR_4->aac_ctx); if ((VAR_6 = decode_audio_specific_config(
&VAR_4->aac_ctx, VAR_0, &VAR_4->aac_ctx.oc[1].m4ac,
VAR_0->extradata, VAR_0->extradata_size*8, 1)) < 0) { pop_output_configuration(&VAR_4->aac_ctx); return VAR_6; } VAR_4->initialized = 1; } } if (show_bits(&gb, 12) == 0xfff) { av_log(VAR_4->aac_ctx.VAR_0, AV_LOG_ERROR,
"ADTS header detected, probably as result of configuration "
"misparsing\n"); return AVERROR_INVALIDDATA; } switch (VAR_4->aac_ctx.oc[1].m4ac.object_type) { case AOT_ER_AAC_LC:
case AOT_ER_AAC_LTP:
case AOT_ER_AAC_LD:
case AOT_ER_AAC_ELD:
VAR_6 = aac_decode_er_frame(VAR_0, VAR_1, VAR_2, &gb); break; default:
VAR_6 = aac_decode_frame_int(VAR_0, VAR_1, VAR_2, &gb, VAR_3); } if (VAR_6 < 0)
return VAR_6; return VAR_5; }