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

Class: kodi::addon::CInstanceAudioEncoder

Audio encoder add-on instance.
For audio encoders as binary add-ons. This class implements a way to handle the encode of given stream to a new format. More...

Functions

 kodi::addon::CInstanceAudioEncoder::CInstanceAudioEncoder (const kodi::addon::IInstanceInfo &instance)
 Audio encoder class constructor used to support multiple instances.
 
virtual bool kodi::addon::CInstanceAudioEncoder::Start (const kodi::addon::AudioEncoderInfoTag &tag)=0
 Start encoder (required)
 
virtual ssize_t kodi::addon::CInstanceAudioEncoder::Encode (const uint8_t *pbtStream, size_t numBytesRead)=0
 Encode a chunk of audio (required)
 
virtual bool kodi::addon::CInstanceAudioEncoder::Finish ()
 Finalize encoding (optional)
 
ssize_t kodi::addon::CInstanceAudioEncoder::Write (const uint8_t *data, size_t length)
 Write block of data.
 
ssize_t kodi::addon::CInstanceAudioEncoder::Seek (ssize_t position, int whence=SEEK_SET)
 Set the file's current position.
 

Detailed Description

Class: kodi::addon::CInstanceAudioEncoder

Audio encoder add-on instance.
For audio encoders as binary add-ons. This class implements a way to handle the encode of given stream to a new format.

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


Here's an example on addon.xml:

<extension
point="kodi.audioencoder"
extension=".flac"
library_@PLATFORM@="@LIBRARY_FILENAME@"/>

Description to audio encoder related addon.xml values:

Name Description
point Addon type specification
At all addon types and for this kind always "kodi.audioencoder".
library_@PLATFORM@ Sets the used library name, which is automatically set by cmake at addon build.
extension The file extensions / styles supported by this addon.


Here is a code example how this addon is used:

class ATTR_DLL_LOCAL CMyAudioEncoder : public kodi::addon::CInstanceAudioEncoder
{
public:
CMyAudioEncoder(const kodi::addon::IInstanceInfo& instance);
int Encode(int numBytesRead, const uint8_t* pbtStream) override;
bool Finish() override; // Optional
};
CMyAudioEncoder::CMyAudioEncoder(const kodi::addon::IInstanceInfo& instance)
: kodi::addon::CInstanceAudioEncoder(instance)
{
...
}
bool CMyAudioEncoder::Start(const kodi::addon::AudioEncoderInfoTag& tag)
{
...
return true;
}
ssize_t CMyAudioEncoder::Encode(const uint8_t* pbtStream, size_t numBytesRead)
{
uint8_t* data = nullptr;
size_t length = 0;
...
return 0;
}
bool CMyAudioEncoder::Finish()
{
...
return true;
}
//----------------------------------------------------------------------
class CMyAddon : public kodi::addon::CAddonBase
{
public:
CMyAddon() = default;
};
// 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::Log(ADDON_LOG_INFO, "Creating my audio encoder instance");
hdl = new CMyAudioEncoder(instance);
}
else if (...)
{
...
}
}
ADDONCREATOR(CMyAddon)
unsigned __int8 uint8_t
Definition DirectXGraphics.h:130
std::string data("<details><url function=\"ParseTMDBRating\" " "cache=\"tmdb-en-12244.json\">" "http://api.themoviedb.org/3/movie/12244" "?api_key=57983e31fb435df4df77afb854740ea9" "&language=en&#x3f;&#x003F;&#0063;</url></details>")
void * KODI_ADDON_INSTANCE_HDL
Definition addon_base.h:121
#define ATTR_DLL_LOCAL
Definition addon_base.h:86
KODI_ADDON_HDL * hdl
Definition addon_base.h:344
const char struct KODI_ADDON_AUDIODECODER_INFO_TAG * tag
Definition addons/kodi-dev-kit/include/kodi/c-api/addon-instance/AudioDecoder.h:122
Definition addon-instance/audioencoder.h:40
Definition kodi-dev-kit/include/kodi/AddonBase.h:775
Definition addon-instance/audioencoder.h:361
Definition kodi-dev-kit/include/kodi/AddonBase.h:498
@ 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_AUDIOENCODER
Audio encoder instance, see kodi::addon::CInstanceAudioEncoder.
Definition versions.h:222
virtual ADDON_STATUS CreateInstance(const kodi::addon::IInstanceInfo &instance, KODI_ADDON_INSTANCE_HDL &hdl)
Instance created.
Definition kodi-dev-kit/include/kodi/AddonBase.h:924
virtual bool Finish()
Finalize encoding (optional)
Definition addon-instance/audioencoder.h:434
virtual bool Start(const kodi::addon::AudioEncoderInfoTag &tag)=0
Start encoder (required)
ssize_t Write(const uint8_t *data, size_t length)
Write block of data.
Definition addon-instance/audioencoder.h:447
virtual ssize_t Encode(const uint8_t *pbtStream, size_t numBytesRead)=0
Encode a chunk of audio (required)
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition kodi-dev-kit/include/kodi/AddonBase.h:1938
#define ADDONCREATOR(AddonClass)
Definition kodi-dev-kit/include/kodi/AddonBase.h:2047
Definition addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h:21
Definition addon_base.h:268
intptr_t ssize_t
Definition win32/PlatformDefs.h:23

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

Function Documentation

◆ CInstanceAudioEncoder()

kodi::addon::CInstanceAudioEncoder::CInstanceAudioEncoder ( const kodi::addon::IInstanceInfo & instance)
inlineexplicit

Audio encoder class constructor used to support multiple instances.

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

Here's example about the use of this:

class CMyAudioEncoder : public kodi::addon::CInstanceAudioEncoder
{
public:
CMyAudioEncoder(const kodi::addon::IInstanceInfo& instance)
{
...
}
...
};
ADDON_STATUS CMyAddon::CreateInstance(const kodi::addon::IInstanceInfo& instance,
{
kodi::Log(ADDON_LOG_INFO, "Creating my audio encoder instance");
hdl = new CMyAudioEncoder(instance);
}

◆ Encode()

virtual ssize_t kodi::addon::CInstanceAudioEncoder::Encode ( const uint8_t * pbtStream,
size_t numBytesRead )
pure virtual

Encode a chunk of audio (required)

Parameters
[in]pbtStreamThe input buffer
[in]numBytesReadNumber of bytes in input buffer
Returns
Number of bytes consumed

◆ Finish()

virtual bool kodi::addon::CInstanceAudioEncoder::Finish ( )
inlinevirtual

Finalize encoding (optional)

Returns
True on success, false on failure.

◆ Seek()

ssize_t kodi::addon::CInstanceAudioEncoder::Seek ( ssize_t position,
int whence = SEEK_SET )
inline

Set the file's current position.

The whence argument is optional and defaults to SEEK_SET (0)

Parameters
[in]positionThe position that you want to seek to
[in]whence[optional] offset relative to
You can set the value of whence to one of three things:
Value int Description
SEEK_SET 0 position is relative to the beginning of the file. This is probably what you had in mind anyway, and is the most commonly used value for whence.
SEEK_CUR 1 position is relative to the current file pointer position. So, in effect, you can say, "Move to my current position plus 30 bytes," or, "move to my current position minus 20 bytes."
SEEK_END 2 position is relative to the end of the file. Just like SEEK_SET except from the other end of the file. Be sure to use negative values for offset if you want to back up from the end of the file, instead of going past the end into oblivion.
Returns
Returns the resulting offset location as measured in bytes from the beginning of the file. On error, the value -1 is returned.
Remarks
Only called from addon itself.

◆ Start()

virtual bool kodi::addon::CInstanceAudioEncoder::Start ( const kodi::addon::AudioEncoderInfoTag & tag)
pure virtual

Start encoder (required)

Parameters
[in]tagInformation tag about
Returns
True on success, false on failure.

◆ Write()

ssize_t kodi::addon::CInstanceAudioEncoder::Write ( const uint8_t * data,
size_t length )
inline

Write block of data.

Parameters
[in]dataPointer to the array of elements to be written
[in]lengthSize in bytes to be written.
Returns
The total number of bytes successfully written is returned.
Remarks
Only called from addon itself.