diff mbox series

[FFmpeg-devel,2/2] lavfi/framesync: use av_gcd_q().

Message ID 20200416193855.275962-2-george@nsup.org
State Accepted
Headers show
Series [FFmpeg-devel,1/2] lavu: add av_gcd_q(). | expand

Checks

Context Check Description
andriy/default pending
andriy/make_warn warning New warnings during build
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Nicolas George April 16, 2020, 7:38 p.m. UTC
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/framesync.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

Comments

Andreas Rheinhardt April 16, 2020, 8:03 p.m. UTC | #1
Nicolas George:
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavfilter/framesync.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
> index bc95f7d904..26e5219d1b 100644
> --- a/libavfilter/framesync.c
> +++ b/libavfilter/framesync.c
> @@ -142,17 +142,8 @@ int ff_framesync_configure(FFFrameSync *fs)
>          for (i = 0; i < fs->nb_in; i++) {
>              if (fs->in[i].sync) {
>                  if (fs->time_base.num) {
> -                    gcd = av_gcd(fs->time_base.den, fs->in[i].time_base.den);
> -                    lcm = (fs->time_base.den / gcd) * fs->in[i].time_base.den;
> -                    if (lcm < AV_TIME_BASE / 2) {
> -                        fs->time_base.den = lcm;
> -                        fs->time_base.num = av_gcd(fs->time_base.num,
> -                                                   fs->in[i].time_base.num);
> -                    } else {
> -                        fs->time_base.num = 1;
> -                        fs->time_base.den = AV_TIME_BASE;
> -                        break;
> -                    }
> +                    fs->time_base = av_gcd_q(fs->time_base, fs->in[i].time_base,
> +                                             AV_TIME_BASE / 2, AV_TIME_BASE_Q);
>                  } else {
>                      fs->time_base = fs->in[i].time_base;
>                  }
> 
lcm is now unused, so should be removed with this commit.
(I'm not commenting on the actual merits of the patch.)

- Andreas

PS: Thanks to Andriy for adding the functionality to patchwork to check
whether a patch introduces new compiler warnings. This has been found
this way.
Nicolas George April 16, 2020, 8:30 p.m. UTC | #2
Andreas Rheinhardt (12020-04-16):
> lcm is now unused, so should be removed with this commit.
> (I'm not commenting on the actual merits of the patch.)

Indeed. I updated the patch, it now contains an extra hunk:

@@ -117,7 +117,6 @@ static void framesync_sync_level_update(FFFrameSync *fs)
 int ff_framesync_configure(FFFrameSync *fs)
 {
     unsigned i;
-    int64_t gcd, lcm;
 
     if (!fs->opt_repeatlast || fs->opt_eof_action == EOF_ACTION_PASS) {
         fs->opt_repeatlast = 0;

And I think I can dispense with re-sending it.

> PS: Thanks to Andriy for adding the functionality to patchwork to check
> whether a patch introduces new compiler warnings. This has been found
> this way.

It is useful indeed. But I should have spotted it. Thanks.

Regards,
diff mbox series

Patch

diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
index bc95f7d904..26e5219d1b 100644
--- a/libavfilter/framesync.c
+++ b/libavfilter/framesync.c
@@ -142,17 +142,8 @@  int ff_framesync_configure(FFFrameSync *fs)
         for (i = 0; i < fs->nb_in; i++) {
             if (fs->in[i].sync) {
                 if (fs->time_base.num) {
-                    gcd = av_gcd(fs->time_base.den, fs->in[i].time_base.den);
-                    lcm = (fs->time_base.den / gcd) * fs->in[i].time_base.den;
-                    if (lcm < AV_TIME_BASE / 2) {
-                        fs->time_base.den = lcm;
-                        fs->time_base.num = av_gcd(fs->time_base.num,
-                                                   fs->in[i].time_base.num);
-                    } else {
-                        fs->time_base.num = 1;
-                        fs->time_base.den = AV_TIME_BASE;
-                        break;
-                    }
+                    fs->time_base = av_gcd_q(fs->time_base, fs->in[i].time_base,
+                                             AV_TIME_BASE / 2, AV_TIME_BASE_Q);
                 } else {
                     fs->time_base = fs->in[i].time_base;
                 }