summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h363
1 files changed, 0 insertions, 363 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h
deleted file mode 100644
index 25e39e2..0000000
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h
+++ /dev/null
@@ -1,363 +0,0 @@
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../AddonBase.h"
12#ifdef BUILD_KODI_ADDON
13#include "../AEChannelData.h"
14#else
15#include "cores/AudioEngine/Utils/AEChannelData.h"
16#endif
17#include <stdint.h>
18
19namespace kodi
20{
21namespace addon
22{
23 class CInstanceAudioDecoder;
24} /* namespace addon */
25} /* namespace kodi */
26
27extern "C"
28{
29
30typedef struct AddonProps_AudioDecoder
31{
32 int dummy;
33} AddonProps_AudioDecoder;
34
35typedef struct AddonToKodiFuncTable_AudioDecoder
36{
37 void* kodiInstance;
38} AddonToKodiFuncTable_AudioDecoder;
39
40struct AddonInstance_AudioDecoder;
41typedef struct KodiToAddonFuncTable_AudioDecoder
42{
43 kodi::addon::CInstanceAudioDecoder* addonInstance;
44 bool (__cdecl* init)(const AddonInstance_AudioDecoder* instance,
45 const char* file, unsigned int filecache,
46 int* channels, int* samplerate,
47 int* bitspersample, int64_t* totaltime,
48 int* bitrate, AEDataFormat* format,
49 const AEChannel** info);
50 int (__cdecl* read_pcm)(const AddonInstance_AudioDecoder* instance, uint8_t* buffer, int size, int* actualsize);
51 int64_t (__cdecl* seek)(const AddonInstance_AudioDecoder* instance, int64_t time);
52 bool (__cdecl* read_tag)(const AddonInstance_AudioDecoder* instance,
53 const char* file, char* title,
54 char* artist, int* length);
55 int (__cdecl* track_count)(const AddonInstance_AudioDecoder* instance, const char* file);
56} KodiToAddonFuncTable_AudioDecoder;
57
58typedef struct AddonInstance_AudioDecoder
59{
60 AddonProps_AudioDecoder props;
61 AddonToKodiFuncTable_AudioDecoder toKodi;
62 KodiToAddonFuncTable_AudioDecoder toAddon;
63} AddonInstance_AudioDecoder;
64
65} /* extern "C" */
66
67namespace kodi
68{
69namespace addon
70{
71
72//==============================================================================
73///
74/// \addtogroup cpp_kodi_addon_audiodecoder
75/// @brief \cpp_class{ kodi::addon::CInstanceAudioDecoder }
76/// **Audio decoder add-on instance**
77///
78/// For audio decoders as binary add-ons. This class implements a way to handle
79/// special types of audio files.
80///
81/// The add-on handles loading of the source file and outputting the audio stream
82/// for consumption by the player.
83///
84/// The addon.xml defines the capabilities of this add-on.
85///
86/// @note The option to have multiple instances is possible with audio-decoder
87/// add-ons. This is useful, since some playback engines are riddled by global
88/// variables, making decoding of multiple streams using the same instance
89/// impossible.
90///
91///
92/// ----------------------------------------------------------------------------
93///
94/// **Here's an example on addon.xml:**
95/// ~~~~~~~~~~~~~{.xml}
96/// <extension
97/// point="kodi.audiodecoder"
98/// name="2sf"
99/// extension=".2sf|.mini2sf"
100/// tags="true"
101/// library_@PLATFORM@="@LIBRARY_FILENAME@"/>
102/// ~~~~~~~~~~~~~
103///
104/// Description to audio decoder related addon.xml values:
105/// | Name | Description
106/// |:------------------------------|----------------------------------------
107/// | <b>`point`</b> | Addon type specification<br>At all addon types and for this kind always <b>"kodi.audiodecoder"</b>.
108/// | <b>`library_@PLATFORM@`</b> | Sets the used library name, which is automatically set by cmake at addon build.
109/// | <b>`name`</b> | The name of the decoder used in Kodi for display.
110/// | <b>`extension`</b> | The file extensions / styles supported by this addon.
111/// | <b>`tags`</b> | Boolean to point out that addon can bring own information to replayed file, if <b>`false`</b> only the file name is used as info.<br>If <b>`true`</b>, \ref CInstanceAudioDecoder::ReadTag is used and must be implemented.
112///
113/// --------------------------------------------------------------------------
114///
115/// **Here is a code example how this addon is used:**
116///
117/// ~~~~~~~~~~~~~{.cpp}
118/// #include <kodi/addon-instance/AudioDecoder.h>
119///
120/// class CMyAudioDecoder : public ::kodi::addon::CInstanceAudioDecoder
121/// {
122/// public:
123/// CMyAudioDecoder(KODI_HANDLE instance);
124///
125/// bool Init(const std::string& filename, unsigned int filecache,
126/// int& channels, int& samplerate,
127/// int& bitspersample, int64_t& totaltime,
128/// int& bitrate, AEDataFormat& format,
129/// std::vector<AEChannel>& channellist) override;
130/// int ReadPCM(uint8_t* buffer, int size, int& actualsize) override;
131/// };
132///
133/// CMyAudioDecoder::CMyAudioDecoder(KODI_HANDLE instance)
134/// : CInstanceAudioDecoder(instance)
135/// {
136/// ...
137/// }
138///
139/// bool CMyAudioDecoder::Init(const std::string& filename, unsigned int filecache,
140/// int& channels, int& samplerate,
141/// int& bitspersample, int64_t& totaltime,
142/// int& bitrate, AEDataFormat& format,
143/// std::vector<AEChannel>& channellist)
144/// {
145/// ...
146/// return true;
147/// }
148///
149/// int CMyAudioDecoder::ReadPCM(uint8_t* buffer, int size, int& actualsize)
150/// {
151/// ...
152/// return 0;
153/// }
154///
155///
156/// /*----------------------------------------------------------------------*/
157///
158/// class CMyAddon : public ::kodi::addon::CAddonBase
159/// {
160/// public:
161/// CMyAddon() { }
162/// ADDON_STATUS CreateInstance(int instanceType,
163/// std::string instanceID,
164/// KODI_HANDLE instance,
165/// KODI_HANDLE& addonInstance) override;
166/// };
167///
168/// /* If you use only one instance in your add-on, can be instanceType and
169/// * instanceID ignored */
170/// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
171/// std::string instanceID,
172/// KODI_HANDLE instance,
173/// KODI_HANDLE& addonInstance)
174/// {
175/// if (instanceType == ADDON_INSTANCE_AUDIODECODER)
176/// {
177/// kodi::Log(ADDON_LOG_NOTICE, "Creating my audio decoder");
178/// addonInstance = new CMyAudioDecoder(instance);
179/// return ADDON_STATUS_OK;
180/// }
181/// else if (...)
182/// {
183/// ...
184/// }
185/// return ADDON_STATUS_UNKNOWN;
186/// }
187///
188/// ADDONCREATOR(CMyAddon)
189/// ~~~~~~~~~~~~~
190///
191/// The destruction of the example class `CMyAudioDecoder` is called from
192/// Kodi's header. Manually deleting the add-on instance is not required.
193///
194class ATTRIBUTE_HIDDEN CInstanceAudioDecoder : public IAddonInstance
195{
196public:
197 //==========================================================================
198 /// @ingroup cpp_kodi_addon_audiodecoder
199 /// @brief Class constructor
200 ///
201 /// @param[in] instance The addon instance class handler given by Kodi
202 /// at \ref kodi::addon::CAddonBase::CreateInstance(...)
203 /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to
204 /// allow compatibility to older Kodi versions.
205 /// @note Recommended to set.
206 ///
207 explicit CInstanceAudioDecoder(KODI_HANDLE instance, const std::string& kodiVersion = "")
208 : IAddonInstance(ADDON_INSTANCE_AUDIODECODER,
209 !kodiVersion.empty() ? kodiVersion
210 : GetKodiTypeVersion(ADDON_INSTANCE_AUDIODECODER))
211 {
212 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
213 throw std::logic_error("kodi::addon::CInstanceAudioDecoder: Creation of multiple together with single instance way is not allowed!");
214
215 SetAddonStruct(instance);
216 }
217 //--------------------------------------------------------------------------
218
219 //==========================================================================
220 /// @ingroup cpp_kodi_addon_audiodecoder
221 /// @brief Initialize a decoder
222 ///
223 /// @param[in] filename The file to read
224 /// @param[in] filecache The file cache size
225 /// @param[out] channels Number of channels in output stream
226 /// @param[out] samplerate Samplerate of output stream
227 /// @param[out] bitspersample Bits per sample in output stream
228 /// @param[out] totaltime Total time for stream
229 /// @param[out] bitrate Average bitrate of input stream
230 /// @param[out] format Data format for output stream
231 /// @param[out] channellist Channel mapping for output stream
232 /// @return true if successfully done, otherwise
233 /// false
234 ///
235 virtual bool Init(const std::string& filename, unsigned int filecache,
236 int& channels, int& samplerate,
237 int& bitspersample, int64_t& totaltime,
238 int& bitrate, AEDataFormat& format,
239 std::vector<AEChannel>& channellist) = 0;
240 //--------------------------------------------------------------------------
241
242 //==========================================================================
243 /// @ingroup cpp_kodi_addon_audiodecoder
244 /// @brief Produce some noise
245 ///
246 /// @param[in] buffer Output buffer
247 /// @param[in] size Size of output buffer
248 /// @param[out] actualsize Actual number of bytes written to output buffer
249 /// @return Return with following possible values:
250 /// | Value | Description |
251 /// |:-----:|:-----------------------------|
252 /// | 0 | on success
253 /// | -1 | on end of stream
254 /// | 1 | on failure
255 ///
256 virtual int ReadPCM(uint8_t* buffer, int size, int& actualsize) = 0;
257 //--------------------------------------------------------------------------
258
259 //==========================================================================
260 /// @ingroup cpp_kodi_addon_audiodecoder
261 /// @brief Seek in output stream
262 ///
263 /// @param[in] time Time position to seek to in milliseconds
264 /// @return Time position seek ended up on
265 ///
266 virtual int64_t Seek(int64_t time) { return time; }
267 //--------------------------------------------------------------------------
268
269 //==========================================================================
270 /// @ingroup cpp_kodi_addon_audiodecoder
271 /// @brief Read tag of a file
272 ///
273 /// @param[in] file File to read tag for
274 /// @param[out] title Title of file
275 /// @param[out] artist Artist of file
276 /// @param[out] length Length of file
277 /// @return True on success, false on failure
278 ///
279 virtual bool ReadTag(const std::string& file, std::string& title, std::string& artist, int& length) { return false; }
280 //--------------------------------------------------------------------------
281
282 //==========================================================================
283 /// @ingroup cpp_kodi_addon_audiodecoder
284 /// @brief Get number of tracks in a file
285 ///
286 /// @param[in] file File to read tag for
287 /// @return Number of tracks in file
288 ///
289 virtual int TrackCount(const std::string& file) { return 1; }
290 //--------------------------------------------------------------------------
291
292private:
293 void SetAddonStruct(KODI_HANDLE instance)
294 {
295 if (instance == nullptr)
296 throw std::logic_error("kodi::addon::CInstanceAudioDecoder: Creation with empty addon structure not allowed, table must be given from Kodi!");
297
298 m_instanceData = static_cast<AddonInstance_AudioDecoder*>(instance);
299
300 m_instanceData->toAddon.addonInstance = this;
301 m_instanceData->toAddon.init = ADDON_Init;
302 m_instanceData->toAddon.read_pcm = ADDON_ReadPCM;
303 m_instanceData->toAddon.seek = ADDON_Seek;
304 m_instanceData->toAddon.read_tag = ADDON_ReadTag;
305 m_instanceData->toAddon.track_count = ADDON_TrackCount;
306 }
307
308 inline static bool ADDON_Init(const AddonInstance_AudioDecoder* instance, const char* file, unsigned int filecache,
309 int* channels, int* samplerate,
310 int* bitspersample, int64_t* totaltime,
311 int* bitrate, AEDataFormat* format,
312 const AEChannel** info)
313 {
314 instance->toAddon.addonInstance->m_channelList.clear();
315 bool ret = instance->toAddon.addonInstance->Init(file, filecache, *channels,
316 *samplerate, *bitspersample,
317 *totaltime, *bitrate, *format,
318 instance->toAddon.addonInstance->m_channelList);
319 if (!instance->toAddon.addonInstance->m_channelList.empty())
320 {
321 if (instance->toAddon.addonInstance->m_channelList.back() != AE_CH_NULL)
322 instance->toAddon.addonInstance->m_channelList.push_back(AE_CH_NULL);
323 *info = instance->toAddon.addonInstance->m_channelList.data();
324 }
325 else
326 *info = nullptr;
327 return ret;
328 }
329
330 inline static int ADDON_ReadPCM(const AddonInstance_AudioDecoder* instance, uint8_t* buffer, int size, int* actualsize)
331 {
332 return instance->toAddon.addonInstance->ReadPCM(buffer, size, *actualsize);
333 }
334
335 inline static int64_t ADDON_Seek(const AddonInstance_AudioDecoder* instance, int64_t time)
336 {
337 return instance->toAddon.addonInstance->Seek(time);
338 }
339
340 inline static bool ADDON_ReadTag(const AddonInstance_AudioDecoder* instance, const char* file, char* title, char* artist, int* length)
341 {
342 std::string intTitle;
343 std::string intArtist;
344 bool ret = instance->toAddon.addonInstance->ReadTag(file, intTitle, intArtist, *length);
345 if (ret)
346 {
347 strncpy(title, intTitle.c_str(), ADDON_STANDARD_STRING_LENGTH_SMALL-1);
348 strncpy(artist, intArtist.c_str(), ADDON_STANDARD_STRING_LENGTH_SMALL-1);
349 }
350 return ret;
351 }
352
353 inline static int ADDON_TrackCount(const AddonInstance_AudioDecoder* instance, const char* file)
354 {
355 return instance->toAddon.addonInstance->TrackCount(file);
356 }
357
358 std::vector<AEChannel> m_channelList;
359 AddonInstance_AudioDecoder* m_instanceData;
360};
361
362} /* namespace addon */
363} /* namespace kodi */