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