11#include "../AddonBase.h"
12#include "../AudioEngine.h"
13#include "../c-api/addon-instance/audiodecoder.h"
25class CInstanceAudioDecoder;
79 void SetTitle(
const std::string& title) { m_title = title; }
82 const std::string&
GetTitle()
const {
return m_title; }
85 void SetArtist(
const std::string& artist) { m_artist = artist; }
88 const std::string&
GetArtist()
const {
return m_artist; }
91 void SetAlbum(
const std::string& album) { m_album = album; }
94 const std::string&
GetAlbum()
const {
return m_album; }
97 void SetAlbumArtist(
const std::string& albumArtist) { m_album_artist = albumArtist; }
112 void SetMediaType(
const std::string& mediaType) { m_media_type = mediaType; }
118 void SetGenre(
const std::string& genre) { m_genre = genre; }
121 const std::string&
GetGenre()
const {
return m_genre; }
142 void SetDiscSubtitle(
const std::string& discSubtitle) { m_disc_subtitle = discSubtitle; }
155 void SetReleaseDate(
const std::string& releaseDate) { m_release_date = releaseDate; }
161 void SetLyrics(
const std::string& lyrics) { m_lyrics = lyrics; }
164 const std::string&
GetLyrics()
const {
return m_lyrics; }
185 void SetComment(
const std::string& comment) { m_comment = comment; }
221 m_cover_art_mem_mimetype = mimetype;
222 m_cover_art_mem.resize(size);
223 m_cover_art_mem.assign(data, data + size);
239 if (!m_cover_art_mem.empty())
241 mimetype = m_cover_art_mem_mimetype;
242 size = m_cover_art_mem.size();
243 return m_cover_art_mem.data();
256 std::string m_artist;
258 std::string m_album_artist;
259 std::string m_media_type;
264 std::string m_disc_subtitle;
266 std::string m_release_date;
267 std::string m_lyrics;
271 std::string m_comment;
272 std::string m_cover_art_path;
273 std::string m_cover_art_mem_mimetype;
274 std::vector<uint8_t> m_cover_art_mem;
470 if (CPrivateBase::m_interface->globalSingleInstance !=
nullptr)
471 throw std::logic_error(
"kodi::addon::CInstanceAudioDecoder: Creation of multiple together "
472 "with single instance way is not allowed!");
474 SetAddonStruct(instance);
487 virtual bool SupportsFile(
const std::string& filename) {
return true; }
509 virtual bool Init(
const std::string& filename,
510 unsigned int filecache,
517 std::vector<AudioEngineChannel>& channellist) = 0;
529 virtual int ReadPCM(uint8_t* buffer,
size_t size,
size_t& actualsize) = 0;
539 virtual int64_t
Seek(int64_t time) {
return time; }
567 virtual int TrackCount(
const std::string& file) {
return 1; }
584 inline static std::string
GetTrack(
const std::string& name,
585 const std::string& trackPath,
592 std::string toLoad(trackPath);
594 if (toLoad.find(ext) != std::string::npos)
596 size_t iStart = toLoad.rfind(
'-') + 1;
597 track = atoi(toLoad.substr(iStart, toLoad.size() - iStart - ext.size()).c_str());
601 size_t slash = trackPath.rfind(
'\\');
602 if (slash == std::string::npos)
603 slash = trackPath.rfind(
'/');
604 toLoad = trackPath.substr(0, slash);
614 instance->hdl =
this;
615 instance->audiodecoder->toAddon->supports_file = ADDON_supports_file;
616 instance->audiodecoder->toAddon->init = ADDON_init;
617 instance->audiodecoder->toAddon->read_pcm = ADDON_read_pcm;
618 instance->audiodecoder->toAddon->seek = ADDON_seek;
619 instance->audiodecoder->toAddon->read_tag = ADDON_read_tag;
620 instance->audiodecoder->toAddon->track_count = ADDON_track_count;
623 inline static bool ADDON_supports_file(
const KODI_ADDON_AUDIODECODER_HDL hdl,
const char* file)
625 return static_cast<CInstanceAudioDecoder*
>(hdl)->SupportsFile(file);
628 inline static bool ADDON_init(
const KODI_ADDON_AUDIODECODER_HDL hdl,
630 unsigned int filecache,
639 CInstanceAudioDecoder* thisClass =
static_cast<CInstanceAudioDecoder*
>(hdl);
641 std::vector<AudioEngineChannel> channelList;
643 bool ret = thisClass->Init(file, filecache, *channels, *samplerate, *bitspersample, *totaltime,
644 *bitrate, *format, channelList);
645 if (!channelList.empty())
650 for (
unsigned int i = 0; i < channelList.size(); ++i)
652 info[i] = channelList[i];
658 inline static int ADDON_read_pcm(
const KODI_ADDON_AUDIODECODER_HDL hdl,
663 return static_cast<CInstanceAudioDecoder*
>(hdl)->ReadPCM(buffer, size, *actualsize);
666 inline static int64_t ADDON_seek(
const KODI_ADDON_AUDIODECODER_HDL hdl, int64_t time)
668 return static_cast<CInstanceAudioDecoder*
>(hdl)->Seek(time);
671 inline static bool ADDON_read_tag(
const KODI_ADDON_AUDIODECODER_HDL hdl,
677#pragma warning(disable : 4996)
680 bool ret =
static_cast<CInstanceAudioDecoder*
>(hdl)->ReadTag(file, cppTag);
683 tag->title = strdup(cppTag.
GetTitle().c_str());
684 tag->artist = strdup(cppTag.
GetArtist().c_str());
685 tag->album = strdup(cppTag.
GetAlbum().c_str());
687 tag->media_type = strdup(cppTag.
GetMediaType().c_str());
688 tag->genre = strdup(cppTag.
GetGenre().c_str());
695 tag->lyrics = strdup(cppTag.
GetLyrics().c_str());
699 tag->comment = strdup(cppTag.
GetComment().c_str());
700 std::string mimetype;
705 tag->cover_art_mem_mimetype = strdup(mimetype.c_str());
706 tag->cover_art_mem_size = size;
707 tag->cover_art_mem =
static_cast<uint8_t*
>(malloc(size));
708 memcpy(tag->cover_art_mem, mem, size);
721 inline static int ADDON_track_count(
const KODI_ADDON_AUDIODECODER_HDL hdl,
const char* file)
723 return static_cast<CInstanceAudioDecoder*
>(hdl)->TrackCount(file);
Definition AudioDecoder.h:42
Definition AudioDecoder.h:431
Definition AddonBase.h:565
Definition AddonBase.h:498
int GetDisc() const
Get disk number (if present)
Definition AudioDecoder.h:139
const std::string & GetAlbumArtist() const
Get album artist name.
Definition AudioDecoder.h:100
void SetDiscSubtitle(const std::string &discSubtitle)
Set disk subtitle name (if present) from music info.
Definition AudioDecoder.h:142
void SetAlbum(const std::string &album)
Set album name.
Definition AudioDecoder.h:91
void SetComment(const std::string &comment)
Set additional information comment (if present).
Definition AudioDecoder.h:185
const uint8_t * GetCoverArtByMem(size_t &size, std::string &mimetype) const
Get cover art data by memory.
Definition AudioDecoder.h:237
const std::string & GetCoverArtByPath() const
Get cover art image path.
Definition AudioDecoder.h:204
void SetMediaType(const std::string &mediaType)
Set the media type of the music item.
Definition AudioDecoder.h:112
void SetDuration(int duration)
Set the duration of music as integer from info.
Definition AudioDecoder.h:124
void SetLyrics(const std::string &lyrics)
Set string from lyrics.
Definition AudioDecoder.h:161
const std::string & GetDiscSubtitle() const
Get disk subtitle name (if present) from music info.
Definition AudioDecoder.h:145
const std::string & GetAlbum() const
Set album name.
Definition AudioDecoder.h:94
void SetDiscTotal(int discTotal)
Set disks amount quantity (if present) from music info as integer.
Definition AudioDecoder.h:148
void SetCoverArtByMem(const uint8_t *data, size_t size, const std::string &mimetype)
Set cover art image by memory.
Definition AudioDecoder.h:217
void SetBitrate(int bitrate)
Set related stream bitrate.
Definition AudioDecoder.h:179
void SetTitle(const std::string &title)
Set the title from music as string on info tag.
Definition AudioDecoder.h:79
const std::string & GetMediaType() const
Get the media type of the music item.
Definition AudioDecoder.h:115
const std::string & GetReleaseDate() const
Get release date as string from music info (if present).
Definition AudioDecoder.h:158
void SetDisc(int disc)
Set disk number (if present) from music info as integer.
Definition AudioDecoder.h:136
void SetArtist(const std::string &artist)
Set artist name.
Definition AudioDecoder.h:85
void SetAlbumArtist(const std::string &albumArtist)
Set album artist name.
Definition AudioDecoder.h:97
void SetChannels(int channels)
Set related stream channels amount.
Definition AudioDecoder.h:173
const std::string & GetComment() const
Get additional information comment (if present).
Definition AudioDecoder.h:188
int GetDuration() const
Get the duration of music as integer from info.
Definition AudioDecoder.h:127
void SetTrack(int track)
Set track number (if present) from music info as integer.
Definition AudioDecoder.h:130
const std::string & GetGenre() const
Get genre name from music as string if present.
Definition AudioDecoder.h:121
int GetBitrate() const
Get related stream bitrate.
Definition AudioDecoder.h:182
void SetCoverArtByPath(const std::string &path)
Set cover art image by path.
Definition AudioDecoder.h:195
void SetReleaseDate(const std::string &releaseDate)
Set release date as string from music info (if present). ISO8601 date YYYY, YYYY-MM or YYYY-MM-DD.
Definition AudioDecoder.h:155
const std::string & GetLyrics() const
Get string from lyrics.
Definition AudioDecoder.h:164
const std::string & GetTitle() const
Get title name.
Definition AudioDecoder.h:82
void SetSamplerate(int samplerate)
Set related stream samplerate.
Definition AudioDecoder.h:167
int GetDiscTotal() const
Get disks amount quantity (if present)
Definition AudioDecoder.h:151
int GetTrack() const
Get track number (if present).
Definition AudioDecoder.h:133
void SetGenre(const std::string &genre)
Set genre name from music as string if present.
Definition AudioDecoder.h:118
int GetChannels() const
Get related stream channels amount.
Definition AudioDecoder.h:176
const std::string & GetArtist() const
Get artist name.
Definition AudioDecoder.h:88
int GetSamplerate() const
Get related stream samplerate.
Definition AudioDecoder.h:170
#define KODI_ADDON_AUDIODECODER_TRACK_EXT
Identifier which is attached to stream files and with defined names in addon.xml (name="?...
Definition audiodecoder.h:26
static std::string GetTrack(const std::string &name, const std::string &trackPath, int &track)
Static auxiliary function to read the track number used from the given path.
Definition AudioDecoder.h:584
virtual bool SupportsFile(const std::string &filename)
Checks addon support given file path.
Definition AudioDecoder.h:487
virtual bool ReadTag(const std::string &file, kodi::addon::AudioDecoderInfoTag &tag)
Read tag of a file.
Definition AudioDecoder.h:554
virtual int64_t Seek(int64_t time)
Seek in output stream.
Definition AudioDecoder.h:539
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)=0
Initialize a decoder.
CInstanceAudioDecoder(const kodi::addon::IInstanceInfo &instance)
Audio decoder class constructor used to support multiple instance types.
Definition AudioDecoder.h:467
virtual int TrackCount(const std::string &file)
Get number of tracks in a file.
Definition AudioDecoder.h:567
virtual int ReadPCM(uint8_t *buffer, size_t size, size_t &actualsize)=0
Produce some noise.
AudioEngineChannel
Definition audio_engine.h:70
@ AUDIOENGINE_CH_NULL
Used inside to indicate the end of a list and not for addon use directly.
Definition audio_engine.h:72
@ AUDIOENGINE_CH_MAX
Maximum possible value, to use e.g. as size inside list.
Definition audio_engine.h:116
Definition audiodecoder.h:78
Definition addon_base.h:268
Definition visualization.h:22