static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,

                        AVPacket *avpkt)

{

    const uint8_t *buf  = avpkt->data;

    int buf_size        = avpkt->size;

    MPADecodeContext *s = avctx->priv_data;

    uint32_t header;

    int ret;



    if (buf_size < HEADER_SIZE)

        return AVERROR_INVALIDDATA;



    header = AV_RB32(buf);

    if (ff_mpa_check_header(header) < 0) {

        av_log(avctx, AV_LOG_ERROR, "Header missing\n");

        return AVERROR_INVALIDDATA;

    }



    if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {

        /* free format: prepare to compute frame size */

        s->frame_size = -1;

        return AVERROR_INVALIDDATA;

    }

    /* update codec info */

    avctx->channels       = s->nb_channels;

    avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;

    if (!avctx->bit_rate)

        avctx->bit_rate = s->bit_rate;



    s->frame = data;



    ret = mp_decode_frame(s, NULL, buf, buf_size);

    if (ret >= 0) {

        s->frame->nb_samples = avctx->frame_size;

        *got_frame_ptr       = 1;

        avctx->sample_rate   = s->sample_rate;

        //FIXME maybe move the other codec info stuff from above here too

    } else {

        av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");

        /* Only return an error if the bad frame makes up the whole packet or

         * the error is related to buffer management.

         * If there is more data in the packet, just consume the bad frame

         * instead of returning an error, which would discard the whole

         * packet. */

        *got_frame_ptr = 0;

        if (buf_size == avpkt->size || ret != AVERROR_INVALIDDATA)

            return ret;

    }

    s->frame_size = 0;

    return buf_size;

}

static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,

                        AVPacket *avpkt)

{

    const uint8_t *buf  = avpkt->data;

    int buf_size        = avpkt->size;

    MPADecodeContext *s = avctx->priv_data;

    uint32_t header;

    int ret;



    if (buf_size < HEADER_SIZE)

        return AVERROR_INVALIDDATA;



    header = AV_RB32(buf);

    if (ff_mpa_check_header(header) < 0) {

        av_log(avctx, AV_LOG_ERROR, "Header missing\n");

        return AVERROR_INVALIDDATA;

    }



    if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {

        

        s->frame_size = -1;

        return AVERROR_INVALIDDATA;

    }

    

    avctx->channels       = s->nb_channels;

    avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;

    if (!avctx->bit_rate)

        avctx->bit_rate = s->bit_rate;



    s->frame = data;



    ret = mp_decode_frame(s, NULL, buf, buf_size);

    if (ret >= 0) {

        s->frame->nb_samples = avctx->frame_size;

        *got_frame_ptr       = 1;

        avctx->sample_rate   = s->sample_rate;

        

    } else {

        av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");

        









        *got_frame_ptr = 0;

        if (buf_size == avpkt->size || ret != AVERROR_INVALIDDATA)

            return ret;

    }

    s->frame_size = 0;

    return 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;

    MPADecodeContext *s = VAR_0->priv_data;

    uint32_t header;

    int VAR_6;



    if (VAR_5 < HEADER_SIZE)

        return AVERROR_INVALIDDATA;



    header = AV_RB32(VAR_4);

    if (ff_mpa_check_header(header) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Header missing\n");

        return AVERROR_INVALIDDATA;

    }



    if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {

        

        s->frame_size = -1;

        return AVERROR_INVALIDDATA;

    }

    

    VAR_0->channels       = s->nb_channels;

    VAR_0->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;

    if (!VAR_0->bit_rate)

        VAR_0->bit_rate = s->bit_rate;



    s->frame = VAR_1;



    VAR_6 = mp_decode_frame(s, NULL, VAR_4, VAR_5);

    if (VAR_6 >= 0) {

        s->frame->nb_samples = VAR_0->frame_size;

        *VAR_2       = 1;

        VAR_0->sample_rate   = s->sample_rate;

        

    } else {

        av_log(VAR_0, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");

        









        *VAR_2 = 0;

        if (VAR_5 == VAR_3->size || VAR_6 != AVERROR_INVALIDDATA)

            return VAR_6;

    }

    s->frame_size = 0;

    return 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; MPADecodeContext *s = VAR_0->priv_data; uint32_t header; int VAR_6; if (VAR_5 < HEADER_SIZE)
return AVERROR_INVALIDDATA; header = AV_RB32(VAR_4); if (ff_mpa_check_header(header) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Header missing\n"); return AVERROR_INVALIDDATA; } if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { s->frame_size = -1; return AVERROR_INVALIDDATA; } VAR_0->channels       = s->nb_channels; VAR_0->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; if (!VAR_0->bit_rate)
VAR_0->bit_rate = s->bit_rate; s->frame = VAR_1; VAR_6 = mp_decode_frame(s, NULL, VAR_4, VAR_5); if (VAR_6 >= 0) { s->frame->nb_samples = VAR_0->frame_size; *VAR_2       = 1; VAR_0->sample_rate   = s->sample_rate; } else { av_log(VAR_0, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n"); *VAR_2 = 0; if (VAR_5 == VAR_3->size || VAR_6 != AVERROR_INVALIDDATA)
return VAR_6; } s->frame_size = 0; return VAR_5; }