[FFmpeg-cvslog] sws: separate the calls to scaled vs unscaled conversion

Anton Khirnov git at videolan.org
Sat Jul 3 17:20:17 EEST 2021


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu May 20 13:37:06 2021 +0200| [fe490ec16531ac2d10a6bd8d3be560d31b00af67] | committer: Anton Khirnov

sws: separate the calls to scaled vs unscaled conversion

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fe490ec16531ac2d10a6bd8d3be560d31b00af67
---

 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);
 
     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 9304a5ef42..193bc383e1 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -878,11 +878,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 974e2d5179..aab7cdb2a2 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1847,7 +1847,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]));



More information about the ffmpeg-cvslog mailing list