static int mp_decode_frame(MPADecodeContext *s,

                           OUT_INT *samples, const uint8_t *buf, int buf_size)

{

    int i, nb_frames, ch;

    OUT_INT *samples_ptr;



    init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8);



    /* skip error protection field */

    if (s->error_protection)

        skip_bits(&s->gb, 16);



    dprintf(s->avctx, "frame %d:\n", s->frame_count);

    switch(s->layer) {

    case 1:

        s->avctx->frame_size = 384;

        nb_frames = mp_decode_layer1(s);

        break;

    case 2:

        s->avctx->frame_size = 1152;

        nb_frames = mp_decode_layer2(s);

        break;

    case 3:

        s->avctx->frame_size = s->lsf ? 576 : 1152;

    default:

        nb_frames = mp_decode_layer3(s);



        s->last_buf_size=0;

        if(s->in_gb.buffer){

            align_get_bits(&s->gb);

            i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;

            if(i >= 0 && i <= BACKSTEP_SIZE){

                memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);

                s->last_buf_size=i;

            }else

                av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);

            s->gb= s->in_gb;

            s->in_gb.buffer= NULL;

        }



        align_get_bits(&s->gb);

        assert((get_bits_count(&s->gb) & 7) == 0);

        i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;



        if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){

            av_log(s->avctx, AV_LOG_WARNING, "invalid new backstep %d\n", i);

            i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);

        }

        assert(i <= buf_size - HEADER_SIZE && i>= 0);

        memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);

        s->last_buf_size += i;



        break;

    }



    /* apply the synthesis filter */

    for(ch=0;ch<s->nb_channels;ch++) {

        samples_ptr = samples + ch;

        for(i=0;i<nb_frames;i++) {

            ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]),

                         window, &s->dither_state,

                         samples_ptr, s->nb_channels,

                         s->sb_samples[ch][i]);

            samples_ptr += 32 * s->nb_channels;

        }

    }



    return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;

}

static int mp_decode_frame(MPADecodeContext *s,

                           OUT_INT *samples, const uint8_t *buf, int buf_size)

{

    int i, nb_frames, ch;

    OUT_INT *samples_ptr;



    init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8);



    

    if (s->error_protection)

        skip_bits(&s->gb, 16);



    dprintf(s->avctx, "frame %d:\n", s->frame_count);

    switch(s->layer) {

    case 1:

        s->avctx->frame_size = 384;

        nb_frames = mp_decode_layer1(s);

        break;

    case 2:

        s->avctx->frame_size = 1152;

        nb_frames = mp_decode_layer2(s);

        break;

    case 3:

        s->avctx->frame_size = s->lsf ? 576 : 1152;

    default:

        nb_frames = mp_decode_layer3(s);



        s->last_buf_size=0;

        if(s->in_gb.buffer){

            align_get_bits(&s->gb);

            i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;

            if(i >= 0 && i <= BACKSTEP_SIZE){

                memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);

                s->last_buf_size=i;

            }else

                av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);

            s->gb= s->in_gb;

            s->in_gb.buffer= NULL;

        }



        align_get_bits(&s->gb);

        assert((get_bits_count(&s->gb) & 7) == 0);

        i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;



        if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){

            av_log(s->avctx, AV_LOG_WARNING, "invalid new backstep %d\n", i);

            i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);

        }

        assert(i <= buf_size - HEADER_SIZE && i>= 0);

        memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);

        s->last_buf_size += i;



        break;

    }



    

    for(ch=0;ch<s->nb_channels;ch++) {

        samples_ptr = samples + ch;

        for(i=0;i<nb_frames;i++) {

            ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]),

                         window, &s->dither_state,

                         samples_ptr, s->nb_channels,

                         s->sb_samples[ch][i]);

            samples_ptr += 32 * s->nb_channels;

        }

    }



    return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;

}

static int FUNC_0(MPADecodeContext *VAR_0,

                           OUT_INT *VAR_1, const uint8_t *VAR_2, int VAR_3)

{

    int VAR_4, VAR_5, VAR_6;

    OUT_INT *samples_ptr;



    init_get_bits(&VAR_0->gb, VAR_2 + HEADER_SIZE, (VAR_3 - HEADER_SIZE)*8);



    

    if (VAR_0->error_protection)

        skip_bits(&VAR_0->gb, 16);



    dprintf(VAR_0->avctx, "frame %d:\n", VAR_0->frame_count);

    switch(VAR_0->layer) {

    case 1:

        VAR_0->avctx->frame_size = 384;

        VAR_5 = mp_decode_layer1(VAR_0);

        break;

    case 2:

        VAR_0->avctx->frame_size = 1152;

        VAR_5 = mp_decode_layer2(VAR_0);

        break;

    case 3:

        VAR_0->avctx->frame_size = VAR_0->lsf ? 576 : 1152;

    default:

        VAR_5 = mp_decode_layer3(VAR_0);



        VAR_0->last_buf_size=0;

        if(VAR_0->in_gb.buffer){

            align_get_bits(&VAR_0->gb);

            VAR_4= (VAR_0->gb.size_in_bits - get_bits_count(&VAR_0->gb))>>3;

            if(VAR_4 >= 0 && VAR_4 <= BACKSTEP_SIZE){

                memmove(VAR_0->last_buf, VAR_0->gb.buffer + (get_bits_count(&VAR_0->gb)>>3), VAR_4);

                VAR_0->last_buf_size=VAR_4;

            }else

                av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", VAR_4);

            VAR_0->gb= VAR_0->in_gb;

            VAR_0->in_gb.buffer= NULL;

        }



        align_get_bits(&VAR_0->gb);

        assert((get_bits_count(&VAR_0->gb) & 7) == 0);

        VAR_4= (VAR_0->gb.size_in_bits - get_bits_count(&VAR_0->gb))>>3;



        if(VAR_4<0 || VAR_4 > BACKSTEP_SIZE || VAR_5<0){

            av_log(VAR_0->avctx, AV_LOG_WARNING, "invalid new backstep %d\n", VAR_4);

            VAR_4= FFMIN(BACKSTEP_SIZE, VAR_3 - HEADER_SIZE);

        }

        assert(VAR_4 <= VAR_3 - HEADER_SIZE && VAR_4>= 0);

        memcpy(VAR_0->last_buf + VAR_0->last_buf_size, VAR_0->gb.buffer + VAR_3 - HEADER_SIZE - VAR_4, VAR_4);

        VAR_0->last_buf_size += VAR_4;



        break;

    }



    

    for(VAR_6=0;VAR_6<VAR_0->nb_channels;VAR_6++) {

        samples_ptr = VAR_1 + VAR_6;

        for(VAR_4=0;VAR_4<VAR_5;VAR_4++) {

            ff_mpa_synth_filter(VAR_0->synth_buf[VAR_6], &(VAR_0->synth_buf_offset[VAR_6]),

                         window, &VAR_0->dither_state,

                         samples_ptr, VAR_0->nb_channels,

                         VAR_0->sb_samples[VAR_6][VAR_4]);

            samples_ptr += 32 * VAR_0->nb_channels;

        }

    }



    return VAR_5 * 32 * sizeof(OUT_INT) * VAR_0->nb_channels;

}

static int FUNC_0(MPADecodeContext *VAR_0,
OUT_INT *VAR_1, const uint8_t *VAR_2, int VAR_3)
{ int VAR_4, VAR_5, VAR_6; OUT_INT *samples_ptr; init_get_bits(&VAR_0->gb, VAR_2 + HEADER_SIZE, (VAR_3 - HEADER_SIZE)*8); if (VAR_0->error_protection)
skip_bits(&VAR_0->gb, 16); dprintf(VAR_0->avctx, "frame %d:\n", VAR_0->frame_count); switch(VAR_0->layer) { case 1:
VAR_0->avctx->frame_size = 384; VAR_5 = mp_decode_layer1(VAR_0); break; case 2:
VAR_0->avctx->frame_size = 1152; VAR_5 = mp_decode_layer2(VAR_0); break; case 3:
VAR_0->avctx->frame_size = VAR_0->lsf ? 576 : 1152; default:
VAR_5 = mp_decode_layer3(VAR_0); VAR_0->last_buf_size=0; if(VAR_0->in_gb.buffer){ align_get_bits(&VAR_0->gb); VAR_4= (VAR_0->gb.size_in_bits - get_bits_count(&VAR_0->gb))>>3; if(VAR_4 >= 0 && VAR_4 <= BACKSTEP_SIZE){ memmove(VAR_0->last_buf, VAR_0->gb.buffer + (get_bits_count(&VAR_0->gb)>>3), VAR_4); VAR_0->last_buf_size=VAR_4; }else av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", VAR_4); VAR_0->gb= VAR_0->in_gb; VAR_0->in_gb.buffer= NULL; } align_get_bits(&VAR_0->gb); assert((get_bits_count(&VAR_0->gb) & 7) == 0); VAR_4= (VAR_0->gb.size_in_bits - get_bits_count(&VAR_0->gb))>>3; if(VAR_4<0 || VAR_4 > BACKSTEP_SIZE || VAR_5<0){ av_log(VAR_0->avctx, AV_LOG_WARNING, "invalid new backstep %d\n", VAR_4); VAR_4= FFMIN(BACKSTEP_SIZE, VAR_3 - HEADER_SIZE); } assert(VAR_4 <= VAR_3 - HEADER_SIZE && VAR_4>= 0); memcpy(VAR_0->last_buf + VAR_0->last_buf_size, VAR_0->gb.buffer + VAR_3 - HEADER_SIZE - VAR_4, VAR_4); VAR_0->last_buf_size += VAR_4; break; } for(VAR_6=0;VAR_6<VAR_0->nb_channels;VAR_6++) { samples_ptr = VAR_1 + VAR_6; for(VAR_4=0;VAR_4<VAR_5;VAR_4++) { ff_mpa_synth_filter(VAR_0->synth_buf[VAR_6], &(VAR_0->synth_buf_offset[VAR_6]),
window, &VAR_0->dither_state,
samples_ptr, VAR_0->nb_channels,
VAR_0->sb_samples[VAR_6][VAR_4]); samples_ptr += 32 * VAR_0->nb_channels; } } return VAR_5 * 32 * sizeof(OUT_INT) * VAR_0->nb_channels; }