void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
    if(!(--ref->buf->refcount))
        ref->buf->free(ref->buf);
    av_free(ref->video);
    av_free(ref);
}
['static int request_frame(AVFilterLink *link)\n{\n    BufferSourceContext *c = link->src->priv;\n    AVFilterBufferRef *picref;\n    if (!c->has_frame) {\n        av_log(link->src, AV_LOG_ERROR,\n               "request_frame() called with no available frame!\\n");\n    }\n    picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |\n                                       AV_PERM_REUSE2,\n                                       link->w, link->h);\n    av_picture_copy((AVPicture *)&picref->data, (AVPicture *)&c->frame,\n                    picref->format, link->w, link->h);\n    picref->pts                    = c->pts;\n    picref->video->pixel_aspect    = c->pixel_aspect;\n    picref->video->interlaced      = c->frame.interlaced_frame;\n    picref->video->top_field_first = c->frame.top_field_first;\n    avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));\n    avfilter_draw_slice(link, 0, link->h, 1);\n    avfilter_end_frame(link);\n    avfilter_unref_buffer(picref);\n    c->has_frame = 0;\n    return 0;\n}', 'AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)\n{\n    AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef));\n    *ret = *ref;\n    if (ref->type == AVMEDIA_TYPE_VIDEO) {\n        ret->video = av_malloc(sizeof(AVFilterBufferRefVideoProps));\n        *ret->video = *ref->video;\n    }\n    ret->perms &= pmask;\n    ret->buf->refcount ++;\n    return ret;\n}', 'void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)\n{\n    void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);\n    AVFilterPad *dst = &link_dpad(link);\n    FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_picref(NULL, picref, 1);\n    if(!(start_frame = dst->start_frame))\n        start_frame = avfilter_default_start_frame;\n    if((dst->min_perms & picref->perms) != dst->min_perms ||\n        dst->rej_perms & picref->perms) {\n        link->cur_buf = avfilter_default_get_video_buffer(link, dst->min_perms, link->w, link->h);\n        link->src_buf = picref;\n        avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf);\n    }\n    else\n        link->cur_buf = picref;\n    start_frame(link, link->cur_buf);\n}', 'void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)\n{\n    uint8_t *src[4], *dst[4];\n    int i, j, vsub;\n    void (*draw_slice)(AVFilterLink *, int, int, int);\n    FF_DPRINTF_START(NULL, draw_slice); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " y:%d h:%d dir:%d\\n", y, h, slice_dir);\n    if(link->src_buf) {\n        vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;\n        for(i = 0; i < 4; i ++) {\n            if(link->src_buf->data[i]) {\n                src[i] = link->src_buf-> data[i] +\n                    (y >> (i==0 ? 0 : vsub)) * link->src_buf-> linesize[i];\n                dst[i] = link->cur_buf->data[i] +\n                    (y >> (i==0 ? 0 : vsub)) * link->cur_buf->linesize[i];\n            } else\n                src[i] = dst[i] = NULL;\n        }\n        for(i = 0; i < 4; i ++) {\n            int planew =\n                ff_get_plane_bytewidth(link->format, link->cur_buf->video->w, i);\n            if(!src[i]) continue;\n            for(j = 0; j < h >> (i==0 ? 0 : vsub); j ++) {\n                memcpy(dst[i], src[i], planew);\n                src[i] += link->src_buf ->linesize[i];\n                dst[i] += link->cur_buf->linesize[i];\n            }\n        }\n    }\n    if(!(draw_slice = link_dpad(link).draw_slice))\n        draw_slice = avfilter_default_draw_slice;\n    draw_slice(link, y, h, slice_dir);\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n    if(!(--ref->buf->refcount))\n        ref->buf->free(ref->buf);\n    av_free(ref->video);\n    av_free(ref);\n}']