[FFmpeg-devel] lavfi/avfilter.c: Correct guess_status_pts to account for differing link timebases.

Submitted by Sasi Inguva on Oct. 6, 2017, 2:49 a.m.

Details

Message ID 20171006024912.19062-1-isasi@google.com
State New
Headers show

Commit Message

Sasi Inguva Oct. 6, 2017, 2:49 a.m.
Signed-off-by: Sasi Inguva <isasi@google.com>
---
 libavfilter/avfilter.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Nicolas George Oct. 6, 2017, 8:01 a.m.
Le quartidi 14 vendémiaire, an CCXXVI, Sasi Inguva a écrit :
> Signed-off-by: Sasi Inguva <isasi@google.com>
> ---
>  libavfilter/avfilter.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)

You are right, this change is needed. Thanks for spotting it and the
patch.

> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 58917ed445..ec7dfc0bd3 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -427,19 +427,19 @@ int ff_request_frame(AVFilterLink *link)
>      return 0;
>  }
>  

> -static int64_t guess_status_pts(AVFilterContext *ctx, int status)
> +static int64_t guess_status_pts_from_src(AVFilterLink *link, int status)

I would prefer if you just added a "AVRational time_base" parameter.
With this version, the code has "link->" indirections all over the
place, that lowers the readability.

>  {
>      unsigned i;
>      int64_t r = INT64_MAX;
>  
> -    for (i = 0; i < ctx->nb_inputs; i++)
> -        if (ctx->inputs[i]->status_out == status)
> -            r = FFMIN(r, ctx->inputs[i]->current_pts);
> +    for (i = 0; i < link->src->nb_inputs; i++)
> +        if (link->src->inputs[i]->status_out == status)
> +          r = FFMIN(r, av_rescale_q(link->src->inputs[i]->current_pts, link->src->inputs[i]->time_base, link->time_base));
>      if (r < INT64_MAX)
>          return r;
> -    av_log(ctx, AV_LOG_WARNING, "EOF timestamp not reliable\n");
> -    for (i = 0; i < ctx->nb_inputs; i++)
> -        r = FFMIN(r, ctx->inputs[i]->status_in_pts);
> +    av_log(link->src, AV_LOG_WARNING, "EOF timestamp not reliable\n");
> +    for (i = 0; i < link->src->nb_inputs; i++)
> +      r = FFMIN(r, av_rescale_q(link->src->inputs[i]->status_in_pts, link->src->inputs[i]->time_base, link->time_base));
>      if (r < INT64_MAX)
>          return r;
>      return AV_NOPTS_VALUE;
> @@ -458,7 +458,7 @@ static int ff_request_frame_to_filter(AVFilterLink *link)
>          ret = ff_request_frame(link->src->inputs[0]);
>      if (ret < 0) {
>          if (ret != AVERROR(EAGAIN) && ret != link->status_in)
> -            ff_avfilter_link_set_in_status(link, ret, guess_status_pts(link->src, ret));
> +            ff_avfilter_link_set_in_status(link, ret, guess_status_pts_from_src(link, ret));
>          if (ret == AVERROR_EOF)
>              ret = 0;
>      }

Regards,
Thomas Mundt Oct. 6, 2017, 11:30 a.m.
2017-10-06 4:49 GMT+02:00 Sasi Inguva <isasi-at-google.com@ffmpeg.org>:

> Signed-off-by: Sasi Inguva <isasi@google.com>
> ---
>  libavfilter/avfilter.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 58917ed445..ec7dfc0bd3 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -427,19 +427,19 @@ int ff_request_frame(AVFilterLink *link)
>      return 0;
>  }
>
> -static int64_t guess_status_pts(AVFilterContext *ctx, int status)
> +static int64_t guess_status_pts_from_src(AVFilterLink *link, int status)
>  {
>      unsigned i;
>      int64_t r = INT64_MAX;
>
> -    for (i = 0; i < ctx->nb_inputs; i++)
> -        if (ctx->inputs[i]->status_out == status)
> -            r = FFMIN(r, ctx->inputs[i]->current_pts);
> +    for (i = 0; i < link->src->nb_inputs; i++)
> +        if (link->src->inputs[i]->status_out == status)
> +          r = FFMIN(r, av_rescale_q(link->src->inputs[i]->current_pts,
> link->src->inputs[i]->time_base, link->time_base));
>      if (r < INT64_MAX)
>          return r;
> -    av_log(ctx, AV_LOG_WARNING, "EOF timestamp not reliable\n");
> -    for (i = 0; i < ctx->nb_inputs; i++)
> -        r = FFMIN(r, ctx->inputs[i]->status_in_pts);
> +    av_log(link->src, AV_LOG_WARNING, "EOF timestamp not reliable\n");
> +    for (i = 0; i < link->src->nb_inputs; i++)
> +      r = FFMIN(r, av_rescale_q(link->src->inputs[i]->status_in_pts,
> link->src->inputs[i]->time_base, link->time_base));
>      if (r < INT64_MAX)
>          return r;
>      return AV_NOPTS_VALUE;
> @@ -458,7 +458,7 @@ static int ff_request_frame_to_filter(AVFilterLink
> *link)
>          ret = ff_request_frame(link->src->inputs[0]);
>      if (ret < 0) {
>          if (ret != AVERROR(EAGAIN) && ret != link->status_in)
> -            ff_avfilter_link_set_in_status(link, ret,
> guess_status_pts(link->src, ret));
> +            ff_avfilter_link_set_in_status(link, ret,
> guess_status_pts_from_src(link, ret));
>          if (ret == AVERROR_EOF)
>              ret = 0;
>      }
>

Thank you for this patch. Works fine for me.

Regards,
Thomas
Thomas Mundt Oct. 6, 2017, 4:34 p.m.
2017-10-06 10:01 GMT+02:00 Nicolas George <george@nsup.org>:

> Le quartidi 14 vendémiaire, an CCXXVI, Sasi Inguva a écrit :
> > Signed-off-by: Sasi Inguva <isasi@google.com>
> > ---
> >  libavfilter/avfilter.c | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
>
> You are right, this change is needed. Thanks for spotting it and the
> patch.
>
> >
> > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> > index 58917ed445..ec7dfc0bd3 100644
> > --- a/libavfilter/avfilter.c
> > +++ b/libavfilter/avfilter.c
> > @@ -427,19 +427,19 @@ int ff_request_frame(AVFilterLink *link)
> >      return 0;
> >  }
> >
>
> > -static int64_t guess_status_pts(AVFilterContext *ctx, int status)
> > +static int64_t guess_status_pts_from_src(AVFilterLink *link, int
> status)
>
> I would prefer if you just added a "AVRational time_base" parameter.
> With this version, the code has "link->" indirections all over the
> place, that lowers the readability.
>
> >  {
> >      unsigned i;
> >      int64_t r = INT64_MAX;
> >
> > -    for (i = 0; i < ctx->nb_inputs; i++)
> > -        if (ctx->inputs[i]->status_out == status)
> > -            r = FFMIN(r, ctx->inputs[i]->current_pts);
> > +    for (i = 0; i < link->src->nb_inputs; i++)
> > +        if (link->src->inputs[i]->status_out == status)
> > +          r = FFMIN(r, av_rescale_q(link->src->inputs[i]->current_pts,
> link->src->inputs[i]->time_base, link->time_base));
> >      if (r < INT64_MAX)
> >          return r;
> > -    av_log(ctx, AV_LOG_WARNING, "EOF timestamp not reliable\n");
> > -    for (i = 0; i < ctx->nb_inputs; i++)
> > -        r = FFMIN(r, ctx->inputs[i]->status_in_pts);
> > +    av_log(link->src, AV_LOG_WARNING, "EOF timestamp not reliable\n");
> > +    for (i = 0; i < link->src->nb_inputs; i++)
> > +      r = FFMIN(r, av_rescale_q(link->src->inputs[i]->status_in_pts,
> link->src->inputs[i]->time_base, link->time_base));
> >      if (r < INT64_MAX)
> >          return r;
> >      return AV_NOPTS_VALUE;
> > @@ -458,7 +458,7 @@ static int ff_request_frame_to_filter(AVFilterLink
> *link)
> >          ret = ff_request_frame(link->src->inputs[0]);
> >      if (ret < 0) {
> >          if (ret != AVERROR(EAGAIN) && ret != link->status_in)
> > -            ff_avfilter_link_set_in_status(link, ret,
> guess_status_pts(link->src, ret));
> > +            ff_avfilter_link_set_in_status(link, ret,
> guess_status_pts_from_src(link, ret));
> >          if (ret == AVERROR_EOF)
> >              ret = 0;
> >      }
>

It would be great if this fix will find its way into FFmpeg 3.4.

Thank you,
Thomas

Patch hide | download patch | download mbox

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 58917ed445..ec7dfc0bd3 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -427,19 +427,19 @@  int ff_request_frame(AVFilterLink *link)
     return 0;
 }
 
-static int64_t guess_status_pts(AVFilterContext *ctx, int status)
+static int64_t guess_status_pts_from_src(AVFilterLink *link, int status)
 {
     unsigned i;
     int64_t r = INT64_MAX;
 
-    for (i = 0; i < ctx->nb_inputs; i++)
-        if (ctx->inputs[i]->status_out == status)
-            r = FFMIN(r, ctx->inputs[i]->current_pts);
+    for (i = 0; i < link->src->nb_inputs; i++)
+        if (link->src->inputs[i]->status_out == status)
+          r = FFMIN(r, av_rescale_q(link->src->inputs[i]->current_pts, link->src->inputs[i]->time_base, link->time_base));
     if (r < INT64_MAX)
         return r;
-    av_log(ctx, AV_LOG_WARNING, "EOF timestamp not reliable\n");
-    for (i = 0; i < ctx->nb_inputs; i++)
-        r = FFMIN(r, ctx->inputs[i]->status_in_pts);
+    av_log(link->src, AV_LOG_WARNING, "EOF timestamp not reliable\n");
+    for (i = 0; i < link->src->nb_inputs; i++)
+      r = FFMIN(r, av_rescale_q(link->src->inputs[i]->status_in_pts, link->src->inputs[i]->time_base, link->time_base));
     if (r < INT64_MAX)
         return r;
     return AV_NOPTS_VALUE;
@@ -458,7 +458,7 @@  static int ff_request_frame_to_filter(AVFilterLink *link)
         ret = ff_request_frame(link->src->inputs[0]);
     if (ret < 0) {
         if (ret != AVERROR(EAGAIN) && ret != link->status_in)
-            ff_avfilter_link_set_in_status(link, ret, guess_status_pts(link->src, ret));
+            ff_avfilter_link_set_in_status(link, ret, guess_status_pts_from_src(link, ret));
         if (ret == AVERROR_EOF)
             ret = 0;
     }