aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-04-01 18:53:58 +0200
committerAnton Khirnov <anton@khirnov.net>2012-04-14 09:25:46 +0200
commit7ae7c41413beb601714a06b4fd18cdb4610b2eda (patch)
treed8dc3a38bef9a6503bd99f57d603fd25b009c37b /libavfilter
parent9206ac80a5c3256738b887cf3cfe39f385ebc672 (diff)
downloadffmpeg-7ae7c41413beb601714a06b4fd18cdb4610b2eda.tar.gz
vsrc_buffer: allow using a NULL buffer to signal EOF.
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/buffersrc.h1
-rw-r--r--libavfilter/vsrc_buffer.c20
2 files changed, 20 insertions, 1 deletions
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index bd82c065e4..918a54faee 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -32,6 +32,7 @@
*
* @param buf buffer containing frame data to be passed down the filtergraph.
* This function will take ownership of buf, the user must not free it.
+ * A NULL buf signals EOF -- i.e. no more frames will be sent to this filter.
*/
int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);
diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index dfe5bf5602..46a18df713 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -35,6 +35,7 @@ typedef struct {
enum PixelFormat pix_fmt;
AVRational time_base; ///< time_base to set in the output link
AVRational pixel_aspect;
+ int eof;
} BufferSourceContext;
#define CHECK_PARAM_CHANGE(s, c, width, height, format)\
@@ -50,6 +51,12 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
AVFilterBufferRef *buf;
int ret;
+ if (!buf) {
+ c->eof = 1;
+ return 0;
+ } else if (c->eof)
+ return AVERROR(EINVAL);
+
if (!av_fifo_space(c->fifo) &&
(ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
sizeof(buf))) < 0)
@@ -79,6 +86,12 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
BufferSourceContext *c = s->priv;
int ret;
+ if (!buf) {
+ c->eof = 1;
+ return 0;
+ } else if (c->eof)
+ return AVERROR(EINVAL);
+
if (!av_fifo_space(c->fifo) &&
(ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
sizeof(buf))) < 0)
@@ -160,6 +173,8 @@ static int request_frame(AVFilterLink *link)
AVFilterBufferRef *buf;
if (!av_fifo_size(c->fifo)) {
+ if (c->eof)
+ return AVERROR_EOF;
av_log(link->src, AV_LOG_ERROR,
"request_frame() called with no available frame!\n");
return AVERROR(EINVAL);
@@ -177,7 +192,10 @@ static int request_frame(AVFilterLink *link)
static int poll_frame(AVFilterLink *link)
{
BufferSourceContext *c = link->src->priv;
- return !!av_fifo_size(c->fifo);
+ int size = av_fifo_size(c->fifo);
+ if (!size && c->eof)
+ return AVERROR_EOF;
+ return size/sizeof(AVFilterBufferRef*);
}
AVFilter avfilter_vsrc_buffer = {