summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h324
1 files changed, 324 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h
new file mode 100644
index 0000000..f541637
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_audioengine.h
@@ -0,0 +1,324 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2014 Team KODI
4 * http://kodi.tv
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 KODI; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string>
25#include <string.h>
26#include <vector>
27
28#include "kodi_audioengine_types.h"
29#ifdef BUILD_KODI_ADDON
30 #include "kodi/AudioEngine/AEChannelData.h"
31 #include "kodi/AudioEngine/AEChannelInfo.h"
32 #include "kodi/AudioEngine/AEStreamData.h"
33#else
34 #include "cores/AudioEngine/Utils/AEChannelData.h"
35 #include "cores/AudioEngine/Utils/AEChannelInfo.h"
36 #include "cores/AudioEngine/Utils/AEStreamData.h"
37#endif
38
39#include "libXBMC_addon.h"
40
41#ifdef _WIN32
42#define AUDIOENGINE_HELPER_DLL "\\library.kodi.audioengine\\libKODI_audioengine" ADDON_HELPER_EXT
43#else
44#define AUDIOENGINE_HELPER_DLL_NAME "libKODI_audioengine-" ADDON_HELPER_ARCH ADDON_HELPER_EXT
45#define AUDIOENGINE_HELPER_DLL "/library.kodi.audioengine/" AUDIOENGINE_HELPER_DLL_NAME
46#endif
47
48class CAddonAEStream;
49
50class CHelper_libKODI_audioengine
51{
52public:
53 CHelper_libKODI_audioengine(void)
54 {
55 m_libKODI_audioengine = NULL;
56 m_Handle = NULL;
57 }
58
59 ~CHelper_libKODI_audioengine(void)
60 {
61 if (m_libKODI_audioengine)
62 {
63 AudioEngine_unregister_me(m_Handle, m_Callbacks);
64 dlclose(m_libKODI_audioengine);
65 }
66 }
67
68 /*!
69 * @brief Resolve all callback methods
70 * @param handle Pointer to the add-on
71 * @return True when all methods were resolved, false otherwise.
72 */
73 bool RegisterMe(void* handle)
74 {
75 m_Handle = handle;
76
77 std::string libBasePath;
78 libBasePath = ((cb_array*)m_Handle)->libPath;
79 libBasePath += AUDIOENGINE_HELPER_DLL;
80
81#if defined(ANDROID)
82 struct stat st;
83 if(stat(libBasePath.c_str(),&st) != 0)
84 {
85 std::string tempbin = getenv("XBMC_ANDROID_LIBS");
86 libBasePath = tempbin + "/" + AUDIOENGINE_HELPER_DLL;
87 }
88#endif
89
90 m_libKODI_audioengine = dlopen(libBasePath.c_str(), RTLD_LAZY);
91 if (m_libKODI_audioengine == NULL)
92 {
93 fprintf(stderr, "Unable to load %s\n", dlerror());
94 return false;
95 }
96
97 AudioEngine_register_me = (void* (*)(void *HANDLE))
98 dlsym(m_libKODI_audioengine, "AudioEngine_register_me");
99 if (AudioEngine_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
100
101 AudioEngine_unregister_me = (void(*)(void* HANDLE, void* CB))
102 dlsym(m_libKODI_audioengine, "AudioEngine_unregister_me");
103 if (AudioEngine_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
104
105 AudioEngine_MakeStream = (CAddonAEStream* (*)(void*, void*, AudioEngineFormat, unsigned int))
106 dlsym(m_libKODI_audioengine, "AudioEngine_make_stream");
107 if (AudioEngine_MakeStream == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
108
109 AudioEngine_FreeStream = (void(*)(CAddonAEStream*))
110 dlsym(m_libKODI_audioengine, "AudioEngine_free_stream");
111 if (AudioEngine_FreeStream == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
112
113 AudioEngine_GetCurrentSinkFormat = (bool(*)(void*, void*, AudioEngineFormat*))
114 dlsym(m_libKODI_audioengine, "AudioEngine_get_current_sink_Format");
115 if (AudioEngine_GetCurrentSinkFormat == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
116
117 m_Callbacks = AudioEngine_register_me(m_Handle);
118 return m_Callbacks != NULL;
119 }
120
121 /**
122 * Creates and returns a new handle to an IAEStream in the format specified, this function should never fail
123 * @param DataFormat The data format the incoming audio will be in (eg, AE_FMT_S16LE)
124 * @param SampleRate The sample rate of the audio data (eg, 48000)
125 * @param ChannelLayout The order of the channels in the audio data
126 * @param Options A bit field of stream options (see: enum AEStreamOptions)
127 * @return a new Handle to an IAEStream that will accept data in the requested format
128 */
129 CAddonAEStream* MakeStream(AudioEngineFormat Format, unsigned int Options = 0)
130 {
131 return AudioEngine_MakeStream(m_Handle, m_Callbacks, Format, Options);
132 }
133
134 /**
135 * This method will remove the specifyed stream from the engine.
136 * For OSX/IOS this is essential to reconfigure the audio output.
137 * @param stream The stream to be altered
138 * @return NULL
139 */
140 void FreeStream(CAddonAEStream **Stream)
141 {
142 AudioEngine_FreeStream(*Stream);
143 *Stream = NULL;
144 }
145
146 /**
147 * Get the current sink data format
148 *
149 * @param Current sink data format. For more details see AudioEngineFormat.
150 * @return Returns true on success, else false.
151 */
152 bool GetCurrentSinkFormat(AudioEngineFormat &SinkFormat)
153 {
154 return AudioEngine_GetCurrentSinkFormat(m_Handle, m_Callbacks, &SinkFormat);
155 }
156
157protected:
158 void* (*AudioEngine_register_me)(void*);
159 void (*AudioEngine_unregister_me)(void*, void*);
160 CAddonAEStream* (*AudioEngine_MakeStream)(void*, void*, AudioEngineFormat, unsigned int);
161 bool (*AudioEngine_GetCurrentSinkFormat)(void*, void*, AudioEngineFormat *SinkFormat);
162 void (*AudioEngine_FreeStream)(CAddonAEStream*);
163
164private:
165 void* m_libKODI_audioengine;
166 void* m_Handle;
167 void* m_Callbacks;
168 struct cb_array
169 {
170 const char* libPath;
171 };
172};
173
174// Audio Engine Stream Class
175class CAddonAEStream
176{
177public:
178 CAddonAEStream(void *Addon, void *Callbacks, AEStreamHandle *StreamHandle);
179 virtual ~CAddonAEStream();
180
181 /**
182 * Returns the amount of space available in the stream
183 * @return The number of bytes AddData will consume
184 */
185 virtual unsigned int GetSpace();
186
187 /**
188 * Add planar or interleaved PCM data to the stream
189 * @param Data array of pointers to the planes
190 * @param Offset to frame in frames
191 * @param Frames number of frames
192 * @return The number of frames consumed
193 */
194 virtual unsigned int AddData(uint8_t* const *Data, unsigned int Offset, unsigned int Frames);
195
196 /**
197 * Returns the time in seconds that it will take
198 * for the next added packet to be heard from the speakers.
199 * @return seconds
200 */
201 virtual double GetDelay();
202
203 /**
204 * Returns if the stream is buffering
205 * @return True if the stream is buffering
206 */
207 virtual bool IsBuffering();
208
209 /**
210 * Returns the time in seconds that it will take
211 * to underrun the cache if no sample is added.
212 * @return seconds
213 */
214 virtual double GetCacheTime();
215
216 /**
217 * Returns the total time in seconds of the cache
218 * @return seconds
219 */
220 virtual double GetCacheTotal();
221
222 /**
223 * Pauses the stream playback
224 */
225 virtual void Pause();
226
227 /**
228 * Resumes the stream after pausing
229 */
230 virtual void Resume();
231
232 /**
233 * Start draining the stream
234 * @note Once called AddData will not consume more data.
235 */
236 virtual void Drain(bool Wait);
237
238 /**
239 * Returns true if the is stream draining
240 */
241 virtual bool IsDraining();
242
243 /**
244 * Returns true if the is stream has finished draining
245 */
246 virtual bool IsDrained();
247
248 /**
249 * Flush all buffers dropping the audio data
250 */
251 virtual void Flush();
252
253 /**
254 * Return the stream's current volume level
255 * @return The volume level between 0.0 and 1.0
256 */
257 virtual float GetVolume();
258
259 /**
260 * Set the stream's volume level
261 * @param volume The new volume level between 0.0 and 1.0
262 */
263 virtual void SetVolume(float Volume);
264
265 /**
266 * Gets the stream's volume amplification in linear units.
267 * @return The volume amplification factor between 1.0 and 1000.0
268 */
269 virtual float GetAmplification();
270
271 /**
272 * Sets the stream's volume amplification in linear units.
273 * @param The volume amplification factor between 1.0 and 1000.0
274 */
275 virtual void SetAmplification(float Amplify);
276
277 /**
278 * Returns the size of one audio frame in bytes (channelCount * resolution)
279 * @return The size in bytes of one frame
280 */
281 virtual const unsigned int GetFrameSize() const;
282
283 /**
284 * Returns the number of channels the stream is configured to accept
285 * @return The channel count
286 */
287 virtual const unsigned int GetChannelCount() const;
288
289 /**
290 * Returns the stream's sample rate, if the stream is using a dynamic sample rate, this value will NOT reflect any changes made by calls to SetResampleRatio()
291 * @return The stream's sample rate (eg, 48000)
292 */
293 virtual const unsigned int GetSampleRate() const;
294
295 /**
296 * Return the data format the stream has been configured with
297 * @return The stream's data format (eg, AE_FMT_S16LE)
298 */
299 virtual const AEDataFormat GetDataFormat() const;
300
301 /**
302 * Return the resample ratio
303 * @note This will return an undefined value if the stream is not resampling
304 * @return the current resample ratio or undefined if the stream is not resampling
305 */
306 virtual double GetResampleRatio();
307
308 /**
309 * Sets the resample ratio
310 * @note This function may return false if the stream is not resampling, if you wish to use this be sure to set the AESTREAM_FORCE_RESAMPLE option
311 * @param ratio the new sample rate ratio, calculated by ((double)desiredRate / (double)GetSampleRate())
312 */
313 virtual void SetResampleRatio(double Ratio);
314
315 /**
316 * Sginal a clock change
317 */
318 virtual void Discontinuity();
319
320 private:
321 AEStreamHandle *m_StreamHandle;
322 void *m_Callbacks;
323 void *m_AddonHandle;
324};