Merge pull request #4011 from fritsch/vdpau-settings
[vuplus_xbmc] / lib / DllSwScale.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21
22 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
23   #include "config.h"
24 #endif
25 #include "DynamicDll.h"
26 #include "DllAvUtil.h"
27 #include "utils/log.h"
28
29 extern "C" {
30 #ifndef HAVE_MMX
31 #define HAVE_MMX
32 #endif
33
34 #ifndef __STDC_CONSTANT_MACROS
35 #define __STDC_CONSTANT_MACROS
36 #endif
37
38 #ifndef __STDC_LIMIT_MACROS
39 #define __STDC_LIMIT_MACROS
40 #endif
41
42 #ifndef __GNUC__
43 #pragma warning(disable:4244)
44 #endif
45
46 #if (defined USE_EXTERNAL_FFMPEG)
47   #include <libswscale/swscale.h>
48 #else
49   #include "libswscale/swscale.h"
50 #endif
51 }
52
53 #include "../xbmc/utils/CPUInfo.h"
54
55 inline int SwScaleCPUFlags()
56 {
57   unsigned int cpuFeatures = g_cpuInfo.GetCPUFeatures();
58   int flags = 0;
59
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;
68
69   return flags;
70 }
71
72 class DllSwScaleInterface
73 {
74 public:
75    virtual ~DllSwScaleInterface() {}
76
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;
80
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;
83
84    virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
85                          int srcSliceH, uint8_t* dst[], int dstStride[])=0;
86
87    virtual void sws_freeContext(struct SwsContext *context)=0;
88 };
89
90 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)
91
92 // We call into this library directly.
93 class DllSwScale : public DllDynamic, public DllSwScaleInterface
94 {
95 public:
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); }
101
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); }
105
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); }
110   
111   // DLL faking.
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");
116 #endif
117     return true;
118   }
119   virtual void Unload() {}
120 };
121
122 #else
123
124 class DllSwScale : public DllDynamic, public DllSwScaleInterface
125 {
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))
133
134   BEGIN_METHOD_RESOLVE()
135     RESOLVE_METHOD(sws_getCachedContext)
136     RESOLVE_METHOD(sws_getContext)
137     RESOLVE_METHOD(sws_scale)
138     RESOLVE_METHOD(sws_freeContext)
139   END_METHOD_RESOLVE()
140
141   /* dependency of libswscale */
142   DllAvUtil m_dllAvUtil;
143
144 public:
145   virtual bool Load()
146   {
147     if (!m_dllAvUtil.Load())
148       return false;
149     return DllDynamic::Load();
150   }
151 };
152
153 #endif