History

vsrc_buffer: allow using a NULL buffer to signal EOF.

Anton Khirnov committed 14 years ago

Commit 7ae7c411 parent 9206ac82 files · +20 −1Browse files

Unified · Split

2 files
  1. libavfilter/buffersrc.h +1 −0
  2. libavfilter/vsrc_buffer.c +19 −1
libavfilter/buffersrc.h+1−0
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 *
3333 * @param buf buffer containing frame data to be passed down the filtergraph.
3434 * This function will take ownership of buf, the user must not free it.
35+ * A NULL buf signals EOF -- i.e. no more frames will be sent to this filter.
3536 */
3637 int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);
3738
libavfilter/vsrc_buffer.c+19−1
@@ -35,6 +35,7 @@ typedef struct { · 34 unmodified lines
3535 enum PixelFormat pix_fmt;
3636 AVRational time_base; ///< time_base to set in the output link
3737 AVRational pixel_aspect;
38+ int eof;
3839 } BufferSourceContext;
3940
4041 #define CHECK_PARAM_CHANGE(s, c, width, height, format)\
@@ -50,6 +51,12 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, · 9 unmodified lines
5051 AVFilterBufferRef *buf;
5152 int ret;
5253
54+ if (!buf) {
55+ c->eof = 1;
56+ return 0;
57+ } else if (c->eof)
58+ return AVERROR(EINVAL);
59+
5360 if (!av_fifo_space(c->fifo) &&
5461 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
5562 sizeof(buf))) < 0)
@@ -79,6 +86,12 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 23 unmodified lines
7986 BufferSourceContext *c = s->priv;
8087 int ret;
8188
89+ if (!buf) {
90+ c->eof = 1;
91+ return 0;
92+ } else if (c->eof)
93+ return AVERROR(EINVAL);
94+
8295 if (!av_fifo_space(c->fifo) &&
8396 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
8497 sizeof(buf))) < 0)
@@ -160,6 +173,8 @@ static int request_frame(AVFilterLink *link) · 75 unmodified lines
160173 AVFilterBufferRef *buf;
161174
162175 if (!av_fifo_size(c->fifo)) {
176+ if (c->eof)
177+ return AVERROR_EOF;
163178 av_log(link->src, AV_LOG_ERROR,
164179 "request_frame() called with no available frame!\n");
165180 return AVERROR(EINVAL);
@@ -177,7 +192,10 @@ static int request_frame(AVFilterLink *link) · 11 unmodified lines
177192 static int poll_frame(AVFilterLink *link)
178193 {
179194 BufferSourceContext *c = link->src->priv;
180− return !!av_fifo_size(c->fifo);
195+ int size = av_fifo_size(c->fifo);
196+ if (!size && c->eof)
197+ return AVERROR_EOF;
198+ return size/sizeof(AVFilterBufferRef*);
181199 }
182200
183201 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