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 ff_audio_data_combine(AudioData *dst, int dst_offset, AudioData *src,\n                          int src_offset, int nb_samples)\n{\n    int ret, p, dst_offset2, dst_move_size;\n    if (dst->sample_fmt != src->sample_fmt || dst->channels != src->channels) {\n        av_log(src, AV_LOG_ERROR, "sample format mismatch\\n");\n        return AVERROR(EINVAL);\n    }\n    if (dst_offset < 0 || dst_offset > dst->nb_samples ||\n        src_offset < 0 || src_offset > src->nb_samples) {\n        av_log(src, AV_LOG_ERROR, "offset out-of-bounds: src=%d dst=%d\\n",\n               src_offset, dst_offset);\n        return AVERROR(EINVAL);\n    }\n    if (nb_samples > src->nb_samples - src_offset)\n        nb_samples = src->nb_samples - src_offset;\n    if (nb_samples <= 0)\n        return 0;\n    if (dst->read_only) {\n        av_log(dst, AV_LOG_ERROR, "dst is read-only\\n");\n        return AVERROR(EINVAL);\n    }\n    ret = ff_audio_data_realloc(dst, dst->nb_samples + nb_samples);\n    if (ret < 0) {\n        av_log(dst, AV_LOG_ERROR, "error reallocating dst\\n");\n        return ret;\n    }\n    dst_offset2   = dst_offset + nb_samples;\n    dst_move_size = dst->nb_samples - dst_offset;\n    for (p = 0; p < src->planes; p++) {\n        if (dst_move_size > 0) {\n            memmove(dst->data[p] + dst_offset2 * dst->stride,\n                    dst->data[p] + dst_offset  * dst->stride,\n                    dst_move_size * dst->stride);\n        }\n        memcpy(dst->data[p] + dst_offset * dst->stride,\n               src->data[p] + src_offset * src->stride,\n               nb_samples * src->stride);\n    }\n    dst->nb_samples += nb_samples;\n    return 0;\n}', 'int ff_audio_data_realloc(AudioData *a, int nb_samples)\n{\n    int ret, new_buf_size, plane_size, p;\n    if (a->allocated_samples >= nb_samples)\n        return 0;\n    if (a->read_only || !a->allow_realloc)\n        return AVERROR(EINVAL);\n    new_buf_size = av_samples_get_buffer_size(&plane_size,\n                                              a->allocated_channels, nb_samples,\n                                              a->sample_fmt, 0);\n    if (new_buf_size < 0)\n        return new_buf_size;\n    if (a->nb_samples > 0 && a->is_planar) {\n        uint8_t *new_data[AVRESAMPLE_MAX_CHANNELS] = { NULL };\n        ret = av_samples_alloc(new_data, &plane_size, a->allocated_channels,\n                               nb_samples, a->sample_fmt, 0);\n        if (ret < 0)\n            return ret;\n        for (p = 0; p < a->planes; p++)\n            memcpy(new_data[p], a->data[p], a->nb_samples * a->stride);\n        av_freep(&a->buffer);\n        memcpy(a->data, new_data, sizeof(new_data));\n        a->buffer = a->data[0];\n    } else {\n        av_freep(&a->buffer);\n        a->buffer = av_malloc(new_buf_size);\n        if (!a->buffer)\n            return AVERROR(ENOMEM);\n        ret = av_samples_fill_arrays(a->data, &plane_size, a->buffer,\n                                     a->allocated_channels, nb_samples,\n                                     a->sample_fmt, 0);\n        if (ret < 0)\n            return ret;\n    }\n    a->buffer_size       = new_buf_size;\n    a->allocated_samples = nb_samples;\n    calc_ptr_alignment(a);\n    a->samples_align = plane_size / a->stride;\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}']