diff mbox series

[FFmpeg-devel,v3,04/18] swscale: add sws_free_context()

Message ID 20241020200851.1414766-5-ffmpeg@haasn.xyz
State New
Headers show
Series major refactor and new scaling API | expand

Commit Message

Niklas Haas Oct. 20, 2024, 8:05 p.m. UTC
From: Niklas Haas <git@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@haasn.dev>
---
 libswscale/swscale.h |  7 +++++++
 libswscale/utils.c   | 10 ++++++++++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

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@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 4b5106cb57..650785a989 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2520,6 +2520,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,