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