History

src_buffer: introduce av_buffersrc_add_ref().

This function merges the features of av_vsrc_buffer_add_video_buffer_ref() and av_buffersrc_buffer().

Nicolas George committed 14 years ago

Commit 3985ec01 parent 77c0b362 files · +46 −24Browse files

Showing the changes to libavfilter/src_buffer.c (1 of 2 files). Show all

Unified · Split

libavfilter/src_buffer.c+20−24
@@ -69,8 +69,8 @@ typedef struct { · 68 unmodified lines
6969 return AVERROR(EINVAL);\
7070 }
7171
72−int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
73− AVFilterBufferRef *picref, int flags)
72+int av_buffersrc_add_ref(AVFilterContext *buffer_filter,
73+ AVFilterBufferRef *picref, int flags)
7474 {
7575 BufferSourceContext *c = buffer_filter->priv;
7676 AVFilterLink *outlink = buffer_filter->outputs[0];
@@ -88,6 +88,8 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 11 unmodified lines
8888 sizeof(buf))) < 0)
8989 return ret;
9090
91+ if (!(flags & AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)) {
92+ /* TODO reindent */
9193 if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {
9294 AVFilterContext *scale = buffer_filter->outputs[0]->dst;
9395 AVFilterLink *link;
@@ -132,7 +134,11 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 38 unmodified lines
132134 if ((ret = link->srcpad->config_props(link)) < 0)
133135 return ret;
134136 }
137+ }
135138
139+ if (flags & AV_BUFFERSRC_FLAG_NO_COPY) {
140+ buf = picref;
141+ } else {
136142 buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
137143 picref->video->w, picref->video->h);
138144 av_image_copy(buf->data, buf->linesize,
@@ -140,8 +146,11 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 1 unmodified line
140146 picref->format, picref->video->w, picref->video->h);
141147 avfilter_copy_buffer_ref_props(buf, picref);
142148
149+ }
150+
143151 if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0) {
144− avfilter_unref_buffer(buf);
152+ if (buf != picref)
153+ avfilter_unref_buffer(buf);
145154 return ret;
146155 }
147156 c->nb_failed_requests = 0;
@@ -149,29 +158,16 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 1 unmodified line
149158 return 0;
150159 }
151160
152−int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
161+int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
162+ AVFilterBufferRef *picref, int flags)
153163 {
154− BufferSourceContext *c = s->priv;
155− int ret;
156−
157− if (!buf) {
158− c->eof = 1;
159− return 0;
160− } else if (c->eof)
161− return AVERROR(EINVAL);
162−
163− if (!av_fifo_space(c->fifo) &&
164− (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
165− sizeof(buf))) < 0)
166− return ret;
167−
168−// CHECK_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format);
169−
170− if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0)
171− return ret;
172− c->nb_failed_requests = 0;
164+ return av_buffersrc_add_ref(buffer_filter, picref, 0);
165+}
173166
174− return 0;
167+int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
168+{
169+ return av_buffersrc_add_ref(s, buf, AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT |
170+ AV_BUFFERSRC_FLAG_NO_COPY);
175171 }
176172
177173 #if CONFIG_AVCODEC

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