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 cRecordings Recordings;
196 cRecording *recording = Recordings.GetByName((char*) req.primary_name.c_str());
197 ScraperGetPosterThumb getter;
198 getter.recording = recording;
200 if (x->scraper && recording) {
201 x->scraper->Service("GetPosterThumb",&getter);
202 return getter.poster.path;
204 return std::string("");
207 case 4: { // I do not know
208 // First get the schedules
209 cSchedulesLock MutexLock;
210 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
211 const cSchedule *Schedule = NULL;
214 cChannel * channel = Channels.GetByChannelID(
215 tChannelID::FromString(req.primary_name.c_str()));
216 Schedule = Schedules->GetSchedule(channel);
218 const cEvent *event = NULL;
219 if (Schedule) event=Schedule->GetEvent(req.primary_id);
220 ScraperGetPosterThumb getter;
221 getter.event = event;
222 getter.recording = NULL;
224 if (x->scraper && event) {
225 x->scraper->Service("GetPosterThumb",&getter);
226 if (getter.poster.width) return getter.poster.path;
229 std::ostringstream file;
230 file<< std::string(x->imageDir)<< req.primary_id << std::string(".jpg");
231 if (!access(file.str().c_str() ,F_OK))
236 std::ostringstream file2;
237 file2 << std::string(x->imageDir) << req.primary_id << std::string("_0.jpg");
238 if (!access(file2.str().c_str() ,F_OK))
242 } else if (x->cacheDir) {
244 std::ostringstream file;
245 file<<std::string(x->cacheDir)<<std::string("/../epgimages/")
246 <<req.primary_id << std::string(".jpg");
247 if (!access(file.str().c_str() ,F_OK))
251 std::ostringstream file2;
252 file2<<std::string(x->cacheDir)<<std::string("/../epgimages/")<<
253 req.primary_id<<std::string("_0.jpg");
254 if (!access(file2.str().c_str() ,F_OK))
259 return std::string("");
261 case 5: { // Channel logo
262 std::transform(req.primary_name.begin(),req.primary_name.end(),
263 req.primary_name.begin(),::tolower);
265 std::string file=std::string(x->logoDir)+req.primary_name+std::string(".png");
266 if (!access(file.c_str() ,F_OK))
271 // if noopacity is there steal the logos
272 if (x->resourceDir) {
273 std::string file=std::string(x->resourceDir)
274 +std::string("/skinnopacity/logos/")+req.primary_name+std::string(".png");
275 if (!access(file.c_str() ,F_OK))
280 return std::string("");
285 return std::string("");
288 return std::string("");
293 void PictureReader::threadMethod()
296 ULONG headerLength = sizeof(ULONG) * 4;
297 UCHAR buffer[headerLength];
299 // threadSetKillable(); ??
301 logger->log("PictRead",Log::DEBUG,"PictureReaderThread started");
305 threadWaitForSignal();
309 logger->log("PictRead",Log::DEBUG,"Thread was signaled, wake up");
315 pthread_mutex_lock(&pictureLock);
316 if (!pictures.empty()) {
318 req = pictures.front();
321 pthread_mutex_unlock(&pictureLock);
322 if (!newpicture) break;
323 std::string pictname = getPictName(req);
327 logger->log("PictRead",Log::DEBUG,"Load Pict %s",pictname.c_str());
330 if (pictname.length()) {
334 stat(pictname.c_str(), &st);
335 filesize = st.st_size;
336 memsize = filesize + headerLength;
338 if (memsize && memsize < 1000000) { // No pictures over 1 MB
339 mem = (UCHAR*)malloc(memsize);
341 FILE * file=fopen(pictname.c_str(),"r");
344 size_t size=fread(mem+headerLength,1,filesize,file);
347 if (size!=filesize) memsize=headerLength; // error
359 p = (ULONG*)&mem[0]; *p = htonl(5); // stream channel
360 p = (ULONG*)&mem[4]; *p = htonl(req.streamID);
361 p = (ULONG*)&mem[8]; *p = htonl(flag); // here insert flag: 0 = ok, data follows
362 p = (ULONG*)&mem[12]; *p = htonl(memsize);
364 if (!tcp->sendPacket(mem, memsize + headerLength)) {
365 logger->log("PictRead",Log::DEBUG,"Sending Picture failed");
368 if (mem != buffer && mem) free(mem);
370 } while (newpicture);
372 logger->log("PictRead",Log::DEBUG,"PictureReaderThread ended");