diff mbox series

[FFmpeg-devel,12/24] sws: separate the calls to scaled vs unscaled conversion

Message ID 20210531075515.19544-12-anton@khirnov.net
State Accepted
Commit fe490ec16531ac2d10a6bd8d3be560d31b00af67
Headers show
Series [FFmpeg-devel,01/24] sws: remove unnecessary braces | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Anton Khirnov May 31, 2021, 7:55 a.m. UTC
Call the scaler function directly rather than through a function
pointer. Drop the now-unused return value from ff_getSwsFunc() and
rename the function to reflect its new role.

This will be useful in the following commits, where it will become
important that the amount of output is different for scaled vs unscaled
case.
---
 libswscale/swscale.c          | 10 ++++++----
 libswscale/swscale_internal.h |  6 +-----
 libswscale/utils.c            |  3 ++-
 tests/checkasm/sw_scale.c     |  4 ++--
 4 files changed, 11 insertions(+), 12 deletions(-)

Comments

Michael Niedermayer June 1, 2021, 12:41 p.m. UTC | #1
On Mon, May 31, 2021 at 09:55:03AM +0200, Anton Khirnov wrote:
> Call the scaler function directly rather than through a function
> pointer. Drop the now-unused return value from ff_getSwsFunc() and
> rename the function to reflect its new role.
> 
> This will be useful in the following commits, where it will become
> important that the amount of output is different for scaled vs unscaled
> case.
> ---
>  libswscale/swscale.c          | 10 ++++++----
>  libswscale/swscale_internal.h |  6 +-----
>  libswscale/utils.c            |  3 ++-
>  tests/checkasm/sw_scale.c     |  4 ++--
>  4 files changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/libswscale/swscale.c b/libswscale/swscale.c
> index 2db40a6807..4b577ef263 100644
> --- a/libswscale/swscale.c
> +++ b/libswscale/swscale.c
> @@ -579,7 +579,7 @@ static av_cold void sws_init_swscale(SwsContext *c)
>          c->needs_hcscale = 1;
>  }
>  
> -SwsFunc ff_getSwsFunc(SwsContext *c)
> +void ff_sws_init_scale(SwsContext *c)
>  {
>      sws_init_swscale(c);
>  
> @@ -591,8 +591,6 @@ SwsFunc ff_getSwsFunc(SwsContext *c)
>          ff_sws_init_swscale_aarch64(c);
>      if (ARCH_ARM)
>          ff_sws_init_swscale_arm(c);
> -
> -    return swscale;
>  }
>  
>  static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)

> @@ -988,7 +986,11 @@ int attribute_align_arg sws_scale(struct SwsContext *c,
>      /* reset slice direction at end of frame */
>      if (srcSliceY_internal + srcSliceH == c->srcH)
>          c->sliceDir = 0;
> -    ret = c->swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);
> +
> +    if (c->swscale)
> +        ret = c->swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);
> +    else
> +        ret = swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);

sws_scale(), c->swscale(), swscale() is confusing
also the line where it was always passed on to the same pointer becomes
conditional here that adds an additional step to confuse

maybe this can be done differently / clearer

thx

[...]
diff mbox series

Patch

diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 2db40a6807..4b577ef263 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -579,7 +579,7 @@  static av_cold void sws_init_swscale(SwsContext *c)
         c->needs_hcscale = 1;
 }
 
-SwsFunc ff_getSwsFunc(SwsContext *c)
+void ff_sws_init_scale(SwsContext *c)
 {
     sws_init_swscale(c);
 
@@ -591,8 +591,6 @@  SwsFunc ff_getSwsFunc(SwsContext *c)
         ff_sws_init_swscale_aarch64(c);
     if (ARCH_ARM)
         ff_sws_init_swscale_arm(c);
-
-    return swscale;
 }
 
 static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
@@ -988,7 +986,11 @@  int attribute_align_arg sws_scale(struct SwsContext *c,
     /* reset slice direction at end of frame */
     if (srcSliceY_internal + srcSliceH == c->srcH)
         c->sliceDir = 0;
-    ret = c->swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);
+
+    if (c->swscale)
+        ret = c->swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);
+    else
+        ret = swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2);
 
     if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
         int dstY = c->dstY ? c->dstY : srcSliceY + srcSliceH;
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index e8a434427b..02a45e7adb 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -872,11 +872,7 @@  void ff_get_unscaled_swscale_ppc(SwsContext *c);
 void ff_get_unscaled_swscale_arm(SwsContext *c);
 void ff_get_unscaled_swscale_aarch64(SwsContext *c);
 
-/**
- * Return function pointer to fastest main scaler path function depending
- * on architecture and available optimizations.
- */
-SwsFunc ff_getSwsFunc(SwsContext *c);
+void ff_sws_init_scale(SwsContext *c);
 
 void ff_sws_init_input_funcs(SwsContext *c);
 void ff_sws_init_output_funcs(SwsContext *c,
diff --git a/libswscale/utils.c b/libswscale/utils.c
index d45d7afcbf..42bef3753f 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1845,7 +1845,8 @@  av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
         }
     }
 
-    c->swscale = ff_getSwsFunc(c);
+    ff_sws_init_scale(c);
+
     return ff_init_filters(c);
 nomem:
     ret = AVERROR(ENOMEM);
diff --git a/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c
index 3ac0f9082f..40c5eb3aa8 100644
--- a/tests/checkasm/sw_scale.c
+++ b/tests/checkasm/sw_scale.c
@@ -93,7 +93,7 @@  static void check_yuv2yuvX(void)
     if (sws_init_context(ctx, NULL, NULL) < 0)
         fail();
 
-    ff_getSwsFunc(ctx);
+    ff_sws_init_scale(ctx);
     for(isi = 0; isi < INPUT_SIZES; ++isi){
         dstW = input_sizes[isi];
         for(osi = 0; osi < 64; osi += 16){
@@ -210,7 +210,7 @@  static void check_hscale(void)
 
                 filter[SRC_PIXELS * width + i] = rnd();
             }
-            ff_getSwsFunc(ctx);
+            ff_sws_init_scale(ctx);
 
             if (check_func(ctx->hcScale, "hscale_%d_to_%d_width%d", ctx->srcBpc, ctx->dstBpc + 1, width)) {
                 memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0]));