summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h232
1 files changed, 232 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h
new file mode 100644
index 0000000..46e34a6
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h
@@ -0,0 +1,232 @@
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 <string>
23#include <vector>
24#include <string.h>
25#include <stdlib.h>
26#include <stdio.h>
27#include "kodi_adsp_types.h"
28#include "libXBMC_addon.h"
29
30typedef void* ADSPHANDLE;
31
32#ifdef _WIN32
33#define ADSP_HELPER_DLL "\\library.kodi.adsp\\libKODI_adsp" ADDON_HELPER_EXT
34#else
35#define ADSP_HELPER_DLL_NAME "libKODI_adsp-" ADDON_HELPER_ARCH ADDON_HELPER_EXT
36#define ADSP_HELPER_DLL "/library.kodi.adsp/" ADSP_HELPER_DLL_NAME
37#endif
38
39class CAddonSoundPlay;
40
41class CHelper_libKODI_adsp
42{
43public:
44 CHelper_libKODI_adsp(void)
45 {
46 m_libKODI_adsp = NULL;
47 m_Handle = NULL;
48 }
49
50 ~CHelper_libKODI_adsp(void)
51 {
52 if (m_libKODI_adsp)
53 {
54 ADSP_unregister_me(m_Handle, m_Callbacks);
55 dlclose(m_libKODI_adsp);
56 }
57 }
58
59 /*!
60 * @brief Resolve all callback methods
61 * @param handle Pointer to the add-on
62 * @return True when all methods were resolved, false otherwise.
63 */
64 bool RegisterMe(void* handle)
65 {
66 m_Handle = handle;
67
68 std::string libBasePath;
69 libBasePath = ((cb_array*)m_Handle)->libPath;
70 libBasePath += ADSP_HELPER_DLL;
71
72#if defined(ANDROID)
73 struct stat st;
74 if(stat(libBasePath.c_str(),&st) != 0)
75 {
76 std::string tempbin = getenv("XBMC_ANDROID_LIBS");
77 libBasePath = tempbin + "/" + ADSP_HELPER_DLL_NAME;
78 }
79#endif
80
81 m_libKODI_adsp = dlopen(libBasePath.c_str(), RTLD_LAZY);
82 if (m_libKODI_adsp == NULL)
83 {
84 fprintf(stderr, "Unable to load %s\n", dlerror());
85 return false;
86 }
87
88 ADSP_register_me = (void* (*)(void *HANDLE))
89 dlsym(m_libKODI_adsp, "ADSP_register_me");
90 if (ADSP_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
91
92 ADSP_unregister_me = (void (*)(void* HANDLE, void* CB))
93 dlsym(m_libKODI_adsp, "ADSP_unregister_me");
94 if (ADSP_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
95
96 ADSP_add_menu_hook = (void (*)(void* HANDLE, void* CB, AE_DSP_MENUHOOK *hook))
97 dlsym(m_libKODI_adsp, "ADSP_add_menu_hook");
98 if (ADSP_add_menu_hook == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
99
100 ADSP_remove_menu_hook = (void (*)(void* HANDLE, void* CB, AE_DSP_MENUHOOK *hook))
101 dlsym(m_libKODI_adsp, "ADSP_remove_menu_hook");
102 if (ADSP_remove_menu_hook == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
103
104 ADSP_register_mode = (void (*)(void *HANDLE, void* CB, AE_DSP_MODES::AE_DSP_MODE *modes))
105 dlsym(m_libKODI_adsp, "ADSP_register_mode");
106 if (ADSP_register_mode == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
107
108 ADSP_unregister_mode = (void (*)(void* HANDLE, void* CB, AE_DSP_MODES::AE_DSP_MODE *modes))
109 dlsym(m_libKODI_adsp, "ADSP_unregister_mode");
110 if (ADSP_unregister_mode == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
111
112 ADSP_get_sound_play = (CAddonSoundPlay* (*)(void *HANDLE, void *CB, const char *filename))
113 dlsym(m_libKODI_adsp, "ADSP_get_sound_play");
114 if (ADSP_get_sound_play == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
115
116 ADSP_release_sound_play = (void (*)(CAddonSoundPlay* p))
117 dlsym(m_libKODI_adsp, "ADSP_release_sound_play");
118 if (ADSP_release_sound_play == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
119
120 m_Callbacks = ADSP_register_me(m_Handle);
121 return m_Callbacks != NULL;
122 }
123
124 /*!
125 * @brief Add or replace a menu hook for the context menu for this add-on
126 * @param hook The hook to add
127 */
128 void AddMenuHook(AE_DSP_MENUHOOK* hook)
129 {
130 return ADSP_add_menu_hook(m_Handle, m_Callbacks, hook);
131 }
132
133 /*!
134 * @brief Remove a menu hook for the context menu for this add-on
135 * @param hook The hook to remove
136 */
137 void RemoveMenuHook(AE_DSP_MENUHOOK* hook)
138 {
139 return ADSP_remove_menu_hook(m_Handle, m_Callbacks, hook);
140 }
141
142 /*!
143 * @brief Add or replace master mode information inside audio dsp database.
144 * Becomes identifier written inside mode to iModeID if it was 0 (undefined)
145 * @param mode The master mode to add or update inside database
146 */
147 void RegisterMode(AE_DSP_MODES::AE_DSP_MODE* mode)
148 {
149 return ADSP_register_mode(m_Handle, m_Callbacks, mode);
150 }
151
152 /*!
153 * @brief Remove a master mode from audio dsp database
154 * @param mode The Mode to remove
155 */
156 void UnregisterMode(AE_DSP_MODES::AE_DSP_MODE* mode)
157 {
158 return ADSP_unregister_mode(m_Handle, m_Callbacks, mode);
159 }
160
161 /*!
162 * @brief Open a sound playing class
163 * @param filename The wav filename to open
164 */
165 CAddonSoundPlay* GetSoundPlay(const char *filename)
166 {
167 return ADSP_get_sound_play(m_Handle, m_Callbacks, filename);
168 }
169
170 /*!
171 * @brief Remove a played file class
172 * @param p The playback to remove
173 */
174 void ReleaseSoundPlay(CAddonSoundPlay* p)
175 {
176 return ADSP_release_sound_play(p);
177 }
178
179protected:
180 void* (*ADSP_register_me)(void*);
181
182 void (*ADSP_unregister_me)(void*, void*);
183 void (*ADSP_add_menu_hook)(void*, void*, AE_DSP_MENUHOOK*);
184 void (*ADSP_remove_menu_hook)(void*, void*, AE_DSP_MENUHOOK*);
185 void (*ADSP_register_mode)(void*, void*, AE_DSP_MODES::AE_DSP_MODE*);
186 void (*ADSP_unregister_mode)(void*, void*, AE_DSP_MODES::AE_DSP_MODE*);
187 CAddonSoundPlay* (*ADSP_get_sound_play)(void*, void*, const char *);
188 void (*ADSP_release_sound_play)(CAddonSoundPlay*);
189
190private:
191 void* m_libKODI_adsp;
192 void* m_Handle;
193 void* m_Callbacks;
194 struct cb_array
195 {
196 const char* libPath;
197 };
198};
199
200class CAddonSoundPlay
201{
202public:
203 CAddonSoundPlay(void *hdl, void *cb, const char *filename);
204 virtual ~CAddonSoundPlay();
205
206 /*! play the sound this object represents */
207 virtual void Play();
208
209 /*! stop playing the sound this object represents */
210 virtual void Stop();
211
212 /*! return true if the sound is currently playing */
213 virtual bool IsPlaying();
214
215 /*! set the playback channel position of this sound, AE_DSP_CH_INVALID for all */
216 virtual void SetChannel(AE_DSP_CHANNEL channel);
217
218 /*! get the current playback volume of this sound, AE_DSP_CH_INVALID for all */
219 virtual AE_DSP_CHANNEL GetChannel();
220
221 /*! set the playback volume of this sound */
222 virtual void SetVolume(float volume);
223
224 /*! get the current playback volume of this sound */
225 virtual float GetVolume();
226
227private:
228 std::string m_Filename;
229 void *m_Handle;
230 void *m_cb;
231 ADSPHANDLE m_PlayHandle;
232};