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;
}
['int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)\n{\n    int i, ret, size;\n    if (av_audio_fifo_space(af) < nb_samples) {\n        int current_size = av_audio_fifo_size(af);\n        if (INT_MAX / 2 - current_size < nb_samples)\n            return AVERROR(EINVAL);\n        if ((ret = av_audio_fifo_realloc(af, 2 * (current_size + nb_samples))) < 0)\n            return ret;\n    }\n    size = nb_samples * af->sample_size;\n    for (i = 0; i < af->nb_buffers; i++) {\n        ret = av_fifo_generic_write(af->buf[i], data[i], size, NULL);\n        if (ret != size)\n            return AVERROR_BUG;\n    }\n    af->nb_samples += nb_samples;\n    return nb_samples;\n}', 'int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples)\n{\n    int i, ret, buf_size;\n    if ((ret = av_samples_get_buffer_size(&buf_size, af->channels, nb_samples,\n                                          af->sample_fmt, 1)) < 0)\n        return ret;\n    for (i = 0; i < af->nb_buffers; i++) {\n        if ((ret = av_fifo_realloc2(af->buf[i], buf_size)) < 0)\n            return ret;\n    }\n    af->allocated_samples = nb_samples;\n    return 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}']