Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches

Detailed Description

Class: kodi::addon::CInstanceAudioDecoder

Audio decoder add-on instance

For audio decoders as binary add-ons. This class implements a way to handle special types of audio files.

The add-on handles loading of the source file and outputting the audio stream for consumption by the player.

The addon.xml defines the capabilities of this add-on.

Note
The option to have multiple instances is possible with audio-decoder add-ons. This is useful, since some playback engines are riddled by global variables, making decoding of multiple streams using the same instance impossible.

Here's an example on addon.xml:

<?xml version="1.0" encoding="UTF-8"?>
<addon
id="audiodecoder.myspecialnamefor"
version="1.0.0"
name="My special audio decoder addon"
provider-name="Your Name">
<requires>@ADDON_DEPENDS@</requires>
<extension
point="kodi.audiodecoder"
name="2sf"
tags="true"
library_@PLATFORM@="@LIBRARY_FILENAME@">
<support>
<extension name=".2sf">
<description>30100</description>
<icon>resources/file_format_music_sound.png</icon>
</extension>
<extension name=".mini2sf"/>
</support>
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">My audio decoder addon addon</summary>
<description lang="en_GB">My audio decoder addon description</description>
<platform>@PLATFORM@</platform>
</extension>
</addon>

Description to audio decoder related addon.xml values:

Name Description
point Addon type specification
At all addon types and for this kind always "kodi.audiodecoder".
library_@PLATFORM@ Sets the used library name, which is automatically set by cmake at addon build.
name The name of the decoder used in Kodi for display.
tags Boolean to point out that addon can bring own information to replayed file, if false only the file name is used as info.
If true, CInstanceAudioDecoder::ReadTag is used and must be implemented.
tracks Boolean to in inform one file can contains several different streams.
<support><extension name="..." /></support> The file extensions / styles supported by this addon.\nOptional can be with <description> and <icon>additional info added where used for list views in Kodi.
<support><mimetype name="..." /></support> A stream URL mimetype where can be used to force to this addon.\nOptional can be with `<description> and <icon>additional info added where used for list views in Kodi.

Here is a code example how this addon is used:

#include <kodi/addon-instance/AudioDecoder.h>
class CMyAudioDecoder : public kodi::addon::CInstanceAudioDecoder
{
public:
CMyAudioDecoder(const kodi::addon::IInstanceInfo& instance);
bool Init(const std::string& filename, unsigned int filecache,
int& channels, int& samplerate,
int& bitspersample, int64_t& totaltime,
int& bitrate, AudioEngineDataFormat& format,
std::vector<AudioEngineChannel>& channellist) override;
int ReadPCM(uint8_t* buffer, int size, int& actualsize) override;
};
CMyAudioDecoder::CMyAudioDecoder(const kodi::addon::IInstanceInfo& instance)
: kodi::addon::CInstanceAudioDecoder(instance)
{
...
}
bool CMyAudioDecoder::Init(const std::string& filename, unsigned int filecache,
int& channels, int& samplerate,
int& bitspersample, int64_t& totaltime,
int& bitrate, AudioEngineDataFormat& format,
std::vector<AudioEngineChannel>& channellist)
{
...
return true;
}
int CMyAudioDecoder::ReadPCM(uint8_t* buffer, int size, int& actualsize)
{
...
}
//----------------------------------------------------------------------
class CMyAddon : public kodi::addon::CAddonBase
{
public:
CMyAddon() = default;
KODI_ADDON_INSTANCE_HDL& hdl) override;
};
// If you use only one instance in your add-on, can be instanceType and
// instanceID ignored
ADDON_STATUS CMyAddon::CreateInstance(const kodi::addon::IInstanceInfo& instance,
KODI_ADDON_INSTANCE_HDL& hdl)
{
{
kodi::Log(ADDON_LOG_INFO, "Creating my audio decoder");
hdl = new CMyAudioDecoder(instance);
}
else if (...)
{
...
}
}
ADDONCREATOR(CMyAddon)
Definition AddonBase.h:583
Definition AudioDecoder.h:431
Definition AddonBase.h:306
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition addon_base.h:187
ADDON_STATUS
Definition addon_base.h:138
@ ADDON_STATUS_OK
For everything OK and no error.
Definition addon_base.h:140
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition addon_base.h:152
@ ADDON_INSTANCE_AUDIODECODER
Audio decoder instance, see kodi::addon::CInstanceAudioDecoder.
Definition versions.h:218
bool IsType(KODI_ADDON_INSTANCE_TYPE type) const
Check asked type used on this class.
Definition AddonBase.h:333
virtual ADDON_STATUS CreateInstance(const kodi::addon::IInstanceInfo &instance, KODI_ADDON_INSTANCE_HDL &hdl)
Instance created.
Definition AddonBase.h:732
@ AUDIODECODER_READ_SUCCESS
On success.
Definition audiodecoder.h:69
AudioEngineDataFormat
Definition audio_engine.h:148
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition AddonBase.h:1746

The destruction of the example class CMyAudioDecoder is called from Kodi's header. Manually deleting the add-on instance is not required.

Topics

 Definitions, structures and enumerators
 Audio decoder add-on instance definition values
All audio decoder functions associated data structures.
 

Function Documentation

◆ CInstanceAudioDecoder()

Audio decoder class constructor used to support multiple instance types.

Parameters
[in]instanceThe instance value given to kodi::addon::CAddonBase::CreateInstance(...).

Here's example about the use of this:

{
public:
CMyAudioDecoder(KODI_HANDLE instance)
: kodi::addon::CInstanceAudioDecoder(instance)
{
...
}
...
};
ADDON_STATUS CMyAddon::CreateInstance(const kodi::addon::IInstanceInfo& instance,
KODI_ADDON_INSTANCE_HDL& hdl)
{
kodi::Log(ADDON_LOG_INFO, "Creating my audio decoder");
hdl = new CMyAudioDecoder(instance);
}
Definition PeripheralUtils.h:48

◆ SupportsFile()

virtual bool SupportsFile ( const std::string & filename)
inlinevirtual

Checks addon support given file path.

Parameters
[in]filenameThe file to read
Returns
true if successfully done and supported, otherwise false
Note
Optional to add, as default becomes true used.

◆ Init()

virtual bool Init ( const std::string & filename,
unsigned int filecache,
int & channels,
int & samplerate,
int & bitspersample,
int64_t & totaltime,
int & bitrate,
AudioEngineDataFormat & format,
std::vector< AudioEngineChannel > & channellist )
pure virtual

Initialize a decoder.

Parameters
[in]filenameThe file to read
[in]filecacheThe file cache size
[out]channelsNumber of channels in output stream
[out]samplerateSamplerate of output stream
[out]bitspersampleBits per sample in output stream
[out]totaltimeTotal time for stream
[out]bitrateAverage bitrate of input stream
[out]formatData format for output stream, see class AudioEngineFormat for available values
[out]channellistChannel mapping for output stream, see enum AudioEngineChannel for available values
Returns
true if successfully done, otherwise false

◆ ReadPCM()

virtual int ReadPCM ( uint8_t * buffer,
size_t size,
size_t & actualsize )
pure virtual

Produce some noise.

Parameters
[in]bufferOutput buffer
[in]sizeSize of output buffer
[out]actualsizeActual number of bytes written to output buffer
Returns

Possible values are:

Value enum Description
0 AUDIODECODER_READ_SUCCESS on success
-1 AUDIODECODER_READ_EOF on end of stream
1 AUDIODECODER_READ_ERROR on failure

◆ Seek()

virtual int64_t Seek ( int64_t time)
inlinevirtual

Seek in output stream.

Parameters
[in]timeTime position to seek to in milliseconds
Returns
Time position seek ended up on

◆ ReadTag()

virtual bool ReadTag ( const std::string & file,
kodi::addon::AudioDecoderInfoTag & tag )
inlinevirtual

Read tag of a file.

Parameters
[in]fileFile to read tag for
[out]tagInformation tag about
Returns
True on success, false on failure

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

Name Type Set call Get call
Title std::string SetTitle GetTitle
Artist std::string SetArtist GetArtist
Album std::string SetAlbum GetAlbum
Album artist std::string SetAlbumArtist GetAlbumArtist
Media type std::string SetMediaType GetMediaType
Genre std::string SetGenre GetGenre
Duration int SetDuration GetDuration
Track number int SetTrack GetTrack
Disc number int SetDisc GetDisc
Disc subtitle name std::string SetDiscSubtitle GetDiscSubtitle
Disc total amount int SetDiscTotal GetDiscTotal
Release date std::string SetReleaseDate GetReleaseDate
Lyrics std::string SetLyrics GetLyrics
Samplerate int SetSamplerate GetSamplerate
Channels amount int SetChannels GetChannels
Bitrate int SetBitrate GetBitrate
Comment text std::string SetComment GetComment
Cover art by path std::string SetCoverArtByPath GetCoverArtByPath
Cover art by memory std::string SetCoverArtByMem GetCoverArtByMem

◆ TrackCount()

virtual int TrackCount ( const std::string & file)
inlinevirtual

Get number of tracks in a file.

Parameters
[in]fileFile to read tag for
Returns
Number of tracks in file

◆ GetTrack()

static std::string GetTrack ( const std::string & name,
const std::string & trackPath,
int & track )
inlinestatic

Static auxiliary function to read the track number used from the given path.

If track number is not found in file name, the originally given file name is returned, track number then remains at "0".

Parameters
[in]nameThe value specified in addon.xml extension under name="???"
[in]trackPathThe full path to evaluate
[out]trackThe track number read out in the path, 0 if not identified as a track path.
Returns
Path to the associated file