void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
    if (!ref)
        return;
    if (!(--ref->buf->refcount))
        ref->buf->free(ref->buf);
    if (ref->extended_data != ref->data)
        av_freep(&ref->extended_data);
    av_free(ref->video);
    av_free(ref->audio);
    av_free(ref);
}
['static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)\n{\n    AVFilterContext  *ctx = inlink->dst;\n    ASyncContext       *s = ctx->priv;\n    AVFilterLink *outlink = ctx->outputs[0];\n    int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);\n    int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts :\n                  av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);\n    int out_size, ret;\n    int64_t delta;\n    if (s->pts == AV_NOPTS_VALUE) {\n        if (pts != AV_NOPTS_VALUE) {\n            s->pts = pts - get_delay(s);\n        }\n        return write_to_fifo(s, buf);\n    }\n    if (pts == AV_NOPTS_VALUE) {\n        return write_to_fifo(s, buf);\n    }\n    delta    = pts - s->pts - get_delay(s);\n    out_size = avresample_available(s->avr);\n    if (labs(delta) > s->min_delta) {\n        av_log(ctx, AV_LOG_VERBOSE, "Discontinuity - %"PRId64" samples.\\n", delta);\n        out_size = av_clipl_int32((int64_t)out_size + delta);\n    } else {\n        if (s->resample) {\n            int comp = av_clip(delta, -s->max_comp, s->max_comp);\n            av_log(ctx, AV_LOG_VERBOSE, "Compensating %d samples per second.\\n", comp);\n            avresample_set_compensation(s->avr, delta, inlink->sample_rate);\n        }\n        delta = 0;\n    }\n    if (out_size > 0) {\n        AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE,\n                                                         out_size);\n        if (!buf_out) {\n            ret = AVERROR(ENOMEM);\n            goto fail;\n        }\n        avresample_read(s->avr, buf_out->extended_data, out_size);\n        buf_out->pts = s->pts;\n        if (delta > 0) {\n            av_samples_set_silence(buf_out->extended_data, out_size - delta,\n                                   delta, nb_channels, buf->format);\n        }\n        ret = ff_filter_samples(outlink, buf_out);\n        if (ret < 0)\n            goto fail;\n        s->got_output = 1;\n    } else {\n        av_log(ctx, AV_LOG_WARNING, "Non-monotonous timestamps, dropping "\n               "whole buffer.\\n");\n    }\n    avresample_read(s->avr, NULL, avresample_available(s->avr));\n    s->pts = pts - avresample_get_delay(s->avr);\n    ret = avresample_convert(s->avr, NULL, 0, 0, buf->extended_data,\n                             buf->linesize[0], buf->audio->nb_samples);\nfail:\n    avfilter_unref_buffer(buf);\n    return ret;\n}', 'int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)\n{\n    int (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);\n    AVFilterPad *dst = link->dstpad;\n    AVFilterBufferRef *buf_out;\n    FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);\n    if (!(filter_samples = dst->filter_samples))\n        filter_samples = default_filter_samples;\n    if ((dst->min_perms & samplesref->perms) != dst->min_perms ||\n        dst->rej_perms & samplesref->perms) {\n        av_log(link->dst, AV_LOG_DEBUG,\n               "Copying audio data in avfilter (have perms %x, need %x, reject %x)\\n",\n               samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);\n        buf_out = ff_default_get_audio_buffer(link, dst->min_perms,\n                                              samplesref->audio->nb_samples);\n        if (!buf_out) {\n            avfilter_unref_buffer(samplesref);\n            return AVERROR(ENOMEM);\n        }\n        buf_out->pts                = samplesref->pts;\n        buf_out->audio->sample_rate = samplesref->audio->sample_rate;\n        av_samples_copy(buf_out->extended_data, samplesref->extended_data,\n                        0, 0, samplesref->audio->nb_samples,\n                        av_get_channel_layout_nb_channels(link->channel_layout),\n                        link->format);\n        avfilter_unref_buffer(samplesref);\n    } else\n        buf_out = samplesref;\n    return filter_samples(link, buf_out);\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n    if (!ref)\n        return;\n    if (!(--ref->buf->refcount))\n        ref->buf->free(ref->buf);\n    if (ref->extended_data != ref->data)\n        av_freep(&ref->extended_data);\n    av_free(ref->video);\n    av_free(ref->audio);\n    av_free(ref);\n}']