1 #include "picturereader.h"
2 #include <vdr/plugin.h>
3 #include <vdr/channels.h>
8 PictureReader::PictureReader(VompClient *client)
10 logger = Log::getInstance();
15 pthread_mutex_init(&pictureLock, NULL);
18 int PictureReader::init(TCP* ttcp)
26 PictureReader::~PictureReader()
31 void PictureReader::addTVMediaRequest(TVMediaRequest& req)
33 logger->log("PictRead",Log::DEBUG,"Got TVMediaRequest, signal thread!");
35 pthread_mutex_lock(&pictureLock);
37 threadSignal(); // Signal, that we have something to do!!!
38 pthread_mutex_unlock(&pictureLock);
41 bool PictureReader::epgImageExists(int event)
44 std::ostringstream file;
45 file<< std::string(x->imageDir)<< event << std::string(".jpg");
46 if (!access(file.str().c_str() ,F_OK))
51 std::ostringstream file2;
52 file2 << std::string(x->imageDir) << event << std::string("_0.jpg");
53 if (!access(file2.str().c_str() ,F_OK))
57 } else if (x->cacheDir) {
59 std::ostringstream file;
60 file<<std::string(x->cacheDir)<<std::string("/../epgimages/")
61 << event << std::string(".jpg");
62 if (!access(file.str().c_str() ,F_OK))
66 std::ostringstream file2;
67 file2<<std::string(x->cacheDir)<<std::string("/../epgimages/")<<
68 event <<std::string("_0.jpg");
69 if (!access(file2.str().c_str() ,F_OK))
77 std::string PictureReader::getPictName(TVMediaRequest & req)
79 logger->log("PictRead",Log::DEBUG,
80 "Request %d %d; %d %d %d %d",req.primary_id,req.secondary_id,
81 req.type,req.type_pict,
82 req.container,req.container_member);
86 if (series.seriesId != (int)req.primary_id ||
87 series.episodeId != (int)req.secondary_id) {
88 series.actors.clear();
89 series.posters.clear();
90 series.banners.clear();
91 series.fanarts.clear();
93 series.seriesId = req.primary_id;
94 series.episodeId = req.secondary_id;
95 x->scraper->Service("GetSeries",&series);
97 if (req.type_pict == 0) {
98 switch (req.container) {
100 return series.episode.episodeImage.path;
103 if (series.actors.size()>req.container_member) {
104 return series.actors[req.container_member].actorThumb.path;
108 if (series.posters.size()>req.container_member) {
109 return series.posters[req.container_member].path;
113 if (series.banners.size()>req.container_member) {
114 return series.banners[req.container_member].path;
118 if (series.fanarts.size()>req.container_member) {
119 return series.fanarts[req.container_member].path;
123 return series.seasonPoster.path;
126 return std::string("");
129 } else if (req.type_pict == 1 && series.posters.size()) { //poster
130 std::string str=series.posters[0].path;
131 size_t pos=str.rfind('/');
132 if (pos!=std::string::npos) {
134 str=str+"poster_thumb.jpg";
137 } else if (req.type_pict == 2) { //poster
138 std::string str=series.seasonPoster.path;
139 size_t pos=str.rfind('/');
140 if (pos!=std::string::npos) {
142 std::ostringstream out;
143 out << str << "season_" <<series.episode.season <<"_thumb.jpg";
147 return std::string("");
150 if (movie.movieId != (int)req.primary_id ) {
151 movie.actors.clear();
152 movie.movieId = req.primary_id;
153 x->scraper->Service("GetMovie",&movie);
155 if (req.type_pict == 0) {
157 switch (req.container) {
159 return movie.poster.path;
162 return movie.fanart.path;
165 return movie.collectionPoster.path;
168 return movie.collectionFanart.path;
171 if (movie.actors.size()>req.container_member) {
172 return movie.actors[req.container_member].actorThumb.path;
176 return std::string("");
179 } else if (req.type_pict == 1) { //poster
180 std::string str=movie.poster.path;
181 size_t pos=str.rfind('/');
182 if (pos!=std::string::npos) {
184 str=str+"poster_thumb.jpg";
188 return std::string("");
192 case 3: { // I do not know
193 // First get the recording
194 #if VDRVERSNUM >= 20301
195 LOCK_RECORDINGS_READ;
196 const cRecordings* tRecordings = Recordings;
198 cThreadLock RecordingsLock(&Recordings);
199 cRecordings* tRecordings = &Recordings;
201 const cRecording *recording = tRecordings->GetByName((char*) req.primary_name.c_str());
202 ScraperGetPosterThumb getter;
203 getter.recording = recording;
205 if (x->scraper && recording) {
206 x->scraper->Service("GetPosterThumb",&getter);
207 return getter.poster.path;
209 return std::string("");
212 case 4: { // I do not know
213 // First get the schedules
215 #if VDRVERSNUM >= 20301
217 const cChannels* tChannels = Channels;
219 cChannels* tChannels = &Channels;
223 #if VDRVERSNUM < 10300
224 cMutexLock MutexLock;
225 const cSchedules *tSchedules = cSIProcessor::Schedules(MutexLock);
226 #elif VDRVERSNUM < 20301
227 cSchedulesLock MutexLock;
228 const cSchedules *tSchedules = cSchedules::Schedules(MutexLock);
231 const cSchedules *tSchedules = Schedules;
234 const cSchedule *Schedule = NULL;
237 const cChannel* channel = tChannels->GetByChannelID(tChannelID::FromString(req.primary_name.c_str()));
238 Schedule = tSchedules->GetSchedule(channel);
240 const cEvent *event = NULL;
241 if (Schedule) event=Schedule->GetEvent(req.primary_id);
242 ScraperGetPosterThumb getter;
243 getter.event = event;
244 getter.recording = NULL;
246 if (x->scraper && event) {
247 x->scraper->Service("GetPosterThumb",&getter);
248 if (getter.poster.width) return getter.poster.path;
251 std::ostringstream file;
252 file<< std::string(x->imageDir)<< req.primary_id << std::string(".jpg");
253 if (!access(file.str().c_str() ,F_OK))
258 std::ostringstream file2;
259 file2 << std::string(x->imageDir) << req.primary_id << std::string("_0.jpg");
260 if (!access(file2.str().c_str() ,F_OK))
264 } else if (x->cacheDir) {
266 std::ostringstream file;
267 file<<std::string(x->cacheDir)<<std::string("/../epgimages/")
268 <<req.primary_id << std::string(".jpg");
269 if (!access(file.str().c_str() ,F_OK))
273 std::ostringstream file2;
274 file2<<std::string(x->cacheDir)<<std::string("/../epgimages/")<<
275 req.primary_id<<std::string("_0.jpg");
276 if (!access(file2.str().c_str() ,F_OK))
281 return std::string("");
283 case 5: { // Channel logo
284 std::transform(req.primary_name.begin(),req.primary_name.end(),
285 req.primary_name.begin(),::tolower);
287 std::string file=std::string(x->logoDir)+req.primary_name+std::string(".png");
288 if (!access(file.c_str() ,F_OK))
293 // if noopacity is there steal the logos
294 if (x->resourceDir) {
295 std::string file=std::string(x->resourceDir)
296 +std::string("/skinnopacity/logos/")+req.primary_name+std::string(".png");
297 if (!access(file.c_str() ,F_OK))
302 return std::string("");
307 return std::string("");
310 return std::string("");
315 void PictureReader::threadMethod()
318 ULONG headerLength = sizeof(ULONG) * 4;
319 UCHAR buffer[headerLength];
321 // threadSetKillable(); ??
323 logger->log("PictRead",Log::DEBUG,"PictureReaderThread started");
327 threadWaitForSignal();
331 logger->log("PictRead",Log::DEBUG,"Thread was signaled, wake up");
337 pthread_mutex_lock(&pictureLock);
338 if (!pictures.empty()) {
340 req = pictures.front();
343 pthread_mutex_unlock(&pictureLock);
344 if (!newpicture) break;
345 std::string pictname = getPictName(req);
349 logger->log("PictRead",Log::DEBUG,"Load Pict %s",pictname.c_str());
352 if (pictname.length()) {
356 stat(pictname.c_str(), &st);
357 filesize = st.st_size;
358 memsize = filesize + headerLength;
360 if (memsize && memsize < 1000000) { // No pictures over 1 MB
361 mem = (UCHAR*)malloc(memsize);
363 FILE * file=fopen(pictname.c_str(),"r");
366 size_t size=fread(mem+headerLength,1,filesize,file);
369 if (size!=filesize) memsize=headerLength; // error
381 p = (ULONG*)&mem[0]; *p = htonl(5); // stream channel
382 p = (ULONG*)&mem[4]; *p = htonl(req.streamID);
383 p = (ULONG*)&mem[8]; *p = htonl(flag); // here insert flag: 0 = ok, data follows
384 p = (ULONG*)&mem[12]; *p = htonl(memsize);
386 if (!tcp->sendPacket(mem, memsize + headerLength)) {
387 logger->log("PictRead",Log::DEBUG,"Sending Picture failed");
390 if (mem != buffer && mem) free(mem);
392 } while (newpicture);
394 logger->log("PictRead",Log::DEBUG,"PictureReaderThread ended");