diff options
author | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2011-05-07 21:35:08 +0200 |
---|---|---|
committer | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2011-05-19 23:15:33 +0200 |
commit | 6070b7e1c520e9ca389403bae20a2ad04c7d54c7 (patch) | |
tree | 4d78a27c7053a106680831caaef01ad70c1b1d2e | |
parent | 3c7650a83d3bdca2fd680af722de344b092f65ec (diff) | |
download | ffmpeg-6070b7e1c520e9ca389403bae20a2ad04c7d54c7.tar.gz |
vsrc_buffer: remove dependency on AVFrame
Rename av_vsrc_buffer_add_frame to
av_vsrc_buffer_add_video_buffer_ref(), and change its inteface to make
it accept in input an AVFilterBufferRef rather than an AVFrame.
This way the interface can be used without requiring the
inclusion/installation of libavcodec headers.
-rw-r--r-- | ffmpeg.c | 11 | ||||
-rw-r--r-- | libavfilter/vsrc_buffer.c | 57 | ||||
-rw-r--r-- | libavfilter/vsrc_buffer.h | 7 |
3 files changed, 35 insertions, 40 deletions
@@ -1643,13 +1643,20 @@ static int output_packet(AVInputStream *ist, int ist_index, #if CONFIG_AVFILTER if(ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { for(i=0;i<nb_ostreams;i++) { + AVFilterBufferRef *picref; ost = ost_table[i]; if (ost->input_video_filter && ost->source_index == ist_index) { if (!picture.sample_aspect_ratio.num) picture.sample_aspect_ratio = ist->st->sample_aspect_ratio; picture.pts = ist->pts; - // add it to be filtered - av_vsrc_buffer_add_frame2(ost->input_video_filter, &picture, ""); //TODO user setable params + + picref = avfilter_get_video_buffer_ref_from_arrays( + picture.data, picture.linesize, AV_PERM_WRITE, + picture.width, picture.height, picture.format); + avfilter_copy_frame_props(picref, &picture); + av_vsrc_buffer_add_video_buffer_ref2(ost->input_video_filter, picref, ""); //TODO user setable params + picref->buf->data[0] = NULL; + avfilter_unref_buffer(picref); } } } diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 84f3b33c3f..b593a207de 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -29,8 +29,7 @@ #include "libavutil/imgutils.h" typedef struct { - AVFrame frame; - int has_frame; + AVFilterBufferRef *picref; int h, w; enum PixelFormat pix_fmt; AVRational time_base; ///< time_base to set in the output link @@ -38,13 +37,14 @@ typedef struct { char sws_param[256]; } BufferSourceContext; -int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, - const char *sws_param) +int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref, + const char *sws_param) { BufferSourceContext *c = buffer_filter->priv; + AVFilterLink *outlink = buffer_filter->outputs[0]; int ret; - if (c->has_frame) { + if (c->picref) { av_log(buffer_filter, AV_LOG_ERROR, "Buffering several frames is not supported. " "Please consume all available frames before adding a new one.\n" @@ -56,14 +56,14 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param); } - if (frame->width != c->w || frame->height != c->h || frame->format != c->pix_fmt) { + if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { AVFilterContext *scale= buffer_filter->outputs[0]->dst; AVFilterLink *link; av_log(buffer_filter, AV_LOG_INFO, "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, - frame->width, frame->height, av_pix_fmt_descriptors[frame->format].name); + picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name); if(!scale || strcmp(scale->filter->name,"scale")){ AVFilter *f= avfilter_get_by_name("scale"); @@ -89,26 +89,28 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, scale->filter->init(scale, c->sws_param, NULL); } - c->pix_fmt = scale->inputs[0]->format = frame->format; - c->w = scale->inputs[0]->w = frame->width; - c->h = scale->inputs[0]->h = frame->height; + c->pix_fmt = scale->inputs[0]->format = picref->format; + c->w = scale->inputs[0]->w = picref->video->w; + c->h = scale->inputs[0]->h = picref->video->h; link= scale->outputs[0]; if ((ret = link->srcpad->config_props(link)) < 0) return ret; } - c->frame = *frame; - memcpy(c->frame.data , frame->data , sizeof(frame->data)); - memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); - c->has_frame = 1; + c->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, + picref->video->w, picref->video->h); + av_image_copy(c->picref->data, c->picref->linesize, + picref->data, picref->linesize, + picref->format, picref->video->w, picref->video->h); + avfilter_copy_buffer_ref_props(c->picref, picref); return 0; } -int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame) +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref) { - return av_vsrc_buffer_add_frame2(buffer_filter, frame, ""); + return av_vsrc_buffer_add_video_buffer_ref2(buffer_filter, picref, ""); } static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) @@ -164,31 +166,18 @@ static int config_props(AVFilterLink *link) static int request_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - AVFilterBufferRef *picref; - if (!c->has_frame) { + if (!c->picref) { av_log(link->src, AV_LOG_ERROR, "request_frame() called with no available frame!\n"); //return -1; } - /* This picture will be needed unmodified later for decoding the next - * frame */ - picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE2, - link->w, link->h); - - av_image_copy(picref->data, picref->linesize, - c->frame.data, c->frame.linesize, - picref->format, link->w, link->h); - avfilter_copy_frame_props(picref, &c->frame); - - avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); + avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0)); avfilter_draw_slice(link, 0, link->h, 1); avfilter_end_frame(link); - avfilter_unref_buffer(picref); - - c->has_frame = 0; + avfilter_unref_buffer(c->picref); + c->picref = NULL; return 0; } @@ -196,7 +185,7 @@ static int request_frame(AVFilterLink *link) static int poll_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - return !!(c->has_frame); + return !!(c->picref); } AVFilter avfilter_vsrc_buffer = { diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h index 2dda546e01..eb9ec56edd 100644 --- a/libavfilter/vsrc_buffer.h +++ b/libavfilter/vsrc_buffer.h @@ -27,12 +27,11 @@ * memory buffer source API for video */ -#include "libavcodec/avcodec.h" /* AVFrame */ #include "avfilter.h" -int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame); +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref); -int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, - const char *sws_param); +int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref, + const char *sws_param); #endif /* AVFILTER_VSRC_BUFFER_H */ |