static int decode_frame(FLACContext *s)

{

    int i, ret;

    GetBitContext *gb = &s->gb;

    FLACFrameInfo fi;



    if ((ret = ff_flac_decode_frame_header(s->avctx, gb, &fi, 0)) < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "invalid frame header\n");

        return ret;

    }



    if (s->channels && fi.channels != s->channels && s->got_streaminfo) {

        s->channels = s->avctx->channels = fi.channels;

        ff_flac_set_channel_layout(s->avctx);

        ret = allocate_buffers(s);

        if (ret < 0)

            return ret;

    }

    s->channels = s->avctx->channels = fi.channels;

    if (!s->avctx->channel_layout)

        ff_flac_set_channel_layout(s->avctx);

    s->ch_mode = fi.ch_mode;



    if (!s->bps && !fi.bps) {

        av_log(s->avctx, AV_LOG_ERROR, "bps not found in STREAMINFO or frame header\n");

        return AVERROR_INVALIDDATA;

    }

    if (!fi.bps) {

        fi.bps = s->bps;

    } else if (s->bps && fi.bps != s->bps) {

        av_log(s->avctx, AV_LOG_ERROR, "switching bps mid-stream is not "

                                       "supported\n");

        return AVERROR_INVALIDDATA;

    }



    if (!s->bps) {

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

        flac_set_bps(s);

    }



    if (!s->max_blocksize)

        s->max_blocksize = FLAC_MAX_BLOCKSIZE;

    if (fi.blocksize > s->max_blocksize) {

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

               s->max_blocksize);

        return AVERROR_INVALIDDATA;

    }

    s->blocksize = fi.blocksize;



    if (!s->samplerate && !fi.samplerate) {

        av_log(s->avctx, AV_LOG_ERROR, "sample rate not found in STREAMINFO"

                                        " or frame header\n");

        return AVERROR_INVALIDDATA;

    }

    if (fi.samplerate == 0)

        fi.samplerate = s->samplerate;

    s->samplerate = s->avctx->sample_rate = fi.samplerate;



    if (!s->got_streaminfo) {

        ret = allocate_buffers(s);

        if (ret < 0)

            return ret;

        ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->channels, s->bps);

        s->got_streaminfo = 1;

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

    }



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



    /* subframes */

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

        if ((ret = decode_subframe(s, i)) < 0)

            return ret;

    }



    align_get_bits(gb);



    /* frame footer */

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



    return 0;

}

static int decode_frame(FLACContext *s)

{

    int i, ret;

    GetBitContext *gb = &s->gb;

    FLACFrameInfo fi;



    if ((ret = ff_flac_decode_frame_header(s->avctx, gb, &fi, 0)) < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "invalid frame header\n");

        return ret;

    }



    if (s->channels && fi.channels != s->channels && s->got_streaminfo) {

        s->channels = s->avctx->channels = fi.channels;

        ff_flac_set_channel_layout(s->avctx);

        ret = allocate_buffers(s);

        if (ret < 0)

            return ret;

    }

    s->channels = s->avctx->channels = fi.channels;

    if (!s->avctx->channel_layout)

        ff_flac_set_channel_layout(s->avctx);

    s->ch_mode = fi.ch_mode;



    if (!s->bps && !fi.bps) {

        av_log(s->avctx, AV_LOG_ERROR, "bps not found in STREAMINFO or frame header\n");

        return AVERROR_INVALIDDATA;

    }

    if (!fi.bps) {

        fi.bps = s->bps;

    } else if (s->bps && fi.bps != s->bps) {

        av_log(s->avctx, AV_LOG_ERROR, "switching bps mid-stream is not "

                                       "supported\n");

        return AVERROR_INVALIDDATA;

    }



    if (!s->bps) {

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

        flac_set_bps(s);

    }



    if (!s->max_blocksize)

        s->max_blocksize = FLAC_MAX_BLOCKSIZE;

    if (fi.blocksize > s->max_blocksize) {

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

               s->max_blocksize);

        return AVERROR_INVALIDDATA;

    }

    s->blocksize = fi.blocksize;



    if (!s->samplerate && !fi.samplerate) {

        av_log(s->avctx, AV_LOG_ERROR, "sample rate not found in STREAMINFO"

                                        " or frame header\n");

        return AVERROR_INVALIDDATA;

    }

    if (fi.samplerate == 0)

        fi.samplerate = s->samplerate;

    s->samplerate = s->avctx->sample_rate = fi.samplerate;



    if (!s->got_streaminfo) {

        ret = allocate_buffers(s);

        if (ret < 0)

            return ret;

        ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->channels, s->bps);

        s->got_streaminfo = 1;

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

    }







    

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

        if ((ret = decode_subframe(s, i)) < 0)

            return ret;

    }



    align_get_bits(gb);



    

    skip_bits(gb, 16); 



    return 0;

}

static int FUNC_0(FLACContext *VAR_0)

{

    int VAR_1, VAR_2;

    GetBitContext *gb = &VAR_0->gb;

    FLACFrameInfo fi;



    if ((VAR_2 = ff_flac_decode_frame_header(VAR_0->avctx, gb, &fi, 0)) < 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid frame header\n");

        return VAR_2;

    }



    if (VAR_0->channels && fi.channels != VAR_0->channels && VAR_0->got_streaminfo) {

        VAR_0->channels = VAR_0->avctx->channels = fi.channels;

        ff_flac_set_channel_layout(VAR_0->avctx);

        VAR_2 = allocate_buffers(VAR_0);

        if (VAR_2 < 0)

            return VAR_2;

    }

    VAR_0->channels = VAR_0->avctx->channels = fi.channels;

    if (!VAR_0->avctx->channel_layout)

        ff_flac_set_channel_layout(VAR_0->avctx);

    VAR_0->ch_mode = fi.ch_mode;



    if (!VAR_0->bps && !fi.bps) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "bps not found in STREAMINFO or frame header\n");

        return AVERROR_INVALIDDATA;

    }

    if (!fi.bps) {

        fi.bps = VAR_0->bps;

    } else if (VAR_0->bps && fi.bps != VAR_0->bps) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "switching bps mid-stream is not "

                                       "supported\n");

        return AVERROR_INVALIDDATA;

    }



    if (!VAR_0->bps) {

        VAR_0->bps = VAR_0->avctx->bits_per_raw_sample = fi.bps;

        flac_set_bps(VAR_0);

    }



    if (!VAR_0->max_blocksize)

        VAR_0->max_blocksize = FLAC_MAX_BLOCKSIZE;

    if (fi.blocksize > VAR_0->max_blocksize) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", fi.blocksize,

               VAR_0->max_blocksize);

        return AVERROR_INVALIDDATA;

    }

    VAR_0->blocksize = fi.blocksize;



    if (!VAR_0->samplerate && !fi.samplerate) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "sample rate not found in STREAMINFO"

                                        " or frame header\n");

        return AVERROR_INVALIDDATA;

    }

    if (fi.samplerate == 0)

        fi.samplerate = VAR_0->samplerate;

    VAR_0->samplerate = VAR_0->avctx->sample_rate = fi.samplerate;



    if (!VAR_0->got_streaminfo) {

        VAR_2 = allocate_buffers(VAR_0);

        if (VAR_2 < 0)

            return VAR_2;

        ff_flacdsp_init(&VAR_0->dsp, VAR_0->avctx->sample_fmt, VAR_0->channels, VAR_0->bps);

        VAR_0->got_streaminfo = 1;

        dump_headers(VAR_0->avctx, (FLACStreaminfo *)VAR_0);

    }







    

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

        if ((VAR_2 = decode_subframe(VAR_0, VAR_1)) < 0)

            return VAR_2;

    }



    align_get_bits(gb);



    

    skip_bits(gb, 16); 



    return 0;

}

static int FUNC_0(FLACContext *VAR_0)
{ int VAR_1, VAR_2; GetBitContext *gb = &VAR_0->gb; FLACFrameInfo fi; if ((VAR_2 = ff_flac_decode_frame_header(VAR_0->avctx, gb, &fi, 0)) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid frame header\n"); return VAR_2; } if (VAR_0->channels && fi.channels != VAR_0->channels && VAR_0->got_streaminfo) { VAR_0->channels = VAR_0->avctx->channels = fi.channels; ff_flac_set_channel_layout(VAR_0->avctx); VAR_2 = allocate_buffers(VAR_0); if (VAR_2 < 0)
return VAR_2; } VAR_0->channels = VAR_0->avctx->channels = fi.channels; if (!VAR_0->avctx->channel_layout)
ff_flac_set_channel_layout(VAR_0->avctx); VAR_0->ch_mode = fi.ch_mode; if (!VAR_0->bps && !fi.bps) { av_log(VAR_0->avctx, AV_LOG_ERROR, "bps not found in STREAMINFO or frame header\n"); return AVERROR_INVALIDDATA; } if (!fi.bps) { fi.bps = VAR_0->bps; } else if (VAR_0->bps && fi.bps != VAR_0->bps) { av_log(VAR_0->avctx, AV_LOG_ERROR, "switching bps mid-stream is not "
"supported\n"); return AVERROR_INVALIDDATA; } if (!VAR_0->bps) { VAR_0->bps = VAR_0->avctx->bits_per_raw_sample = fi.bps; flac_set_bps(VAR_0); } if (!VAR_0->max_blocksize)
VAR_0->max_blocksize = FLAC_MAX_BLOCKSIZE; if (fi.blocksize > VAR_0->max_blocksize) { av_log(VAR_0->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", fi.blocksize,
VAR_0->max_blocksize); return AVERROR_INVALIDDATA; } VAR_0->blocksize = fi.blocksize; if (!VAR_0->samplerate && !fi.samplerate) { av_log(VAR_0->avctx, AV_LOG_ERROR, "sample rate not found in STREAMINFO"
" or frame header\n"); return AVERROR_INVALIDDATA; } if (fi.samplerate == 0)
fi.samplerate = VAR_0->samplerate; VAR_0->samplerate = VAR_0->avctx->sample_rate = fi.samplerate; if (!VAR_0->got_streaminfo) { VAR_2 = allocate_buffers(VAR_0); if (VAR_2 < 0)
return VAR_2; ff_flacdsp_init(&VAR_0->dsp, VAR_0->avctx->sample_fmt, VAR_0->channels, VAR_0->bps); VAR_0->got_streaminfo = 1; dump_headers(VAR_0->avctx, (FLACStreaminfo *)VAR_0); } for (VAR_1 = 0; VAR_1 < VAR_0->channels; VAR_1++) { if ((VAR_2 = decode_subframe(VAR_0, VAR_1)) < 0)
return VAR_2; } align_get_bits(gb); skip_bits(gb, 16); return 0; }