static int decode_frame_mp3on4(AVCodecContext * avctx,

                        void *data, int *data_size,

                        const uint8_t * buf, int buf_size)

{

    MP3On4DecodeContext *s = avctx->priv_data;

    MPADecodeContext *m;

    int len, out_size = 0;

    uint32_t header;

    OUT_INT *out_samples = data;

    OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];

    OUT_INT *outptr, *bp;

    int fsize;

    int fr, i, j, n;



    len = buf_size;



    *data_size = 0;

    // Discard too short frames

    if (buf_size < HEADER_SIZE)

        return -1;



    // If only one decoder interleave is not needed

    outptr = s->frames == 1 ? out_samples : decoded_buf;



    for (fr = 0; fr < s->frames; fr++) {

        fsize = AV_RB16(buf) >> 4;

        fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);

        m = s->mp3decctx[fr];

        assert (m != NULL);



        header = (AV_RB32(buf) & 0x000fffff) | s->syncword; // patch header



        if (ff_mpa_check_header(header) < 0) { // Bad header, discard block

            *data_size = 0;

            return buf_size;

        }



        ff_mpegaudio_decode_header(m, header);

        out_size += mp_decode_frame(m, outptr, buf, fsize);

        buf += fsize;

        len -= fsize;



        if(s->frames > 1) {

            n = m->avctx->frame_size*m->nb_channels;

            /* interleave output data */

            bp = out_samples + s->coff[fr];

            if(m->nb_channels == 1) {

                for(j = 0; j < n; j++) {

                    *bp = decoded_buf[j];

                    bp += avctx->channels;

                }

            } else {

                for(j = 0; j < n; j++) {

                    bp[0] = decoded_buf[j++];

                    bp[1] = decoded_buf[j];

                    bp += avctx->channels;

                }

            }

        }

    }



    /* update codec info */

    avctx->sample_rate = s->mp3decctx[0]->sample_rate;

    avctx->bit_rate = 0;

    for (i = 0; i < s->frames; i++)

        avctx->bit_rate += s->mp3decctx[i]->bit_rate;



    *data_size = out_size;

    return buf_size;

}

static int decode_frame_mp3on4(AVCodecContext * avctx,

                        void *data, int *data_size,

                        const uint8_t * buf, int buf_size)

{

    MP3On4DecodeContext *s = avctx->priv_data;

    MPADecodeContext *m;

    int len, out_size = 0;

    uint32_t header;

    OUT_INT *out_samples = data;

    OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];

    OUT_INT *outptr, *bp;

    int fsize;

    int fr, i, j, n;



    len = buf_size;



    *data_size = 0;

    

    if (buf_size < HEADER_SIZE)

        return -1;



    

    outptr = s->frames == 1 ? out_samples : decoded_buf;



    for (fr = 0; fr < s->frames; fr++) {

        fsize = AV_RB16(buf) >> 4;

        fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);

        m = s->mp3decctx[fr];

        assert (m != NULL);



        header = (AV_RB32(buf) & 0x000fffff) | s->syncword; 



        if (ff_mpa_check_header(header) < 0) { 

            *data_size = 0;

            return buf_size;

        }



        ff_mpegaudio_decode_header(m, header);

        out_size += mp_decode_frame(m, outptr, buf, fsize);

        buf += fsize;

        len -= fsize;



        if(s->frames > 1) {

            n = m->avctx->frame_size*m->nb_channels;

            

            bp = out_samples + s->coff[fr];

            if(m->nb_channels == 1) {

                for(j = 0; j < n; j++) {

                    *bp = decoded_buf[j];

                    bp += avctx->channels;

                }

            } else {

                for(j = 0; j < n; j++) {

                    bp[0] = decoded_buf[j++];

                    bp[1] = decoded_buf[j];

                    bp += avctx->channels;

                }

            }

        }

    }



    

    avctx->sample_rate = s->mp3decctx[0]->sample_rate;

    avctx->bit_rate = 0;

    for (i = 0; i < s->frames; i++)

        avctx->bit_rate += s->mp3decctx[i]->bit_rate;



    *data_size = out_size;

    return buf_size;

}

static int FUNC_0(AVCodecContext * VAR_0,

                        void *VAR_1, int *VAR_2,

                        const uint8_t * VAR_3, int VAR_4)

{

    MP3On4DecodeContext *s = VAR_0->priv_data;

    MPADecodeContext *m;

    int VAR_5, VAR_6 = 0;

    uint32_t header;

    OUT_INT *out_samples = VAR_1;

    OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];

    OUT_INT *outptr, *bp;

    int VAR_7;

    int VAR_8, VAR_9, VAR_10, VAR_11;



    VAR_5 = VAR_4;



    *VAR_2 = 0;

    

    if (VAR_4 < HEADER_SIZE)

        return -1;



    

    outptr = s->frames == 1 ? out_samples : decoded_buf;



    for (VAR_8 = 0; VAR_8 < s->frames; VAR_8++) {

        VAR_7 = AV_RB16(VAR_3) >> 4;

        VAR_7 = FFMIN3(VAR_7, VAR_5, MPA_MAX_CODED_FRAME_SIZE);

        m = s->mp3decctx[VAR_8];

        assert (m != NULL);



        header = (AV_RB32(VAR_3) & 0x000fffff) | s->syncword; 



        if (ff_mpa_check_header(header) < 0) { 

            *VAR_2 = 0;

            return VAR_4;

        }



        ff_mpegaudio_decode_header(m, header);

        VAR_6 += mp_decode_frame(m, outptr, VAR_3, VAR_7);

        VAR_3 += VAR_7;

        VAR_5 -= VAR_7;



        if(s->frames > 1) {

            VAR_11 = m->VAR_0->frame_size*m->nb_channels;

            

            bp = out_samples + s->coff[VAR_8];

            if(m->nb_channels == 1) {

                for(VAR_10 = 0; VAR_10 < VAR_11; VAR_10++) {

                    *bp = decoded_buf[VAR_10];

                    bp += VAR_0->channels;

                }

            } else {

                for(VAR_10 = 0; VAR_10 < VAR_11; VAR_10++) {

                    bp[0] = decoded_buf[VAR_10++];

                    bp[1] = decoded_buf[VAR_10];

                    bp += VAR_0->channels;

                }

            }

        }

    }



    

    VAR_0->sample_rate = s->mp3decctx[0]->sample_rate;

    VAR_0->bit_rate = 0;

    for (VAR_9 = 0; VAR_9 < s->frames; VAR_9++)

        VAR_0->bit_rate += s->mp3decctx[VAR_9]->bit_rate;



    *VAR_2 = VAR_6;

    return VAR_4;

}

static int FUNC_0(AVCodecContext * VAR_0,
void *VAR_1, int *VAR_2,
const uint8_t * VAR_3, int VAR_4)
{ MP3On4DecodeContext *s = VAR_0->priv_data; MPADecodeContext *m; int VAR_5, VAR_6 = 0; uint32_t header; OUT_INT *out_samples = VAR_1; OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS]; OUT_INT *outptr, *bp; int VAR_7; int VAR_8, VAR_9, VAR_10, VAR_11; VAR_5 = VAR_4; *VAR_2 = 0; if (VAR_4 < HEADER_SIZE)
return -1; outptr = s->frames == 1 ? out_samples : decoded_buf; for (VAR_8 = 0; VAR_8 < s->frames; VAR_8++) { VAR_7 = AV_RB16(VAR_3) >> 4; VAR_7 = FFMIN3(VAR_7, VAR_5, MPA_MAX_CODED_FRAME_SIZE); m = s->mp3decctx[VAR_8]; assert (m != NULL); header = (AV_RB32(VAR_3) & 0x000fffff) | s->syncword; if (ff_mpa_check_header(header) < 0) { *VAR_2 = 0; return VAR_4; } ff_mpegaudio_decode_header(m, header); VAR_6 += mp_decode_frame(m, outptr, VAR_3, VAR_7); VAR_3 += VAR_7; VAR_5 -= VAR_7; if(s->frames > 1) { VAR_11 = m->VAR_0->frame_size*m->nb_channels; bp = out_samples + s->coff[VAR_8]; if(m->nb_channels == 1) { for(VAR_10 = 0; VAR_10 < VAR_11; VAR_10++) { *bp = decoded_buf[VAR_10]; bp += VAR_0->channels; } } else { for(VAR_10 = 0; VAR_10 < VAR_11; VAR_10++) { bp[0] = decoded_buf[VAR_10++]; bp[1] = decoded_buf[VAR_10]; bp += VAR_0->channels; } } } } VAR_0->sample_rate = s->mp3decctx[0]->sample_rate; VAR_0->bit_rate = 0; for (VAR_9 = 0; VAR_9 < s->frames; VAR_9++) VAR_0->bit_rate += s->mp3decctx[VAR_9]->bit_rate; *VAR_2 = VAR_6; return VAR_4; }