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
32 *32 *
33 * @param buf buffer containing frame data to be passed down the filtergraph.33 * @param buf buffer containing frame data to be passed down the filtergraph.
34 * This function will take ownership of buf, the user must not free it.34 * 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.
35 */36 */
36int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);37int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);
37 38
libavfilter/vsrc_buffer.c+19−1
@@ -35,6 +35,7 @@ typedef struct { · 34 unmodified lines
35 enum PixelFormat pix_fmt;35 enum PixelFormat pix_fmt;
36 AVRational time_base; ///< time_base to set in the output link36 AVRational time_base; ///< time_base to set in the output link
37 AVRational pixel_aspect;37 AVRational pixel_aspect;
38 int eof;
38} BufferSourceContext;39} BufferSourceContext;
39 40
40#define CHECK_PARAM_CHANGE(s, c, width, height, format)\41#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
50 AVFilterBufferRef *buf;51 AVFilterBufferRef *buf;
51 int ret;52 int ret;
52 53
54 if (!buf) {
55 c->eof = 1;
56 return 0;
57 } else if (c->eof)
58 return AVERROR(EINVAL);
59
53 if (!av_fifo_space(c->fifo) &&60 if (!av_fifo_space(c->fifo) &&
54 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +61 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
55 sizeof(buf))) < 0)62 sizeof(buf))) < 0)
@@ -79,6 +86,12 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 23 unmodified lines
79 BufferSourceContext *c = s->priv;86 BufferSourceContext *c = s->priv;
80 int ret;87 int ret;
81 88
89 if (!buf) {
90 c->eof = 1;
91 return 0;
92 } else if (c->eof)
93 return AVERROR(EINVAL);
94
82 if (!av_fifo_space(c->fifo) &&95 if (!av_fifo_space(c->fifo) &&
83 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +96 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
84 sizeof(buf))) < 0)97 sizeof(buf))) < 0)
@@ -160,6 +173,8 @@ static int request_frame(AVFilterLink *link) · 75 unmodified lines
160 AVFilterBufferRef *buf;173 AVFilterBufferRef *buf;
161 174
162 if (!av_fifo_size(c->fifo)) {175 if (!av_fifo_size(c->fifo)) {
176 if (c->eof)
177 return AVERROR_EOF;
163 av_log(link->src, AV_LOG_ERROR,178 av_log(link->src, AV_LOG_ERROR,
164 "request_frame() called with no available frame!\n");179 "request_frame() called with no available frame!\n");
165 return AVERROR(EINVAL);180 return AVERROR(EINVAL);
@@ -177,7 +192,10 @@ static int request_frame(AVFilterLink *link) · 11 unmodified lines
177static int poll_frame(AVFilterLink *link)192static int poll_frame(AVFilterLink *link)
178{193{
179 BufferSourceContext *c = link->src->priv;194 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*);
181}199}
182 200
183AVFilter avfilter_vsrc_buffer = {201AVFilter 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