AVFilter: use picture pool to avoid malloc().

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2011-05-06 23:53:06 +02:00
parent fa3eddc011
commit 39f66edbea
4 changed files with 71 additions and 2 deletions

View File

@@ -25,7 +25,6 @@
#include "avfilter.h"
#include "internal.h"
/* TODO: buffer pool. see comment for avfilter_default_get_video_buffer() */
void ff_avfilter_default_free_buffer(AVFilterBuffer *ptr)
{
av_free(ptr->data[0]);
@@ -39,7 +38,26 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
{
int linesize[4];
uint8_t *data[4];
int i;
AVFilterBufferRef *picref = NULL;
AVFilterPool *pool= link->pool;
if(pool) for(i=0; i<POOL_SIZE; i++){
picref= pool->pic[i];
if(picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h){
AVFilterBuffer *pic= picref->buf;
pool->pic[i]= NULL;
pool->count--;
picref->video->w = w;
picref->video->h = h;
picref->perms = perms | AV_PERM_READ;
picref->format= link->format;
pic->refcount = 1;
memcpy(picref->data, pic->data, sizeof(picref->data));
memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
return picref;
}
}
// +2 is needed for swscaler, +16 to be SIMD-friendly
if (av_image_alloc(data, linesize, w, h, link->format, 16) < 0)
@@ -51,6 +69,8 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
av_free(data[0]);
return NULL;
}
picref->buf->priv= link;
picref->buf->free= NULL;
return picref;
}