From b566869f938f2725c132de932cc1daab3cef9bd4 Mon Sep 17 00:00:00 2001 From: TangoCash Date: Thu, 20 Sep 2018 12:24:22 +0200 Subject: [PATCH] speed up starting neutrino while loading xmltv logos, the better way Signed-off-by: Thilo Graf --- src/zapit/include/zapit/bouquets.h | 7 +++++- src/zapit/src/bouquets.cpp | 39 +++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/zapit/include/zapit/bouquets.h b/src/zapit/include/zapit/bouquets.h index 898e7542b..22de6162e 100644 --- a/src/zapit/include/zapit/bouquets.h +++ b/src/zapit/include/zapit/bouquets.h @@ -108,8 +108,12 @@ class CBouquetManager std::map EpgIDMapping; void readEPGMapping(); t_channel_id reMapEpgID(t_channel_id channelid); + //logo downloads + static void* LogoThread(void* _logolist); + pthread_t thrLogo; + ZapitChannelList LogoList; public: - CBouquetManager() { remainChannels = NULL; }; + CBouquetManager() { remainChannels = NULL; thrLogo = 0; }; ~CBouquetManager(); class ChannelIterator { @@ -157,6 +161,7 @@ class CBouquetManager void setBouquetLock(CZapitBouquet* bouquet, bool state); void loadWebtv(); void loadWebradio(); + void loadLogos(); void loadWebchannels(int mode); std::string ReadMarkerValue(std::string strLine, const char* strMarkerName); //bouquet writeChannelsNames selection options diff --git a/src/zapit/src/bouquets.cpp b/src/zapit/src/bouquets.cpp index e9c968507..f02f250a2 100644 --- a/src/zapit/src/bouquets.cpp +++ b/src/zapit/src/bouquets.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -54,6 +55,7 @@ #define GROUP_NAME_MARKER "group-title=" extern CBouquetManager *g_bouquetManager; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; #define GET_ATTR(node, name, fmt, arg) \ do { \ @@ -527,6 +529,7 @@ void CBouquetManager::loadBouquets(bool ignoreBouquetFile) loadWebtv(); loadWebradio(); + loadLogos(); parseBouquetsXml(UBOUQUETS_XML, true); renumServices(); CServiceManager::getInstance()->SetCIFilter(); @@ -1037,7 +1040,10 @@ void CBouquetManager::loadWebchannels(int mode) CZapitChannel * channel = new CZapitChannel(title.c_str(), chid, url, desc.c_str(), chid, epg_script.c_str(), mode); CServiceManager::getInstance()->AddChannel(channel); if (!alogo.empty()) - channel->setAlternateLogo(downloadUrlToRandomFile(alogo, LOGODIR_TMP)); + { + channel->setAlternateLogo(alogo); + LogoList.push_back(channel); + } channel->flags = CZapitChannel::UPDATED; if (gbouquet) gbouquet->addService(channel); @@ -1112,6 +1118,37 @@ void CBouquetManager::loadWebchannels(int mode) } } +void CBouquetManager::loadLogos() +{ + + if(thrLogo != 0) + { + pthread_cancel(thrLogo); + pthread_join(thrLogo, NULL); + thrLogo = 0; + } + + if (LogoList.size() > 0) + pthread_create(&thrLogo, NULL, LogoThread, (void*)&LogoList); +} + +void* CBouquetManager::LogoThread(void* _logolist) +{ + set_threadname(__func__); + pthread_mutex_lock (&mutex); + ZapitChannelList *LogoList = (ZapitChannelList *)_logolist; + for (ZapitChannelList::iterator it = LogoList->begin(); it != LogoList->end(); ++it) + { + CZapitChannel *cc = (*it); + if (cc) + cc->setAlternateLogo(downloadUrlToRandomFile(cc->getAlternateLogo(), LOGODIR_TMP)); + } + LogoList->clear(); + pthread_mutex_unlock(&mutex); + pthread_exit(0); + return NULL; +} + CBouquetManager::ChannelIterator::ChannelIterator(CBouquetManager* owner, const bool TV) { Owner = owner;