Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out
@ 2022-11-21  0:24 Andreas Rheinhardt
  2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 2/6] swscale/utils: Don't allocate AVFrames for slice contexts Andreas Rheinhardt
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-11-21  0:24 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Initializing slice threads currently uses the function
(sws_init_context()) that is also used for initializing
user-facing contexts with the only difference being that
nb_threads is set to one before initializing the slice contexts.

Yet sws_init_context() also initializes lots of stuff
that is not slice-dependent, i.e. (src|dst)Range. This
currently only works because the code sets these fields
to the same values for all slice contexts. This is not
nice; even worse, it entails that log messages are printed
once per slice context (and therefore fill the screen).

This commit lays the groundwork to fix this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libswscale/utils.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 85640a143f..c6fa07f752 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1268,6 +1268,9 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
     }
 }
 
+static int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
+                                   SwsFilter *dstFilter);
+
 static int context_init_threaded(SwsContext *c,
                                  SwsFilter *src_filter, SwsFilter *dst_filter)
 {
@@ -1301,7 +1304,7 @@ static int context_init_threaded(SwsContext *c,
 
         c->slice_ctx[i]->nb_threads = 1;
 
-        ret = sws_init_context(c->slice_ctx[i], src_filter, dst_filter);
+        ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter);
         if (ret < 0)
             return ret;
 
@@ -1322,8 +1325,8 @@ static int context_init_threaded(SwsContext *c,
     return 0;
 }
 
-av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
-                             SwsFilter *dstFilter)
+static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
+                                           SwsFilter *dstFilter)
 {
     int i;
     int usesVFilter, usesHFilter;
@@ -1344,13 +1347,6 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
     static const float float_mult = 1.0f / 255.0f;
     static AVOnce rgb2rgb_once = AV_ONCE_INIT;
 
-    if (c->nb_threads != 1) {
-        ret = context_init_threaded(c, srcFilter, dstFilter);
-        if (ret < 0 || c->nb_threads > 1)
-            return ret;
-        // threading disabled in this build, init as single-threaded
-    }
-
     cpu_flags = av_get_cpu_flags();
     flags     = c->flags;
     emms_c();
@@ -2054,6 +2050,21 @@ fail: // FIXME replace things by appropriate error codes
     return ret;
 }
 
+av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
+                             SwsFilter *dstFilter)
+{
+    int ret;
+
+    if (c->nb_threads != 1) {
+        ret = context_init_threaded(c, srcFilter, dstFilter);
+        if (ret < 0 || c->nb_threads > 1)
+            return ret;
+        // threading disabled in this build, init as single-threaded
+    }
+
+    return sws_init_single_context(c, srcFilter, dstFilter);
+}
+
 SwsContext *sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
                                int dstW, int dstH, enum AVPixelFormat dstFormat,
                                int flags, const double *param)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 2/6] swscale/utils: Don't allocate AVFrames for slice contexts
  2022-11-21  0:24 [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
@ 2022-11-21  0:26 ` Andreas Rheinhardt
  2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 3/6] swscale/utils: Avoid calling ff_thread_once() unnecessarily Andreas Rheinhardt
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-11-21  0:26 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Only the parent context's AVFrames are ever used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libswscale/utils.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index c6fa07f752..053c6bb76b 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1317,11 +1317,6 @@ static int context_init_threaded(SwsContext *c,
         }
     }
 
-    c->frame_src = av_frame_alloc();
-    c->frame_dst = av_frame_alloc();
-    if (!c->frame_src || !c->frame_dst)
-        return AVERROR(ENOMEM);
-
     return 0;
 }
 
@@ -1581,11 +1576,6 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
     if (!FF_ALLOCZ_TYPED_ARRAY(c->formatConvBuffer, FFALIGN(srcW * 2 + 78, 16) * 2))
         goto nomem;
 
-    c->frame_src = av_frame_alloc();
-    c->frame_dst = av_frame_alloc();
-    if (!c->frame_src || !c->frame_dst)
-        goto nomem;
-
     c->srcBpc = desc_src->comp[0].depth;
     if (c->srcBpc < 8)
         c->srcBpc = 8;
@@ -2055,6 +2045,11 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
 {
     int ret;
 
+    c->frame_src = av_frame_alloc();
+    c->frame_dst = av_frame_alloc();
+    if (!c->frame_src || !c->frame_dst)
+        return AVERROR(ENOMEM);
+
     if (c->nb_threads != 1) {
         ret = context_init_threaded(c, srcFilter, dstFilter);
         if (ret < 0 || c->nb_threads > 1)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 3/6] swscale/utils: Avoid calling ff_thread_once() unnecessarily
  2022-11-21  0:24 [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
  2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 2/6] swscale/utils: Don't allocate AVFrames for slice contexts Andreas Rheinhardt
@ 2022-11-21  0:26 ` Andreas Rheinhardt
  2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 4/6] swscale/utils: Move functions to avoid forward declarations Andreas Rheinhardt
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-11-21  0:26 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 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)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 4/6] swscale/utils: Move functions to avoid forward declarations
  2022-11-21  0:24 [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
  2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 2/6] swscale/utils: Don't allocate AVFrames for slice contexts Andreas Rheinhardt
  2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 3/6] swscale/utils: Avoid calling ff_thread_once() unnecessarily Andreas Rheinhardt
@ 2022-11-21  0:26 ` Andreas Rheinhardt
  2022-11-21  0:27 ` [FFmpeg-devel] [PATCH 5/6] swscale/utils: Derive range from YUVJ-pix-fmt only once Andreas Rheinhardt
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-11-21  0:26 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libswscale/utils.c | 407 ++++++++++++++++++++++-----------------------
 1 file changed, 200 insertions(+), 207 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index fb788fc330..cdd89e4b58 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -59,13 +59,6 @@
 #include "swscale.h"
 #include "swscale_internal.h"
 
-static SwsVector *sws_getIdentityVec(void);
-static void sws_addVec(SwsVector *a, SwsVector *b);
-static void sws_shiftVec(SwsVector *a, int shift);
-static void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level);
-
-static void handle_formats(SwsContext *c);
-
 typedef struct FormatEntry {
     uint8_t is_supported_in         :1;
     uint8_t is_supported_out        :1;
@@ -926,6 +919,74 @@ static void fill_xyztables(struct SwsContext *c)
     }
 }
 
+static int handle_jpeg(enum AVPixelFormat *format)
+{
+    switch (*format) {
+    case AV_PIX_FMT_YUVJ420P:
+        *format = AV_PIX_FMT_YUV420P;
+        return 1;
+    case AV_PIX_FMT_YUVJ411P:
+        *format = AV_PIX_FMT_YUV411P;
+        return 1;
+    case AV_PIX_FMT_YUVJ422P:
+        *format = AV_PIX_FMT_YUV422P;
+        return 1;
+    case AV_PIX_FMT_YUVJ444P:
+        *format = AV_PIX_FMT_YUV444P;
+        return 1;
+    case AV_PIX_FMT_YUVJ440P:
+        *format = AV_PIX_FMT_YUV440P;
+        return 1;
+    case AV_PIX_FMT_GRAY8:
+    case AV_PIX_FMT_YA8:
+    case AV_PIX_FMT_GRAY9LE:
+    case AV_PIX_FMT_GRAY9BE:
+    case AV_PIX_FMT_GRAY10LE:
+    case AV_PIX_FMT_GRAY10BE:
+    case AV_PIX_FMT_GRAY12LE:
+    case AV_PIX_FMT_GRAY12BE:
+    case AV_PIX_FMT_GRAY14LE:
+    case AV_PIX_FMT_GRAY14BE:
+    case AV_PIX_FMT_GRAY16LE:
+    case AV_PIX_FMT_GRAY16BE:
+    case AV_PIX_FMT_YA16BE:
+    case AV_PIX_FMT_YA16LE:
+        return 1;
+    default:
+        return 0;
+    }
+}
+
+static int handle_0alpha(enum AVPixelFormat *format)
+{
+    switch (*format) {
+    case AV_PIX_FMT_0BGR    : *format = AV_PIX_FMT_ABGR   ; return 1;
+    case AV_PIX_FMT_BGR0    : *format = AV_PIX_FMT_BGRA   ; return 4;
+    case AV_PIX_FMT_0RGB    : *format = AV_PIX_FMT_ARGB   ; return 1;
+    case AV_PIX_FMT_RGB0    : *format = AV_PIX_FMT_RGBA   ; return 4;
+    default:                                          return 0;
+    }
+}
+
+static int handle_xyz(enum AVPixelFormat *format)
+{
+    switch (*format) {
+    case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1;
+    case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1;
+    default:                                                return 0;
+    }
+}
+
+static void handle_formats(SwsContext *c)
+{
+    c->src0Alpha |= handle_0alpha(&c->srcFormat);
+    c->dst0Alpha |= handle_0alpha(&c->dstFormat);
+    c->srcXYZ    |= handle_xyz(&c->srcFormat);
+    c->dstXYZ    |= handle_xyz(&c->dstFormat);
+    if (c->srcXYZ || c->dstXYZ)
+        fill_xyztables(c);
+}
+
 static int range_override_needed(enum AVPixelFormat format)
 {
     return !isYUV(format) && !isGray(format);
@@ -1112,74 +1173,6 @@ int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
     return 0;
 }
 
-static int handle_jpeg(enum AVPixelFormat *format)
-{
-    switch (*format) {
-    case AV_PIX_FMT_YUVJ420P:
-        *format = AV_PIX_FMT_YUV420P;
-        return 1;
-    case AV_PIX_FMT_YUVJ411P:
-        *format = AV_PIX_FMT_YUV411P;
-        return 1;
-    case AV_PIX_FMT_YUVJ422P:
-        *format = AV_PIX_FMT_YUV422P;
-        return 1;
-    case AV_PIX_FMT_YUVJ444P:
-        *format = AV_PIX_FMT_YUV444P;
-        return 1;
-    case AV_PIX_FMT_YUVJ440P:
-        *format = AV_PIX_FMT_YUV440P;
-        return 1;
-    case AV_PIX_FMT_GRAY8:
-    case AV_PIX_FMT_YA8:
-    case AV_PIX_FMT_GRAY9LE:
-    case AV_PIX_FMT_GRAY9BE:
-    case AV_PIX_FMT_GRAY10LE:
-    case AV_PIX_FMT_GRAY10BE:
-    case AV_PIX_FMT_GRAY12LE:
-    case AV_PIX_FMT_GRAY12BE:
-    case AV_PIX_FMT_GRAY14LE:
-    case AV_PIX_FMT_GRAY14BE:
-    case AV_PIX_FMT_GRAY16LE:
-    case AV_PIX_FMT_GRAY16BE:
-    case AV_PIX_FMT_YA16BE:
-    case AV_PIX_FMT_YA16LE:
-        return 1;
-    default:
-        return 0;
-    }
-}
-
-static int handle_0alpha(enum AVPixelFormat *format)
-{
-    switch (*format) {
-    case AV_PIX_FMT_0BGR    : *format = AV_PIX_FMT_ABGR   ; return 1;
-    case AV_PIX_FMT_BGR0    : *format = AV_PIX_FMT_BGRA   ; return 4;
-    case AV_PIX_FMT_0RGB    : *format = AV_PIX_FMT_ARGB   ; return 1;
-    case AV_PIX_FMT_RGB0    : *format = AV_PIX_FMT_RGBA   ; return 4;
-    default:                                          return 0;
-    }
-}
-
-static int handle_xyz(enum AVPixelFormat *format)
-{
-    switch (*format) {
-    case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1;
-    case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1;
-    default:                                                return 0;
-    }
-}
-
-static void handle_formats(SwsContext *c)
-{
-    c->src0Alpha |= handle_0alpha(&c->srcFormat);
-    c->dst0Alpha |= handle_0alpha(&c->dstFormat);
-    c->srcXYZ    |= handle_xyz(&c->srcFormat);
-    c->dstXYZ    |= handle_xyz(&c->dstFormat);
-    if (c->srcXYZ || c->dstXYZ)
-        fill_xyztables(c);
-}
-
 SwsContext *sws_alloc_context(void)
 {
     SwsContext *c = av_mallocz(sizeof(SwsContext));
@@ -1271,55 +1264,6 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
 static int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
                                    SwsFilter *dstFilter);
 
-static int context_init_threaded(SwsContext *c,
-                                 SwsFilter *src_filter, SwsFilter *dst_filter)
-{
-    int ret;
-
-    ret = avpriv_slicethread_create(&c->slicethread, (void*)c,
-                                    ff_sws_slice_worker, NULL, c->nb_threads);
-    if (ret == AVERROR(ENOSYS)) {
-        c->nb_threads = 1;
-        return 0;
-    } else if (ret < 0)
-        return ret;
-
-    c->nb_threads = ret;
-
-    c->slice_ctx = av_calloc(c->nb_threads, sizeof(*c->slice_ctx));
-    c->slice_err = av_calloc(c->nb_threads, sizeof(*c->slice_err));
-    if (!c->slice_ctx || !c->slice_err)
-        return AVERROR(ENOMEM);
-
-    for (int i = 0; i < c->nb_threads; i++) {
-        c->slice_ctx[i] = sws_alloc_context();
-        if (!c->slice_ctx[i])
-            return AVERROR(ENOMEM);
-
-        c->slice_ctx[i]->parent = c;
-
-        ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c);
-        if (ret < 0)
-            return ret;
-
-        c->slice_ctx[i]->nb_threads = 1;
-
-        ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter);
-        if (ret < 0)
-            return ret;
-
-        c->nb_slice_ctx++;
-
-        if (c->slice_ctx[i]->dither == SWS_DITHER_ED) {
-            av_log(c, AV_LOG_VERBOSE,
-                   "Error-diffusion dither is in use, scaling will be single-threaded.");
-            break;
-        }
-    }
-
-    return 0;
-}
-
 static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
                                            SwsFilter *dstFilter)
 {
@@ -2037,6 +1981,55 @@ fail: // FIXME replace things by appropriate error codes
     return ret;
 }
 
+static int context_init_threaded(SwsContext *c,
+                                 SwsFilter *src_filter, SwsFilter *dst_filter)
+{
+    int ret;
+
+    ret = avpriv_slicethread_create(&c->slicethread, (void*)c,
+                                    ff_sws_slice_worker, NULL, c->nb_threads);
+    if (ret == AVERROR(ENOSYS)) {
+        c->nb_threads = 1;
+        return 0;
+    } else if (ret < 0)
+        return ret;
+
+    c->nb_threads = ret;
+
+    c->slice_ctx = av_calloc(c->nb_threads, sizeof(*c->slice_ctx));
+    c->slice_err = av_calloc(c->nb_threads, sizeof(*c->slice_err));
+    if (!c->slice_ctx || !c->slice_err)
+        return AVERROR(ENOMEM);
+
+    for (int i = 0; i < c->nb_threads; i++) {
+        c->slice_ctx[i] = sws_alloc_context();
+        if (!c->slice_ctx[i])
+            return AVERROR(ENOMEM);
+
+        c->slice_ctx[i]->parent = c;
+
+        ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c);
+        if (ret < 0)
+            return ret;
+
+        c->slice_ctx[i]->nb_threads = 1;
+
+        ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter);
+        if (ret < 0)
+            return ret;
+
+        c->nb_slice_ctx++;
+
+        if (c->slice_ctx[i]->dither == SWS_DITHER_ED) {
+            av_log(c, AV_LOG_VERBOSE,
+                   "Error-diffusion dither is in use, scaling will be single-threaded.");
+            break;
+        }
+    }
+
+    return 0;
+}
+
 av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
                              SwsFilter *dstFilter)
 {
@@ -2123,89 +2116,6 @@ static void makenan_vec(SwsVector *a)
         a->coeff[i] = NAN;
 }
 
-SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
-                                float lumaSharpen, float chromaSharpen,
-                                float chromaHShift, float chromaVShift,
-                                int verbose)
-{
-    SwsFilter *filter = av_malloc(sizeof(SwsFilter));
-    if (!filter)
-        return NULL;
-
-    if (lumaGBlur != 0.0) {
-        filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
-        filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
-    } else {
-        filter->lumH = sws_getIdentityVec();
-        filter->lumV = sws_getIdentityVec();
-    }
-
-    if (chromaGBlur != 0.0) {
-        filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
-        filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
-    } else {
-        filter->chrH = sws_getIdentityVec();
-        filter->chrV = sws_getIdentityVec();
-    }
-
-    if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV)
-        goto fail;
-
-    if (chromaSharpen != 0.0) {
-        SwsVector *id = sws_getIdentityVec();
-        if (!id)
-            goto fail;
-        sws_scaleVec(filter->chrH, -chromaSharpen);
-        sws_scaleVec(filter->chrV, -chromaSharpen);
-        sws_addVec(filter->chrH, id);
-        sws_addVec(filter->chrV, id);
-        sws_freeVec(id);
-    }
-
-    if (lumaSharpen != 0.0) {
-        SwsVector *id = sws_getIdentityVec();
-        if (!id)
-            goto fail;
-        sws_scaleVec(filter->lumH, -lumaSharpen);
-        sws_scaleVec(filter->lumV, -lumaSharpen);
-        sws_addVec(filter->lumH, id);
-        sws_addVec(filter->lumV, id);
-        sws_freeVec(id);
-    }
-
-    if (chromaHShift != 0.0)
-        sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5));
-
-    if (chromaVShift != 0.0)
-        sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5));
-
-    sws_normalizeVec(filter->chrH, 1.0);
-    sws_normalizeVec(filter->chrV, 1.0);
-    sws_normalizeVec(filter->lumH, 1.0);
-    sws_normalizeVec(filter->lumV, 1.0);
-
-    if (isnan_vec(filter->chrH) ||
-        isnan_vec(filter->chrV) ||
-        isnan_vec(filter->lumH) ||
-        isnan_vec(filter->lumV))
-        goto fail;
-
-    if (verbose)
-        sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
-    if (verbose)
-        sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
-
-    return filter;
-
-fail:
-    sws_freeVec(filter->lumH);
-    sws_freeVec(filter->lumV);
-    sws_freeVec(filter->chrH);
-    sws_freeVec(filter->chrV);
-    av_freep(&filter);
-    return NULL;
-}
-
 SwsVector *sws_allocVec(int length)
 {
     SwsVector *vec;
@@ -2417,6 +2327,89 @@ void sws_freeFilter(SwsFilter *filter)
     av_free(filter);
 }
 
+SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
+                                float lumaSharpen, float chromaSharpen,
+                                float chromaHShift, float chromaVShift,
+                                int verbose)
+{
+    SwsFilter *filter = av_malloc(sizeof(SwsFilter));
+    if (!filter)
+        return NULL;
+
+    if (lumaGBlur != 0.0) {
+        filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
+        filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
+    } else {
+        filter->lumH = sws_getIdentityVec();
+        filter->lumV = sws_getIdentityVec();
+    }
+
+    if (chromaGBlur != 0.0) {
+        filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
+        filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
+    } else {
+        filter->chrH = sws_getIdentityVec();
+        filter->chrV = sws_getIdentityVec();
+    }
+
+    if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV)
+        goto fail;
+
+    if (chromaSharpen != 0.0) {
+        SwsVector *id = sws_getIdentityVec();
+        if (!id)
+            goto fail;
+        sws_scaleVec(filter->chrH, -chromaSharpen);
+        sws_scaleVec(filter->chrV, -chromaSharpen);
+        sws_addVec(filter->chrH, id);
+        sws_addVec(filter->chrV, id);
+        sws_freeVec(id);
+    }
+
+    if (lumaSharpen != 0.0) {
+        SwsVector *id = sws_getIdentityVec();
+        if (!id)
+            goto fail;
+        sws_scaleVec(filter->lumH, -lumaSharpen);
+        sws_scaleVec(filter->lumV, -lumaSharpen);
+        sws_addVec(filter->lumH, id);
+        sws_addVec(filter->lumV, id);
+        sws_freeVec(id);
+    }
+
+    if (chromaHShift != 0.0)
+        sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5));
+
+    if (chromaVShift != 0.0)
+        sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5));
+
+    sws_normalizeVec(filter->chrH, 1.0);
+    sws_normalizeVec(filter->chrV, 1.0);
+    sws_normalizeVec(filter->lumH, 1.0);
+    sws_normalizeVec(filter->lumV, 1.0);
+
+    if (isnan_vec(filter->chrH) ||
+        isnan_vec(filter->chrV) ||
+        isnan_vec(filter->lumH) ||
+        isnan_vec(filter->lumV))
+        goto fail;
+
+    if (verbose)
+        sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
+    if (verbose)
+        sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
+
+    return filter;
+
+fail:
+    sws_freeVec(filter->lumH);
+    sws_freeVec(filter->lumV);
+    sws_freeVec(filter->chrH);
+    sws_freeVec(filter->chrV);
+    av_freep(&filter);
+    return NULL;
+}
+
 void sws_freeContext(SwsContext *c)
 {
     int i;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 5/6] swscale/utils: Derive range from YUVJ-pix-fmt only once
  2022-11-21  0:24 [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
                   ` (2 preceding siblings ...)
  2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 4/6] swscale/utils: Move functions to avoid forward declarations Andreas Rheinhardt
@ 2022-11-21  0:27 ` Andreas Rheinhardt
  2022-11-21  0:27 ` [FFmpeg-devel] [PATCH 6/6] swscale/utils: Fix indentation Andreas Rheinhardt
  2022-11-23 21:43 ` [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-11-21  0:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Currently, it is done once per slice-thread, leading to
one warning per slice-thread in case a YUVJ pixel format
has been originally used.

This also fixes the anomaly that said parameter are only
updated for the user-facing context (whose values are retrievable
via av_opt_get()) if slice-threading is not in use.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libswscale/utils.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index cdd89e4b58..5a728afd89 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1277,8 +1277,7 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
     int dstH              = c->dstH;
     int dst_stride        = FFALIGN(dstW * sizeof(int16_t) + 66, 16);
     int flags, cpu_flags;
-    enum AVPixelFormat srcFormat = c->srcFormat;
-    enum AVPixelFormat dstFormat = c->dstFormat;
+    enum AVPixelFormat srcFormat, dstFormat;
     const AVPixFmtDescriptor *desc_src;
     const AVPixFmtDescriptor *desc_dst;
     int ret = 0;
@@ -1291,12 +1290,6 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
 
     unscaled = (srcW == dstW && srcH == dstH);
 
-    c->srcRange |= handle_jpeg(&c->srcFormat);
-    c->dstRange |= handle_jpeg(&c->dstFormat);
-
-    if(srcFormat!=c->srcFormat || dstFormat!=c->dstFormat)
-        av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n");
-
     if (!c->contrast && !c->saturation && !c->dstFormatBpp)
         sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->srcRange,
                                  ff_yuv2rgb_coeffs[SWS_CS_DEFAULT],
@@ -2034,6 +2027,7 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
                              SwsFilter *dstFilter)
 {
     static AVOnce rgb2rgb_once = AV_ONCE_INIT;
+    enum AVPixelFormat src_format, dst_format;
     int ret;
 
     c->frame_src = av_frame_alloc();
@@ -2044,6 +2038,14 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
     if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0)
         return AVERROR_UNKNOWN;
 
+    src_format = c->srcFormat;
+    dst_format = c->dstFormat;
+    c->srcRange |= handle_jpeg(&c->srcFormat);
+    c->dstRange |= handle_jpeg(&c->dstFormat);
+
+    if (src_format != c->srcFormat || dst_format != c->dstFormat)
+        av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n");
+
     if (c->nb_threads != 1) {
         ret = context_init_threaded(c, srcFilter, dstFilter);
         if (ret < 0 || c->nb_threads > 1)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH 6/6] swscale/utils: Fix indentation
  2022-11-21  0:24 [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
                   ` (3 preceding siblings ...)
  2022-11-21  0:27 ` [FFmpeg-devel] [PATCH 5/6] swscale/utils: Derive range from YUVJ-pix-fmt only once Andreas Rheinhardt
@ 2022-11-21  0:27 ` Andreas Rheinhardt
  2022-11-23 21:43 ` [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-11-21  0:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Forgotten after c1eb3e7fecdc270e03a700d61ef941600a6af491.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libswscale/utils.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 5a728afd89..90734f66ef 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1307,16 +1307,16 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
 
     if (!(unscaled && sws_isSupportedEndiannessConversion(srcFormat) &&
           av_pix_fmt_swap_endianness(srcFormat) == dstFormat)) {
-    if (!sws_isSupportedInput(srcFormat)) {
-        av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n",
-               av_get_pix_fmt_name(srcFormat));
-        return AVERROR(EINVAL);
-    }
-    if (!sws_isSupportedOutput(dstFormat)) {
-        av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n",
-               av_get_pix_fmt_name(dstFormat));
-        return AVERROR(EINVAL);
-    }
+        if (!sws_isSupportedInput(srcFormat)) {
+            av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n",
+                   av_get_pix_fmt_name(srcFormat));
+            return AVERROR(EINVAL);
+        }
+        if (!sws_isSupportedOutput(dstFormat)) {
+            av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n",
+                   av_get_pix_fmt_name(dstFormat));
+            return AVERROR(EINVAL);
+        }
     }
     av_assert2(desc_src && desc_dst);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out
  2022-11-21  0:24 [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
                   ` (4 preceding siblings ...)
  2022-11-21  0:27 ` [FFmpeg-devel] [PATCH 6/6] swscale/utils: Fix indentation Andreas Rheinhardt
@ 2022-11-23 21:43 ` Andreas Rheinhardt
  5 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-11-23 21:43 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> Initializing slice threads currently uses the function
> (sws_init_context()) that is also used for initializing
> user-facing contexts with the only difference being that
> nb_threads is set to one before initializing the slice contexts.
> 
> Yet sws_init_context() also initializes lots of stuff
> that is not slice-dependent, i.e. (src|dst)Range. This
> currently only works because the code sets these fields
> to the same values for all slice contexts. This is not
> nice; even worse, it entails that log messages are printed
> once per slice context (and therefore fill the screen).
> 
> This commit lays the groundwork to fix this.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libswscale/utils.c | 31 +++++++++++++++++++++----------
>  1 file changed, 21 insertions(+), 10 deletions(-)
> 
> diff --git a/libswscale/utils.c b/libswscale/utils.c
> index 85640a143f..c6fa07f752 100644
> --- a/libswscale/utils.c
> +++ b/libswscale/utils.c
> @@ -1268,6 +1268,9 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
>      }
>  }
>  
> +static int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
> +                                   SwsFilter *dstFilter);
> +
>  static int context_init_threaded(SwsContext *c,
>                                   SwsFilter *src_filter, SwsFilter *dst_filter)
>  {
> @@ -1301,7 +1304,7 @@ static int context_init_threaded(SwsContext *c,
>  
>          c->slice_ctx[i]->nb_threads = 1;
>  
> -        ret = sws_init_context(c->slice_ctx[i], src_filter, dst_filter);
> +        ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter);
>          if (ret < 0)
>              return ret;
>  
> @@ -1322,8 +1325,8 @@ static int context_init_threaded(SwsContext *c,
>      return 0;
>  }
>  
> -av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
> -                             SwsFilter *dstFilter)
> +static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
> +                                           SwsFilter *dstFilter)
>  {
>      int i;
>      int usesVFilter, usesHFilter;
> @@ -1344,13 +1347,6 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
>      static const float float_mult = 1.0f / 255.0f;
>      static AVOnce rgb2rgb_once = AV_ONCE_INIT;
>  
> -    if (c->nb_threads != 1) {
> -        ret = context_init_threaded(c, srcFilter, dstFilter);
> -        if (ret < 0 || c->nb_threads > 1)
> -            return ret;
> -        // threading disabled in this build, init as single-threaded
> -    }
> -
>      cpu_flags = av_get_cpu_flags();
>      flags     = c->flags;
>      emms_c();
> @@ -2054,6 +2050,21 @@ fail: // FIXME replace things by appropriate error codes
>      return ret;
>  }
>  
> +av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
> +                             SwsFilter *dstFilter)
> +{
> +    int ret;
> +
> +    if (c->nb_threads != 1) {
> +        ret = context_init_threaded(c, srcFilter, dstFilter);
> +        if (ret < 0 || c->nb_threads > 1)
> +            return ret;
> +        // threading disabled in this build, init as single-threaded
> +    }
> +
> +    return sws_init_single_context(c, srcFilter, dstFilter);
> +}
> +
>  SwsContext *sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
>                                 int dstW, int dstH, enum AVPixelFormat dstFormat,
>                                 int flags, const double *param)

Will apply this patchset tomorrow unless there are objections.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-23 21:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21  0:24 [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt
2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 2/6] swscale/utils: Don't allocate AVFrames for slice contexts Andreas Rheinhardt
2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 3/6] swscale/utils: Avoid calling ff_thread_once() unnecessarily Andreas Rheinhardt
2022-11-21  0:26 ` [FFmpeg-devel] [PATCH 4/6] swscale/utils: Move functions to avoid forward declarations Andreas Rheinhardt
2022-11-21  0:27 ` [FFmpeg-devel] [PATCH 5/6] swscale/utils: Derive range from YUVJ-pix-fmt only once Andreas Rheinhardt
2022-11-21  0:27 ` [FFmpeg-devel] [PATCH 6/6] swscale/utils: Fix indentation Andreas Rheinhardt
2022-11-23 21:43 ` [FFmpeg-devel] [PATCH 1/6] swscale/utils: Factor initializing single slice context out Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git