summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2017-07-23 16:59:43 +0200
committermanuel <manuel@mausz.at>2017-07-23 16:59:43 +0200
commit4c3251ec645c8b71820dab7e51e612e5919d4e75 (patch)
tree9533268a93e58fc2e16de1b8ee3fafe3784e5225 /xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h
parentf44ecaa4f27e7538ddcad66d40e543bffa2d2d86 (diff)
downloadkodi-pvr-build-4c3251ec645c8b71820dab7e51e612e5919d4e75.tar.gz
kodi-pvr-build-4c3251ec645c8b71820dab7e51e612e5919d4e75.tar.bz2
kodi-pvr-build-4c3251ec645c8b71820dab7e51e612e5919d4e75.zip
sync with upstream
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.h240
1 files changed, 240 insertions, 0 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
new file mode 100644
index 0000000..f56f8ae
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioDecoder.h
@@ -0,0 +1,240 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2017 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 "../AddonBase.h"
23#ifdef BUILD_KODI_ADDON
24#include "../AEChannelData.h"
25#else
26#include "cores/AudioEngine/Utils/AEChannelData.h"
27#endif
28#include <stdint.h>
29
30namespace kodi { namespace addon { class CInstanceAudioDecoder; }}
31
32extern "C"
33{
34
35 typedef struct AddonProps_AudioDecoder
36 {
37 int dummy;
38 } AddonProps_AudioDecoder;
39
40 typedef struct AddonToKodiFuncTable_AudioDecoder
41 {
42 void* kodiInstance;
43 } AddonToKodiFuncTable_AudioDecoder;
44
45 struct AddonInstance_AudioDecoder;
46 typedef struct KodiToAddonFuncTable_AudioDecoder
47 {
48 kodi::addon::CInstanceAudioDecoder* addonInstance;
49 bool (__cdecl* init) (const AddonInstance_AudioDecoder* instance,
50 const char* file, unsigned int filecache,
51 int* channels, int* samplerate,
52 int* bitspersample, int64_t* totaltime,
53 int* bitrate, AEDataFormat* format,
54 const AEChannel** info);
55 int (__cdecl* read_pcm) (const AddonInstance_AudioDecoder* instance, uint8_t* buffer, int size, int* actualsize);
56 int64_t (__cdecl* seek) (const AddonInstance_AudioDecoder* instance, int64_t time);
57 bool (__cdecl* read_tag) (const AddonInstance_AudioDecoder* instance,
58 const char* file, char* title,
59 char* artist, int* length);
60 int (__cdecl* track_count) (const AddonInstance_AudioDecoder* instance, const char* file);
61 } KodiToAddonFuncTable_AudioDecoder;
62
63 typedef struct AddonInstance_AudioDecoder
64 {
65 AddonProps_AudioDecoder props;
66 AddonToKodiFuncTable_AudioDecoder toKodi;
67 KodiToAddonFuncTable_AudioDecoder toAddon;
68 } AddonInstance_AudioDecoder;
69
70} /* extern "C" */
71
72namespace kodi
73{
74namespace addon
75{
76
77 class CInstanceAudioDecoder : public IAddonInstance
78 {
79 public:
80 //==========================================================================
81 /// @brief Class constructor
82 ///
83 /// @param[in] instance The from Kodi given instance given be
84 /// add-on CreateInstance call with instance
85 /// id ADDON_INSTANCE_AUDIODECODER.
86 CInstanceAudioDecoder(KODI_HANDLE instance)
87 : IAddonInstance(ADDON_INSTANCE_AUDIODECODER)
88 {
89 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
90 throw std::logic_error("kodi::addon::CInstanceAudioDecoder: Creation of multiple together with single instance way is not allowed!");
91
92 SetAddonStruct(instance);
93 }
94 //--------------------------------------------------------------------------
95
96 //==========================================================================
97 /// @ingroup cpp_kodi_addon_audiodecoder
98 /// @brief Initialize a decoder
99 ///
100 /// @param[in] filename The file to read
101 /// @param[in] filecache The file cache size
102 /// @param[out] channels Number of channels in output stream
103 /// @param[out] samplerate Samplerate of output stream
104 /// @param[out] bitspersample Bits per sample in output stream
105 /// @param[out] totaltime Total time for stream
106 /// @param[out] bitrate Average bitrate of input stream
107 /// @param[out] format Data format for output stream
108 /// @param[out] channellist Channel mapping for output stream
109 /// @return true if successfully done, otherwise
110 /// false
111 ///
112 virtual bool Init(const std::string& filename, unsigned int filecache,
113 int& channels, int& samplerate,
114 int& bitspersample, int64_t& totaltime,
115 int& bitrate, AEDataFormat& format,
116 std::vector<AEChannel>& channellist) = 0;
117 //--------------------------------------------------------------------------
118
119 //==========================================================================
120 /// @ingroup cpp_kodi_addon_audiodecoder
121 /// @brief Produce some noise
122 ///
123 /// @param[in] buffer Output buffer
124 /// @param[in] size Size of output buffer
125 /// @param[out] actualsize Actual number of bytes written to output buffer
126 /// @return Return with following possible values:
127 /// | Value | Description |
128 /// |:-----:|:-----------------------------|
129 /// | 0 | on success
130 /// | -1 | on end of stream
131 /// | 1 | on failure
132 ///
133 virtual int ReadPCM(uint8_t* buffer, int size, int& actualsize) = 0;
134 //--------------------------------------------------------------------------
135
136 //==========================================================================
137 /// @ingroup cpp_kodi_addon_audiodecoder
138 /// @brief Seek in output stream
139 ///
140 /// @param[in] time Time position to seek to in milliseconds
141 /// @return Time position seek ended up on
142 ///
143 virtual int64_t Seek(int64_t time) { return time; }
144 //--------------------------------------------------------------------------
145
146 //==========================================================================
147 /// @ingroup cpp_kodi_addon_audiodecoder
148 /// @brief Read tag of a file
149 ///
150 /// @param[in] file File to read tag for
151 /// @param[out] title Title of file
152 /// @param[out] artist Artist of file
153 /// @param[out] length Length of file
154 /// @return True on success, false on failure
155 ///
156 virtual bool ReadTag(const std::string& file, std::string& title, std::string& artist, int& length) { return false; }
157 //--------------------------------------------------------------------------
158
159 //==========================================================================
160 /// @ingroup cpp_kodi_addon_audiodecoder
161 /// @brief Get number of tracks in a file
162 ///
163 /// @param[in] file File to read tag for
164 /// @return Number of tracks in file
165 ///
166 virtual int TrackCount(const std::string& file) { return 1; }
167 //--------------------------------------------------------------------------
168
169 private:
170 void SetAddonStruct(KODI_HANDLE instance)
171 {
172 if (instance == nullptr)
173 throw std::logic_error("kodi::addon::CInstanceAudioDecoder: Creation with empty addon structure not allowed, table must be given from Kodi!");
174
175 m_instanceData = static_cast<AddonInstance_AudioDecoder*>(instance);
176
177 m_instanceData->toAddon.addonInstance = this;
178 m_instanceData->toAddon.init = ADDON_Init;
179 m_instanceData->toAddon.read_pcm = ADDON_ReadPCM;
180 m_instanceData->toAddon.seek = ADDON_Seek;
181 m_instanceData->toAddon.read_tag = ADDON_ReadTag;
182 m_instanceData->toAddon.track_count = ADDON_TrackCount;
183 }
184
185 inline static bool ADDON_Init(const AddonInstance_AudioDecoder* instance, const char* file, unsigned int filecache,
186 int* channels, int* samplerate,
187 int* bitspersample, int64_t* totaltime,
188 int* bitrate, AEDataFormat* format,
189 const AEChannel** info)
190 {
191 instance->toAddon.addonInstance->m_channelList.clear();
192 bool ret = instance->toAddon.addonInstance->Init(file, filecache, *channels,
193 *samplerate, *bitspersample,
194 *totaltime, *bitrate, *format,
195 instance->toAddon.addonInstance->m_channelList);
196 if (!instance->toAddon.addonInstance->m_channelList.empty())
197 {
198 if (instance->toAddon.addonInstance->m_channelList.back() != AE_CH_NULL)
199 instance->toAddon.addonInstance->m_channelList.push_back(AE_CH_NULL);
200 *info = instance->toAddon.addonInstance->m_channelList.data();
201 }
202 else
203 *info = nullptr;
204 return ret;
205 }
206
207 inline static int ADDON_ReadPCM(const AddonInstance_AudioDecoder* instance, uint8_t* buffer, int size, int* actualsize)
208 {
209 return instance->toAddon.addonInstance->ReadPCM(buffer, size, *actualsize);
210 }
211
212 inline static int64_t ADDON_Seek(const AddonInstance_AudioDecoder* instance, int64_t time)
213 {
214 return instance->toAddon.addonInstance->Seek(time);
215 }
216
217 inline static bool ADDON_ReadTag(const AddonInstance_AudioDecoder* instance, const char* file, char* title, char* artist, int* length)
218 {
219 std::string intTitle;
220 std::string intArtist;
221 bool ret = instance->toAddon.addonInstance->ReadTag(file, intTitle, intArtist, *length);
222 if (ret)
223 {
224 strncpy(title, intTitle.c_str(), ADDON_STANDARD_STRING_LENGTH_SMALL-1);
225 strncpy(artist, intArtist.c_str(), ADDON_STANDARD_STRING_LENGTH_SMALL-1);
226 }
227 return ret;
228 }
229
230 inline static int ADDON_TrackCount(const AddonInstance_AudioDecoder* instance, const char* file)
231 {
232 return instance->toAddon.addonInstance->TrackCount(file);
233 }
234
235 std::vector<AEChannel> m_channelList;
236 AddonInstance_AudioDecoder* m_instanceData;
237 };
238
239} /* namespace addon */
240} /* namespace kodi */