[FFmpeg-devel] [PATCH 04/19] swscale: add sws_free_context()

Niklas Haas ffmpeg at haasn.xyz
Fri Oct 11 01:26:51 EEST 2024


From: Niklas Haas <git at haasn.dev>

Merely a convenience wrapper around sws_freeContext(). The name change is for
parity with the other sws_* functions.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git at haasn.dev>
---
 libswscale/swscale.h |  7 +++++++
 libswscale/utils.c   | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/libswscale/swscale.h b/libswscale/swscale.h
index b5dea09bef..f9fd340240 100644
--- a/libswscale/swscale.h
+++ b/libswscale/swscale.h
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2024 Niklas Haas
  * Copyright (C) 2001-2011 Michael Niedermayer <michaelni at gmx.at>
  *
  * This file is part of FFmpeg.
@@ -78,6 +79,12 @@ const AVClass *sws_get_class(void);
  */
 SwsContext *sws_alloc_context(void);
 
+/**
+ * Free the context and everything associated with it, and write NULL
+ * to the provided pointer.
+ */
+void sws_free_context(SwsContext **ctx);
+
 /* values for the flags, the stuff on the command line is different */
 #define SWS_FAST_BILINEAR     1
 #define SWS_BILINEAR          2
diff --git a/libswscale/utils.c b/libswscale/utils.c
index b75c9a2bb4..d80a3f0a80 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2514,6 +2514,16 @@ void sws_freeContext(SwsContext *sws)
     av_free(sws);
 }
 
+void sws_free_context(SwsContext **pctx)
+{
+    SwsContext *ctx = *pctx;
+    if (!ctx)
+        return;
+
+    sws_freeContext(ctx);
+    *pctx = NULL;
+}
+
 SwsContext *sws_getCachedContext(SwsContext *sws, int srcW,
                                  int srcH, enum AVPixelFormat srcFormat,
                                  int dstW, int dstH,
-- 
2.46.1



More information about the ffmpeg-devel mailing list