[MPlayer-cvslog] r19667 - in trunk/libswscale: swscale.c swscale.h

gpoirier subversion at mplayerhq.hu
Mon Sep 4 11:38:26 CEST 2006


Author: gpoirier
Date: Mon Sep  4 11:38:24 2006
New Revision: 19667

Modified:
   trunk/libswscale/swscale.c
   trunk/libswscale/swscale.h

Log:
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
Patch by Victor Paesa <wzrlpy at arsystel.com>
Original thread:
Date: Aug 31, 2006 7:15 PM
Subject: [Ffmpeg-devel] [PATCH] Add sws_getCachedContext() to swscale library


Modified: trunk/libswscale/swscale.c
==============================================================================
--- trunk/libswscale/swscale.c	(original)
+++ trunk/libswscale/swscale.c	Mon Sep  4 11:38:24 2006
@@ -2754,3 +2754,37 @@
 	av_free(c);
 }
 
+/**
+ * Checks if context is valid or reallocs a new one instead.
+ * If context is NULL, just calls sws_getContext() to get a new one.
+ * Otherwise, checks if the parameters are the same already saved in context.
+ * If that is the case, returns the current context.
+ * Otherwise, frees context and gets a new one.
+ *
+ * Be warned that srcFilter, dstFilter are not checked, they are
+ * asumed to remain valid.
+ */
+struct SwsContext *sws_getCachedContext(struct SwsContext *context,
+                        int srcW, int srcH, int srcFormat,
+                        int dstW, int dstH, int dstFormat, int flags,
+                        SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
+{
+    if (context != NULL) {
+        if ((context->srcW != srcW) || (context->srcH != srcH) ||
+            (context->srcFormat != srcFormat) ||
+            (context->dstW != dstW) || (context->dstH != dstH) ||
+            (context->dstFormat != dstFormat) || (context->flags != flags) ||
+            (context->param != param))
+        {
+            sws_freeContext(context);
+            context = NULL;
+        }
+    }
+    if (context == NULL) {
+        return sws_getContext(srcW, srcH, srcFormat,
+                        dstW, dstH, dstFormat, flags,
+                        srcFilter, dstFilter, param);
+    }
+    return context;
+}
+

Modified: trunk/libswscale/swscale.h
==============================================================================
--- trunk/libswscale/swscale.h	(original)
+++ trunk/libswscale/swscale.h	Mon Sep  4 11:38:24 2006
@@ -135,6 +135,11 @@
 				int verbose);
 void sws_freeFilter(SwsFilter *filter);
 
+struct SwsContext *sws_getCachedContext(struct SwsContext *context,
+                int srcW, int srcH, int srcFormat,
+                int dstW, int dstH, int dstFormat, int flags,
+                SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
+
 #ifdef __cplusplus
 }
 #endif



More information about the MPlayer-cvslog mailing list