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, see
18 * <http://www.gnu.org/licenses/>.
22 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
25 #include "DynamicDll.h"
26 #include "DllAvUtil.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 #include <libswscale/swscale.h>
49 #include "libswscale/swscale.h"
53 #include "../xbmc/utils/CPUInfo.h"
55 inline int SwScaleCPUFlags()
57 unsigned int cpuFeatures = g_cpuInfo.GetCPUFeatures();
60 if (cpuFeatures & CPU_FEATURE_MMX)
61 flags |= SWS_CPU_CAPS_MMX;
62 if (cpuFeatures & CPU_FEATURE_MMX2)
63 flags |= SWS_CPU_CAPS_MMX2;
64 if (cpuFeatures & CPU_FEATURE_3DNOW)
65 flags |= SWS_CPU_CAPS_3DNOW;
66 if (cpuFeatures & CPU_FEATURE_ALTIVEC)
67 flags |= SWS_CPU_CAPS_ALTIVEC;
72 class DllSwScaleInterface
75 virtual ~DllSwScaleInterface() {}
77 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
78 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
79 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
81 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
82 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)=0;
84 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
85 int srcSliceH, uint8_t* dst[], int dstStride[])=0;
87 virtual void sws_freeContext(struct SwsContext *context)=0;
90 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)
92 // We call into this library directly.
93 class DllSwScale : public DllDynamic, public DllSwScaleInterface
96 virtual ~DllSwScale() {}
97 virtual struct SwsContext *sws_getCachedContext(struct SwsContext *context,
98 int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
99 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
100 { return ::sws_getCachedContext(context, srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
102 virtual struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
103 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
104 { return ::sws_getContext(srcW, srcH, (enum PixelFormat)srcFormat, dstW, dstH, (enum PixelFormat)dstFormat, flags, srcFilter, dstFilter, param); }
106 virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
107 int srcSliceH, uint8_t* dst[], int dstStride[])
108 { return ::sws_scale(context, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); }
109 virtual void sws_freeContext(struct SwsContext *context) { ::sws_freeContext(context); }
112 virtual bool ResolveExports() { return true; }
113 virtual bool Load() {
114 #if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
115 CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
119 virtual void Unload() {}
124 class DllSwScale : public DllDynamic, public DllSwScaleInterface
126 DECLARE_DLL_WRAPPER(DllSwScale, DLL_PATH_LIBSWSCALE)
127 DEFINE_METHOD11(struct SwsContext *, sws_getCachedContext, ( struct SwsContext *p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8,
128 SwsFilter * p9, SwsFilter * p10, double * p11))
129 DEFINE_METHOD10(struct SwsContext *, sws_getContext, ( int p1, int p2, int p3, int p4, int p5, int p6, int p7,
130 SwsFilter * p8, SwsFilter * p9, double * p10))
131 DEFINE_METHOD7(int, sws_scale, (struct SwsContext *p1, uint8_t** p2, int *p3, int p4, int p5, uint8_t **p6, int *p7))
132 DEFINE_METHOD1(void, sws_freeContext, (struct SwsContext *p1))
134 BEGIN_METHOD_RESOLVE()
135 RESOLVE_METHOD(sws_getCachedContext)
136 RESOLVE_METHOD(sws_getContext)
137 RESOLVE_METHOD(sws_scale)
138 RESOLVE_METHOD(sws_freeContext)
141 /* dependency of libswscale */
142 DllAvUtil m_dllAvUtil;
147 if (!m_dllAvUtil.Load())
149 return DllDynamic::Load();