[FFmpeg-cvslog] lavu/tx: add ff_tx_clear_ctx()

Lynne git at videolan.org
Thu Nov 24 16:59:38 EET 2022


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Sat Oct  1 12:20:10 2022 +0200| [dd77e61182865e396195a19b1e6ec697717cef56] | committer: Lynne

lavu/tx: add ff_tx_clear_ctx()

This function allows implementations to clean up a context after
successfully initializing subcontexts.

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

 libavutil/tx.c      | 27 +++++++++++++++++++--------
 libavutil/tx_priv.h |  3 +++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/libavutil/tx.c b/libavutil/tx.c
index 246a7aa980..13fb54f916 100644
--- a/libavutil/tx.c
+++ b/libavutil/tx.c
@@ -225,24 +225,35 @@ int ff_tx_gen_split_radix_parity_revtab(AVTXContext *s, int len, int inv,
     return 0;
 }
 
-static void reset_ctx(AVTXContext *s)
+static void reset_ctx(AVTXContext *s, int free_sub)
 {
     if (!s)
         return;
 
     if (s->sub)
-        for (int i = 0; i < s->nb_sub; i++)
-            reset_ctx(&s->sub[i]);
+        for (int i = 0; i < TX_MAX_SUB; i++)
+            reset_ctx(&s->sub[i], free_sub + 1);
 
-    if (s->cd_self->uninit)
+    if (s->cd_self && s->cd_self->uninit)
         s->cd_self->uninit(s);
 
-    av_freep(&s->sub);
+    if (free_sub)
+        av_freep(&s->sub);
+
     av_freep(&s->map);
     av_freep(&s->exp);
     av_freep(&s->tmp);
 
-    memset(s, 0, sizeof(*s));
+    /* Nothing else needs to be reset, it gets overwritten if another
+     * ff_tx_init_subtx() call is made. */
+    s->nb_sub = 0;
+    s->opaque = NULL;
+    memset(s->fn, 0, sizeof(*s->fn));
+}
+
+void ff_tx_clear_ctx(AVTXContext *s)
+{
+    reset_ctx(s, 0);
 }
 
 av_cold void av_tx_uninit(AVTXContext **ctx)
@@ -250,7 +261,7 @@ av_cold void av_tx_uninit(AVTXContext **ctx)
     if (!(*ctx))
         return;
 
-    reset_ctx(*ctx);
+    reset_ctx(*ctx, 1);
     av_freep(ctx);
 }
 
@@ -635,7 +646,7 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType type,
         s->fn[s->nb_sub] = NULL;
         s->cd[s->nb_sub] = NULL;
 
-        reset_ctx(sctx);
+        reset_ctx(sctx, 0);
         if (ret == AVERROR(ENOMEM))
             break;
     }
diff --git a/libavutil/tx_priv.h b/libavutil/tx_priv.h
index 56e78631ba..d9e38ba19b 100644
--- a/libavutil/tx_priv.h
+++ b/libavutil/tx_priv.h
@@ -240,6 +240,9 @@ int ff_tx_init_subtx(AVTXContext *s, enum AVTXType type,
                      uint64_t flags, FFTXCodeletOptions *opts,
                      int len, int inv, const void *scale);
 
+/* Clear the context by freeing all tables, maps and subtransforms. */
+void ff_tx_clear_ctx(AVTXContext *s);
+
 /*
  * Generates the PFA permutation table into AVTXContext->pfatab. The end table
  * is appended to the start table.



More information about the ffmpeg-cvslog mailing list