[FFmpeg-cvslog] swscale/utils: Avoid calling ff_thread_once() unnecessarily

Andreas Rheinhardt git at videolan.org
Thu Nov 24 22:15:39 EET 2022


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sat Nov 19 05:44:44 2022 +0100| [baccc1c5417f990ebfc1b6780e2dab255a72ee3c] | committer: Andreas Rheinhardt

swscale/utils: Avoid calling ff_thread_once() unnecessarily

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libswscale/utils.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 053c6bb76b..fb788fc330 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1340,13 +1340,10 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
     int ret = 0;
     enum AVPixelFormat tmpFmt;
     static const float float_mult = 1.0f / 255.0f;
-    static AVOnce rgb2rgb_once = AV_ONCE_INIT;
 
     cpu_flags = av_get_cpu_flags();
     flags     = c->flags;
     emms_c();
-    if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0)
-        return AVERROR_UNKNOWN;
 
     unscaled = (srcW == dstW && srcH == dstH);
 
@@ -2043,6 +2040,7 @@ fail: // FIXME replace things by appropriate error codes
 av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
                              SwsFilter *dstFilter)
 {
+    static AVOnce rgb2rgb_once = AV_ONCE_INIT;
     int ret;
 
     c->frame_src = av_frame_alloc();
@@ -2050,6 +2048,9 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
     if (!c->frame_src || !c->frame_dst)
         return AVERROR(ENOMEM);
 
+    if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0)
+        return AVERROR_UNKNOWN;
+
     if (c->nb_threads != 1) {
         ret = context_init_threaded(c, srcFilter, dstFilter);
         if (ret < 0 || c->nb_threads > 1)



More information about the ffmpeg-cvslog mailing list