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