diff mbox

[FFmpeg-devel,3/4] lavfi/buffersrc: add av_buffersrc_close().

Message ID 20170406084451.27892-3-george@nsup.org
State Superseded
Headers show

Commit Message

Nicolas George April 6, 2017, 8:44 a.m. UTC
TODO APIChanges and minor bump.

Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/buffersrc.c | 22 ++++++++++++----------
 libavfilter/buffersrc.h |  8 ++++++++
 2 files changed, 20 insertions(+), 10 deletions(-)

Comments

wm4 April 6, 2017, 9:03 a.m. UTC | #1
On Thu,  6 Apr 2017 10:44:50 +0200
Nicolas George <george@nsup.org> wrote:

> TODO APIChanges and minor bump.
> 
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavfilter/buffersrc.c | 22 ++++++++++++----------
>  libavfilter/buffersrc.h |  8 ++++++++
>  2 files changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
> index 3f80d5f413..250b06dfbc 100644
> --- a/libavfilter/buffersrc.c
> +++ b/libavfilter/buffersrc.c
> @@ -196,16 +196,9 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
>  
>      s->nb_failed_requests = 0;
>  
> -    if (!frame) {
> -        s->eof = 1;
> -        ff_avfilter_link_set_in_status(ctx->outputs[0], AVERROR_EOF, AV_NOPTS_VALUE);
> -        if ((flags & AV_BUFFERSRC_FLAG_PUSH)) {
> -            ret = push_frame(ctx->graph);
> -            if (ret < 0)
> -                return ret;
> -        }
> -        return 0;
> -    } else if (s->eof)
> +    if (!frame)
> +        return av_buffersrc_close(ctx, AV_NOPTS_VALUE, flags);
> +    if (s->eof)
>          return AVERROR(EINVAL);
>  
>      refcounted = !!frame->buf[0];
> @@ -267,6 +260,15 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
>      return 0;
>  }
>  
> +int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags)
> +{
> +    BufferSourceContext *s = ctx->priv;
> +
> +    s->eof = 1;
> +    ff_avfilter_link_set_in_status(ctx->outputs[0], AVERROR_EOF, pts);
> +    return (flags & AV_BUFFERSRC_FLAG_PUSH) ? push_frame(ctx->graph) : 0;
> +}
> +
>  static av_cold int init_video(AVFilterContext *ctx)
>  {
>      BufferSourceContext *c = ctx->priv;
> diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
> index e42c78196b..0652113f2b 100644
> --- a/libavfilter/buffersrc.h
> +++ b/libavfilter/buffersrc.h
> @@ -193,6 +193,14 @@ av_warn_unused_result
>  int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src,
>                                   AVFrame *frame, int flags);
>  
> +/**
> + * Close the buffer source after EOF.
> + *
> + * This is similar to passing NULL to av_buffersrc_add_frame_flags()
> + * except it takes the timestamp of the EOF, i.e. the timestamp of the end
> + * of the last frame.
> + */
> +int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags);
>  
>  /**
>   * @}

Not sure why this special function, instead of adding a frame duration
field to AVFrame. (Which would not necessarily be the often unreliable
or broken pkt_duration.)
diff mbox

Patch

diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index 3f80d5f413..250b06dfbc 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -196,16 +196,9 @@  static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
 
     s->nb_failed_requests = 0;
 
-    if (!frame) {
-        s->eof = 1;
-        ff_avfilter_link_set_in_status(ctx->outputs[0], AVERROR_EOF, AV_NOPTS_VALUE);
-        if ((flags & AV_BUFFERSRC_FLAG_PUSH)) {
-            ret = push_frame(ctx->graph);
-            if (ret < 0)
-                return ret;
-        }
-        return 0;
-    } else if (s->eof)
+    if (!frame)
+        return av_buffersrc_close(ctx, AV_NOPTS_VALUE, flags);
+    if (s->eof)
         return AVERROR(EINVAL);
 
     refcounted = !!frame->buf[0];
@@ -267,6 +260,15 @@  static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
     return 0;
 }
 
+int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags)
+{
+    BufferSourceContext *s = ctx->priv;
+
+    s->eof = 1;
+    ff_avfilter_link_set_in_status(ctx->outputs[0], AVERROR_EOF, pts);
+    return (flags & AV_BUFFERSRC_FLAG_PUSH) ? push_frame(ctx->graph) : 0;
+}
+
 static av_cold int init_video(AVFilterContext *ctx)
 {
     BufferSourceContext *c = ctx->priv;
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index e42c78196b..0652113f2b 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -193,6 +193,14 @@  av_warn_unused_result
 int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src,
                                  AVFrame *frame, int flags);
 
+/**
+ * Close the buffer source after EOF.
+ *
+ * This is similar to passing NULL to av_buffersrc_add_frame_flags()
+ * except it takes the timestamp of the EOF, i.e. the timestamp of the end
+ * of the last frame.
+ */
+int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags);
 
 /**
  * @}