/* TODO: set the buffer's priv member to a context structure for the whole * filter chain. This will allow for a buffer pool instead of the constant * alloc & free cycle currently implemented. */ AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms) { AVFilterPic *pic = av_mallocz(sizeof(AVFilterPic)); AVFilterPicRef *ref = av_mallocz(sizeof(AVFilterPicRef)); int i, tempsize; char *buf; ref->pic = pic; ref->w = link->w; ref->h = link->h; /* make sure the buffer gets read permission or it's useless for output */ ref->perms = perms | AV_PERM_READ; pic->refcount = 1; pic->format = link->v_format; pic->free = avfilter_default_free_video_buffer; ff_fill_linesize((AVPicture *)pic, pic->format, ref->w); for (i=0; i<4;i++) pic->linesize[i] = FFALIGN(pic->linesize[i], 16); tempsize = ff_fill_pointer((AVPicture *)pic, NULL, pic->format, ref->h); buf = av_malloc(tempsize); ff_fill_pointer((AVPicture *)pic, buf, pic->format, ref->h); memcpy(ref->data, pic->data, sizeof(pic->data)); memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize)); return ref; }
static inline void get_buffer(AVFrame *p, int width, int height) { ff_fill_linesize(p, width); for(int plane=0;plane<3;plane++) { p->data[plane] = (uint8_t *) av_malloc(p->linesize[plane]*height); } }