Merge pull request #4011 from fritsch/vdpau-settings
[vuplus_xbmc] / lib / DllSwResample.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 #ifndef HAVE_MMX
30 #define HAVE_MMX
31 #endif
32 #ifndef __STDC_CONSTANT_MACROS
33 #define __STDC_CONSTANT_MACROS
34 #endif
35 #ifndef __GNUC__
36 #pragma warning(disable:4244)
37 #endif
38 #if (defined USE_EXTERNAL_FFMPEG)
39   #if (defined USE_LIBAV_HACKS)
40     #include "xbmc-libav-hacks/libav_hacks.h"
41   #else
42     #include <libswresample/swresample.h>
43   #endif
44 #else
45   #include "libswresample/swresample.h"
46 #endif
47 }
48
49 class DllSwResampleInterface
50 {
51 public:
52   virtual ~DllSwResampleInterface() {}
53   virtual struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)=0;
54   virtual int swr_init(struct SwrContext *s)=0;
55   virtual void swr_free(struct SwrContext **s)=0;
56   virtual int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count)=0;
57   virtual int64_t swr_get_delay(struct SwrContext *s, int64_t base) = 0;
58   virtual int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map) = 0;
59   virtual int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) = 0;
60   virtual int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance) = 0;
61 };
62
63 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)
64
65 // Use direct mapping
66 class DllSwResample : public DllDynamic, DllSwResampleInterface
67 {
68 public:
69   virtual ~DllSwResample() {}
70
71   // DLL faking.
72   virtual bool ResolveExports() { return true; }
73   virtual bool Load() {
74 #if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
75     CLog::Log(LOGDEBUG, "DllAvFormat: Using libswresample system library");
76 #endif
77     return true;
78   }
79   virtual void Unload() {}
80   virtual struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx) { return ::swr_alloc_set_opts(s, out_ch_layout, out_sample_fmt, out_sample_rate, in_ch_layout, in_sample_fmt, in_sample_rate, log_offset, log_ctx); }
81   virtual int swr_init(struct SwrContext *s) { return ::swr_init(s); }
82   virtual void swr_free(struct SwrContext **s){ return ::swr_free(s); }
83   virtual int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count){ return ::swr_convert(s, out, out_count, in, in_count); }
84   virtual int64_t swr_get_delay(struct SwrContext *s, int64_t base) { return ::swr_get_delay(s, base); }
85   virtual int swr_set_channel_mapping (struct SwrContext *s, const int *channel_map) { return ::swr_set_channel_mapping(s, channel_map); }
86   virtual int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) { return ::swr_set_matrix(s, matrix, stride); }
87   virtual int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance) { return ::swr_set_compensation(s, sample_delta, compensation_distance); }
88 };
89
90 #else
91
92 class DllSwResample : public DllDynamic, DllSwResampleInterface
93 {
94   DECLARE_DLL_WRAPPER(DllSwResample, DLL_PATH_LIBSWRESAMPLE)
95
96   LOAD_SYMBOLS()
97
98   DEFINE_METHOD9(SwrContext*, swr_alloc_set_opts, (struct SwrContext *p1, int64_t p2, enum AVSampleFormat p3, int p4, int64_t p5, enum AVSampleFormat p6, int p7, int p8, void * p9));
99   DEFINE_METHOD1(int, swr_init, (struct SwrContext *p1))
100   DEFINE_METHOD1(void, swr_free, (struct SwrContext **p1))
101   DEFINE_METHOD5(int, swr_convert, (struct SwrContext *p1, uint8_t **p2, int p3, const uint8_t **p4, int p5))
102   DEFINE_METHOD2(int64_t, swr_get_delay, (struct SwrContext *p1, int64_t p2))
103   DEFINE_METHOD2(int, swr_set_channel_mapping, (struct SwrContext *p1, const int *p2))
104   DEFINE_METHOD3(int, swr_set_matrix, (struct SwrContext *p1, const double *p2, int p3))
105   DEFINE_METHOD3(int, swr_set_compensation, (struct SwrContext *p1, int p2, int p3))
106
107   BEGIN_METHOD_RESOLVE()
108     RESOLVE_METHOD(swr_alloc_set_opts)
109     RESOLVE_METHOD(swr_init)
110     RESOLVE_METHOD(swr_free)
111     RESOLVE_METHOD(swr_convert)
112     RESOLVE_METHOD(swr_get_delay)
113     RESOLVE_METHOD(swr_set_channel_mapping)
114     RESOLVE_METHOD(swr_set_matrix)
115     RESOLVE_METHOD(swr_set_compensation)
116   END_METHOD_RESOLVE()
117
118   /* dependencies of libavformat */
119   DllAvUtil m_dllAvUtil;
120
121 public:
122
123   virtual bool Load()
124   {
125     if (!m_dllAvUtil.Load())
126       return false;
127     return DllDynamic::Load();
128   }
129 };
130
131 #endif