diff mbox series

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

Message ID 20241014134354.180848-5-ffmpeg@haasn.xyz
State New
Headers show
Series swscale: major refactoring and new API | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Niklas Haas Oct. 14, 2024, 1:37 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 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,