1 #include "picturereader.h"
2 #include <vdr/plugin.h>
6 PictureReader::PictureReader(VompClient *client)
8 logger = Log::getInstance();
13 pthread_mutex_init(&pictureLock, NULL);
16 int PictureReader::init(TCP* ttcp)
24 PictureReader::~PictureReader()
29 void PictureReader::addTVMediaRequest(TVMediaRequest& req)
31 logger->log("PictRead",Log::DEBUG,"Got TVMediaRequest, signal thread!");
33 pthread_mutex_lock(&pictureLock);
35 threadSignal(); // Signal, that we have something to do!!!
36 pthread_mutex_unlock(&pictureLock);
39 std::string PictureReader::getPictName(TVMediaRequest & req)
41 logger->log("PictRead",Log::DEBUG,
42 "Request %d %d; %d %d %d %d",req.primary_id,req.secondary_id,
43 req.type,req.type_pict,
44 req.container,req.container_member);
48 if (series.seriesId != req.primary_id ||
49 series.episodeId != req.secondary_id) {
50 series.actors.clear();
51 series.posters.clear();
52 series.banners.clear();
53 series.fanarts.clear();
55 series.seriesId = req.primary_id;
56 series.episodeId = req.secondary_id;
57 x->scraper->Service("GetSeries",&series);
59 if (req.type_pict == 0) {
60 switch (req.container) {
62 return series.episode.episodeImage.path;
65 if (series.actors.size()>req.container_member) {
66 return series.actors[req.container_member].actorThumb.path;
70 if (series.posters.size()>req.container_member) {
71 return series.posters[req.container_member].path;
75 if (series.banners.size()>req.container_member) {
76 return series.banners[req.container_member].path;
80 if (series.fanarts.size()>req.container_member) {
81 return series.fanarts[req.container_member].path;
85 return series.seasonPoster.path;
88 return std::string("");
91 } else if (req.type_pict == 1 && series.posters.size()) { //poster
92 std::string str=series.posters[0].path;
93 size_t pos=str.rfind('/');
94 if (pos!=std::string::npos) {
96 str=str+"poster_thumb.jpg";
99 } else if (req.type_pict == 2) { //poster
100 std::string str=series.seasonPoster.path;
101 size_t pos=str.rfind('/');
102 if (pos!=std::string::npos) {
104 std::ostringstream out;
105 out << str << "season_" <<series.episode.season <<"_thumb.jpg";
109 return std::string("");
112 if (movie.movieId != req.primary_id ) {
113 movie.actors.clear();
114 movie.movieId = req.primary_id;
115 x->scraper->Service("GetMovie",&movie);
117 if (req.type_pict == 0) {
119 switch (req.container) {
121 return movie.poster.path;
124 return movie.fanart.path;
127 return movie.collectionPoster.path;
130 return movie.collectionFanart.path;
133 if (movie.actors.size()>req.container_member) {
134 return movie.actors[req.container_member].actorThumb.path;
138 return std::string("");
141 } else if (req.type_pict == 1) { //poster
142 std::string str=movie.poster.path;
143 size_t pos=str.rfind('/');
144 if (pos!=std::string::npos) {
146 str=str+"poster_thumb.jpg";
150 return std::string("");
156 return std::string("");
164 void PictureReader::threadMethod()
167 ULONG headerLength = sizeof(ULONG) * 4;
168 UCHAR buffer[headerLength];
171 // threadSetKillable(); ??
173 logger->log("PictRead",Log::DEBUG,"PictureReaderThread started");
177 threadWaitForSignal();
181 logger->log("PictRead",Log::DEBUG,"Thread was signaled, wake up");
187 pthread_mutex_lock(&pictureLock);
188 if (!pictures.empty()) {
190 req = pictures.front();
193 pthread_mutex_unlock(&pictureLock);
194 if (!newpicture) break;
195 std::string pictname = getPictName(req);
199 logger->log("PictRead",Log::DEBUG,"Load Pict %s",pictname.c_str());
202 if (pictname.length()) {
206 stat(pictname.c_str(), &st);
207 filesize = st.st_size;
208 memsize = filesize + headerLength;
210 if (memsize && memsize < 1000000) { // No pictures over 1 MB
211 mem = (UCHAR*)malloc(memsize);
213 FILE * file=fopen(pictname.c_str(),"r");
216 size_t size=fread(mem+headerLength,1,filesize,file);
219 if (size!=filesize) memsize=headerLength; // error
231 p = (ULONG*)&mem[0]; *p = htonl(5); // stream channel
232 p = (ULONG*)&mem[4]; *p = htonl(req.streamID);
233 p = (ULONG*)&mem[8]; *p = htonl(flag); // here insert flag: 0 = ok, data follows
234 p = (ULONG*)&mem[12]; *p = htonl(memsize);
236 if (!tcp->sendPacket(mem, memsize + headerLength)) {
237 logger->log("PictRead",Log::DEBUG,"Sending Picture failed");
240 if (mem != buffer && mem) free(mem);
242 } while (newpicture);
244 logger->log("PictRead",Log::DEBUG,"PictureReaderThread ended");