3 * Copyright (C) 2005-2010 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 * http://www.gnu.org/copyleft/gpl.html
23 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
26 #include "DynamicDll.h"
27 #include "utils/log.h"
34 #ifndef __STDC_CONSTANT_MACROS
35 #define __STDC_CONSTANT_MACROS
38 #ifndef __STDC_LIMIT_MACROS
39 #define __STDC_LIMIT_MACROS
43 #pragma warning(disable:4244)
46 #if (defined USE_EXTERNAL_FFMPEG)
47 #if (defined HAVE_LIBAVUTIL_AVUTIL_H)
48 #include <libavutil/avutil.h>
49 #elif (defined HAVE_FFMPEG_AVUTIL_H)
50 #include <ffmpeg/avutil.h>
52 #if (defined HAVE_LIBSWSCALE_SWSCALE_H)
53 #include <libswscale/swscale.h>
54 #elif (defined HAVE_FFMPEG_SWSCALE_H)
55 #include <ffmpeg/swscale.h>
57 #if (defined HAVE_LIBSWSCALE_RGB2RGB_H)
58 #include <libswscale/rgb2rgb.h>
59 #elif (defined HAVE_FFMPEG_RGB2RGB_H)
60 #include <ffmpeg/rgb2rgb.h>
63 #include "libavutil/avutil.h"
64 #include "libswscale/swscale.h"
65 #include "libswscale/rgb2rgb.h"
69 inline int SwScaleCPUFlags()
71 #if !defined(__powerpc__) && !defined(__ppc__) && !defined(__arm__)
72 return SWS_CPU_CAPS_MMX;
73 #elif defined(__powerpc__) || defined(__ppc__)
74 return SWS_CPU_CAPS_ALTIVEC;
80 class DllSwScaleInterface
83 virtual ~DllSwScaleInterface() {}
85 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
86 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
87 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
89 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
90 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
92 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
93 int srcSliceH, uint8_t* dst[], int dstStride[])=0;
94 #if (! defined USE_EXTERNAL_FFMPEG)
95 virtual void sws_rgb2rgb_init(int flags)=0;
96 #elif (defined HAVE_LIBSWSCALE_RGB2RGB_H) || (defined HAVE_FFMPEG_RGB2RGB_H)
97 virtual void sws_rgb2rgb_init(int flags)=0;
100 virtual void sws_freeContext(struct SwsContext *context)=0;
103 #if (defined USE_EXTERNAL_FFMPEG)
105 // We call into this library directly.
106 class DllSwScale : public DllDynamic, public DllSwScaleInterface
109 virtual ~DllSwScale() {}
110 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
111 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
112 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
113 { return ::sws_getCachedContext(context, srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
115 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
116 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
117 { return ::sws_getContext(srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
119 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
120 int srcSliceH, uint8_t* dst[], int dstStride[])
121 { return ::sws_scale(context, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); }
122 #if (! defined USE_EXTERNAL_FFMPEG)
123 virtual void sws_rgb2rgb_init(int flags) { ::sws_rgb2rgb_init(flags); }
124 #elif (defined HAVE_LIBSWSCALE_RGB2RGB_H) || (defined HAVE_FFMPEG_RGB2RGB_H)
125 virtual void sws_rgb2rgb_init(int flags) { ::sws_rgb2rgb_init(flags); }
127 virtual void sws_freeContext(struct SwsContext *context) { ::sws_freeContext(context); }
130 virtual bool ResolveExports() { return true; }
131 virtual bool Load() {
132 CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
135 virtual void Unload() {}
140 class DllSwScale : public DllDynamic, public DllSwScaleInterface
142 DECLARE_DLL_WRAPPER(DllSwScale, DLL_PATH_LIBSWSCALE)
143 DEFINE_METHOD11(struct SwsContext *, sws_getCachedContext, ( struct SwsContext *p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8,
144 SwsFilter * p9, SwsFilter * p10, double * p11))
145 DEFINE_METHOD10(struct SwsContext *, sws_getContext, ( int p1, int p2, int p3, int p4, int p5, int p6, int p7,
146 SwsFilter * p8, SwsFilter * p9, double * p10))
147 DEFINE_METHOD7(int, sws_scale, (struct SwsContext *p1, uint8_t** p2, int *p3, int p4, int p5, uint8_t **p6, int *p7))
148 DEFINE_METHOD1(void, sws_rgb2rgb_init, (int p1))
149 DEFINE_METHOD1(void, sws_freeContext, (struct SwsContext *p1))
151 BEGIN_METHOD_RESOLVE()
152 RESOLVE_METHOD(sws_getCachedContext)
153 RESOLVE_METHOD(sws_getContext)
154 RESOLVE_METHOD(sws_scale)
155 RESOLVE_METHOD(sws_rgb2rgb_init)
156 RESOLVE_METHOD(sws_freeContext)