History

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.

Stefano Sabatini committed 15 years ago

Commit 6070b7e1 parent 3c7650a3 files · +35 −40Browse files

Showing the changes to libavfilter/vsrc_buffer.c (1 of 3 files). Show all

Unified · Split

libavfilter/vsrc_buffer.c+23−34
@@ -29,8 +29,7 @@ · 28 unmodified lines
2929 #include "libavutil/imgutils.h"
3030
3131 typedef struct {
32− AVFrame frame;
33− int has_frame;
32+ AVFilterBufferRef *picref;
3433 int h, w;
3534 enum PixelFormat pix_fmt;
3635 AVRational time_base; ///< time_base to set in the output link
@@ -38,13 +37,14 @@ typedef struct { · 1 unmodified line
3837 char sws_param[256];
3938 } BufferSourceContext;
4039
41−int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame,
42− const char *sws_param)
40+int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref,
41+ const char *sws_param)
4342 {
4443 BufferSourceContext *c = buffer_filter->priv;
44+ AVFilterLink *outlink = buffer_filter->outputs[0];
4545 int ret;
4646
47− if (c->has_frame) {
47+ if (c->picref) {
4848 av_log(buffer_filter, AV_LOG_ERROR,
4949 "Buffering several frames is not supported. "
5050 "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, · 5 unmodified lines
5656 snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param);
5757 }
5858
59− if (frame->width != c->w || frame->height != c->h || frame->format != c->pix_fmt) {
59+ if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {
6060 AVFilterContext *scale= buffer_filter->outputs[0]->dst;
6161 AVFilterLink *link;
6262
6363 av_log(buffer_filter, AV_LOG_INFO,
6464 "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
6565 c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,
66− frame->width, frame->height, av_pix_fmt_descriptors[frame->format].name);
66+ picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name);
6767
6868 if(!scale || strcmp(scale->filter->name,"scale")){
6969 AVFilter *f= avfilter_get_by_name("scale");
@@ -89,26 +89,28 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, · 19 unmodified lines
8989 scale->filter->init(scale, c->sws_param, NULL);
9090 }
9191
92− c->pix_fmt = scale->inputs[0]->format = frame->format;
93− c->w = scale->inputs[0]->w = frame->width;
94− c->h = scale->inputs[0]->h = frame->height;
92+ c->pix_fmt = scale->inputs[0]->format = picref->format;
93+ c->w = scale->inputs[0]->w = picref->video->w;
94+ c->h = scale->inputs[0]->h = picref->video->h;
9595
9696 link= scale->outputs[0];
9797 if ((ret = link->srcpad->config_props(link)) < 0)
9898 return ret;
9999 }
100100
101− c->frame = *frame;
102− memcpy(c->frame.data , frame->data , sizeof(frame->data));
103− memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
104− c->has_frame = 1;
101+ c->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
102+ picref->video->w, picref->video->h);
103+ av_image_copy(c->picref->data, c->picref->linesize,
104+ picref->data, picref->linesize,
105+ picref->format, picref->video->w, picref->video->h);
106+ avfilter_copy_buffer_ref_props(c->picref, picref);
105107
106108 return 0;
107109 }
108110
109−int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame)
111+int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref)
110112 {
111− return av_vsrc_buffer_add_frame2(buffer_filter, frame, "");
113+ return av_vsrc_buffer_add_video_buffer_ref2(buffer_filter, picref, "");
112114 }
113115
114116 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
@@ -164,31 +166,18 @@ static int config_props(AVFilterLink *link) · 49 unmodified lines
164166 static int request_frame(AVFilterLink *link)
165167 {
166168 BufferSourceContext *c = link->src->priv;
167− AVFilterBufferRef *picref;
168169
169− if (!c->has_frame) {
170+ if (!c->picref) {
170171 av_log(link->src, AV_LOG_ERROR,
171172 "request_frame() called with no available frame!\n");
172173 //return -1;
173174 }
174175
175− /* This picture will be needed unmodified later for decoding the next
176− * frame */
177− picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
178− AV_PERM_REUSE2,
179− link->w, link->h);
180−
181− av_image_copy(picref->data, picref->linesize,
182− c->frame.data, c->frame.linesize,
183− picref->format, link->w, link->h);
184− avfilter_copy_frame_props(picref, &c->frame);
185−
186− avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
176+ avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0));
187177 avfilter_draw_slice(link, 0, link->h, 1);
188178 avfilter_end_frame(link);
189− avfilter_unref_buffer(picref);
190−
191− c->has_frame = 0;
179+ avfilter_unref_buffer(c->picref);
180+ c->picref = NULL;
192181
193182 return 0;
194183 }
@@ -196,7 +185,7 @@ static int request_frame(AVFilterLink *link) · 1 unmodified line
196185 static int poll_frame(AVFilterLink *link)
197186 {
198187 BufferSourceContext *c = link->src->priv;
199− return !!(c->has_frame);
188+ return !!(c->picref);
200189 }
201190
202191 AVFilter avfilter_vsrc_buffer = {

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