Merge pull request #4539 from Matricom/amcodec
[vuplus_xbmc] / lib / DllPostProc.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 "utils/log.h"
27
28 extern "C" {
29 #define HAVE_MMX
30 #ifndef __STDC_CONSTANT_MACROS
31 #define __STDC_CONSTANT_MACROS
32 #endif
33 #ifndef __STDC_LIMIT_MACROS
34 #define __STDC_LIMIT_MACROS
35 #endif
36 #ifndef __GNUC__
37 #pragma warning(disable:4244)
38 #endif
39   
40 #if (defined USE_EXTERNAL_FFMPEG)
41   #include <libavutil/avutil.h>
42   #include <libpostproc/postprocess.h>
43 #else
44   #include "libavutil/avutil.h"
45   #include "libpostproc/postprocess.h"
46 #endif
47 }
48
49 #include "utils/CPUInfo.h"
50
51 inline int PPCPUFlags()
52 {
53   unsigned int cpuFeatures = g_cpuInfo.GetCPUFeatures();
54   int flags = 0;
55
56   if (cpuFeatures & CPU_FEATURE_MMX)
57     flags |= PP_CPU_CAPS_MMX;
58   if (cpuFeatures & CPU_FEATURE_MMX2)
59     flags |= PP_CPU_CAPS_MMX2;
60   if (cpuFeatures & CPU_FEATURE_3DNOW)
61     flags |= PP_CPU_CAPS_3DNOW;
62   if (cpuFeatures & CPU_FEATURE_ALTIVEC)
63     flags |= PP_CPU_CAPS_ALTIVEC;
64
65   return flags;
66 }
67
68 class DllPostProcInterface
69 {
70 public:
71    virtual ~DllPostProcInterface() {}
72   virtual void pp_postprocess(uint8_t * src[3], int srcStride[3], uint8_t * dst[3], int dstStride[3],
73                    int horizontalSize, int verticalSize, QP_STORE_T *QP_store,  int QP_stride,
74                            pp_mode *mode, pp_context *ppContext, int pict_type)=0;                 
75   virtual pp_mode *pp_get_mode_by_name_and_quality(char *name, int quality)=0;
76   virtual void pp_free_mode(pp_mode *mode)=0;
77   virtual pp_context *pp_get_context(int width, int height, int flags)=0;
78   virtual void pp_free_context(pp_context *ppContext)=0;
79 };
80
81 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)
82
83 // We call directly.
84 class DllPostProc : public DllDynamic, DllPostProcInterface
85 {
86 public:
87   
88   virtual ~DllPostProc() {}
89   virtual void pp_postprocess(uint8_t * src[3], int srcStride[3], uint8_t * dst[3], int dstStride[3],
90                   int horizontalSize, int verticalSize, QP_STORE_T *QP_store,  int QP_stride,
91                   pp_mode *mode, pp_context *ppContext, int pict_type) { ::pp_postprocess((const uint8_t** )src, srcStride, dst, dstStride, horizontalSize, verticalSize, QP_store, QP_stride, mode, ppContext, pict_type); }             
92   virtual pp_mode *pp_get_mode_by_name_and_quality(char *name, int quality) { return ::pp_get_mode_by_name_and_quality(name, quality); }
93   virtual void pp_free_mode(pp_mode *mode) { ::pp_free_mode(mode); }
94   virtual pp_context *pp_get_context(int width, int height, int flags) { return ::pp_get_context(width, height, flags); }
95   virtual void pp_free_context(pp_context *ppContext) { ::pp_free_context(ppContext); }
96   
97   // DLL faking.
98   virtual bool ResolveExports() { return true; }
99   virtual bool Load() {
100 #if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
101     CLog::Log(LOGDEBUG, "DllPostProc: Using libpostproc system library");
102 #endif
103     return true;
104   }
105   virtual void Unload() {}
106 };
107
108 #else
109 class DllPostProc : public DllDynamic, DllPostProcInterface
110 {
111   DECLARE_DLL_WRAPPER(DllPostProc, DLL_PATH_LIBPOSTPROC)
112   DEFINE_METHOD11(void, pp_postprocess, (uint8_t* p1[3], int p2[3], uint8_t * p3[3], int p4[3],
113                       int p5, int p6, QP_STORE_T *p7,  int p8,
114                       pp_mode *p9, pp_context *p10, int p11))
115   DEFINE_METHOD2(pp_mode*, pp_get_mode_by_name_and_quality, (char *p1, int p2))
116   DEFINE_METHOD1(void, pp_free_mode, (pp_mode *p1))
117   DEFINE_METHOD3(pp_context*, pp_get_context, (int p1, int p2, int p3))
118   DEFINE_METHOD1(void, pp_free_context, (pp_context *p1))
119
120   BEGIN_METHOD_RESOLVE()
121     RESOLVE_METHOD(pp_postprocess)
122     RESOLVE_METHOD(pp_get_mode_by_name_and_quality)
123     RESOLVE_METHOD(pp_free_mode)
124     RESOLVE_METHOD(pp_get_context)
125     RESOLVE_METHOD(pp_free_context)
126   END_METHOD_RESOLVE()
127 };
128
129 #endif