History

AVFilter: use picture pool to avoid malloc(). Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer committed 15 years ago

Commit 39f66ed1 parent fa3eddc4 files · +71 −2Browse files

Showing the changes to libavfilter/avfilter.c (1 of 4 files). Show all

Unified · Split

libavfilter/avfilter.c+42−1
@@ -25,6 +25,7 @@ · 24 unmodified lines
25#include "libavutil/rational.h"25#include "libavutil/rational.h"
26#include "libavutil/audioconvert.h"26#include "libavutil/audioconvert.h"
27#include "libavutil/imgutils.h"27#include "libavutil/imgutils.h"
28#include "libavutil/avassert.h"
28#include "avfilter.h"29#include "avfilter.h"
29#include "internal.h"30#include "internal.h"
30 31
@@ -69,12 +70,50 @@ AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask) · 38 unmodified lines
69 return ret;70 return ret;
70}71}
71 72
73static void store_in_pool(AVFilterBufferRef *ref)
74{
75 int i;
76 AVFilterLink *link= ref->buf->priv;
77 AVFilterPool *pool;
78
79 av_assert0(ref->buf->data[0]);
80
81 if(!link->pool)
82 link->pool = av_mallocz(sizeof(AVFilterPool));
83 pool= link->pool;
84
85 if(pool->count == POOL_SIZE){
86 AVFilterBufferRef *ref1= pool->pic[0];
87 av_freep(&ref1->video);
88 av_freep(&ref1->audio);
89 av_freep(&ref1->buf->data[0]);
90 av_freep(&ref1->buf);
91 av_free(ref1);
92 memmove(&pool->pic[0], &pool->pic[1], sizeof(void*)*(POOL_SIZE-1));
93 pool->count--;
94 pool->pic[POOL_SIZE-1] = NULL;
95 }
96
97 for(i=0; i<POOL_SIZE; i++){
98 if(!pool->pic[i]){
99 pool->pic[i]= ref;
100 pool->count++;
101 break;
102 }
103 }
104}
105
72void avfilter_unref_buffer(AVFilterBufferRef *ref)106void avfilter_unref_buffer(AVFilterBufferRef *ref)
73{107{
74 if (!ref)108 if (!ref)
75 return;109 return;
76 if (!(--ref->buf->refcount))110 if (!(--ref->buf->refcount)){
111 if(!ref->buf->free){
112 store_in_pool(ref);
113 return;
114 }
77 ref->buf->free(ref->buf);115 ref->buf->free(ref->buf);
116 }
78 av_freep(&ref->video);117 av_freep(&ref->video);
79 av_freep(&ref->audio);118 av_freep(&ref->audio);
80 av_free(ref);119 av_free(ref);
@@ -646,6 +685,7 @@ void avfilter_free(AVFilterContext *filter) · 565 unmodified lines
646 if ((link = filter->inputs[i])) {685 if ((link = filter->inputs[i])) {
647 if (link->src)686 if (link->src)
648 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;687 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
688 av_freep(&link->pool);
649 avfilter_formats_unref(&link->in_formats);689 avfilter_formats_unref(&link->in_formats);
650 avfilter_formats_unref(&link->out_formats);690 avfilter_formats_unref(&link->out_formats);
651 }691 }
@@ -655,6 +695,7 @@ void avfilter_free(AVFilterContext *filter) · 3 unmodified lines
655 if ((link = filter->outputs[i])) {695 if ((link = filter->outputs[i])) {
656 if (link->dst)696 if (link->dst)
657 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;697 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
698 av_freep(&link->pool);
658 avfilter_formats_unref(&link->in_formats);699 avfilter_formats_unref(&link->in_formats);
659 avfilter_formats_unref(&link->out_formats);700 avfilter_formats_unref(&link->out_formats);
660 }701 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t