int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
                               enum AVSampleFormat sample_fmt, int align)
{
    int line_size;
    int sample_size = av_get_bytes_per_sample(sample_fmt);
    int planar      = av_sample_fmt_is_planar(sample_fmt);
    if (!sample_size || nb_samples <= 0 || nb_channels <= 0)
        return AVERROR(EINVAL);
    if (!align) {
        if (nb_samples > INT_MAX - 31)
            return AVERROR(EINVAL);
        align = 1;
        nb_samples = FFALIGN(nb_samples, 32);
    }
    if (nb_channels > INT_MAX / align ||
        (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)
        return AVERROR(EINVAL);
    line_size = planar ? FFALIGN(nb_samples * sample_size,               align) :
                         FFALIGN(nb_samples * sample_size * nb_channels, align);
    if (linesize)
        *linesize = line_size;
    return planar ? line_size * nb_channels : line_size;
}
['static int decode_frame(FLACContext *s)\n{\n    int i, ret;\n    GetBitContext *gb = &s->gb;\n    FLACFrameInfo fi;\n    if ((ret = ff_flac_decode_frame_header(s->avctx, gb, &fi, 0)) < 0) {\n        av_log(s->avctx, AV_LOG_ERROR, "invalid frame header\\n");\n        return ret;\n    }\n    if (s->channels && fi.channels != s->channels && s->got_streaminfo) {\n        s->channels = s->avctx->channels = fi.channels;\n        ff_flac_set_channel_layout(s->avctx);\n        ret = allocate_buffers(s);\n        if (ret < 0)\n            return ret;\n    }\n    s->channels = s->avctx->channels = fi.channels;\n    if (!s->avctx->channel_layout)\n        ff_flac_set_channel_layout(s->avctx);\n    s->ch_mode = fi.ch_mode;\n    if (!s->bps && !fi.bps) {\n        av_log(s->avctx, AV_LOG_ERROR, "bps not found in STREAMINFO or frame header\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (!fi.bps) {\n        fi.bps = s->bps;\n    } else if (s->bps && fi.bps != s->bps) {\n        av_log(s->avctx, AV_LOG_ERROR, "switching bps mid-stream is not "\n                                       "supported\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (!s->bps) {\n        s->bps = s->avctx->bits_per_raw_sample = fi.bps;\n        flac_set_bps(s);\n    }\n    if (!s->max_blocksize)\n        s->max_blocksize = FLAC_MAX_BLOCKSIZE;\n    if (fi.blocksize > s->max_blocksize) {\n        av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\\n", fi.blocksize,\n               s->max_blocksize);\n        return AVERROR_INVALIDDATA;\n    }\n    s->blocksize = fi.blocksize;\n    if (!s->samplerate && !fi.samplerate) {\n        av_log(s->avctx, AV_LOG_ERROR, "sample rate not found in STREAMINFO"\n                                        " or frame header\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (fi.samplerate == 0)\n        fi.samplerate = s->samplerate;\n    s->samplerate = s->avctx->sample_rate = fi.samplerate;\n    if (!s->got_streaminfo) {\n        ret = allocate_buffers(s);\n        if (ret < 0)\n            return ret;\n        ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps);\n        s->got_streaminfo = 1;\n        dump_headers(s->avctx, (FLACStreaminfo *)s);\n    }\n    for (i = 0; i < s->channels; i++) {\n        if ((ret = decode_subframe(s, i)) < 0)\n            return ret;\n    }\n    align_get_bits(gb);\n    skip_bits(gb, 16);\n    return 0;\n}', 'static int allocate_buffers(FLACContext *s)\n{\n    int buf_size;\n    buf_size = av_samples_get_buffer_size(NULL, s->channels, s->max_blocksize,\n                                          AV_SAMPLE_FMT_S32P, 0);\n    if (buf_size < 0)\n        return buf_size;\n    av_fast_malloc(&s->decoded_buffer, &s->decoded_buffer_size, buf_size);\n    if (!s->decoded_buffer)\n        return AVERROR(ENOMEM);\n    return av_samples_fill_arrays((uint8_t **)s->decoded, NULL,\n                                  s->decoded_buffer, s->channels,\n                                  s->max_blocksize, AV_SAMPLE_FMT_S32P, 0);\n}', 'int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,\n                               enum AVSampleFormat sample_fmt, int align)\n{\n    int line_size;\n    int sample_size = av_get_bytes_per_sample(sample_fmt);\n    int planar      = av_sample_fmt_is_planar(sample_fmt);\n    if (!sample_size || nb_samples <= 0 || nb_channels <= 0)\n        return AVERROR(EINVAL);\n    if (!align) {\n        if (nb_samples > INT_MAX - 31)\n            return AVERROR(EINVAL);\n        align = 1;\n        nb_samples = FFALIGN(nb_samples, 32);\n    }\n    if (nb_channels > INT_MAX / align ||\n        (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)\n        return AVERROR(EINVAL);\n    line_size = planar ? FFALIGN(nb_samples * sample_size,               align) :\n                         FFALIGN(nb_samples * sample_size * nb_channels, align);\n    if (linesize)\n        *linesize = line_size;\n    return planar ? line_size * nb_channels : line_size;\n}']