summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/include/kodi/AudioEngine.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/AudioEngine.h')
-rw-r--r--xbmc/addons/kodi-dev-kit/include/kodi/AudioEngine.h619
1 files changed, 619 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/AudioEngine.h b/xbmc/addons/kodi-dev-kit/include/kodi/AudioEngine.h
new file mode 100644
index 0000000..36d1dd1
--- /dev/null
+++ b/xbmc/addons/kodi-dev-kit/include/kodi/AudioEngine.h
@@ -0,0 +1,619 @@
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
16namespace kodi
17{
18namespace 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///@{
102class ATTRIBUTE_HIDDEN AudioEngineFormat
103 : public addon::CStructHdl<AudioEngineFormat, AUDIO_ENGINE_FORMAT>
104{
105public:
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//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
239// "C++" AudioEngine addon interface
240//{{{
241
242//============================================================================
243///
244/// @defgroup cpp_kodi_audioengine_CAEStream class CAEStream
245/// @ingroup cpp_kodi_audioengine
246/// @brief **Audio Engine Stream Class**\n
247/// Class that can be created by the addon in order to be able to transfer
248/// audiostream data processed on the addon to Kodi and output it audibly.
249///
250/// This can create individually several times and performed in different
251/// processes simultaneously.
252///
253/// It has the header @ref AudioEngine.h "#include <kodi/AudioEngine.h>" be
254/// included to enjoy it.
255///
256//----------------------------------------------------------------------------
257class ATTRIBUTE_HIDDEN CAEStream
258{
259public:
260 //==========================================================================
261 /// @ingroup cpp_kodi_audioengine_CAEStream
262 /// @brief Contructs new class to an Kodi IAEStream in the format specified.
263 ///
264 /// @param[in] format The data format the incoming audio will be in
265 /// (e.g. \ref AUDIOENGINE_FMT_S16LE)
266 /// @param[in] options [opt] A bit field of stream options (see: enum \ref AudioEngineStreamOptions)
267 ///
268 ///
269 /// ------------------------------------------------------------------------
270 ///
271 /// @copydetails cpp_kodi_audioengine_Defs_AudioEngineFormat_Help
272 ///
273 /// ------------------------------------------------------------------------
274 ///
275 /// **Bit options to pass (on Kodi by <c>IAE::MakeStream</c>)**
276 ///
277 /// | enum AEStreamOptions | Value: | Description:
278 /// |----------------------------:|:------:|:-----------------------------------
279 /// | AUDIO_STREAM_FORCE_RESAMPLE | 1 << 0 | Force resample even if rates match
280 /// | AUDIO_STREAM_PAUSED | 1 << 1 | Create the stream paused
281 /// | AUDIO_STREAM_AUTOSTART | 1 << 2 | Autostart the stream when enough data is buffered
282 ///
283 ///
284 /// ------------------------------------------------------------------------
285 ///
286 /// **Example:**
287 /// ~~~~~~~~~~~~~{.cpp}
288 ///
289 /// #include <kodi/AudioEngine.h>
290 ///
291 /// ...
292 ///
293 /// kodi::audioengine::AudioEngineFormat format;
294 ///
295 /// format.SetDataFormat(AUDIOENGINE_FMT_FLOATP); /* The stream's data format (eg, AUDIOENGINE_FMT_S16LE) */
296 /// format.SetChannelLayout(std::vector<AudioEngineChannel>(AUDIOENGINE_CH_FL, AUDIOENGINE_CH_FR)); /* The stream's channel layout */
297 /// format.SetSampleRate(48000); /* The stream's sample rate (eg, 48000) */
298 /// format.SetFrameSize(sizeof(float)*2); /* The size of one frame in bytes */
299 /// format.SetFramesAmount(882); /* The number of samples in one frame */
300 ///
301 /// kodi::audioengine::CAEStream* stream = new kodi::audioengine::CAEStream(format, AUDIO_STREAM_AUTOSTART);
302 ///
303 /// ~~~~~~~~~~~~~
304 ///
305 CAEStream(AudioEngineFormat& format, unsigned int options = 0)
306 : m_kodiBase(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase),
307 m_cb(::kodi::addon::CAddonBase::m_interface->toKodi->kodi_audioengine)
308 {
309 m_StreamHandle = m_cb->make_stream(m_kodiBase, format, options);
310 if (m_StreamHandle == nullptr)
311 {
312 kodi::Log(ADDON_LOG_FATAL, "CAEStream: make_stream failed!");
313 }
314 }
315 //--------------------------------------------------------------------------
316
317 //==========================================================================
318 /// @ingroup cpp_kodi_audioengine_CAEStream
319 /// @brief Class destructor.
320 ///
321 ~CAEStream()
322 {
323 if (m_StreamHandle)
324 {
325 m_cb->free_stream(m_kodiBase, m_StreamHandle);
326 m_StreamHandle = nullptr;
327 }
328 }
329 //--------------------------------------------------------------------------
330
331 //==========================================================================
332 /// @ingroup cpp_kodi_audioengine_CAEStream
333 /// @brief Returns the amount of space available in the stream.
334 ///
335 /// @return The number of bytes AddData will consume
336 ///
337 unsigned int GetSpace() { return m_cb->aestream_get_space(m_kodiBase, m_StreamHandle); }
338 //--------------------------------------------------------------------------
339
340 //==========================================================================
341 /// @ingroup cpp_kodi_audioengine_CAEStream
342 /// @brief Add planar or interleaved PCM data to the stream.
343 ///
344 /// @param[in] data array of pointers to the planes
345 /// @param[in] offset to frame in frames
346 /// @param[in] frames number of frames
347 /// @param[in] pts [opt] presentation timestamp, default is 0
348 /// @param[in] hasDownmix [opt] set true if downmix is present, default is false
349 /// @param[in] centerMixLevel [opt] level to mix left and right to center default is 1.0
350 /// @return The number of frames consumed
351 ///
352 unsigned int AddData(uint8_t* const* data,
353 unsigned int offset,
354 unsigned int frames,
355 double pts = 0,
356 bool hasDownmix = false,
357 double centerMixLevel = 1.0)
358 {
359 return m_cb->aestream_add_data(m_kodiBase, m_StreamHandle, data, offset, frames, pts,
360 hasDownmix, centerMixLevel);
361 }
362 //--------------------------------------------------------------------------
363
364 //==========================================================================
365 /// @ingroup cpp_kodi_audioengine_CAEStream
366 /// @brief Returns the time in seconds that it will take for the next added
367 /// packet to be heard from the speakers.
368 ///
369 /// @return seconds
370 ///
371 double GetDelay() { return m_cb->aestream_get_delay(m_kodiBase, m_StreamHandle); }
372 //--------------------------------------------------------------------------
373
374 //==========================================================================
375 /// @ingroup cpp_kodi_audioengine_CAEStream
376 /// @brief Returns if the stream is buffering.
377 ///
378 /// @return True if the stream is buffering
379 ///
380 bool IsBuffering() { return m_cb->aestream_is_buffering(m_kodiBase, m_StreamHandle); }
381 //--------------------------------------------------------------------------
382
383 //==========================================================================
384 /// @ingroup cpp_kodi_audioengine_CAEStream
385 /// @brief Returns the time in seconds of the stream's cached audio samples.
386 /// Engine buffers excluded.
387 ///
388 /// @return seconds
389 ///
390 double GetCacheTime() { return m_cb->aestream_get_cache_time(m_kodiBase, m_StreamHandle); }
391 //--------------------------------------------------------------------------
392
393 //==========================================================================
394 /// @ingroup cpp_kodi_audioengine_CAEStream
395 /// @brief Returns the total time in seconds of the cache.
396 ///
397 /// @return seconds
398 ///
399 double GetCacheTotal() { return m_cb->aestream_get_cache_total(m_kodiBase, m_StreamHandle); }
400 //--------------------------------------------------------------------------
401
402 //==========================================================================
403 /// @ingroup cpp_kodi_audioengine_CAEStream
404 /// @brief Pauses the stream playback.
405 ///
406 void Pause() { return m_cb->aestream_pause(m_kodiBase, m_StreamHandle); }
407 //--------------------------------------------------------------------------
408
409 //==========================================================================
410 /// @ingroup cpp_kodi_audioengine_CAEStream
411 /// @brief Resumes the stream after pausing
412 ///
413 void Resume() { return m_cb->aestream_resume(m_kodiBase, m_StreamHandle); }
414 //--------------------------------------------------------------------------
415
416 //==========================================================================
417 /// @ingroup cpp_kodi_audioengine_CAEStream
418 /// @brief Start draining the stream.
419 ///
420 /// @param[in] wait [opt] Wait until drain is finished if set to true,
421 /// otherwise it returns direct
422 ///
423 /// @note Once called AddData will not consume more data.
424 ///
425 void Drain(bool wait = true) { return m_cb->aestream_drain(m_kodiBase, m_StreamHandle, wait); }
426 //--------------------------------------------------------------------------
427
428 //==========================================================================
429 /// @ingroup cpp_kodi_audioengine_CAEStream
430 /// @brief Returns true if the is stream draining.
431 ///
432 bool IsDraining() { return m_cb->aestream_is_draining(m_kodiBase, m_StreamHandle); }
433 //--------------------------------------------------------------------------
434
435 //==========================================================================
436 /// @ingroup cpp_kodi_audioengine_CAEStream
437 /// @brief Returns true if the is stream has finished draining.
438 ///
439 bool IsDrained() { return m_cb->aestream_is_drained(m_kodiBase, m_StreamHandle); }
440 //--------------------------------------------------------------------------
441
442 //==========================================================================
443 /// @ingroup cpp_kodi_audioengine_CAEStream
444 /// @brief Flush all buffers dropping the audio data.
445 ///
446 void Flush() { return m_cb->aestream_flush(m_kodiBase, m_StreamHandle); }
447 //--------------------------------------------------------------------------
448
449 //==========================================================================
450 /// @ingroup cpp_kodi_audioengine_CAEStream
451 /// @brief Return the stream's current volume level.
452 ///
453 /// @return The volume level between 0.0 and 1.0
454 ///
455 float GetVolume() { return m_cb->aestream_get_volume(m_kodiBase, m_StreamHandle); }
456 //--------------------------------------------------------------------------
457
458 //==========================================================================
459 /// @ingroup cpp_kodi_audioengine_CAEStream
460 /// @brief Set the stream's volume level.
461 ///
462 /// @param[in] volume The new volume level between 0.0 and 1.0
463 ///
464 void SetVolume(float volume)
465 {
466 return m_cb->aestream_set_volume(m_kodiBase, m_StreamHandle, volume);
467 }
468 //--------------------------------------------------------------------------
469
470 //==========================================================================
471 /// @ingroup cpp_kodi_audioengine_CAEStream
472 /// @brief Gets the stream's volume amplification in linear units.
473 ///
474 /// @return The volume amplification factor between 1.0 and 1000.0
475 ///
476 float GetAmplification() { return m_cb->aestream_get_amplification(m_kodiBase, m_StreamHandle); }
477 //--------------------------------------------------------------------------
478
479 //==========================================================================
480 /// @ingroup cpp_kodi_audioengine_CAEStream
481 /// @brief Sets the stream's volume amplification in linear units.
482 ///
483 /// @param[in] amplify The volume amplification factor between 1.0 and 1000.0
484 ///
485 void SetAmplification(float amplify)
486 {
487 return m_cb->aestream_set_amplification(m_kodiBase, m_StreamHandle, amplify);
488 }
489 //--------------------------------------------------------------------------
490
491 //==========================================================================
492 /// @ingroup cpp_kodi_audioengine_CAEStream
493 /// @brief Returns the size of one audio frame in bytes (channelCount * resolution).
494 ///
495 /// @return The size in bytes of one frame
496 ///
497 unsigned int GetFrameSize() const
498 {
499 return m_cb->aestream_get_frame_size(m_kodiBase, m_StreamHandle);
500 }
501 //--------------------------------------------------------------------------
502
503 //==========================================================================
504 /// @ingroup cpp_kodi_audioengine_CAEStream
505 /// @brief Returns the number of channels the stream is configured to accept.
506 ///
507 /// @return The channel count
508 ///
509 unsigned int GetChannelCount() const
510 {
511 return m_cb->aestream_get_channel_count(m_kodiBase, m_StreamHandle);
512 }
513 //--------------------------------------------------------------------------
514
515 //==========================================================================
516 /// @ingroup cpp_kodi_audioengine_CAEStream
517 /// @brief Returns the stream's sample rate, if the stream is using a dynamic
518 /// sample rate, this value will NOT reflect any changes made by calls to
519 /// SetResampleRatio().
520 ///
521 /// @return The stream's sample rate (eg, 48000)
522 ///
523 unsigned int GetSampleRate() const
524 {
525 return m_cb->aestream_get_sample_rate(m_kodiBase, m_StreamHandle);
526 }
527 //--------------------------------------------------------------------------
528
529 //==========================================================================
530 /// @ingroup cpp_kodi_audioengine_CAEStream
531 /// @brief Return the data format the stream has been configured with.
532 ///
533 /// @return The stream's data format (eg, AUDIOENGINE_FMT_S16LE)
534 ///
535 AudioEngineDataFormat GetDataFormat() const
536 {
537 return m_cb->aestream_get_data_format(m_kodiBase, m_StreamHandle);
538 }
539 //--------------------------------------------------------------------------
540
541 //==========================================================================
542 /// @ingroup cpp_kodi_audioengine_CAEStream
543 /// @brief Return the resample ratio.
544 ///
545 /// @note This will return an undefined value if the stream is not resampling.
546 ///
547 /// @return the current resample ratio or undefined if the stream is not resampling
548 ///
549 double GetResampleRatio()
550 {
551 return m_cb->aestream_get_resample_ratio(m_kodiBase, m_StreamHandle);
552 }
553 //--------------------------------------------------------------------------
554
555 //==========================================================================
556 /// @ingroup cpp_kodi_audioengine_CAEStream
557 /// @brief Sets the resample ratio.
558 ///
559 /// @note This function may return false if the stream is not resampling, if
560 /// you wish to use this be sure to set the AESTREAM_FORCE_RESAMPLE option.
561 ///
562 /// @param[in] ratio the new sample rate ratio, calculated by
563 /// ((double)desiredRate / (double)GetSampleRate())
564 ///
565 void SetResampleRatio(double ratio)
566 {
567 m_cb->aestream_set_resample_ratio(m_kodiBase, m_StreamHandle, ratio);
568 }
569 //--------------------------------------------------------------------------
570
571private:
572 void* m_kodiBase;
573 AddonToKodiFuncTable_kodi_audioengine* m_cb;
574 AEStreamHandle* m_StreamHandle;
575};
576//----------------------------------------------------------------------------
577
578//============================================================================
579/// @ingroup cpp_kodi_audioengine
580/// @brief Get the current sink data format.
581///
582/// @param[in] format Current sink data format. For more details see AudioEngineFormat.
583/// @return Returns true on success, else false.
584///
585///
586/// ------------------------------------------------------------------------
587///
588/// **Example:**
589/// ~~~~~~~~~~~~~{.cpp}
590///
591/// #include <kodi/AudioEngine.h>
592///
593/// ...
594///
595/// kodi::audioengine::AudioEngineFormat format;
596/// if (!kodi::audioengine::GetCurrentSinkFormat(format))
597/// return false;
598///
599/// std::vector<AudioEngineChannel> layout = format.GetChannelLayout();
600///
601/// ...
602/// return true;
603///
604/// ~~~~~~~~~~~~~
605///
606inline bool ATTRIBUTE_HIDDEN GetCurrentSinkFormat(AudioEngineFormat& format)
607{
608 using namespace kodi::addon;
609 return CAddonBase::m_interface->toKodi->kodi_audioengine->get_current_sink_format(
610 CAddonBase::m_interface->toKodi->kodiBase, format);
611}
612//----------------------------------------------------------------------------
613
614//}}}
615
616} // namespace audioengine
617} // namespace kodi
618
619#endif /* __cplusplus */