diff options
Diffstat (limited to 'libavfilter/buffer.c')
-rw-r--r-- | libavfilter/buffer.c | 140 |
1 files changed, 31 insertions, 109 deletions
diff --git a/libavfilter/buffer.c b/libavfilter/buffer.c index 9a3f131dd0..29fedc4126 100644 --- a/libavfilter/buffer.c +++ b/libavfilter/buffer.c @@ -92,84 +92,13 @@ AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask) return ret; } -void ff_free_pool(AVFilterPool *pool) -{ - int i; - - av_assert0(pool->refcount > 0); - - for (i = 0; i < POOL_SIZE; i++) { - if (pool->pic[i]) { - AVFilterBufferRef *picref = pool->pic[i]; - /* free buffer: picrefs stored in the pool are not - * supposed to contain a free callback */ - av_assert0(!picref->buf->refcount); - av_freep(&picref->buf->data[0]); - av_freep(&picref->buf); - - av_freep(&picref->audio); - av_assert0(!picref->video || !picref->video->qp_table); - av_freep(&picref->video); - av_freep(&pool->pic[i]); - pool->count--; - } - } - pool->draining = 1; - - if (!--pool->refcount) { - av_assert0(!pool->count); - av_free(pool); - } -} - -static void store_in_pool(AVFilterBufferRef *ref) -{ - int i; - AVFilterPool *pool= ref->buf->priv; - - av_assert0(ref->buf->data[0]); - av_assert0(pool->refcount>0); - - if (ref->video) - av_freep(&ref->video->qp_table); - - if (pool->count == POOL_SIZE) { - AVFilterBufferRef *ref1 = pool->pic[0]; - av_freep(&ref1->video); - av_freep(&ref1->audio); - av_freep(&ref1->buf->data[0]); - av_freep(&ref1->buf); - av_free(ref1); - memmove(&pool->pic[0], &pool->pic[1], sizeof(void*)*(POOL_SIZE-1)); - pool->count--; - pool->pic[POOL_SIZE-1] = NULL; - } - - for (i = 0; i < POOL_SIZE; i++) { - if (!pool->pic[i]) { - pool->pic[i] = ref; - pool->count++; - break; - } - } - if (pool->draining) { - ff_free_pool(pool); - } else - --pool->refcount; -} - void avfilter_unref_buffer(AVFilterBufferRef *ref) { if (!ref) return; av_assert0(ref->buf->refcount > 0); - if (!(--ref->buf->refcount)) { - if (!ref->buf->free) { - store_in_pool(ref); - return; - } + if (!(--ref->buf->refcount)) ref->buf->free(ref->buf); - } if (ref->extended_data != ref->data) av_freep(&ref->extended_data); if (ref->video) @@ -186,6 +115,36 @@ void avfilter_unref_bufferp(AVFilterBufferRef **ref) *ref = NULL; } +int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src) +{ + dst->pts = src->pts; + dst->pos = av_frame_get_pkt_pos(src); + dst->format = src->format; + + av_dict_free(&dst->metadata); + av_dict_copy(&dst->metadata, av_frame_get_metadata(src), 0); + + switch (dst->type) { + case AVMEDIA_TYPE_VIDEO: + dst->video->w = src->width; + dst->video->h = src->height; + dst->video->sample_aspect_ratio = src->sample_aspect_ratio; + dst->video->interlaced = src->interlaced_frame; + dst->video->top_field_first = src->top_field_first; + dst->video->key_frame = src->key_frame; + dst->video->pict_type = src->pict_type; + break; + case AVMEDIA_TYPE_AUDIO: + dst->audio->sample_rate = src->sample_rate; + dst->audio->channel_layout = src->channel_layout; + break; + default: + return AVERROR(EINVAL); + } + + return 0; +} + void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src) { // copy common properties @@ -206,40 +165,3 @@ void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *s av_dict_free(&dst->metadata); av_dict_copy(&dst->metadata, src->metadata, 0); } - -AVFilterBufferRef *ff_copy_buffer_ref(AVFilterLink *outlink, - AVFilterBufferRef *ref) -{ - AVFilterBufferRef *buf; - int channels; - - switch (outlink->type) { - - case AVMEDIA_TYPE_VIDEO: - buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, - ref->video->w, ref->video->h); - if(!buf) - return NULL; - av_image_copy(buf->data, buf->linesize, - (void*)ref->data, ref->linesize, - ref->format, ref->video->w, ref->video->h); - break; - - case AVMEDIA_TYPE_AUDIO: - buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE, - ref->audio->nb_samples); - if(!buf) - return NULL; - channels = ref->audio->channels; - av_samples_copy(buf->extended_data, ref->buf->extended_data, - 0, 0, ref->audio->nb_samples, - channels, - ref->format); - break; - - default: - return NULL; - } - avfilter_copy_buffer_ref_props(buf, ref); - return buf; -} |