summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioEncoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioEncoder.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioEncoder.h223
1 files changed, 223 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioEncoder.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioEncoder.h
new file mode 100644
index 0000000..3d59a99
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/AudioEncoder.h
@@ -0,0 +1,223 @@
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
24namespace kodi { namespace addon { class CInstanceAudioEncoder; }}
25
26extern "C"
27{
28
29 typedef struct AddonProps_AudioEncoder
30 {
31 int dummy;
32 } AddonProps_AudioEncoder;
33
34 typedef struct AddonToKodiFuncTable_AudioEncoder
35 {
36 void* kodiInstance;
37 int (*write) (void* kodiInstance, const uint8_t* data, int len);
38 int64_t (*seek)(void* kodiInstance, int64_t pos, int whence);
39 } AddonToKodiFuncTable_AudioEncoder;
40
41 struct AddonInstance_AudioEncoder;
42 typedef struct KodiToAddonFuncTable_AudioEncoder
43 {
44 kodi::addon::CInstanceAudioEncoder* addonInstance;
45 bool (__cdecl* start) (const AddonInstance_AudioEncoder* instance, int in_channels, int in_rate, int in_bits,
46 const char* title, const char* artist,
47 const char* albumartist, const char* album,
48 const char* year, const char* track,
49 const char* genre, const char* comment,
50 int track_length);
51 int (__cdecl* encode) (const AddonInstance_AudioEncoder* instance, int num_bytes_read, const uint8_t* pbt_stream);
52 bool (__cdecl* finish) (const AddonInstance_AudioEncoder* instance);
53 } KodiToAddonFuncTable_AudioEncoder;
54
55 typedef struct AddonInstance_AudioEncoder
56 {
57 AddonProps_AudioEncoder props;
58 AddonToKodiFuncTable_AudioEncoder toKodi;
59 KodiToAddonFuncTable_AudioEncoder toAddon;
60 } AddonInstance_AudioEncoder;
61
62} /* extern "C" */
63
64namespace kodi
65{
66namespace addon
67{
68
69 class CInstanceAudioEncoder : public IAddonInstance
70 {
71 public:
72 //==========================================================================
73 /// @brief Class constructor
74 ///
75 /// @param[in] instance The from Kodi given instance given be
76 /// add-on CreateInstance call with instance
77 /// id ADDON_INSTANCE_AUDIOENCODER.
78 CInstanceAudioEncoder(KODI_HANDLE instance)
79 : IAddonInstance(ADDON_INSTANCE_AUDIOENCODER)
80 {
81 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
82 throw std::logic_error("kodi::addon::CInstanceAudioEncoder: Creation of multiple together with single instance way is not allowed!");
83
84 SetAddonStruct(instance);
85 }
86 //--------------------------------------------------------------------------
87
88 //==========================================================================
89 /// \brief Start encoder (**required**)
90 ///
91 /// \param[in] inChannels Number of channels
92 /// \param[in] inRate Sample rate of input data
93 /// \param[in] inBits Bits per sample in input data
94 /// \param[in] title The title of the song
95 /// \param[in] artist The artist of the song
96 /// \param[in] albumartist The albumartist of the song
97 /// \param[in] year The year of the song
98 /// \param[in] track The track number of the song
99 /// \param[in] genre The genre of the song
100 /// \param[in] comment A comment to attach to the song
101 /// \param[in] trackLength Total track length in seconds
102 /// \return True on success, false on failure.
103 ///
104 virtual bool Start(int inChannels,
105 int inRate,
106 int inBits,
107 const std::string& title,
108 const std::string& artist,
109 const std::string& albumartist,
110 const std::string& album,
111 const std::string& year,
112 const std::string& track,
113 const std::string& genre,
114 const std::string& comment,
115 int trackLength) = 0;
116 //--------------------------------------------------------------------------
117
118 //==========================================================================
119 /// \brief Encode a chunk of audio (**required**)
120 ///
121 /// \param[in] numBytesRead Number of bytes in input buffer
122 /// \param[in] pbtStream the input buffer
123 /// \return Number of bytes consumed
124 ///
125 virtual int Encode(int numBytesRead, const uint8_t* pbtStream) = 0;
126 //--------------------------------------------------------------------------
127
128 //==========================================================================
129 /// \brief Finalize encoding (**optional**)
130 ///
131 /// \return True on success, false on failure.
132 ///
133 virtual bool Finish() { return true; }
134 //--------------------------------------------------------------------------
135
136 //==========================================================================
137 /// \brief Write block of data
138 ///
139 /// \param[in] data Pointer to the array of elements to be
140 /// written
141 /// \param[in] length Size in bytes to be written.
142 /// \return The total number of bytes
143 /// successfully written is returned.
144 int Write(const uint8_t* data, int length)
145 {
146 return m_instanceData->toKodi.write(m_instanceData->toKodi.kodiInstance, data, length);
147 }
148 //--------------------------------------------------------------------------
149
150 //==========================================================================
151 /// \brief Set the file's current position.
152 ///
153 /// The whence argument is optional and defaults to SEEK_SET (0)
154 ///
155 /// \param[in] position the position that you want to seek to
156 /// \param[in] whence [optional] offset relative to
157 /// You can set the value of whence to one
158 /// of three things:
159 /// | Value | int | Description |
160 /// |:--------:|:---:|:---------------------------------------------------|
161 /// | SEEK_SET | 0 | position is relative to the beginning of the file. This is probably what you had in mind anyway, and is the most commonly used value for whence.
162 /// | SEEK_CUR | 1 | position is relative to the current file pointer position. So, in effect, you can say, "Move to my current position plus 30 bytes," or, "move to my current position minus 20 bytes."
163 /// | SEEK_END | 2 | position is relative to the end of the file. Just like SEEK_SET except from the other end of the file. Be sure to use negative values for offset if you want to back up from the end of the file, instead of going past the end into oblivion.
164 ///
165 /// \return Returns the resulting offset location as
166 /// measured in bytes from the beginning of
167 /// the file. On error, the value -1 is
168 /// returned.
169 int64_t Seek(int64_t position, int whence = SEEK_SET)
170 {
171 return m_instanceData->toKodi.seek(m_instanceData->toKodi.kodiInstance, position, whence);
172 }
173 //--------------------------------------------------------------------------
174
175 private:
176 void SetAddonStruct(KODI_HANDLE instance)
177 {
178 if (instance == nullptr)
179 throw std::logic_error("kodi::addon::CInstanceAudioEncoder: Creation with empty addon structure not allowed, table must be given from Kodi!");
180
181 m_instanceData = static_cast<AddonInstance_AudioEncoder*>(instance);
182 m_instanceData->toAddon.addonInstance = this;
183 m_instanceData->toAddon.start = ADDON_Start;
184 m_instanceData->toAddon.encode = ADDON_Encode;
185 m_instanceData->toAddon.finish = ADDON_Finish;
186 }
187
188 inline static bool ADDON_Start(const AddonInstance_AudioEncoder* instance, int inChannels, int inRate, int inBits,
189 const char* title, const char* artist,
190 const char* albumartist, const char* album,
191 const char* year, const char* track,
192 const char* genre, const char* comment,
193 int trackLength)
194 {
195 return instance->toAddon.addonInstance->Start(inChannels,
196 inRate,
197 inBits,
198 title,
199 artist,
200 albumartist,
201 album,
202 year,
203 track,
204 genre,
205 comment,
206 trackLength);
207 }
208
209 inline static int ADDON_Encode(const AddonInstance_AudioEncoder* instance, int numBytesRead, const uint8_t* pbtStream)
210 {
211 return instance->toAddon.addonInstance->Encode(numBytesRead, pbtStream);
212 }
213
214 inline static bool ADDON_Finish(const AddonInstance_AudioEncoder* instance)
215 {
216 return instance->toAddon.addonInstance->Finish();
217 }
218
219 AddonInstance_AudioEncoder* m_instanceData;
220 };
221
222} /* namespace addon */
223} /* namespace kodi */