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 "DllAvUtil.h"
28 #include "utils/log.h"
35 #ifndef __STDC_CONSTANT_MACROS
36 #define __STDC_CONSTANT_MACROS
39 #ifndef __STDC_LIMIT_MACROS
40 #define __STDC_LIMIT_MACROS
44 #pragma warning(disable:4244)
47 #if (defined USE_EXTERNAL_FFMPEG)
48 #if (defined HAVE_LIBSWSCALE_SWSCALE_H)
49 #include <libswscale/swscale.h>
50 #elif (defined HAVE_FFMPEG_SWSCALE_H)
51 #include <ffmpeg/swscale.h>
54 #include "libswscale/swscale.h"
58 #include "../xbmc/utils/CPUInfo.h"
60 inline int SwScaleCPUFlags()
62 unsigned int cpuFeatures = g_cpuInfo.GetCPUFeatures();
65 if (cpuFeatures & CPU_FEATURE_MMX)
66 flags |= SWS_CPU_CAPS_MMX;
67 if (cpuFeatures & CPU_FEATURE_MMX2)
68 flags |= SWS_CPU_CAPS_MMX2;
69 if (cpuFeatures & CPU_FEATURE_3DNOW)
70 flags |= SWS_CPU_CAPS_3DNOW;
71 if (cpuFeatures & CPU_FEATURE_ALTIVEC)
72 flags |= SWS_CPU_CAPS_ALTIVEC;
77 class DllSwScaleInterface
80 virtual ~DllSwScaleInterface() {}
82 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
83 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
84 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
86 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
87 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
89 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
90 int srcSliceH, uint8_t* dst[], int dstStride[])=0;
92 virtual void sws_freeContext(struct SwsContext *context)=0;
95 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
97 // We call into this library directly.
98 class DllSwScale : public DllDynamic, public DllSwScaleInterface
101 virtual ~DllSwScale() {}
102 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
103 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
104 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
105 { return ::sws_getCachedContext(context, srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
107 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
108 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
109 { return ::sws_getContext(srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
111 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
112 int srcSliceH, uint8_t* dst[], int dstStride[])
113 { return ::sws_scale(context, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); }
114 virtual void sws_freeContext(struct SwsContext *context) { ::sws_freeContext(context); }
117 virtual bool ResolveExports() { return true; }
118 virtual bool Load() {
119 CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
122 virtual void Unload() {}
127 class DllSwScale : public DllDynamic, public DllSwScaleInterface
129 DECLARE_DLL_WRAPPER(DllSwScale, DLL_PATH_LIBSWSCALE)
130 DEFINE_METHOD11(struct SwsContext *, sws_getCachedContext, ( struct SwsContext *p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8,
131 SwsFilter * p9, SwsFilter * p10, double * p11))
132 DEFINE_METHOD10(struct SwsContext *, sws_getContext, ( int p1, int p2, int p3, int p4, int p5, int p6, int p7,
133 SwsFilter * p8, SwsFilter * p9, double * p10))
134 DEFINE_METHOD7(int, sws_scale, (struct SwsContext *p1, uint8_t** p2, int *p3, int p4, int p5, uint8_t **p6, int *p7))
135 DEFINE_METHOD1(void, sws_freeContext, (struct SwsContext *p1))
137 BEGIN_METHOD_RESOLVE()
138 RESOLVE_METHOD(sws_getCachedContext)
139 RESOLVE_METHOD(sws_getContext)
140 RESOLVE_METHOD(sws_scale)
141 RESOLVE_METHOD(sws_freeContext)
144 /* dependency of libswscale */
145 DllAvUtil m_dllAvUtil;
150 if (!m_dllAvUtil.Load())
152 return DllDynamic::Load();