From 401667516f56aacc1aaaa70f4694fda5ad12fc47 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 27 Sep 2014 20:01:00 +0200 Subject: [PATCH] Support for channel logos --- vdrcommand.h | 1 + vompclient.c | 22 ++++++++++++++++++---- vompclient.h | 7 ++++++- vompclientrrproc.c | 37 ++++++++++++++++++++++++++++++++----- vompclientrrproc.h | 1 + vompserver.c | 17 +++++++++-------- 6 files changed, 67 insertions(+), 18 deletions(-) diff --git a/vdrcommand.h b/vdrcommand.h index de3d29f..c9e4032 100644 --- a/vdrcommand.h +++ b/vdrcommand.h @@ -76,6 +76,7 @@ const static ULONG VDR_LOADTVMEDIA =41; const static ULONG VDR_LOADTVMEDIARECTHUMB =42; const static ULONG VDR_GETEVENTSCRAPEREVENTTYPE = 43; const static ULONG VDR_LOADTVMEDIAEVENTTHUMB =44; +const static ULONG VDR_LOADCHANNELLOGO = 45; const static ULONG VDR_SHUTDOWN = 666; diff --git a/vompclient.c b/vompclient.c index fb36de7..bc15aef 100644 --- a/vompclient.c +++ b/vompclient.c @@ -40,16 +40,20 @@ pthread_mutex_t threadClientMutex; int VompClient::nr_clients = 0; cPlugin *VompClient::scraper = NULL; +time_t VompClient::lastScrapQuery = 0; -VompClient::VompClient(Config* cfgBase, char* tconfigDir, int tsocket) +VompClient::VompClient(Config* cfgBase, char* tconfigDir, char* tlogoDir, + char *tresourceDir, int tsocket) : rrproc(*this), tcp(tsocket), i18n(tconfigDir) { #ifndef VOMPSTANDALONE lp = NULL; recplayer = NULL; recordingManager = NULL; - if (!scraper) scraper = cPluginManager::GetPlugin("scraper2vdr"); pict = new PictureReader(this); + if (!scraper) scrapQuery(); + logoDir = tlogoDir; + resourceDir = tresourceDir; #endif log = Log::getInstance(); loggedIn = false; @@ -107,6 +111,16 @@ VompClient::~VompClient() } } +cPlugin *VompClient::scrapQuery() +{ + if (scraper) return scraper; + if ((time(NULL)-lastScrapQuery) > 5*60) { + lastScrapQuery = time(NULL); + if (!scraper) scraper = cPluginManager::GetPlugin("scraper2vdr"); + } + return scraper; +} + void VompClient::setCharset(int charset) { charcoding=charset; @@ -401,7 +415,7 @@ cChannel* VompClient::channelFromNumber(ULONG channelNumber) { if (!channel->GroupSep()) { - log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name()); +// log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name()); if (channel->Number() == (int)channelNumber) { @@ -411,7 +425,7 @@ cChannel* VompClient::channelFromNumber(ULONG channelNumber) #else int apid1 = channel->Apid(0); #endif - log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1); +// log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1); return channel; } } diff --git a/vompclient.h b/vompclient.h index 8c54b84..1856cdd 100644 --- a/vompclient.h +++ b/vompclient.h @@ -71,7 +71,8 @@ class VompClient friend class PictureReader; public: - VompClient(Config* baseConfig, char* configDir, int tsocket); + VompClient(Config* baseConfig, char* configDir, char* logoDir, + char* resourceDir, int tsocket); ~VompClient(); int run(); @@ -111,7 +112,11 @@ class VompClient cRecordings* recordingManager; RecPlayer* recplayer; static cPlugin * scraper; + static time_t lastScrapQuery; + static cPlugin* scrapQuery(); PictureReader * pict; + char *logoDir; + char *resourceDir; #endif MediaPlayer *media; diff --git a/vompclientrrproc.c b/vompclientrrproc.c index f45fa29..5af35da 100644 --- a/vompclientrrproc.c +++ b/vompclientrrproc.c @@ -296,7 +296,9 @@ bool VompClientRRProc::processPacket() case VDR_LOADTVMEDIAEVENTTHUMB: result = processLoadTvMediaEventThumb(); break; - + case VDR_LOADCHANNELLOGO: + result = processLoadChannelLogo(); + break; #endif case VDR_GETMEDIALIST: result = processGetMediaList(); @@ -2021,7 +2023,7 @@ int VompClientRRProc::processGetRecScraperEventType() ScraperGetEventType call; call.type = tNone; - if (recording && x.scraper) + if (recording && x.scrapQuery()) { call.recording = recording; x.scraper->Service("GetEventType",&call); @@ -2066,7 +2068,7 @@ int VompClientRRProc::processGetEventScraperEventType() } } - if (event && x.scraper) + if (event && x.scrapQuery()) { call.event = event; x.scraper->Service("GetEventType",&call); @@ -2092,7 +2094,7 @@ int VompClientRRProc::processGetScraperMovieInfo() cMovie movie; movie.movieId = ntohl(*(ULONG*)req->data); - if (!x.scraper) { + if (!x.scrapQuery()) { log->log("RRProc", Log::DEBUG, "No Scraper, get SeriesInfo"); return 0; //stupid, I have no scraper why are you still asking } @@ -2143,7 +2145,7 @@ int VompClientRRProc::processGetScraperSeriesInfo() cSeries series; series.seriesId = ntohl(*(ULONG*)req->data); series.episodeId = ntohl(*(ULONG*)(req->data+4)); - if (!x.scraper) { + if (!x.scrapQuery()) { log->log("RRProc", Log::DEBUG, "No Scraper, get SeriesInfo"); return 0; //stupid, I have no scraper why are you still asking } @@ -2275,6 +2277,31 @@ int VompClientRRProc::processLoadTvMediaEventThumb() return 1; } +int VompClientRRProc::processLoadChannelLogo() +{ + TVMediaRequest tvreq; + tvreq.streamID = req->requestID; + tvreq.type = 5; // channel logo + UINT channelid = ntohl(*(ULONG*)req->data); + tvreq.primary_id = channelid; + tvreq.secondary_id = 0; + cChannel* channel = x.channelFromNumber(channelid); + + if (channel) tvreq.primary_name = std::string((const char*)channel->Name()); + tvreq.type_pict = 1; + tvreq.container = 0; + tvreq.container_member = 0; + log->log("RRProc", Log::DEBUG, "TVMedia request %d %d %s",req->requestID,channelid, channel->Name()); + x.pict->addTVMediaRequest(tvreq); + + + resp->finalise(); + + x.tcp.sendPacket(resp->getPtr(), resp->getLen()); + + return 1; +} + diff --git a/vompclientrrproc.h b/vompclientrrproc.h index e59fddf..1c0fb6b 100644 --- a/vompclientrrproc.h +++ b/vompclientrrproc.h @@ -90,6 +90,7 @@ class VompClientRRProc : public Thread int processLoadTvMediaRecThumb(); int processGetEventScraperEventType(); int processLoadTvMediaEventThumb(); + int processLoadChannelLogo(); #endif int processLogin(); diff --git a/vompserver.c b/vompserver.c index b59a037..3ded2b0 100644 --- a/vompserver.c +++ b/vompserver.c @@ -74,6 +74,7 @@ cPluginVompserver::~cPluginVompserver() // Clean up after yourself! mvpserver.stop(); if (configDir) delete[] configDir; + } const char *cPluginVompserver::CommandLineHelp(void) @@ -91,15 +92,15 @@ bool cPluginVompserver::ProcessArgs(int argc, char *argv[]) { if (c == 'c') { - const char* vdrdeveldevelret = cPlugin::ConfigDirectory(optarg); - if (!vdrdeveldevelret) + const char* vdrret = cPlugin::ConfigDirectory(optarg); + if (!vdrret) { dsyslog("VOMP: Could not get config dir from VDR"); return false; } - configDir = new char[strlen(vdrdeveldevelret)+1]; - strcpy(configDir, vdrdeveldevelret); + configDir = new char[strlen(vdrret)+1]; + strcpy(configDir, vdrret); } else { @@ -122,14 +123,14 @@ bool cPluginVompserver::Start(void) if (!configDir) { - const char* vdrdeveldevelret = cPlugin::ConfigDirectory("vompserver"); - if (!vdrdeveldevelret) + const char* vdrret = cPlugin::ConfigDirectory("vompserver"); + if (!vdrret) { dsyslog("VOMP: Could not get config dir from VDR"); return false; } - configDir = new char[strlen(vdrdeveldevelret)+1]; - strcpy(configDir, vdrdeveldevelret); + configDir = new char[strlen(vdrret)+1]; + strcpy(configDir, vdrret); } int success = mvpserver.run(configDir); -- 2.39.2