diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-05-06 23:53:06 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-05-06 23:53:06 +0200 |
commit | 39f66edbeae5ccabefe38b2fcb25d6c242d868c0 (patch) | |
tree | 0cc5e445e6e10361bf3d40ec3d793fa1a91a9adf /libavfilter/defaults.c | |
parent | fa3eddc0110cb237cd57c3e82cafdbcbf798b3a1 (diff) | |
download | ffmpeg-39f66edbeae5ccabefe38b2fcb25d6c242d868c0.tar.gz |
AVFilter: use picture pool to avoid malloc().
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter/defaults.c')
-rw-r--r-- | libavfilter/defaults.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c index 1da2630471..ef798ddd8d 100644 --- a/libavfilter/defaults.c +++ b/libavfilter/defaults.c @@ -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; } |