From 268a7af2f4386fbf2c8abf035eb43a8d9aa4ad7a Mon Sep 17 00:00:00 2001 From: gpoirier Date: Mon, 4 Sep 2006 09:38:24 +0000 Subject: Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead. Patch by Victor Paesa Original thread: Date: Aug 31, 2006 7:15 PM Subject: [Ffmpeg-devel] [PATCH] Add sws_getCachedContext() to swscale library git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@19667 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libswscale/swscale.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libswscale/swscale.c') diff --git a/libswscale/swscale.c b/libswscale/swscale.c index fc5690c738..7a8c202fcb 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -2754,3 +2754,37 @@ void sws_freeContext(SwsContext *c){ 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; +} + -- cgit v1.2.3