Drop support for old ffmpeg header layout.
[vuplus_xbmc] / lib / DllSwScale.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 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   #include <libswscale/swscale.h>
49 #else
50   #include "libswscale/swscale.h"
51 #endif
52 }
53
54 #include "../xbmc/utils/CPUInfo.h"
55
56 inline int SwScaleCPUFlags()
57 {
58   unsigned int cpuFeatures = g_cpuInfo.GetCPUFeatures();
59   int flags = 0;
60
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;
69
70   return flags;
71 }
72
73 class DllSwScaleInterface
74 {
75 public:
76    virtual ~DllSwScaleInterface() {}
77
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;
81
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;
84
85    virtual int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
86                          int srcSliceH, uint8_t* dst[], int dstStride[])=0;
87
88    virtual void sws_freeContext(struct SwsContext *context)=0;
89 };
90
91 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) 
92
93 // We call into this library directly.
94 class DllSwScale : public DllDynamic, public DllSwScaleInterface
95 {
96 public:
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); }
102
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); }
106
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); }
111   
112   // DLL faking.
113   virtual bool ResolveExports() { return true; }
114   virtual bool Load() {
115 #if !defined(TARGET_DARWIN)
116     CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
117 #endif
118     return true;
119   }
120   virtual void Unload() {}
121 };
122
123 #else
124
125 class DllSwScale : public DllDynamic, public DllSwScaleInterface
126 {
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))
134
135   BEGIN_METHOD_RESOLVE()
136     RESOLVE_METHOD(sws_getCachedContext)
137     RESOLVE_METHOD(sws_getContext)
138     RESOLVE_METHOD(sws_scale)
139     RESOLVE_METHOD(sws_freeContext)
140   END_METHOD_RESOLVE()
141
142   /* dependency of libswscale */
143   DllAvUtil m_dllAvUtil;
144
145 public:
146   virtual bool Load()
147   {
148     if (!m_dllAvUtil.Load())
149       return false;
150     return DllDynamic::Load();
151   }
152 };
153
154 #endif