diff options
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h | 595 |
1 files changed, 595 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h new file mode 100644 index 0000000..a6bea7d --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h | |||
| @@ -0,0 +1,595 @@ | |||
| 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 | #include "../AudioEngine.h" | ||
| 13 | #include "../c-api/addon-instance/audio_decoder.h" | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace addon | ||
| 19 | { | ||
| 20 | |||
| 21 | class CInstanceAudioDecoder; | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_addon_audiodecoder_Defs_AudioDecoderInfoTag class AudioDecoderInfoTag | ||
| 25 | /// @ingroup cpp_kodi_addon_audiodecoder_Defs | ||
| 26 | /// @brief **Info tag data structure**\n | ||
| 27 | /// Representation of available information of processed audio file. | ||
| 28 | /// | ||
| 29 | /// This is used to store all the necessary data of audio stream and to have on | ||
| 30 | /// e.g. GUI for information. | ||
| 31 | /// | ||
| 32 | /// ---------------------------------------------------------------------------- | ||
| 33 | /// | ||
| 34 | /// @copydetails cpp_kodi_addon_audiodecoder_Defs_AudioDecoderInfoTag_Help | ||
| 35 | /// | ||
| 36 | ///@{ | ||
| 37 | class AudioDecoderInfoTag : public CStructHdl<AudioDecoderInfoTag, AUDIO_DECODER_INFO_TAG> | ||
| 38 | { | ||
| 39 | /*! \cond PRIVATE */ | ||
| 40 | friend class CInstanceAudioDecoder; | ||
| 41 | /*! \endcond */ | ||
| 42 | |||
| 43 | public: | ||
| 44 | /*! \cond PRIVATE */ | ||
| 45 | AudioDecoderInfoTag() { memset(m_cStructure, 0, sizeof(AUDIO_DECODER_INFO_TAG)); } | ||
| 46 | AudioDecoderInfoTag(const AudioDecoderInfoTag& tag) : CStructHdl(tag) {} | ||
| 47 | /*! \endcond */ | ||
| 48 | |||
| 49 | /// @defgroup cpp_kodi_addon_audiodecoder_Defs_AudioDecoderInfoTag_Help Value Help | ||
| 50 | /// @ingroup cpp_kodi_addon_audiodecoder_Defs_AudioDecoderInfoTag | ||
| 51 | /// | ||
| 52 | /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_audiodecoder_Defs_AudioDecoderInfoTag :</b> | ||
| 53 | /// | Name | Type | Set call | Get call | ||
| 54 | /// |------|------|----------|---------- | ||
| 55 | /// | **Title** | `std::string` | @ref AudioDecoderInfoTag::SetTitle "SetTitle" | @ref AudioDecoderInfoTag::GetTitle "GetTitle" | ||
| 56 | /// | **Artist** | `std::string` | @ref AudioDecoderInfoTag::SetArtist "SetArtist" | @ref AudioDecoderInfoTag::GetArtist "GetArtist" | ||
| 57 | /// | **Album** | `std::string` | @ref AudioDecoderInfoTag::SetAlbum "SetAlbum" | @ref AudioDecoderInfoTag::GetAlbum "GetAlbum" | ||
| 58 | /// | **Album artist** | `std::string` | @ref AudioDecoderInfoTag::SetAlbumArtist "SetAlbumArtist" | @ref AudioDecoderInfoTag::GetAlbumArtist "GetAlbumArtist" | ||
| 59 | /// | **Media type** | `std::string` | @ref AudioDecoderInfoTag::SetMediaType "SetMediaType" | @ref AudioDecoderInfoTag::GetMediaType "GetMediaType" | ||
| 60 | /// | **Genre** | `std::string` | @ref AudioDecoderInfoTag::SetGenre "SetGenre" | @ref AudioDecoderInfoTag::GetGenre "GetGenre" | ||
| 61 | /// | **Duration** | `int` | @ref AudioDecoderInfoTag::SetDuration "SetDuration" | @ref AudioDecoderInfoTag::GetDuration "GetDuration" | ||
| 62 | /// | **Track number** | `int` | @ref AudioDecoderInfoTag::SetTrack "SetTrack" | @ref AudioDecoderInfoTag::GetTrack "GetTrack" | ||
| 63 | /// | **Disc number** | `int` | @ref AudioDecoderInfoTag::SetDisc "SetDisc" | @ref AudioDecoderInfoTag::GetDisc "GetDisc" | ||
| 64 | /// | **Disc subtitle name** | `std::string` | @ref AudioDecoderInfoTag::SetDiscSubtitle "SetDiscSubtitle" | @ref AudioDecoderInfoTag::GetDiscSubtitle "GetDiscSubtitle" | ||
| 65 | /// | **Disc total amount** | `int` | @ref AudioDecoderInfoTag::SetDiscTotal "SetDiscTotal" | @ref AudioDecoderInfoTag::GetDiscTotal "GetDiscTotal" | ||
| 66 | /// | **Release date** | `std::string` | @ref AudioDecoderInfoTag::SetReleaseDate "SetReleaseDate" | @ref AudioDecoderInfoTag::GetReleaseDate "GetReleaseDate" | ||
| 67 | /// | **Lyrics** | `std::string` | @ref AudioDecoderInfoTag::SetLyrics "SetLyrics" | @ref AudioDecoderInfoTag::GetLyrics "GetLyrics" | ||
| 68 | /// | **Samplerate** | `int` | @ref AudioDecoderInfoTag::SetSamplerate "SetSamplerate" | @ref AudioDecoderInfoTag::GetSamplerate "GetSamplerate" | ||
| 69 | /// | **Channels amount** | `int` | @ref AudioDecoderInfoTag::SetChannels "SetChannels" | @ref AudioDecoderInfoTag::GetChannels "GetChannels" | ||
| 70 | /// | **Bitrate** | `int` | @ref AudioDecoderInfoTag::SetBitrate "SetBitrate" | @ref AudioDecoderInfoTag::GetBitrate "GetBitrate" | ||
| 71 | /// | **Comment text** | `std::string` | @ref AudioDecoderInfoTag::SetComment "SetComment" | @ref AudioDecoderInfoTag::GetComment "GetComment" | ||
| 72 | /// | ||
| 73 | |||
| 74 | /// @addtogroup cpp_kodi_addon_audiodecoder_Defs_AudioDecoderInfoTag | ||
| 75 | ///@{ | ||
| 76 | |||
| 77 | /// @brief Set the title from music as string on info tag. | ||
| 78 | void SetTitle(const std::string& title) | ||
| 79 | { | ||
| 80 | strncpy(m_cStructure->title, title.c_str(), sizeof(m_cStructure->title) - 1); | ||
| 81 | } | ||
| 82 | |||
| 83 | /// @brief Get title name | ||
| 84 | std::string GetTitle() const { return m_cStructure->title; } | ||
| 85 | |||
| 86 | /// @brief Set artist name | ||
| 87 | void SetArtist(const std::string& artist) | ||
| 88 | { | ||
| 89 | strncpy(m_cStructure->artist, artist.c_str(), sizeof(m_cStructure->artist) - 1); | ||
| 90 | } | ||
| 91 | |||
| 92 | /// @brief Get artist name | ||
| 93 | std::string GetArtist() const { return m_cStructure->artist; } | ||
| 94 | |||
| 95 | /// @brief Set album name | ||
| 96 | void SetAlbum(const std::string& album) | ||
| 97 | { | ||
| 98 | strncpy(m_cStructure->album, album.c_str(), sizeof(m_cStructure->album) - 1); | ||
| 99 | } | ||
| 100 | |||
| 101 | /// @brief Set album name | ||
| 102 | std::string GetAlbum() const { return m_cStructure->album; } | ||
| 103 | |||
| 104 | /// @brief Set album artist name | ||
| 105 | void SetAlbumArtist(const std::string& albumArtist) | ||
| 106 | { | ||
| 107 | strncpy(m_cStructure->album_artist, albumArtist.c_str(), | ||
| 108 | sizeof(m_cStructure->album_artist) - 1); | ||
| 109 | } | ||
| 110 | |||
| 111 | /// @brief Get album artist name | ||
| 112 | std::string GetAlbumArtist() const { return m_cStructure->album_artist; } | ||
| 113 | |||
| 114 | /// @brief Set the media type of the music item. | ||
| 115 | /// | ||
| 116 | /// Available strings about media type for music: | ||
| 117 | /// | String | Description | | ||
| 118 | /// |---------------:|:--------------------------------------------------| | ||
| 119 | /// | artist | If it is defined as an artist | ||
| 120 | /// | album | If it is defined as an album | ||
| 121 | /// | music | If it is defined as an music | ||
| 122 | /// | song | If it is defined as a song | ||
| 123 | /// | ||
| 124 | void SetMediaType(const std::string& mediaType) | ||
| 125 | { | ||
| 126 | strncpy(m_cStructure->media_type, mediaType.c_str(), sizeof(m_cStructure->media_type) - 1); | ||
| 127 | } | ||
| 128 | |||
| 129 | /// @brief Get the media type of the music item. | ||
| 130 | std::string GetMediaType() const { return m_cStructure->media_type; } | ||
| 131 | |||
| 132 | /// @brief Set genre name from music as string if present. | ||
| 133 | void SetGenre(const std::string& genre) | ||
| 134 | { | ||
| 135 | strncpy(m_cStructure->genre, genre.c_str(), sizeof(m_cStructure->genre) - 1); | ||
| 136 | } | ||
| 137 | |||
| 138 | /// @brief Get genre name from music as string if present. | ||
| 139 | std::string GetGenre() const { return m_cStructure->genre; } | ||
| 140 | |||
| 141 | /// @brief Set the duration of music as integer from info. | ||
| 142 | void SetDuration(int duration) { m_cStructure->duration = duration; } | ||
| 143 | |||
| 144 | /// @brief Get the duration of music as integer from info. | ||
| 145 | int GetDuration() const { return m_cStructure->duration; } | ||
| 146 | |||
| 147 | /// @brief Set track number (if present) from music info as integer. | ||
| 148 | void SetTrack(int track) { m_cStructure->track = track; } | ||
| 149 | |||
| 150 | /// @brief Get track number (if present). | ||
| 151 | int GetTrack() const { return m_cStructure->track; } | ||
| 152 | |||
| 153 | /// @brief Set disk number (if present) from music info as integer. | ||
| 154 | void SetDisc(int disc) { m_cStructure->disc = disc; } | ||
| 155 | |||
| 156 | /// @brief Get disk number (if present) | ||
| 157 | int GetDisc() const { return m_cStructure->disc; } | ||
| 158 | |||
| 159 | /// @brief Set disk subtitle name (if present) from music info. | ||
| 160 | void SetDiscSubtitle(const std::string& discSubtitle) | ||
| 161 | { | ||
| 162 | strncpy(m_cStructure->disc_subtitle, discSubtitle.c_str(), | ||
| 163 | sizeof(m_cStructure->disc_subtitle) - 1); | ||
| 164 | } | ||
| 165 | |||
| 166 | /// @brief Get disk subtitle name (if present) from music info. | ||
| 167 | std::string GetDiscSubtitle() const { return m_cStructure->disc_subtitle; } | ||
| 168 | |||
| 169 | /// @brief Set disks amount quantity (if present) from music info as integer. | ||
| 170 | void SetDiscTotal(int discTotal) { m_cStructure->disc_total = discTotal; } | ||
| 171 | |||
| 172 | /// @brief Get disks amount quantity (if present) | ||
| 173 | int GetDiscTotal() const { return m_cStructure->disc_total; } | ||
| 174 | |||
| 175 | /// @brief Set release date as string from music info (if present).\n | ||
| 176 | /// [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) date YYYY, YYYY-MM or YYYY-MM-DD | ||
| 177 | void SetReleaseDate(const std::string& releaseDate) | ||
| 178 | { | ||
| 179 | strncpy(m_cStructure->release_date, releaseDate.c_str(), | ||
| 180 | sizeof(m_cStructure->release_date) - 1); | ||
| 181 | } | ||
| 182 | |||
| 183 | /// @brief Get release date as string from music info (if present). | ||
| 184 | std::string GetReleaseDate() const { return m_cStructure->release_date; } | ||
| 185 | |||
| 186 | /// @brief Set string from lyrics. | ||
| 187 | void SetLyrics(const std::string& lyrics) | ||
| 188 | { | ||
| 189 | strncpy(m_cStructure->lyrics, lyrics.c_str(), sizeof(m_cStructure->lyrics) - 1); | ||
| 190 | } | ||
| 191 | |||
| 192 | /// @brief Get string from lyrics. | ||
| 193 | std::string GetLyrics() const { return m_cStructure->lyrics; } | ||
| 194 | |||
| 195 | /// @brief Set related stream samplerate. | ||
| 196 | void SetSamplerate(int samplerate) { m_cStructure->samplerate = samplerate; } | ||
| 197 | |||
| 198 | /// @brief Get related stream samplerate. | ||
| 199 | int GetSamplerate() const { return m_cStructure->samplerate; } | ||
| 200 | |||
| 201 | /// @brief Set related stream channels amount. | ||
| 202 | void SetChannels(int channels) { m_cStructure->channels = channels; } | ||
| 203 | |||
| 204 | /// @brief Get related stream channels amount. | ||
| 205 | int GetChannels() const { return m_cStructure->channels; } | ||
| 206 | |||
| 207 | /// @brief Set related stream bitrate. | ||
| 208 | void SetBitrate(int bitrate) { m_cStructure->bitrate = bitrate; } | ||
| 209 | |||
| 210 | /// @brief Get related stream bitrate. | ||
| 211 | int GetBitrate() const { return m_cStructure->bitrate; } | ||
| 212 | |||
| 213 | /// @brief Set additional information comment (if present). | ||
| 214 | void SetComment(const std::string& comment) | ||
| 215 | { | ||
| 216 | strncpy(m_cStructure->comment, comment.c_str(), sizeof(m_cStructure->comment) - 1); | ||
| 217 | } | ||
| 218 | |||
| 219 | /// @brief Get additional information comment (if present). | ||
| 220 | std::string GetComment() const { return m_cStructure->comment; } | ||
| 221 | |||
| 222 | ///@} | ||
| 223 | |||
| 224 | private: | ||
| 225 | AudioDecoderInfoTag(const AUDIO_DECODER_INFO_TAG* tag) : CStructHdl(tag) {} | ||
| 226 | AudioDecoderInfoTag(AUDIO_DECODER_INFO_TAG* tag) : CStructHdl(tag) {} | ||
| 227 | }; | ||
| 228 | ///@} | ||
| 229 | //------------------------------------------------------------------------------ | ||
| 230 | |||
| 231 | //============================================================================== | ||
| 232 | /// @defgroup cpp_kodi_addon_audiodecoder_Defs Definitions, structures and enumerators | ||
| 233 | /// @ingroup cpp_kodi_addon_audiodecoder | ||
| 234 | /// @brief **Audio decoder add-on instance definition values**\n | ||
| 235 | /// All audio decoder functions associated data structures. | ||
| 236 | /// | ||
| 237 | /// Used to exchange the available options between Kodi and addon.\n | ||
| 238 | /// The groups described here correspond to the groups of functions on audio | ||
| 239 | /// decoder instance class. | ||
| 240 | /// | ||
| 241 | |||
| 242 | //============================================================================== | ||
| 243 | /// | ||
| 244 | /// \addtogroup cpp_kodi_addon_audiodecoder | ||
| 245 | /// @brief \cpp_class{ kodi::addon::CInstanceAudioDecoder } | ||
| 246 | /// **Audio decoder add-on instance** | ||
| 247 | /// | ||
| 248 | /// For audio decoders as binary add-ons. This class implements a way to handle | ||
| 249 | /// special types of audio files. | ||
| 250 | /// | ||
| 251 | /// The add-on handles loading of the source file and outputting the audio stream | ||
| 252 | /// for consumption by the player. | ||
| 253 | /// | ||
| 254 | /// The addon.xml defines the capabilities of this add-on. | ||
| 255 | /// | ||
| 256 | /// @note The option to have multiple instances is possible with audio-decoder | ||
| 257 | /// add-ons. This is useful, since some playback engines are riddled by global | ||
| 258 | /// variables, making decoding of multiple streams using the same instance | ||
| 259 | /// impossible. | ||
| 260 | /// | ||
| 261 | /// | ||
| 262 | /// ---------------------------------------------------------------------------- | ||
| 263 | /// | ||
| 264 | /// **Here's an example on addon.xml:** | ||
| 265 | /// ~~~~~~~~~~~~~{.xml} | ||
| 266 | /// <?xml version="1.0" encoding="UTF-8"?> | ||
| 267 | /// <addon | ||
| 268 | /// id="audiodecoder.myspecialnamefor" | ||
| 269 | /// version="1.0.0" | ||
| 270 | /// name="My special audio decoder addon" | ||
| 271 | /// provider-name="Your Name"> | ||
| 272 | /// <requires>@ADDON_DEPENDS@</requires> | ||
| 273 | /// <extension | ||
| 274 | /// point="kodi.audiodecoder" | ||
| 275 | /// name="2sf" | ||
| 276 | /// extension=".2sf|.mini2sf" | ||
| 277 | /// tags="true" | ||
| 278 | /// library_@PLATFORM@="@LIBRARY_FILENAME@"/> | ||
| 279 | /// <extension point="xbmc.addon.metadata"> | ||
| 280 | /// <summary lang="en_GB">My audio decoder addon addon</summary> | ||
| 281 | /// <description lang="en_GB">My audio decoder addon description</description> | ||
| 282 | /// <platform>@PLATFORM@</platform> | ||
| 283 | /// </extension> | ||
| 284 | /// </addon> | ||
| 285 | /// ~~~~~~~~~~~~~ | ||
| 286 | /// | ||
| 287 | /// Description to audio decoder related addon.xml values: | ||
| 288 | /// | Name | Description | ||
| 289 | /// |:------------------------------|---------------------------------------- | ||
| 290 | /// | <b>`point`</b> | Addon type specification<br>At all addon types and for this kind always <b>"kodi.audiodecoder"</b>. | ||
| 291 | /// | <b>`library_@PLATFORM@`</b> | Sets the used library name, which is automatically set by cmake at addon build. | ||
| 292 | /// | <b>`name`</b> | The name of the decoder used in Kodi for display. | ||
| 293 | /// | <b>`extension`</b> | The file extensions / styles supported by this addon. | ||
| 294 | /// | <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. | ||
| 295 | /// | ||
| 296 | /// -------------------------------------------------------------------------- | ||
| 297 | /// | ||
| 298 | /// **Here is a code example how this addon is used:** | ||
| 299 | /// | ||
| 300 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 301 | /// #include <kodi/addon-instance/AudioDecoder.h> | ||
| 302 | /// | ||
| 303 | /// class CMyAudioDecoder : public kodi::addon::CInstanceAudioDecoder | ||
| 304 | /// { | ||
| 305 | /// public: | ||
| 306 | /// CMyAudioDecoder(KODI_HANDLE instance, const std::string& version); | ||
| 307 | /// | ||
| 308 | /// bool Init(const std::string& filename, unsigned int filecache, | ||
| 309 | /// int& channels, int& samplerate, | ||
| 310 | /// int& bitspersample, int64_t& totaltime, | ||
| 311 | /// int& bitrate, AudioEngineDataFormat& format, | ||
| 312 | /// std::vector<AudioEngineChannel>& channellist) override; | ||
| 313 | /// int ReadPCM(uint8_t* buffer, int size, int& actualsize) override; | ||
| 314 | /// }; | ||
| 315 | /// | ||
| 316 | /// CMyAudioDecoder::CMyAudioDecoder(KODI_HANDLE instance, const std::string& version) | ||
| 317 | /// : kodi::addon::CInstanceAudioDecoder(instance, version) | ||
| 318 | /// { | ||
| 319 | /// ... | ||
| 320 | /// } | ||
| 321 | /// | ||
| 322 | /// bool CMyAudioDecoder::Init(const std::string& filename, unsigned int filecache, | ||
| 323 | /// int& channels, int& samplerate, | ||
| 324 | /// int& bitspersample, int64_t& totaltime, | ||
| 325 | /// int& bitrate, AudioEngineDataFormat& format, | ||
| 326 | /// std::vector<AudioEngineChannel>& channellist) | ||
| 327 | /// { | ||
| 328 | /// ... | ||
| 329 | /// return true; | ||
| 330 | /// } | ||
| 331 | /// | ||
| 332 | /// int CMyAudioDecoder::ReadPCM(uint8_t* buffer, int size, int& actualsize) | ||
| 333 | /// { | ||
| 334 | /// ... | ||
| 335 | /// return 0; | ||
| 336 | /// } | ||
| 337 | /// | ||
| 338 | /// | ||
| 339 | /// //---------------------------------------------------------------------- | ||
| 340 | /// | ||
| 341 | /// class CMyAddon : public kodi::addon::CAddonBase | ||
| 342 | /// { | ||
| 343 | /// public: | ||
| 344 | /// CMyAddon() { } | ||
| 345 | /// ADDON_STATUS CreateInstance(int instanceType, | ||
| 346 | /// const std::string& instanceID, | ||
| 347 | /// KODI_HANDLE instance, | ||
| 348 | /// const std::string& version, | ||
| 349 | /// KODI_HANDLE& addonInstance) override; | ||
| 350 | /// }; | ||
| 351 | /// | ||
| 352 | /// // If you use only one instance in your add-on, can be instanceType and | ||
| 353 | /// // instanceID ignored | ||
| 354 | /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType, | ||
| 355 | /// const std::string& instanceID, | ||
| 356 | /// KODI_HANDLE instance, | ||
| 357 | /// const std::string& version, | ||
| 358 | /// KODI_HANDLE& addonInstance) | ||
| 359 | /// { | ||
| 360 | /// if (instanceType == ADDON_INSTANCE_AUDIODECODER) | ||
| 361 | /// { | ||
| 362 | /// kodi::Log(ADDON_LOG_INFO, "Creating my audio decoder"); | ||
| 363 | /// addonInstance = new CMyAudioDecoder(instance, version); | ||
| 364 | /// return ADDON_STATUS_OK; | ||
| 365 | /// } | ||
| 366 | /// else if (...) | ||
| 367 | /// { | ||
| 368 | /// ... | ||
| 369 | /// } | ||
| 370 | /// return ADDON_STATUS_UNKNOWN; | ||
| 371 | /// } | ||
| 372 | /// | ||
| 373 | /// ADDONCREATOR(CMyAddon) | ||
| 374 | /// ~~~~~~~~~~~~~ | ||
| 375 | /// | ||
| 376 | /// The destruction of the example class `CMyAudioDecoder` is called from | ||
| 377 | /// Kodi's header. Manually deleting the add-on instance is not required. | ||
| 378 | /// | ||
| 379 | class ATTRIBUTE_HIDDEN CInstanceAudioDecoder : public IAddonInstance | ||
| 380 | { | ||
| 381 | public: | ||
| 382 | //========================================================================== | ||
| 383 | /// @ingroup cpp_kodi_addon_audiodecoder | ||
| 384 | /// @brief Audio decoder class constructor used to support multiple instance | ||
| 385 | /// types. | ||
| 386 | /// | ||
| 387 | /// @param[in] instance The instance value given to | ||
| 388 | /// <b>`kodi::addon::CAddonBase::CreateInstance(...)`</b>. | ||
| 389 | /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to | ||
| 390 | /// allow compatibility to older Kodi versions. | ||
| 391 | /// | ||
| 392 | /// @note Recommended to set <b>`kodiVersion`</b>. | ||
| 393 | /// | ||
| 394 | /// | ||
| 395 | /// -------------------------------------------------------------------------- | ||
| 396 | /// | ||
| 397 | /// **Here's example about the use of this:** | ||
| 398 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 399 | /// class CMyAudioDecoder : public kodi::addon::CInstanceAudioDecoder | ||
| 400 | /// { | ||
| 401 | /// public: | ||
| 402 | /// CMyAudioDecoder(KODI_HANDLE instance, const std::string& kodiVersion) | ||
| 403 | /// : kodi::addon::CInstanceAudioDecoder(instance, kodiVersion) | ||
| 404 | /// { | ||
| 405 | /// ... | ||
| 406 | /// } | ||
| 407 | /// | ||
| 408 | /// ... | ||
| 409 | /// }; | ||
| 410 | /// | ||
| 411 | /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType, | ||
| 412 | /// const std::string& instanceID, | ||
| 413 | /// KODI_HANDLE instance, | ||
| 414 | /// const std::string& version, | ||
| 415 | /// KODI_HANDLE& addonInstance) | ||
| 416 | /// { | ||
| 417 | /// kodi::Log(ADDON_LOG_INFO, "Creating my audio decoder"); | ||
| 418 | /// addonInstance = new CMyAudioDecoder(instance, version); | ||
| 419 | /// return ADDON_STATUS_OK; | ||
| 420 | /// } | ||
| 421 | /// ~~~~~~~~~~~~~ | ||
| 422 | /// | ||
| 423 | explicit CInstanceAudioDecoder(KODI_HANDLE instance, const std::string& kodiVersion = "") | ||
| 424 | : IAddonInstance(ADDON_INSTANCE_AUDIODECODER, | ||
| 425 | !kodiVersion.empty() ? kodiVersion | ||
| 426 | : GetKodiTypeVersion(ADDON_INSTANCE_AUDIODECODER)) | ||
| 427 | { | ||
| 428 | if (CAddonBase::m_interface->globalSingleInstance != nullptr) | ||
| 429 | throw std::logic_error("kodi::addon::CInstanceAudioDecoder: Creation of multiple together with single instance way is not allowed!"); | ||
| 430 | |||
| 431 | SetAddonStruct(instance); | ||
| 432 | } | ||
| 433 | //-------------------------------------------------------------------------- | ||
| 434 | |||
| 435 | //========================================================================== | ||
| 436 | /// @ingroup cpp_kodi_addon_audiodecoder | ||
| 437 | /// @brief Initialize a decoder. | ||
| 438 | /// | ||
| 439 | /// @param[in] filename The file to read | ||
| 440 | /// @param[in] filecache The file cache size | ||
| 441 | /// @param[out] channels Number of channels in output stream | ||
| 442 | /// @param[out] samplerate Samplerate of output stream | ||
| 443 | /// @param[out] bitspersample Bits per sample in output stream | ||
| 444 | /// @param[out] totaltime Total time for stream | ||
| 445 | /// @param[out] bitrate Average bitrate of input stream | ||
| 446 | /// @param[out] format Data format for output stream, see | ||
| 447 | /// @ref cpp_kodi_audioengine_Defs_AudioEngineFormat for | ||
| 448 | /// available values | ||
| 449 | /// @param[out] channellist Channel mapping for output streamm, see | ||
| 450 | /// @ref cpp_kodi_audioengine_Defs_AudioEngineChannel | ||
| 451 | /// for available values | ||
| 452 | /// @return true if successfully done, otherwise false | ||
| 453 | /// | ||
| 454 | virtual bool Init(const std::string& filename, | ||
| 455 | unsigned int filecache, | ||
| 456 | int& channels, | ||
| 457 | int& samplerate, | ||
| 458 | int& bitspersample, | ||
| 459 | int64_t& totaltime, | ||
| 460 | int& bitrate, | ||
| 461 | AudioEngineDataFormat& format, | ||
| 462 | std::vector<AudioEngineChannel>& channellist) = 0; | ||
| 463 | //-------------------------------------------------------------------------- | ||
| 464 | |||
| 465 | //========================================================================== | ||
| 466 | /// @ingroup cpp_kodi_addon_audiodecoder | ||
| 467 | /// @brief Produce some noise. | ||
| 468 | /// | ||
| 469 | /// @param[in] buffer Output buffer | ||
| 470 | /// @param[in] size Size of output buffer | ||
| 471 | /// @param[out] actualsize Actual number of bytes written to output buffer | ||
| 472 | /// @return Return with following possible values: | ||
| 473 | /// | Value | Description | ||
| 474 | /// |:-----:|:------------ | ||
| 475 | /// | 0 | on success | ||
| 476 | /// | -1 | on end of stream | ||
| 477 | /// | 1 | on failure | ||
| 478 | /// | ||
| 479 | virtual int ReadPCM(uint8_t* buffer, int size, int& actualsize) = 0; | ||
| 480 | //-------------------------------------------------------------------------- | ||
| 481 | |||
| 482 | //========================================================================== | ||
| 483 | /// @ingroup cpp_kodi_addon_audiodecoder | ||
| 484 | /// @brief Seek in output stream. | ||
| 485 | /// | ||
| 486 | /// @param[in] time Time position to seek to in milliseconds | ||
| 487 | /// @return Time position seek ended up on | ||
| 488 | /// | ||
| 489 | virtual int64_t Seek(int64_t time) { return time; } | ||
| 490 | //-------------------------------------------------------------------------- | ||
| 491 | |||
| 492 | //========================================================================== | ||
| 493 | /// @ingroup cpp_kodi_addon_audiodecoder | ||
| 494 | /// @brief Read tag of a file. | ||
| 495 | /// | ||
| 496 | /// @param[in] file File to read tag for | ||
| 497 | /// @param[out] tag Information tag about | ||
| 498 | /// @return True on success, false on failure | ||
| 499 | /// | ||
| 500 | /// -------------------------------------------------------------------------- | ||
| 501 | /// | ||
| 502 | /// @copydetails cpp_kodi_addon_audiodecoder_Defs_AudioDecoderInfoTag_Help | ||
| 503 | /// | ||
| 504 | virtual bool ReadTag(const std::string& file, kodi::addon::AudioDecoderInfoTag& tag) | ||
| 505 | { | ||
| 506 | return false; | ||
| 507 | } | ||
| 508 | //-------------------------------------------------------------------------- | ||
| 509 | |||
| 510 | //========================================================================== | ||
| 511 | /// @ingroup cpp_kodi_addon_audiodecoder | ||
| 512 | /// @brief Get number of tracks in a file. | ||
| 513 | /// | ||
| 514 | /// @param[in] file File to read tag for | ||
| 515 | /// @return Number of tracks in file | ||
| 516 | /// | ||
| 517 | virtual int TrackCount(const std::string& file) { return 1; } | ||
| 518 | //-------------------------------------------------------------------------- | ||
| 519 | |||
| 520 | private: | ||
| 521 | void SetAddonStruct(KODI_HANDLE instance) | ||
| 522 | { | ||
| 523 | if (instance == nullptr) | ||
| 524 | throw std::logic_error("kodi::addon::CInstanceAudioDecoder: Creation with empty addon structure not allowed, table must be given from Kodi!"); | ||
| 525 | |||
| 526 | m_instanceData = static_cast<AddonInstance_AudioDecoder*>(instance); | ||
| 527 | |||
| 528 | m_instanceData->toAddon->addonInstance = this; | ||
| 529 | m_instanceData->toAddon->init = ADDON_Init; | ||
| 530 | m_instanceData->toAddon->read_pcm = ADDON_ReadPCM; | ||
| 531 | m_instanceData->toAddon->seek = ADDON_Seek; | ||
| 532 | m_instanceData->toAddon->read_tag = ADDON_ReadTag; | ||
| 533 | m_instanceData->toAddon->track_count = ADDON_TrackCount; | ||
| 534 | } | ||
| 535 | |||
| 536 | inline static bool ADDON_Init(const AddonInstance_AudioDecoder* instance, | ||
| 537 | const char* file, | ||
| 538 | unsigned int filecache, | ||
| 539 | int* channels, | ||
| 540 | int* samplerate, | ||
| 541 | int* bitspersample, | ||
| 542 | int64_t* totaltime, | ||
| 543 | int* bitrate, | ||
| 544 | AudioEngineDataFormat* format, | ||
| 545 | const AudioEngineChannel** info) | ||
| 546 | { | ||
| 547 | CInstanceAudioDecoder* thisClass = | ||
| 548 | static_cast<CInstanceAudioDecoder*>(instance->toAddon->addonInstance); | ||
| 549 | |||
| 550 | thisClass->m_channelList.clear(); | ||
| 551 | bool ret = thisClass->Init(file, filecache, *channels, *samplerate, *bitspersample, *totaltime, | ||
| 552 | *bitrate, *format, thisClass->m_channelList); | ||
| 553 | if (!thisClass->m_channelList.empty()) | ||
| 554 | { | ||
| 555 | if (thisClass->m_channelList.back() != AUDIOENGINE_CH_NULL) | ||
| 556 | thisClass->m_channelList.push_back(AUDIOENGINE_CH_NULL); | ||
| 557 | *info = thisClass->m_channelList.data(); | ||
| 558 | } | ||
| 559 | else | ||
| 560 | *info = nullptr; | ||
| 561 | return ret; | ||
| 562 | } | ||
| 563 | |||
| 564 | inline static int ADDON_ReadPCM(const AddonInstance_AudioDecoder* instance, uint8_t* buffer, int size, int* actualsize) | ||
| 565 | { | ||
| 566 | return static_cast<CInstanceAudioDecoder*>(instance->toAddon->addonInstance) | ||
| 567 | ->ReadPCM(buffer, size, *actualsize); | ||
| 568 | } | ||
| 569 | |||
| 570 | inline static int64_t ADDON_Seek(const AddonInstance_AudioDecoder* instance, int64_t time) | ||
| 571 | { | ||
| 572 | return static_cast<CInstanceAudioDecoder*>(instance->toAddon->addonInstance)->Seek(time); | ||
| 573 | } | ||
| 574 | |||
| 575 | inline static bool ADDON_ReadTag(const AddonInstance_AudioDecoder* instance, | ||
| 576 | const char* file, | ||
| 577 | struct AUDIO_DECODER_INFO_TAG* tag) | ||
| 578 | { | ||
| 579 | kodi::addon::AudioDecoderInfoTag cppTag(tag); | ||
| 580 | return static_cast<CInstanceAudioDecoder*>(instance->toAddon->addonInstance) | ||
| 581 | ->ReadTag(file, cppTag); | ||
| 582 | } | ||
| 583 | |||
| 584 | inline static int ADDON_TrackCount(const AddonInstance_AudioDecoder* instance, const char* file) | ||
| 585 | { | ||
| 586 | return static_cast<CInstanceAudioDecoder*>(instance->toAddon->addonInstance)->TrackCount(file); | ||
| 587 | } | ||
| 588 | |||
| 589 | std::vector<AudioEngineChannel> m_channelList; | ||
| 590 | AddonInstance_AudioDecoder* m_instanceData; | ||
| 591 | }; | ||
| 592 | |||
| 593 | } /* namespace addon */ | ||
| 594 | } /* namespace kodi */ | ||
| 595 | #endif /* __cplusplus */ | ||
