3 * Copyright (C) 2005-2013 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 #include <libswscale/swscale.h>
50 #include "libswscale/swscale.h"
54 #include "../xbmc/utils/CPUInfo.h"
56 inline int SwScaleCPUFlags()
58 unsigned int cpuFeatures = g_cpuInfo.GetCPUFeatures();
61 if (cpuFeatures & CPU_FEATURE_MMX)
62 flags |= SWS_CPU_CAPS_MMX;
63 if (cpuFeatures & CPU_FEATURE_MMX2)
64 flags |= SWS_CPU_CAPS_MMX2;
65 if (cpuFeatures & CPU_FEATURE_3DNOW)
66 flags |= SWS_CPU_CAPS_3DNOW;
67 if (cpuFeatures & CPU_FEATURE_ALTIVEC)
68 flags |= SWS_CPU_CAPS_ALTIVEC;
73 class DllSwScaleInterface
76 virtual ~DllSwScaleInterface() {}
78 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
79 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
80 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
82 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
83 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
85 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
86 int srcSliceH, uint8_t* dst[], int dstStride[])=0;
88 virtual void sws_freeContext(struct SwsContext *context)=0;
91 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
93 // We call into this library directly.
94 class DllSwScale : public DllDynamic, public DllSwScaleInterface
97 virtual ~DllSwScale() {}
98 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
99 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
100 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
101 { return ::sws_getCachedContext(context, srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
103 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
104 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
105 { return ::sws_getContext(srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
107 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
108 int srcSliceH, uint8_t* dst[], int dstStride[])
109 { return ::sws_scale(context, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); }
110 virtual void sws_freeContext(struct SwsContext *context) { ::sws_freeContext(context); }
113 virtual bool ResolveExports() { return true; }
114 virtual bool Load() {
115 #if !defined(TARGET_DARWIN)
116 CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
120 virtual void Unload() {}
125 class DllSwScale : public DllDynamic, public DllSwScaleInterface
127 DECLARE_DLL_WRAPPER(DllSwScale, DLL_PATH_LIBSWSCALE)
128 DEFINE_METHOD11(struct SwsContext *, sws_getCachedContext, ( struct SwsContext *p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8,
129 SwsFilter * p9, SwsFilter * p10, double * p11))
130 DEFINE_METHOD10(struct SwsContext *, sws_getContext, ( int p1, int p2, int p3, int p4, int p5, int p6, int p7,
131 SwsFilter * p8, SwsFilter * p9, double * p10))
132 DEFINE_METHOD7(int, sws_scale, (struct SwsContext *p1, uint8_t** p2, int *p3, int p4, int p5, uint8_t **p6, int *p7))
133 DEFINE_METHOD1(void, sws_freeContext, (struct SwsContext *p1))
135 BEGIN_METHOD_RESOLVE()
136 RESOLVE_METHOD(sws_getCachedContext)
137 RESOLVE_METHOD(sws_getContext)
138 RESOLVE_METHOD(sws_scale)
139 RESOLVE_METHOD(sws_freeContext)
142 /* dependency of libswscale */
143 DllAvUtil m_dllAvUtil;
148 if (!m_dllAvUtil.Load())
150 return DllDynamic::Load();