Merge pull request #1487 from alcoheca/rpc-scanstart
[vuplus_xbmc] / lib / DllSwScale.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2010 Team XBMC
4  *      http://www.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, write to
18  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *  http://www.gnu.org/copyleft/gpl.html
20  *
21  */
22
23 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
24   #include "config.h"
25 #endif
26 #include "DynamicDll.h"
27 #include "DllAvUtil.h"
28 #include "utils/log.h"
29
30 extern "C" {
31 #ifndef HAVE_MMX
32 #define HAVE_MMX
33 #endif
34
35 #ifndef __STDC_CONSTANT_MACROS
36 #define __STDC_CONSTANT_MACROS
37 #endif
38
39 #ifndef __STDC_LIMIT_MACROS
40 #define __STDC_LIMIT_MACROS
41 #endif
42
43 #ifndef __GNUC__
44 #pragma warning(disable:4244)
45 #endif
46
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>
52   #endif
53 #else
54   #include "libswscale/swscale.h"
55 #endif
56 }
57
58 #include "../xbmc/utils/CPUInfo.h"
59
60 inline int SwScaleCPUFlags()
61 {
62   unsigned int cpuFeatures = g_cpuInfo.GetCPUFeatures();
63   int flags = 0;
64
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;
73
74   return flags;
75 }
76
77 class DllSwScaleInterface
78 {
79 public:
80    virtual ~DllSwScaleInterface() {}
81
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;
85
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;
88
89    virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
90                          int srcSliceH, uint8_t* dst[], int dstStride[])=0;
91
92    virtual void sws_freeContext(struct SwsContext *context)=0;
93 };
94
95 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) 
96
97 // We call into this library directly.
98 class DllSwScale : public DllDynamic, public DllSwScaleInterface
99 {
100 public:
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); }
106
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); }
110
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); }
115   
116   // DLL faking.
117   virtual bool ResolveExports() { return true; }
118   virtual bool Load() {
119 #if !defined(TARGET_DARWIN)
120     CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
121 #endif
122     return true;
123   }
124   virtual void Unload() {}
125 };
126
127 #else
128
129 class DllSwScale : public DllDynamic, public DllSwScaleInterface
130 {
131   DECLARE_DLL_WRAPPER(DllSwScale, DLL_PATH_LIBSWSCALE)
132   DEFINE_METHOD11(struct SwsContext *, sws_getCachedContext, ( struct SwsContext *p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8,
133                                                          SwsFilter * p9, SwsFilter * p10, double * p11))
134   DEFINE_METHOD10(struct SwsContext *, sws_getContext, ( int p1, int p2, int p3, int p4, int p5, int p6, int p7, 
135                                                          SwsFilter * p8, SwsFilter * p9, double * p10))
136   DEFINE_METHOD7(int, sws_scale, (struct SwsContext *p1, uint8_t** p2, int *p3, int p4, int p5, uint8_t **p6, int *p7))
137   DEFINE_METHOD1(void, sws_freeContext, (struct SwsContext *p1))
138
139   BEGIN_METHOD_RESOLVE()
140     RESOLVE_METHOD(sws_getCachedContext)
141     RESOLVE_METHOD(sws_getContext)
142     RESOLVE_METHOD(sws_scale)
143     RESOLVE_METHOD(sws_freeContext)
144   END_METHOD_RESOLVE()
145
146   /* dependency of libswscale */
147   DllAvUtil m_dllAvUtil;
148
149 public:
150   virtual bool Load()
151   {
152     if (!m_dllAvUtil.Load())
153       return false;
154     return DllDynamic::Load();
155   }
156 };
157
158 #endif