Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches

Audio Engine Stream Class
Class that can be created by the addon in order to be able to transfer audiostream data processed on the addon to Kodi and output it audibly. More...

Functions

 kodi::audioengine::CAEStream::CAEStream (AudioEngineFormat &format, unsigned int options=0)
 Constructs new class to a Kodi IAEStream in the format specified.
 
 kodi::audioengine::CAEStream::~CAEStream ()
 Class destructor.
 
unsigned int kodi::audioengine::CAEStream::GetSpace ()
 Returns the amount of space available in the stream.
 
unsigned int kodi::audioengine::CAEStream::AddData (uint8_t *const *data, unsigned int offset, unsigned int frames, double pts=0, bool hasDownmix=false, double centerMixLevel=1.0)
 Add planar or interleaved PCM data to the stream.
 
double kodi::audioengine::CAEStream::GetDelay ()
 Returns the time in seconds that it will take for the next added packet to be heard from the speakers.
 
bool kodi::audioengine::CAEStream::IsBuffering ()
 Returns if the stream is buffering.
 
double kodi::audioengine::CAEStream::GetCacheTime ()
 Returns the time in seconds of the stream's cached audio samples. Engine buffers excluded.
 
double kodi::audioengine::CAEStream::GetCacheTotal ()
 Returns the total time in seconds of the cache.
 
void kodi::audioengine::CAEStream::Pause ()
 Pauses the stream playback.
 
void kodi::audioengine::CAEStream::Resume ()
 Resumes the stream after pausing.
 
void kodi::audioengine::CAEStream::Drain (bool wait=true)
 Start draining the stream.
 
bool kodi::audioengine::CAEStream::IsDraining ()
 Returns true if the is stream draining.
 
bool kodi::audioengine::CAEStream::IsDrained ()
 Returns true if the is stream has finished draining.
 
void kodi::audioengine::CAEStream::Flush ()
 Flush all buffers dropping the audio data.
 
float kodi::audioengine::CAEStream::GetVolume ()
 Return the stream's current volume level.
 
void kodi::audioengine::CAEStream::SetVolume (float volume)
 Set the stream's volume level.
 
float kodi::audioengine::CAEStream::GetAmplification ()
 Gets the stream's volume amplification in linear units.
 
void kodi::audioengine::CAEStream::SetAmplification (float amplify)
 Sets the stream's volume amplification in linear units.
 
unsigned int kodi::audioengine::CAEStream::GetFrameSize () const
 Returns the size of one audio frame in bytes (channelCount * resolution).
 
unsigned int kodi::audioengine::CAEStream::GetChannelCount () const
 Returns the number of channels the stream is configured to accept.
 
unsigned int kodi::audioengine::CAEStream::GetSampleRate () const
 Returns the stream's sample rate, if the stream is using a dynamic sample rate, this value will NOT reflect any changes made by calls to SetResampleRatio().
 
AudioEngineDataFormat kodi::audioengine::CAEStream::GetDataFormat () const
 Return the data format the stream has been configured with.
 
double kodi::audioengine::CAEStream::GetResampleRatio ()
 Return the resample ratio.
 
void kodi::audioengine::CAEStream::SetResampleRatio (double ratio)
 Sets the resample ratio.
 

Detailed Description

Audio Engine Stream Class
Class that can be created by the addon in order to be able to transfer audiostream data processed on the addon to Kodi and output it audibly.

This can create individually several times and performed in different processes simultaneously.

It has the header #include <kodi/AudioEngine.h> be included to enjoy it.

Function Documentation

◆ AddData()

unsigned int kodi::audioengine::CAEStream::AddData ( uint8_t *const * data,
unsigned int offset,
unsigned int frames,
double pts = 0,
bool hasDownmix = false,
double centerMixLevel = 1.0 )
inline

Add planar or interleaved PCM data to the stream.

Parameters
[in]dataarray of pointers to the planes
[in]offsetto frame in frames
[in]framesnumber of frames
[in]pts[opt] presentation timestamp, default is 0
[in]hasDownmix[opt] set true if downmix is present, default is false
[in]centerMixLevel[opt] level to mix left and right to center default is 1.0
Returns
The number of frames consumed

◆ CAEStream()

kodi::audioengine::CAEStream::CAEStream ( AudioEngineFormat & format,
unsigned int options = 0 )
inline

Constructs new class to a Kodi IAEStream in the format specified.

Parameters
[in]formatThe data format the incoming audio will be in (e.g. AUDIOENGINE_FMT_S16LE)
[in]options[opt] A bit field of stream options (see: enum AudioEngineStreamOptions)

The following table contains values that can be set with class AudioEngineFormat :

Name Type Set call Get call
Data format, see AudioEngineDataFormat for available types enum SetDataFormat GetDataFormat
Sample rate unsigned int SetSampleRate GetSampleRate
Encoded rate unsigned int SetEncodedRate GetEncodedRate
Channel layout, see AudioEngineChannel for available types std::vector<enum AudioEngineChannel> SetChannelLayout GetChannelLayout
Frames amount unsigned int SetFramesAmount GetFramesAmount
Frame size unsigned int SetFrameSize GetFrameSize

Further is CompareFormat included to compare this class with another.


**Bit options to pass (on Kodi by IAE::MakeStream)**

enum AEStreamOptions Value: Description:
AUDIO_STREAM_FORCE_RESAMPLE 1 << 0 Force resample even if rates match
AUDIO_STREAM_PAUSED 1 << 1 Create the stream paused
AUDIO_STREAM_AUTOSTART 1 << 2 Autostart the stream when enough data is buffered

Example:

...
kodi::audioengine::AudioEngineFormat format;
format.SetDataFormat(AUDIOENGINE_FMT_FLOATP); /* The stream's data format (eg, AUDIOENGINE_FMT_S16LE) *&zwj;/
format.SetChannelLayout(std::vector<AudioEngineChannel>(AUDIOENGINE_CH_FL, AUDIOENGINE_CH_FR)); /* The stream's channel layout *&zwj;/
format.SetSampleRate(48000); /* The stream's sample rate (eg, 48000) *&zwj;/
format.SetFrameSize(sizeof(float)*2); /* The size of one frame in bytes *&zwj;/
format.SetFramesAmount(882); /* The number of samples in one frame *&zwj;/
kodi::audioengine::CAEStream* stream = new kodi::audioengine::CAEStream(format, AUDIO_STREAM_AUTOSTART);
const char unsigned int int int int int64_t int enum AudioEngineDataFormat * format
Definition addons/kodi-dev-kit/include/kodi/c-api/addon-instance/AudioDecoder.h:113
@ AUDIOENGINE_FMT_FLOATP
Definition audio_engine.h:217

◆ Drain()

void kodi::audioengine::CAEStream::Drain ( bool wait = true)
inline

Start draining the stream.

Parameters
[in]wait[opt] Wait until drain is finished if set to true, otherwise it returns direct
Note
Once called AddData will not consume more data.

◆ Flush()

void kodi::audioengine::CAEStream::Flush ( )
inline

Flush all buffers dropping the audio data.

◆ GetAmplification()

float kodi::audioengine::CAEStream::GetAmplification ( )
inline

Gets the stream's volume amplification in linear units.

Returns
The volume amplification factor between 1.0 and 1000.0

◆ GetCacheTime()

double kodi::audioengine::CAEStream::GetCacheTime ( )
inline

Returns the time in seconds of the stream's cached audio samples. Engine buffers excluded.

Returns
seconds

◆ GetCacheTotal()

double kodi::audioengine::CAEStream::GetCacheTotal ( )
inline

Returns the total time in seconds of the cache.

Returns
seconds

◆ GetChannelCount()

unsigned int kodi::audioengine::CAEStream::GetChannelCount ( ) const
inline

Returns the number of channels the stream is configured to accept.

Returns
The channel count

◆ GetDataFormat()

AudioEngineDataFormat kodi::audioengine::CAEStream::GetDataFormat ( ) const
inline

Return the data format the stream has been configured with.

Returns
The stream's data format (eg, AUDIOENGINE_FMT_S16LE)

◆ GetDelay()

double kodi::audioengine::CAEStream::GetDelay ( )
inline

Returns the time in seconds that it will take for the next added packet to be heard from the speakers.

Returns
seconds

◆ GetFrameSize()

unsigned int kodi::audioengine::CAEStream::GetFrameSize ( ) const
inline

Returns the size of one audio frame in bytes (channelCount * resolution).

Returns
The size in bytes of one frame

◆ GetResampleRatio()

double kodi::audioengine::CAEStream::GetResampleRatio ( )
inline

Return the resample ratio.

Note
This will return an undefined value if the stream is not resampling.
Returns
the current resample ratio or undefined if the stream is not resampling

◆ GetSampleRate()

unsigned int kodi::audioengine::CAEStream::GetSampleRate ( ) const
inline

Returns the stream's sample rate, if the stream is using a dynamic sample rate, this value will NOT reflect any changes made by calls to SetResampleRatio().

Returns
The stream's sample rate (eg, 48000)

◆ GetSpace()

unsigned int kodi::audioengine::CAEStream::GetSpace ( )
inline

Returns the amount of space available in the stream.

Returns
The number of bytes AddData will consume

◆ GetVolume()

float kodi::audioengine::CAEStream::GetVolume ( )
inline

Return the stream's current volume level.

Returns
The volume level between 0.0 and 1.0

◆ IsBuffering()

bool kodi::audioengine::CAEStream::IsBuffering ( )
inline

Returns if the stream is buffering.

Returns
True if the stream is buffering

◆ IsDrained()

bool kodi::audioengine::CAEStream::IsDrained ( )
inline

Returns true if the is stream has finished draining.

◆ IsDraining()

bool kodi::audioengine::CAEStream::IsDraining ( )
inline

Returns true if the is stream draining.

◆ Pause()

void kodi::audioengine::CAEStream::Pause ( )
inline

Pauses the stream playback.

◆ Resume()

void kodi::audioengine::CAEStream::Resume ( )
inline

Resumes the stream after pausing.

◆ SetAmplification()

void kodi::audioengine::CAEStream::SetAmplification ( float amplify)
inline

Sets the stream's volume amplification in linear units.

Parameters
[in]amplifyThe volume amplification factor between 1.0 and 1000.0

◆ SetResampleRatio()

void kodi::audioengine::CAEStream::SetResampleRatio ( double ratio)
inline

Sets the resample ratio.

Note
This function may return false if the stream is not resampling, if you wish to use this be sure to set the AESTREAM_FORCE_RESAMPLE option.
Parameters
[in]ratiothe new sample rate ratio, calculated by ((double)desiredRate / (double)GetSampleRate())

◆ SetVolume()

void kodi::audioengine::CAEStream::SetVolume ( float volume)
inline

Set the stream's volume level.

Parameters
[in]volumeThe new volume level between 0.0 and 1.0

◆ ~CAEStream()

kodi::audioengine::CAEStream::~CAEStream ( )
inline

Class destructor.