static int decode_frame(FLACContext *s, int alloc_data_size)

{

    int bs_code, sr_code, bps_code, i;

    int ch_mode, bps, blocksize, samplerate;

    GetBitContext *gb = &s->gb;



    /* frame sync code */

    skip_bits(&s->gb, 16);



    /* block size and sample rate codes */

    bs_code = get_bits(gb, 4);

    sr_code = get_bits(gb, 4);



    /* channels and decorrelation */

    ch_mode = get_bits(gb, 4);

    if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) {

        ch_mode = FLAC_CHMODE_INDEPENDENT;

    } else if (ch_mode > FLAC_CHMODE_MID_SIDE || s->channels != 2) {

        av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",

               ch_mode, s->channels);

        return -1;

    }



    /* bits per sample */

    bps_code = get_bits(gb, 3);

    if (bps_code == 0)

        bps= s->bps;

    else if ((bps_code != 3) && (bps_code != 7))

        bps = sample_size_table[bps_code];

    else {

        av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n",

               bps_code);

        return -1;

    }

    if (bps > 16) {

        s->avctx->sample_fmt = SAMPLE_FMT_S32;

        s->sample_shift = 32 - bps;

        s->is32 = 1;

    } else {

        s->avctx->sample_fmt = SAMPLE_FMT_S16;

        s->sample_shift = 16 - bps;

        s->is32 = 0;

    }

    s->bps = s->avctx->bits_per_raw_sample = bps;



    /* reserved bit */

    if (get_bits1(gb)) {

        av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");

        return -1;

    }



    /* sample or frame count */

    if (get_utf8(gb) < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "utf8 fscked\n");

        return -1;

    }



    /* blocksize */

    if (bs_code == 0) {

        av_log(s->avctx, AV_LOG_ERROR, "reserved blocksize code: 0\n");

        return -1;

    } else if (bs_code == 6)

        blocksize = get_bits(gb, 8)+1;

    else if (bs_code == 7)

        blocksize = get_bits(gb, 16)+1;

    else

        blocksize = ff_flac_blocksize_table[bs_code];



    if (blocksize > s->max_blocksize) {

        av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize,

               s->max_blocksize);

        return -1;

    }



    if (blocksize * s->channels * (s->is32 ? 4 : 2) > alloc_data_size)

        return -1;



    /* sample rate */

    if (sr_code == 0)

        samplerate= s->samplerate;

    else if (sr_code < 12)

        samplerate = ff_flac_sample_rate_table[sr_code];

    else if (sr_code == 12)

        samplerate = get_bits(gb, 8) * 1000;

    else if (sr_code == 13)

        samplerate = get_bits(gb, 16);

    else if (sr_code == 14)

        samplerate = get_bits(gb, 16) * 10;

    else {

        av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n",

               sr_code);

        return -1;

    }



    /* header CRC-8 check */

    skip_bits(gb, 8);

    if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,

               get_bits_count(gb)/8)) {

        av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch\n");

        return -1;

    }



    s->blocksize    = blocksize;

    s->samplerate   = samplerate;

    s->bps          = bps;

    s->ch_mode      = ch_mode;



//    dump_headers(s->avctx, (FLACStreaminfo *)s);



    /* subframes */

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

        if (decode_subframe(s, i) < 0)

            return -1;

    }



    align_get_bits(gb);



    /* frame footer */

    skip_bits(gb, 16); /* data crc */



    return 0;

}

static int decode_frame(FLACContext *s, int alloc_data_size)

{

    int bs_code, sr_code, bps_code, i;

    int ch_mode, bps, blocksize, samplerate;

    GetBitContext *gb = &s->gb;



    

    skip_bits(&s->gb, 16);



    

    bs_code = get_bits(gb, 4);

    sr_code = get_bits(gb, 4);



    

    ch_mode = get_bits(gb, 4);

    if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) {

        ch_mode = FLAC_CHMODE_INDEPENDENT;

    } else if (ch_mode > FLAC_CHMODE_MID_SIDE || s->channels != 2) {

        av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",

               ch_mode, s->channels);

        return -1;

    }



    

    bps_code = get_bits(gb, 3);

    if (bps_code == 0)

        bps= s->bps;

    else if ((bps_code != 3) && (bps_code != 7))

        bps = sample_size_table[bps_code];

    else {

        av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n",

               bps_code);

        return -1;

    }

    if (bps > 16) {

        s->avctx->sample_fmt = SAMPLE_FMT_S32;

        s->sample_shift = 32 - bps;

        s->is32 = 1;

    } else {

        s->avctx->sample_fmt = SAMPLE_FMT_S16;

        s->sample_shift = 16 - bps;

        s->is32 = 0;

    }

    s->bps = s->avctx->bits_per_raw_sample = bps;



    

    if (get_bits1(gb)) {

        av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");

        return -1;

    }



    

    if (get_utf8(gb) < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "utf8 fscked\n");

        return -1;

    }



    

    if (bs_code == 0) {

        av_log(s->avctx, AV_LOG_ERROR, "reserved blocksize code: 0\n");

        return -1;

    } else if (bs_code == 6)

        blocksize = get_bits(gb, 8)+1;

    else if (bs_code == 7)

        blocksize = get_bits(gb, 16)+1;

    else

        blocksize = ff_flac_blocksize_table[bs_code];



    if (blocksize > s->max_blocksize) {

        av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize,

               s->max_blocksize);

        return -1;

    }



    if (blocksize * s->channels * (s->is32 ? 4 : 2) > alloc_data_size)

        return -1;



    

    if (sr_code == 0)

        samplerate= s->samplerate;

    else if (sr_code < 12)

        samplerate = ff_flac_sample_rate_table[sr_code];

    else if (sr_code == 12)

        samplerate = get_bits(gb, 8) * 1000;

    else if (sr_code == 13)

        samplerate = get_bits(gb, 16);

    else if (sr_code == 14)

        samplerate = get_bits(gb, 16) * 10;

    else {

        av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n",

               sr_code);

        return -1;

    }



    

    skip_bits(gb, 8);

    if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,

               get_bits_count(gb)/8)) {

        av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch\n");

        return -1;

    }



    s->blocksize    = blocksize;

    s->samplerate   = samplerate;

    s->bps          = bps;

    s->ch_mode      = ch_mode;







    

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

        if (decode_subframe(s, i) < 0)

            return -1;

    }



    align_get_bits(gb);



    

    skip_bits(gb, 16); 



    return 0;

}

static int FUNC_0(FLACContext *VAR_0, int VAR_1)

{

    int VAR_2, VAR_3, VAR_4, VAR_5;

    int VAR_6, VAR_7, VAR_8, VAR_9;

    GetBitContext *gb = &VAR_0->gb;



    

    skip_bits(&VAR_0->gb, 16);



    

    VAR_2 = get_bits(gb, 4);

    VAR_3 = get_bits(gb, 4);



    

    VAR_6 = get_bits(gb, 4);

    if (VAR_6 < FLAC_MAX_CHANNELS && VAR_0->channels == VAR_6+1) {

        VAR_6 = FLAC_CHMODE_INDEPENDENT;

    } else if (VAR_6 > FLAC_CHMODE_MID_SIDE || VAR_0->channels != 2) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",

               VAR_6, VAR_0->channels);

        return -1;

    }



    

    VAR_4 = get_bits(gb, 3);

    if (VAR_4 == 0)

        VAR_7= VAR_0->VAR_7;

    else if ((VAR_4 != 3) && (VAR_4 != 7))

        VAR_7 = sample_size_table[VAR_4];

    else {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n",

               VAR_4);

        return -1;

    }

    if (VAR_7 > 16) {

        VAR_0->avctx->sample_fmt = SAMPLE_FMT_S32;

        VAR_0->sample_shift = 32 - VAR_7;

        VAR_0->is32 = 1;

    } else {

        VAR_0->avctx->sample_fmt = SAMPLE_FMT_S16;

        VAR_0->sample_shift = 16 - VAR_7;

        VAR_0->is32 = 0;

    }

    VAR_0->VAR_7 = VAR_0->avctx->bits_per_raw_sample = VAR_7;



    

    if (get_bits1(gb)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");

        return -1;

    }



    

    if (get_utf8(gb) < 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "utf8 fscked\n");

        return -1;

    }



    

    if (VAR_2 == 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "reserved VAR_8 code: 0\n");

        return -1;

    } else if (VAR_2 == 6)

        VAR_8 = get_bits(gb, 8)+1;

    else if (VAR_2 == 7)

        VAR_8 = get_bits(gb, 16)+1;

    else

        VAR_8 = ff_flac_blocksize_table[VAR_2];



    if (VAR_8 > VAR_0->max_blocksize) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 %d > %d\n", VAR_8,

               VAR_0->max_blocksize);

        return -1;

    }



    if (VAR_8 * VAR_0->channels * (VAR_0->is32 ? 4 : 2) > VAR_1)

        return -1;



    

    if (VAR_3 == 0)

        VAR_9= VAR_0->VAR_9;

    else if (VAR_3 < 12)

        VAR_9 = ff_flac_sample_rate_table[VAR_3];

    else if (VAR_3 == 12)

        VAR_9 = get_bits(gb, 8) * 1000;

    else if (VAR_3 == 13)

        VAR_9 = get_bits(gb, 16);

    else if (VAR_3 == 14)

        VAR_9 = get_bits(gb, 16) * 10;

    else {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n",

               VAR_3);

        return -1;

    }



    

    skip_bits(gb, 8);

    if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,

               get_bits_count(gb)/8)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "header crc mismatch\n");

        return -1;

    }



    VAR_0->VAR_8    = VAR_8;

    VAR_0->VAR_9   = VAR_9;

    VAR_0->VAR_7          = VAR_7;

    VAR_0->VAR_6      = VAR_6;







    

    for (VAR_5 = 0; VAR_5 < VAR_0->channels; VAR_5++) {

        if (decode_subframe(VAR_0, VAR_5) < 0)

            return -1;

    }



    align_get_bits(gb);



    

    skip_bits(gb, 16); 



    return 0;

}

static int FUNC_0(FLACContext *VAR_0, int VAR_1)
{ int VAR_2, VAR_3, VAR_4, VAR_5; int VAR_6, VAR_7, VAR_8, VAR_9; GetBitContext *gb = &VAR_0->gb; skip_bits(&VAR_0->gb, 16); VAR_2 = get_bits(gb, 4); VAR_3 = get_bits(gb, 4); VAR_6 = get_bits(gb, 4); if (VAR_6 < FLAC_MAX_CHANNELS && VAR_0->channels == VAR_6+1) { VAR_6 = FLAC_CHMODE_INDEPENDENT; } else if (VAR_6 > FLAC_CHMODE_MID_SIDE || VAR_0->channels != 2) { av_log(VAR_0->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",
VAR_6, VAR_0->channels); return -1; } VAR_4 = get_bits(gb, 3); if (VAR_4 == 0)
VAR_7= VAR_0->VAR_7; else if ((VAR_4 != 3) && (VAR_4 != 7))
VAR_7 = sample_size_table[VAR_4]; else { av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n",
VAR_4); return -1; } if (VAR_7 > 16) { VAR_0->avctx->sample_fmt = SAMPLE_FMT_S32; VAR_0->sample_shift = 32 - VAR_7; VAR_0->is32 = 1; } else { VAR_0->avctx->sample_fmt = SAMPLE_FMT_S16; VAR_0->sample_shift = 16 - VAR_7; VAR_0->is32 = 0; } VAR_0->VAR_7 = VAR_0->avctx->bits_per_raw_sample = VAR_7; if (get_bits1(gb)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); return -1; } if (get_utf8(gb) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "utf8 fscked\n"); return -1; } if (VAR_2 == 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "reserved VAR_8 code: 0\n"); return -1; } else if (VAR_2 == 6) VAR_8 = get_bits(gb, 8)+1; else if (VAR_2 == 7)
VAR_8 = get_bits(gb, 16)+1; else
VAR_8 = ff_flac_blocksize_table[VAR_2]; if (VAR_8 > VAR_0->max_blocksize) { av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_8 %d > %d\n", VAR_8,
VAR_0->max_blocksize); return -1; } if (VAR_8 * VAR_0->channels * (VAR_0->is32 ? 4 : 2) > VAR_1)
return -1; if (VAR_3 == 0)
VAR_9= VAR_0->VAR_9; else if (VAR_3 < 12)
VAR_9 = ff_flac_sample_rate_table[VAR_3]; else if (VAR_3 == 12)
VAR_9 = get_bits(gb, 8) * 1000; else if (VAR_3 == 13)
VAR_9 = get_bits(gb, 16); else if (VAR_3 == 14)
VAR_9 = get_bits(gb, 16) * 10; else { av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n",
VAR_3); return -1; } skip_bits(gb, 8); if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,
get_bits_count(gb)/8)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "header crc mismatch\n"); return -1; } VAR_0->VAR_8    = VAR_8; VAR_0->VAR_9   = VAR_9; VAR_0->VAR_7          = VAR_7; VAR_0->VAR_6      = VAR_6; for (VAR_5 = 0; VAR_5 < VAR_0->channels; VAR_5++) { if (decode_subframe(VAR_0, VAR_5) < 0)
return -1; } align_get_bits(gb); skip_bits(gb, 16); return 0; }