diff options
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/AudioEngine.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/AudioEngine.h | 618 |
1 files changed, 618 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/AudioEngine.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/AudioEngine.h new file mode 100644 index 0000000..0cfefac --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/AudioEngine.h | |||
| @@ -0,0 +1,618 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2019 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 "c-api/audio_engine.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace audioengine | ||
| 19 | { | ||
| 20 | |||
| 21 | //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ | ||
| 22 | // Main page text for audio engine group by Doxygen. | ||
| 23 | //{{{ | ||
| 24 | |||
| 25 | //============================================================================== | ||
| 26 | /// | ||
| 27 | /// @defgroup cpp_kodi_audioengine Interface - kodi::audioengine | ||
| 28 | /// @ingroup cpp | ||
| 29 | /// @brief **Audio engine functions**\n | ||
| 30 | /// This interface contains auxiliary functions and classes which allow an addon | ||
| 31 | /// to play their own individual audio stream in Kodi. | ||
| 32 | /// | ||
| 33 | /// Using @ref cpp_kodi_audioengine_CAEStream "kodi::audioengine::CAEStream", | ||
| 34 | /// a class can be created in this regard, about which the necessary stream data and | ||
| 35 | /// information are given to Kodi. | ||
| 36 | /// | ||
| 37 | /// Via @ref kodi::audioengine::GetCurrentSinkFormat(), the audio formats currently | ||
| 38 | /// processed in Kodi can be called up beforehand in order to adapt your own stream | ||
| 39 | /// to them. | ||
| 40 | /// | ||
| 41 | /// However, the created stream can also differ from this because Kodi changes | ||
| 42 | /// it to suit it. | ||
| 43 | /// | ||
| 44 | /// | ||
| 45 | /// ------------------------------------------------------------------------ | ||
| 46 | /// | ||
| 47 | /// **Example:** | ||
| 48 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 49 | /// | ||
| 50 | /// #include <kodi/AudioEngine.h> | ||
| 51 | /// | ||
| 52 | /// ... | ||
| 53 | /// | ||
| 54 | /// kodi::audioengine::AudioEngineFormat format; | ||
| 55 | /// if (!kodi::audioengine::GetCurrentSinkFormat(format)) | ||
| 56 | /// return false; | ||
| 57 | /// | ||
| 58 | /// format.SetDataFormat(AUDIOENGINE_FMT_FLOATP); | ||
| 59 | /// format.SetChannelLayout(std::vector<AudioEngineChannel>(AUDIOENGINE_CH_FL, AUDIOENGINE_CH_FR)); | ||
| 60 | /// | ||
| 61 | /// unsigned int myUsedSampleRate = format.GetSampleRate(); | ||
| 62 | /// | ||
| 63 | /// ... | ||
| 64 | /// | ||
| 65 | /// kodi::audioengine::CAEStream* stream = new kodi::audioengine::CAEStream(format, AUDIO_STREAM_AUTOSTART); | ||
| 66 | /// | ||
| 67 | /// ~~~~~~~~~~~~~ | ||
| 68 | /// | ||
| 69 | /// ------------------------------------------------------------------------ | ||
| 70 | /// | ||
| 71 | /// It has the header \ref AudioEngine.h "#include <kodi/AudioEngine.h>" be included | ||
| 72 | /// to enjoy it. | ||
| 73 | /// | ||
| 74 | //------------------------------------------------------------------------------ | ||
| 75 | |||
| 76 | //============================================================================== | ||
| 77 | /// | ||
| 78 | /// @defgroup cpp_kodi_audioengine_Defs Definitions, structures and enumerators | ||
| 79 | /// @ingroup cpp_kodi_audioengine | ||
| 80 | /// @brief **Library definition values**\n | ||
| 81 | /// All audio engine functions associated data structures. | ||
| 82 | /// | ||
| 83 | //------------------------------------------------------------------------------ | ||
| 84 | |||
| 85 | //}}} | ||
| 86 | |||
| 87 | //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ | ||
| 88 | // "C++" related audio engine definitions | ||
| 89 | //{{{ | ||
| 90 | |||
| 91 | //============================================================================== | ||
| 92 | /// @defgroup cpp_kodi_audioengine_Defs_AudioEngineFormat class AudioEngineFormat | ||
| 93 | /// @ingroup cpp_kodi_audioengine_Defs | ||
| 94 | /// @brief **Audio format structure**\n | ||
| 95 | /// The audio format structure that fully defines a stream's audio | ||
| 96 | /// information. | ||
| 97 | /// | ||
| 98 | /// With the help of this format information, Kodi adjusts its processing | ||
| 99 | /// accordingly. | ||
| 100 | /// | ||
| 101 | //@{ | ||
| 102 | class ATTRIBUTE_HIDDEN AudioEngineFormat | ||
| 103 | : public addon::CStructHdl<AudioEngineFormat, AUDIO_ENGINE_FORMAT> | ||
| 104 | { | ||
| 105 | public: | ||
| 106 | /*! \cond PRIVATE */ | ||
| 107 | AudioEngineFormat() | ||
| 108 | { | ||
| 109 | m_cStructure->m_dataFormat = AUDIOENGINE_FMT_INVALID; | ||
| 110 | m_cStructure->m_sampleRate = 0; | ||
| 111 | m_cStructure->m_encodedRate = 0; | ||
| 112 | m_cStructure->m_frames = 0; | ||
| 113 | m_cStructure->m_frameSize = 0; | ||
| 114 | m_cStructure->m_channelCount = 0; | ||
| 115 | |||
| 116 | for (size_t ch = 0; ch < AUDIOENGINE_CH_MAX; ++ch) | ||
| 117 | m_cStructure->m_channels[ch] = AUDIOENGINE_CH_NULL; | ||
| 118 | } | ||
| 119 | AudioEngineFormat(const AudioEngineFormat& channel) : CStructHdl(channel) {} | ||
| 120 | AudioEngineFormat(const AUDIO_ENGINE_FORMAT* channel) : CStructHdl(channel) {} | ||
| 121 | AudioEngineFormat(AUDIO_ENGINE_FORMAT* channel) : CStructHdl(channel) {} | ||
| 122 | /*! \endcond */ | ||
| 123 | |||
| 124 | /// @defgroup cpp_kodi_audioengine_Defs_AudioEngineFormat_Help *Value Help* | ||
| 125 | /// @ingroup cpp_kodi_audioengine_Defs_AudioEngineFormat | ||
| 126 | /// | ||
| 127 | /// <b>The following table contains values that can be set with @ref cpp_kodi_audioengine_Defs_AudioEngineFormat :</b> | ||
| 128 | /// | Name | Type | Set call | Get call | ||
| 129 | /// |------|------|----------|---------- | ||
| 130 | /// | **Data format**, see @ref AudioEngineDataFormat for available types | enum | @ref AudioEngineFormat::SetDataFormat "SetDataFormat" | @ref AudioEngineFormat::GetDataFormat "GetDataFormat" | ||
| 131 | /// | **Sample rate** | unsigned int | @ref AudioEngineFormat::SetSampleRate "SetSampleRate" | @ref AudioEngineFormat::GetSampleRate "GetSampleRate" | ||
| 132 | /// | **Encoded rate** | unsigned int | @ref AudioEngineFormat::SetEncodedRate "SetEncodedRate" | @ref AudioEngineFormat::GetEncodedRate "GetEncodedRate" | ||
| 133 | /// | **Channel layout**, see @ref AudioEngineChannel for available types | std::vector<enum AudioEngineChannel> | @ref AudioEngineFormat::SetChannelLayout "SetChannelLayout" | @ref AudioEngineFormat::GetChannelLayout "GetChannelLayout" | ||
| 134 | /// | **Frames amount** | unsigned int | @ref AudioEngineFormat::SetFramesAmount "SetFramesAmount" | @ref AudioEngineFormat::GetFramesAmount "GetFramesAmount" | ||
| 135 | /// | **Frame size** | unsigned int | @ref AudioEngineFormat::SetFrameSize "SetFrameSize" | @ref AudioEngineFormat::GetFrameSize "GetFrameSize" | ||
| 136 | /// | ||
| 137 | /// Further is @ref AudioEngineFormat::CompareFormat "CompareFormat" included to compare this class with another. | ||
| 138 | /// | ||
| 139 | |||
| 140 | /// @addtogroup cpp_kodi_audioengine_Defs_AudioEngineFormat | ||
| 141 | /// @copydetails cpp_kodi_audioengine_Defs_AudioEngineFormat_Help | ||
| 142 | //@{ | ||
| 143 | |||
| 144 | /// @brief The stream's data format (eg, AUDIOENGINE_FMT_S16LE) | ||
| 145 | void SetDataFormat(enum AudioEngineDataFormat format) { m_cStructure->m_dataFormat = format; } | ||
| 146 | |||
| 147 | /// @brief To get with @ref SetDataFormat changed values. | ||
| 148 | enum AudioEngineDataFormat GetDataFormat() const { return m_cStructure->m_dataFormat; } | ||
| 149 | |||
| 150 | /// @brief The stream's sample rate (eg, 48000) | ||
| 151 | void SetSampleRate(unsigned int rate) { m_cStructure->m_sampleRate = rate; } | ||
| 152 | |||
| 153 | /// @brief To get with @ref SetSampleRate changed values. | ||
| 154 | unsigned int GetSampleRate() const { return m_cStructure->m_sampleRate; } | ||
| 155 | |||
| 156 | /// @brief The encoded streams sample rate if a bitstream, otherwise undefined | ||
| 157 | void SetEncodedRate(unsigned int rate) { m_cStructure->m_encodedRate = rate; } | ||
| 158 | |||
| 159 | /// @brief To get with @ref SetEncodedRate changed values. | ||
| 160 | unsigned int GetEncodedRate() const { return m_cStructure->m_encodedRate; } | ||
| 161 | |||
| 162 | /// @brief The stream's channel layout | ||
| 163 | void SetChannelLayout(const std::vector<enum AudioEngineChannel>& layout) | ||
| 164 | { | ||
| 165 | // Reset first all to empty values to AUDIOENGINE_CH_NULL, in case given list is empty | ||
| 166 | m_cStructure->m_channelCount = 0; | ||
| 167 | for (size_t ch = 0; ch < AUDIOENGINE_CH_MAX; ++ch) | ||
| 168 | m_cStructure->m_channels[ch] = AUDIOENGINE_CH_NULL; | ||
| 169 | |||
| 170 | for (size_t ch = 0; ch < layout.size() && ch < AUDIOENGINE_CH_MAX; ++ch) | ||
| 171 | { | ||
| 172 | m_cStructure->m_channels[ch] = layout[ch]; | ||
| 173 | m_cStructure->m_channelCount++; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 177 | /// @brief To get with @ref SetChannelLayout changed values. | ||
| 178 | std::vector<enum AudioEngineChannel> GetChannelLayout() const | ||
| 179 | { | ||
| 180 | std::vector<enum AudioEngineChannel> channels; | ||
| 181 | for (size_t ch = 0; ch < AUDIOENGINE_CH_MAX; ++ch) | ||
| 182 | { | ||
| 183 | if (m_cStructure->m_channels[ch] == AUDIOENGINE_CH_NULL) | ||
| 184 | break; | ||
| 185 | |||
| 186 | channels.push_back(m_cStructure->m_channels[ch]); | ||
| 187 | } | ||
| 188 | return channels; | ||
| 189 | } | ||
| 190 | |||
| 191 | /// @brief The number of frames per period | ||
| 192 | void SetFramesAmount(unsigned int frames) { m_cStructure->m_frames = frames; } | ||
| 193 | |||
| 194 | /// @brief To get with @ref SetFramesAmount changed values. | ||
| 195 | unsigned int GetFramesAmount() const { return m_cStructure->m_frames; } | ||
| 196 | |||
| 197 | /// @brief The size of one frame in bytes | ||
| 198 | void SetFrameSize(unsigned int frameSize) { m_cStructure->m_frameSize = frameSize; } | ||
| 199 | |||
| 200 | /// @brief To get with @ref SetFrameSize changed values. | ||
| 201 | unsigned int GetFrameSize() const { return m_cStructure->m_frameSize; } | ||
| 202 | |||
| 203 | /// @brief Function to compare the format structure with another | ||
| 204 | bool CompareFormat(const AudioEngineFormat* fmt) | ||
| 205 | { | ||
| 206 | if (!fmt) | ||
| 207 | { | ||
| 208 | return false; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (m_cStructure->m_dataFormat != fmt->m_cStructure->m_dataFormat || | ||
| 212 | m_cStructure->m_sampleRate != fmt->m_cStructure->m_sampleRate || | ||
| 213 | m_cStructure->m_encodedRate != fmt->m_cStructure->m_encodedRate || | ||
| 214 | m_cStructure->m_frames != fmt->m_cStructure->m_frames || | ||
| 215 | m_cStructure->m_frameSize != fmt->m_cStructure->m_frameSize || | ||
| 216 | m_cStructure->m_channelCount != fmt->m_cStructure->m_channelCount) | ||
| 217 | { | ||
| 218 | return false; | ||
| 219 | } | ||
| 220 | |||
| 221 | for (unsigned int ch = 0; ch < AUDIOENGINE_CH_MAX; ++ch) | ||
| 222 | { | ||
| 223 | if (fmt->m_cStructure->m_channels[ch] != m_cStructure->m_channels[ch]) | ||
| 224 | { | ||
| 225 | return false; | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | return true; | ||
| 230 | } | ||
| 231 | }; | ||
| 232 | //@} | ||
| 233 | //---------------------------------------------------------------------------- | ||
| 234 | |||
| 235 | //}}} | ||
| 236 | |||
| 237 | //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ | ||
| 238 | // "C++" AudioEngine addon interface | ||
| 239 | //{{{ | ||
| 240 | |||
| 241 | //============================================================================ | ||
| 242 | /// | ||
| 243 | /// @defgroup cpp_kodi_audioengine_CAEStream class CAEStream | ||
| 244 | /// @ingroup cpp_kodi_audioengine | ||
| 245 | /// @brief **Audio Engine Stream Class**\n | ||
| 246 | /// Class that can be created by the addon in order to be able to transfer | ||
| 247 | /// audiostream data processed on the addon to Kodi and output it audibly. | ||
| 248 | /// | ||
| 249 | /// This can create individually several times and performed in different | ||
| 250 | /// processes simultaneously. | ||
| 251 | /// | ||
| 252 | /// It has the header @ref AudioEngine.h "#include <kodi/AudioEngine.h>" be | ||
| 253 | /// included to enjoy it. | ||
| 254 | /// | ||
| 255 | //---------------------------------------------------------------------------- | ||
| 256 | class ATTRIBUTE_HIDDEN CAEStream | ||
| 257 | { | ||
| 258 | public: | ||
| 259 | //========================================================================== | ||
| 260 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 261 | /// @brief Contructs new class to an Kodi IAEStream in the format specified. | ||
| 262 | /// | ||
| 263 | /// @param[in] format The data format the incoming audio will be in | ||
| 264 | /// (e.g. \ref AUDIOENGINE_FMT_S16LE) | ||
| 265 | /// @param[in] options [opt] A bit field of stream options (see: enum \ref AudioEngineStreamOptions) | ||
| 266 | /// | ||
| 267 | /// | ||
| 268 | /// ------------------------------------------------------------------------ | ||
| 269 | /// | ||
| 270 | /// @copydetails cpp_kodi_audioengine_Defs_AudioEngineFormat_Help | ||
| 271 | /// | ||
| 272 | /// ------------------------------------------------------------------------ | ||
| 273 | /// | ||
| 274 | /// **Bit options to pass (on Kodi by <c>IAE::MakeStream</c>)** | ||
| 275 | /// | ||
| 276 | /// | enum AEStreamOptions | Value: | Description: | ||
| 277 | /// |----------------------------:|:------:|:----------------------------------- | ||
| 278 | /// | AUDIO_STREAM_FORCE_RESAMPLE | 1 << 0 | Force resample even if rates match | ||
| 279 | /// | AUDIO_STREAM_PAUSED | 1 << 1 | Create the stream paused | ||
| 280 | /// | AUDIO_STREAM_AUTOSTART | 1 << 2 | Autostart the stream when enough data is buffered | ||
| 281 | /// | ||
| 282 | /// | ||
| 283 | /// ------------------------------------------------------------------------ | ||
| 284 | /// | ||
| 285 | /// **Example:** | ||
| 286 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 287 | /// | ||
| 288 | /// #include <kodi/AudioEngine.h> | ||
| 289 | /// | ||
| 290 | /// ... | ||
| 291 | /// | ||
| 292 | /// kodi::audioengine::AudioEngineFormat format; | ||
| 293 | /// | ||
| 294 | /// format.SetDataFormat(AUDIOENGINE_FMT_FLOATP); /* The stream's data format (eg, AUDIOENGINE_FMT_S16LE) */ | ||
| 295 | /// format.SetChannelLayout(std::vector<AudioEngineChannel>(AUDIOENGINE_CH_FL, AUDIOENGINE_CH_FR)); /* The stream's channel layout */ | ||
| 296 | /// format.SetSampleRate(48000); /* The stream's sample rate (eg, 48000) */ | ||
| 297 | /// format.SetFrameSize(sizeof(float)*2); /* The size of one frame in bytes */ | ||
| 298 | /// format.SetFramesAmount(882); /* The number of samples in one frame */ | ||
| 299 | /// | ||
| 300 | /// kodi::audioengine::CAEStream* stream = new kodi::audioengine::CAEStream(format, AUDIO_STREAM_AUTOSTART); | ||
| 301 | /// | ||
| 302 | /// ~~~~~~~~~~~~~ | ||
| 303 | /// | ||
| 304 | CAEStream(AudioEngineFormat& format, unsigned int options = 0) | ||
| 305 | : m_kodiBase(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase), | ||
| 306 | m_cb(::kodi::addon::CAddonBase::m_interface->toKodi->kodi_audioengine) | ||
| 307 | { | ||
| 308 | m_StreamHandle = m_cb->make_stream(m_kodiBase, format, options); | ||
| 309 | if (m_StreamHandle == nullptr) | ||
| 310 | { | ||
| 311 | kodi::Log(ADDON_LOG_FATAL, "CAEStream: make_stream failed!"); | ||
| 312 | } | ||
| 313 | } | ||
| 314 | //-------------------------------------------------------------------------- | ||
| 315 | |||
| 316 | //========================================================================== | ||
| 317 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 318 | /// @brief Class destructor. | ||
| 319 | /// | ||
| 320 | ~CAEStream() | ||
| 321 | { | ||
| 322 | if (m_StreamHandle) | ||
| 323 | { | ||
| 324 | m_cb->free_stream(m_kodiBase, m_StreamHandle); | ||
| 325 | m_StreamHandle = nullptr; | ||
| 326 | } | ||
| 327 | } | ||
| 328 | //-------------------------------------------------------------------------- | ||
| 329 | |||
| 330 | //========================================================================== | ||
| 331 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 332 | /// @brief Returns the amount of space available in the stream. | ||
| 333 | /// | ||
| 334 | /// @return The number of bytes AddData will consume | ||
| 335 | /// | ||
| 336 | unsigned int GetSpace() { return m_cb->aestream_get_space(m_kodiBase, m_StreamHandle); } | ||
| 337 | //-------------------------------------------------------------------------- | ||
| 338 | |||
| 339 | //========================================================================== | ||
| 340 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 341 | /// @brief Add planar or interleaved PCM data to the stream. | ||
| 342 | /// | ||
| 343 | /// @param[in] data array of pointers to the planes | ||
| 344 | /// @param[in] offset to frame in frames | ||
| 345 | /// @param[in] frames number of frames | ||
| 346 | /// @param[in] pts [opt] presentation timestamp, default is 0 | ||
| 347 | /// @param[in] hasDownmix [opt] set true if downmix is present, default is false | ||
| 348 | /// @param[in] centerMixLevel [opt] level to mix left and right to center default is 1.0 | ||
| 349 | /// @return The number of frames consumed | ||
| 350 | /// | ||
| 351 | unsigned int AddData(uint8_t* const* data, | ||
| 352 | unsigned int offset, | ||
| 353 | unsigned int frames, | ||
| 354 | double pts = 0, | ||
| 355 | bool hasDownmix = false, | ||
| 356 | double centerMixLevel = 1.0) | ||
| 357 | { | ||
| 358 | return m_cb->aestream_add_data(m_kodiBase, m_StreamHandle, data, offset, frames, pts, | ||
| 359 | hasDownmix, centerMixLevel); | ||
| 360 | } | ||
| 361 | //-------------------------------------------------------------------------- | ||
| 362 | |||
| 363 | //========================================================================== | ||
| 364 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 365 | /// @brief Returns the time in seconds that it will take for the next added | ||
| 366 | /// packet to be heard from the speakers. | ||
| 367 | /// | ||
| 368 | /// @return seconds | ||
| 369 | /// | ||
| 370 | double GetDelay() { return m_cb->aestream_get_delay(m_kodiBase, m_StreamHandle); } | ||
| 371 | //-------------------------------------------------------------------------- | ||
| 372 | |||
| 373 | //========================================================================== | ||
| 374 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 375 | /// @brief Returns if the stream is buffering. | ||
| 376 | /// | ||
| 377 | /// @return True if the stream is buffering | ||
| 378 | /// | ||
| 379 | bool IsBuffering() { return m_cb->aestream_is_buffering(m_kodiBase, m_StreamHandle); } | ||
| 380 | //-------------------------------------------------------------------------- | ||
| 381 | |||
| 382 | //========================================================================== | ||
| 383 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 384 | /// @brief Returns the time in seconds of the stream's cached audio samples. | ||
| 385 | /// Engine buffers excluded. | ||
| 386 | /// | ||
| 387 | /// @return seconds | ||
| 388 | /// | ||
| 389 | double GetCacheTime() { return m_cb->aestream_get_cache_time(m_kodiBase, m_StreamHandle); } | ||
| 390 | //-------------------------------------------------------------------------- | ||
| 391 | |||
| 392 | //========================================================================== | ||
| 393 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 394 | /// @brief Returns the total time in seconds of the cache. | ||
| 395 | /// | ||
| 396 | /// @return seconds | ||
| 397 | /// | ||
| 398 | double GetCacheTotal() { return m_cb->aestream_get_cache_total(m_kodiBase, m_StreamHandle); } | ||
| 399 | //-------------------------------------------------------------------------- | ||
| 400 | |||
| 401 | //========================================================================== | ||
| 402 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 403 | /// @brief Pauses the stream playback. | ||
| 404 | /// | ||
| 405 | void Pause() { return m_cb->aestream_pause(m_kodiBase, m_StreamHandle); } | ||
| 406 | //-------------------------------------------------------------------------- | ||
| 407 | |||
| 408 | //========================================================================== | ||
| 409 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 410 | /// @brief Resumes the stream after pausing | ||
| 411 | /// | ||
| 412 | void Resume() { return m_cb->aestream_resume(m_kodiBase, m_StreamHandle); } | ||
| 413 | //-------------------------------------------------------------------------- | ||
| 414 | |||
| 415 | //========================================================================== | ||
| 416 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 417 | /// @brief Start draining the stream. | ||
| 418 | /// | ||
| 419 | /// @param[in] wait [opt] Wait until drain is finished if set to true, | ||
| 420 | /// otherwise it returns direct | ||
| 421 | /// | ||
| 422 | /// @note Once called AddData will not consume more data. | ||
| 423 | /// | ||
| 424 | void Drain(bool wait = true) { return m_cb->aestream_drain(m_kodiBase, m_StreamHandle, wait); } | ||
| 425 | //-------------------------------------------------------------------------- | ||
| 426 | |||
| 427 | //========================================================================== | ||
| 428 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 429 | /// @brief Returns true if the is stream draining. | ||
| 430 | /// | ||
| 431 | bool IsDraining() { return m_cb->aestream_is_draining(m_kodiBase, m_StreamHandle); } | ||
| 432 | //-------------------------------------------------------------------------- | ||
| 433 | |||
| 434 | //========================================================================== | ||
| 435 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 436 | /// @brief Returns true if the is stream has finished draining. | ||
| 437 | /// | ||
| 438 | bool IsDrained() { return m_cb->aestream_is_drained(m_kodiBase, m_StreamHandle); } | ||
| 439 | //-------------------------------------------------------------------------- | ||
| 440 | |||
| 441 | //========================================================================== | ||
| 442 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 443 | /// @brief Flush all buffers dropping the audio data. | ||
| 444 | /// | ||
| 445 | void Flush() { return m_cb->aestream_flush(m_kodiBase, m_StreamHandle); } | ||
| 446 | //-------------------------------------------------------------------------- | ||
| 447 | |||
| 448 | //========================================================================== | ||
| 449 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 450 | /// @brief Return the stream's current volume level. | ||
| 451 | /// | ||
| 452 | /// @return The volume level between 0.0 and 1.0 | ||
| 453 | /// | ||
| 454 | float GetVolume() { return m_cb->aestream_get_volume(m_kodiBase, m_StreamHandle); } | ||
| 455 | //-------------------------------------------------------------------------- | ||
| 456 | |||
| 457 | //========================================================================== | ||
| 458 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 459 | /// @brief Set the stream's volume level. | ||
| 460 | /// | ||
| 461 | /// @param[in] volume The new volume level between 0.0 and 1.0 | ||
| 462 | /// | ||
| 463 | void SetVolume(float volume) | ||
| 464 | { | ||
| 465 | return m_cb->aestream_set_volume(m_kodiBase, m_StreamHandle, volume); | ||
| 466 | } | ||
| 467 | //-------------------------------------------------------------------------- | ||
| 468 | |||
| 469 | //========================================================================== | ||
| 470 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 471 | /// @brief Gets the stream's volume amplification in linear units. | ||
| 472 | /// | ||
| 473 | /// @return The volume amplification factor between 1.0 and 1000.0 | ||
| 474 | /// | ||
| 475 | float GetAmplification() { return m_cb->aestream_get_amplification(m_kodiBase, m_StreamHandle); } | ||
| 476 | //-------------------------------------------------------------------------- | ||
| 477 | |||
| 478 | //========================================================================== | ||
| 479 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 480 | /// @brief Sets the stream's volume amplification in linear units. | ||
| 481 | /// | ||
| 482 | /// @param[in] amplify The volume amplification factor between 1.0 and 1000.0 | ||
| 483 | /// | ||
| 484 | void SetAmplification(float amplify) | ||
| 485 | { | ||
| 486 | return m_cb->aestream_set_amplification(m_kodiBase, m_StreamHandle, amplify); | ||
| 487 | } | ||
| 488 | //-------------------------------------------------------------------------- | ||
| 489 | |||
| 490 | //========================================================================== | ||
| 491 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 492 | /// @brief Returns the size of one audio frame in bytes (channelCount * resolution). | ||
| 493 | /// | ||
| 494 | /// @return The size in bytes of one frame | ||
| 495 | /// | ||
| 496 | unsigned int GetFrameSize() const | ||
| 497 | { | ||
| 498 | return m_cb->aestream_get_frame_size(m_kodiBase, m_StreamHandle); | ||
| 499 | } | ||
| 500 | //-------------------------------------------------------------------------- | ||
| 501 | |||
| 502 | //========================================================================== | ||
| 503 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 504 | /// @brief Returns the number of channels the stream is configured to accept. | ||
| 505 | /// | ||
| 506 | /// @return The channel count | ||
| 507 | /// | ||
| 508 | unsigned int GetChannelCount() const | ||
| 509 | { | ||
| 510 | return m_cb->aestream_get_channel_count(m_kodiBase, m_StreamHandle); | ||
| 511 | } | ||
| 512 | //-------------------------------------------------------------------------- | ||
| 513 | |||
| 514 | //========================================================================== | ||
| 515 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 516 | /// @brief Returns the stream's sample rate, if the stream is using a dynamic | ||
| 517 | /// sample rate, this value will NOT reflect any changes made by calls to | ||
| 518 | /// SetResampleRatio(). | ||
| 519 | /// | ||
| 520 | /// @return The stream's sample rate (eg, 48000) | ||
| 521 | /// | ||
| 522 | unsigned int GetSampleRate() const | ||
| 523 | { | ||
| 524 | return m_cb->aestream_get_sample_rate(m_kodiBase, m_StreamHandle); | ||
| 525 | } | ||
| 526 | //-------------------------------------------------------------------------- | ||
| 527 | |||
| 528 | //========================================================================== | ||
| 529 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 530 | /// @brief Return the data format the stream has been configured with. | ||
| 531 | /// | ||
| 532 | /// @return The stream's data format (eg, AUDIOENGINE_FMT_S16LE) | ||
| 533 | /// | ||
| 534 | AudioEngineDataFormat GetDataFormat() const | ||
| 535 | { | ||
| 536 | return m_cb->aestream_get_data_format(m_kodiBase, m_StreamHandle); | ||
| 537 | } | ||
| 538 | //-------------------------------------------------------------------------- | ||
| 539 | |||
| 540 | //========================================================================== | ||
| 541 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 542 | /// @brief Return the resample ratio. | ||
| 543 | /// | ||
| 544 | /// @note This will return an undefined value if the stream is not resampling. | ||
| 545 | /// | ||
| 546 | /// @return the current resample ratio or undefined if the stream is not resampling | ||
| 547 | /// | ||
| 548 | double GetResampleRatio() | ||
| 549 | { | ||
| 550 | return m_cb->aestream_get_resample_ratio(m_kodiBase, m_StreamHandle); | ||
| 551 | } | ||
| 552 | //-------------------------------------------------------------------------- | ||
| 553 | |||
| 554 | //========================================================================== | ||
| 555 | /// @ingroup cpp_kodi_audioengine_CAEStream | ||
| 556 | /// @brief Sets the resample ratio. | ||
| 557 | /// | ||
| 558 | /// @note This function may return false if the stream is not resampling, if | ||
| 559 | /// you wish to use this be sure to set the AESTREAM_FORCE_RESAMPLE option. | ||
| 560 | /// | ||
| 561 | /// @param[in] ratio the new sample rate ratio, calculated by | ||
| 562 | /// ((double)desiredRate / (double)GetSampleRate()) | ||
| 563 | /// | ||
| 564 | void SetResampleRatio(double ratio) | ||
| 565 | { | ||
| 566 | m_cb->aestream_set_resample_ratio(m_kodiBase, m_StreamHandle, ratio); | ||
| 567 | } | ||
| 568 | //-------------------------------------------------------------------------- | ||
| 569 | |||
| 570 | private: | ||
| 571 | void* m_kodiBase; | ||
| 572 | AddonToKodiFuncTable_kodi_audioengine* m_cb; | ||
| 573 | AEStreamHandle* m_StreamHandle; | ||
| 574 | }; | ||
| 575 | //---------------------------------------------------------------------------- | ||
| 576 | |||
| 577 | //============================================================================ | ||
| 578 | /// @ingroup cpp_kodi_audioengine | ||
| 579 | /// @brief Get the current sink data format. | ||
| 580 | /// | ||
| 581 | /// @param[in] format Current sink data format. For more details see AudioEngineFormat. | ||
| 582 | /// @return Returns true on success, else false. | ||
| 583 | /// | ||
| 584 | /// | ||
| 585 | /// ------------------------------------------------------------------------ | ||
| 586 | /// | ||
| 587 | /// **Example:** | ||
| 588 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 589 | /// | ||
| 590 | /// #include <kodi/AudioEngine.h> | ||
| 591 | /// | ||
| 592 | /// ... | ||
| 593 | /// | ||
| 594 | /// kodi::audioengine::AudioEngineFormat format; | ||
| 595 | /// if (!kodi::audioengine::GetCurrentSinkFormat(format)) | ||
| 596 | /// return false; | ||
| 597 | /// | ||
| 598 | /// std::vector<AudioEngineChannel> layout = format.GetChannelLayout(); | ||
| 599 | /// | ||
| 600 | /// ... | ||
| 601 | /// return true; | ||
| 602 | /// | ||
| 603 | /// ~~~~~~~~~~~~~ | ||
| 604 | /// | ||
| 605 | inline bool ATTRIBUTE_HIDDEN GetCurrentSinkFormat(AudioEngineFormat& format) | ||
| 606 | { | ||
| 607 | using namespace kodi::addon; | ||
| 608 | return CAddonBase::m_interface->toKodi->kodi_audioengine->get_current_sink_format( | ||
| 609 | CAddonBase::m_interface->toKodi->kodiBase, format); | ||
| 610 | } | ||
| 611 | //---------------------------------------------------------------------------- | ||
| 612 | |||
| 613 | //}}} | ||
| 614 | |||
| 615 | } // namespace audioengine | ||
| 616 | } // namespace kodi | ||
| 617 | |||
| 618 | #endif /* __cplusplus */ | ||
