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 poll_filter(OutputStream *ost)\n{\n    OutputFile    *of = output_files[ost->file_index];\n    AVFrame *filtered_frame = NULL;\n    int frame_size, ret;\n    if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) {\n        return AVERROR(ENOMEM);\n    }\n    filtered_frame = ost->filtered_frame;\n    if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&\n        !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))\n        ret = av_buffersink_get_samples(ost->filter->filter, filtered_frame,\n                                         ost->st->codec->frame_size);\n    else\n        ret = av_buffersink_get_frame(ost->filter->filter, filtered_frame);\n    if (ret < 0)\n        return ret;\n    if (filtered_frame->pts != AV_NOPTS_VALUE) {\n        int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;\n        filtered_frame->pts = av_rescale_q(filtered_frame->pts,\n                                           ost->filter->filter->inputs[0]->time_base,\n                                           ost->st->codec->time_base) -\n                              av_rescale_q(start_time,\n                                           AV_TIME_BASE_Q,\n                                           ost->st->codec->time_base);\n    }\n    switch (ost->filter->filter->inputs[0]->type) {\n    case AVMEDIA_TYPE_VIDEO:\n        if (!ost->frame_aspect_ratio)\n            ost->st->codec->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;\n        do_video_out(of->ctx, ost, filtered_frame, &frame_size);\n        if (vstats_filename && frame_size)\n            do_video_stats(ost, frame_size);\n        break;\n    case AVMEDIA_TYPE_AUDIO:\n        do_audio_out(of->ctx, ost, filtered_frame);\n        break;\n    default:\n        av_assert0(0);\n    }\n    av_frame_unref(filtered_frame);\n    return 0;\n}', 'int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,\n                                                  AVFrame *frame, int nb_samples)\n{\n    BufferSinkContext *s = ctx->priv;\n    AVFilterLink   *link = ctx->inputs[0];\n    int ret = 0;\n    if (!s->audio_fifo) {\n        int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);\n        if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, nb_samples)))\n            return AVERROR(ENOMEM);\n    }\n    while (ret >= 0) {\n        if (av_audio_fifo_size(s->audio_fifo) >= nb_samples)\n            return read_from_fifo(ctx, frame, nb_samples);\n        ret = ff_request_frame(link);\n        if (ret == AVERROR_EOF && av_audio_fifo_size(s->audio_fifo))\n            return read_from_fifo(ctx, frame, av_audio_fifo_size(s->audio_fifo));\n        else if (ret < 0)\n            return ret;\n        if (s->cur_frame->pts != AV_NOPTS_VALUE) {\n            s->next_pts = s->cur_frame->pts -\n                          av_rescale_q(av_audio_fifo_size(s->audio_fifo),\n                                       (AVRational){ 1, link->sample_rate },\n                                       link->time_base);\n        }\n        ret = av_audio_fifo_write(s->audio_fifo, (void**)s->cur_frame->extended_data,\n                                  s->cur_frame->nb_samples);\n        av_frame_free(&s->cur_frame);\n    }\n    return ret;\n}', 'AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,\n                                 int nb_samples)\n{\n    AVAudioFifo *af;\n    int buf_size, i;\n    if (av_samples_get_buffer_size(&buf_size, channels, nb_samples, sample_fmt, 1) < 0)\n        return NULL;\n    af = av_mallocz(sizeof(*af));\n    if (!af)\n        return NULL;\n    af->channels    = channels;\n    af->sample_fmt  = sample_fmt;\n    af->sample_size = buf_size / nb_samples;\n    af->nb_buffers  = av_sample_fmt_is_planar(sample_fmt) ? channels : 1;\n    af->buf = av_mallocz(af->nb_buffers * sizeof(*af->buf));\n    if (!af->buf)\n        goto error;\n    for (i = 0; i < af->nb_buffers; i++) {\n        af->buf[i] = av_fifo_alloc(buf_size);\n        if (!af->buf[i])\n            goto error;\n    }\n    af->allocated_samples = nb_samples;\n    return af;\nerror:\n    av_audio_fifo_free(af);\n    return NULL;\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}']