2 Copyright 2012 Marten Richter, 2020 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
20 #include "surfacevector.h"
22 #include "vdrresponsepacket.h"
26 #include "osdvector.h"
28 // The next section is activated, if the magick++ PictureReader is provided, it should be available for many POSIX platforms
29 #ifdef PICTURE_DECODER_MAGICK
30 #define MAGICKCORE_QUANTUM_DEPTH 16
31 #define MAGICKCORE_HDRI_ENABLE 0
34 using namespace Magick;
36 class MagickDecoder: public OsdVector::PictureDecoder
39 MagickDecoder(OsdVector::PictureReader* treader): OsdVector::PictureDecoder(treader) {pictInfValid = false;};
41 unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem);
43 bool getDecodedPicture( struct OsdVector::PictureInfo& pict_inf);
45 void freeReference(void* ref);
48 OsdVector::PictureInfo pictInf;
52 unsigned char* MagickDecoder::decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem)
54 if (pictInfValid) return buffer; // does support only one image at a Time;
57 Blob* imageblob = new Blob();
62 Log::getInstance()->log("MagickDecoder", Log::DEBUG, "decodePicture");
64 if (freemem) myblob.updateNoCopy(buffer, length, Blob::MallocAllocator);
65 else myblob.update(buffer, length);
67 magicimage.read(myblob);
69 magicimage.write(imageblob, "RGBA");
72 catch ( Exception& error_ )
74 Log::getInstance()->log("MagickDecoder", Log::DEBUG, "Libmagick: %s", error_.what());
76 Log::getInstance()->log("MagickDecoder", Log::DEBUG, "Libmagick: error mark2");
77 unsigned char* newbuffer = (unsigned char*) malloc(length);
78 memcpy(newbuffer, myblob.data(), length);
82 pictInf.reference = (void*) imageblob;
83 pictInf.width = magicimage.columns();
84 pictInf.height = magicimage.rows();
85 pictInf.image = imageblob->data();
86 pictInf.decoder = this;
87 pictInf.type = OsdVector::PictureInfo::RGBAMemBlock;
88 pictInf.lindex = index;
93 // I can handle everything, so the return value is always true
96 void MagickDecoder::freeReference(void* ref)
98 Blob* todelete = (Blob*) ref;
102 bool MagickDecoder::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
104 if (!pictInfValid) return false;
107 pictInfValid = false;
114 OsdVector::OsdVector()
116 setlocale(LC_CTYPE, "C.UTF-8");
117 #ifdef PICTURE_DECODER_MAGICK
118 reader.addDecoder(new MagickDecoder(&reader));
122 bool OsdVector::screenShot(const char* fileName)
124 //Do nothing, if no libmagick is there
125 #ifdef PICTURE_DECODER_MAGICK
127 getRealScreenSize(width, height);
128 size_t length = width * height * 4;
129 void* mem = malloc(length);
135 if (!screenShotInternal(mem, width, height, true))
137 Log::getInstance()->log("OsdVector", Log::DEBUG, "Screenshot failed!");
142 myblob.updateNoCopy(mem, length, Blob::MallocAllocator);
143 Image image(myblob, Geometry(width, height), 8, "RGBA");
144 image.write(fileName);
146 catch ( Exception& error_ )
148 Log::getInstance()->log("MagickEncoder", Log::DEBUG, "Libmagick: %s", error_.what());
157 Surface* OsdVector::createNewSurface()
159 return new SurfaceVector(this);
162 void OsdVector::Blank()
164 // do nothing? remove this one?
167 int OsdVector::restore()
169 // First clear the contents of all registered surfaces
170 surfaces_mutex.lock();
172 //Now go through all surfaces and clear them
173 for (auto& surface : surfaces)
175 surface.commands.clear();
176 surface.commands.reserve(2048);
179 //also clear all handles, they are now invalid, no need to release them
183 drawstyleHandles.clear();
184 drawstyleHandlesRefCounts.clear();
185 drawstyleHandles_lastit_valid = drawstyleHandlesRefCounts_lastit_valid = false;
189 loadindex_ref.clear();
190 tvmedias_load.clear();
191 tvmedias_load_inv.clear();
192 tvmedias_loaded.clear();
194 surfaces_mutex.unlock();
198 void OsdVector::drawSurfaces()
200 surfaces_mutex.lock();
201 std::list<SurfaceInfo*> todraw; //First figure out if a surfaces is below another surface
202 std::list<SurfaceInfo>::iterator itty1 = surfaces.begin();
204 while (itty1 != surfaces.end())
206 std::list<SurfaceInfo>::iterator itty2 = itty1;
210 while (itty2 != surfaces.end())
212 SurfaceInfo& ref1 = *itty1;
213 SurfaceInfo& ref2 = *itty2;
215 if (ref1.x >= ref2.x && ref1.y >= ref2.y
216 && (ref1.x + ref1.w) <= (ref2.x + ref2.w)
217 && (ref1.y + ref1.h) <= (ref2.y + ref2.h) )
226 if (!hidden) // we are not hidden, perfect
228 todraw.push_back(&(*itty1));
235 getScreenSize(swidth, sheight);
236 //Now go through all surfaces and draw them
237 std::list<SurfaceInfo*>::iterator curdraw = todraw.begin();
239 while (curdraw != todraw.end())
241 drawSetTrans(*(*curdraw));
242 std::vector<SVGCommand>::iterator commands = (*(*curdraw)).commands.begin();
243 std::vector<SVGCommand>::iterator end = (*(*curdraw)).commands.end();
245 while (commands != end)
247 // update any images loaded in the mean time
248 if ((*commands).instr == DrawImageLoading)
250 LoadIndex loadindex = (*commands).target.loadindex;
252 if (tvmedias_loaded.find(loadindex) != tvmedias_loaded.end())
254 (*commands).instr = DrawImage;
255 (*commands).target.image = tvmedias_loaded[loadindex];;
256 incImageRef((*commands).target.image);
257 removeLoadIndexRef(loadindex);
262 // Now check if the command is on screen!
263 if (!(*commands).Outside(0, 0, swidth, sheight))
265 executeDrawCommand(*commands);
274 surfaces_mutex.unlock();
277 void OsdVector::updateOrAddSurface(const SurfaceVector* surf, float x, float y, float height, float width, std::vector<SVGCommand>& commands)
279 std::lock_guard<std::mutex> lg(surfaces_mutex);
283 Log::getInstance()->log("OsdVector", Log::CRAZY, "updateOrAddSurface, surfaces.length %i", surfaces.size());
287 // First determine it is already in our system
288 for(si = surfaces.begin(); si != surfaces.end(); si++)
290 if (si->surface == surf)
292 // If the surface given (surf) is already in our surfaces vector, reset our SurfaceInfo->commands vector
293 decrementAllRefCounts(si->commands);
294 si->commands.clear();
299 // if not found, make a new SurfaceInfo
300 if (si == surfaces.end())
303 new_sc.surface = surf;
308 si = surfaces.insert(si, new_sc);
311 // update any images loaded in the mean time
313 for (SVGCommand& command : commands)
315 if (command.instr == DrawImageLoading)
317 LoadIndex loadindex = command.target.loadindex;
319 if (tvmedias_loaded.find(loadindex) != tvmedias_loaded.end())
321 command.instr = DrawImage;
322 command.target.image = tvmedias_loaded[loadindex];
323 incImageRef(command.target.image);
324 removeLoadIndexRef(loadindex);
329 si->commands = commands; // Copy surf->commands to our SurfaceInfo->commands
330 incrementAllRefCounts(si->commands);
332 cleanupOrphanedRefs();
335 Log::getInstance()->log("OsdVector", Log::CRAZY, "After UOAS:");
340 void OsdVector::removeSurface(const SurfaceVector* surf)
342 std::lock_guard<std::mutex> lg(surfaces_mutex); // FIXME - Can block here on shutdown if a timer is fired just as the wrong time
343 for (auto i = surfaces.begin(); i != surfaces.end(); i++)
345 if (i->surface == surf)
347 decrementAllRefCounts(i->commands);
355 void OsdVector::decrementAllRefCounts(std::vector<SVGCommand>& commands)
357 for (SVGCommand& command : commands)
359 VectorHandle handle = command.getHandle();
360 if (handle != 0) // command might not have a handle
361 decrementDrawStyleHandleRefCount(handle);
363 ImageIndex ii = command.getImageIndex();
364 if (ii) removeImageRef(ii);
366 LoadIndex li = command.getLoadIndex();
367 if (li) removeLoadIndexRef(li);
371 void OsdVector::incrementAllRefCounts(std::vector<SVGCommand>& commands)
373 for (SVGCommand& command : commands)
375 VectorHandle handle = command.getHandle();
376 if (handle != 0) // command might not have a handle
377 incrementDrawStyleHandleRefCount(handle);
379 ImageIndex ii = command.getImageIndex();
380 if (ii) incImageRef(ii);
382 LoadIndex li = command.getLoadIndex();
383 if (li) incLoadIndexRef(li);
387 void OsdVector::incImageRef(ImageIndex index)
389 if (images_ref.find(index) == images_ref.end())
391 images_ref[index] = 1;
399 void OsdVector::removeImageRef(const ImageIndex ref)
404 int OsdVector::getLoadIndexRef(LoadIndex index)
406 surfaces_mutex.lock();
408 if (loadindex_ref.find(index) == loadindex_ref.end())
414 return loadindex_ref[index];
417 surfaces_mutex.unlock();
420 void OsdVector::incLoadIndexRef(LoadIndex index)
422 if (loadindex_ref.find(index) == loadindex_ref.end())
424 loadindex_ref[index] = 1;
428 loadindex_ref[index]++;
432 void OsdVector::removeLoadIndexRef(const LoadIndex ref)
434 loadindex_ref[ref]--;
436 if (loadindex_ref[ref] == 0)
438 //now check, if it is already loaded
439 std::map<LoadIndex, ImageIndex>::iterator itty = tvmedias_loaded.find(ref);
441 if ( itty != tvmedias_loaded.end())
443 removeImageRef((*itty).second); // remove lock
446 tvmedias_loaded.erase(ref);
447 // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia removeLoadIndexRef %d %llx",tvmedias_load.size(),ref);
448 tvmedias_load.erase(tvmedias_load_inv[ref]);
449 tvmedias_load_inv.erase(ref);
451 reader.invalidateLoadIndex(ref);
455 void OsdVector::cleanupOrphanedRefs()
457 // Do some garbage collection
459 std::map<void*, ImageIndex>::iterator mitty = monobitmaps.begin();
461 while (mitty != monobitmaps.end())
463 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*mitty).second);
464 int count = (*curitty).second;
468 ImageIndex ref = (*curitty).first;
469 monobitmaps.erase(mitty++);
470 images_ref.erase(curitty++);
471 destroyImageRef(ref);
476 /*map<string,ImageIndex>::iterator jitty=jpegs.begin();
477 while (jitty!=jpegs.end()) {
478 map<ImageIndex,int>::iterator curitty=images_ref.find((*jitty).second);
479 int count=(*curitty).second;
481 ImageIndex ref=(*curitty).first;
482 jpegs.erase(jitty++);
483 images_ref.erase(curitty++);
484 destroyImageRef(ref);
488 std::map<TVMediaInfo, ImageIndex>::iterator titty = tvmedias.begin();
490 while (titty != tvmedias.end())
492 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*titty).second);
493 int count = (*curitty).second;
497 ImageIndex ref = (*curitty).first;
498 tvmedias.erase(titty++);
499 images_ref.erase(curitty);
500 destroyImageRef(ref);
506 std::map<TVMediaInfo, LoadIndex>::iterator litty = tvmedias_load.begin();
508 while (litty != tvmedias_load.end())
510 std::map<LoadIndex, int>::iterator curitty = loadindex_ref.find((*litty).second);
511 int count = (*curitty).second;
515 tvmedias_load_inv.erase((*litty).second);
516 tvmedias_loaded.erase((*litty).second);
517 tvmedias_load.erase(litty++);
522 std::list<ImageIndex>::iterator pitty = palettepics.begin();
524 while (pitty != palettepics.end())
526 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*pitty));
527 int count = (*curitty).second;
531 ImageIndex ref = (*curitty).first;
532 palettepics.erase(pitty++);
533 images_ref.erase(curitty++);
534 destroyImageRef(ref);
539 std::map<ImageIndex, int>::iterator citty = images_ref.begin();
541 while (citty != images_ref.end())
543 int count = (*citty).second;
547 ImageIndex ref = (*citty).first;
548 images_ref.erase(citty++);
549 destroyImageRef(ref);
555 std::map<DrawStyle, VectorHandle>::iterator sitty = drawstyleHandles.begin();
557 while (sitty != drawstyleHandles.end())
559 std::map<VectorHandle, int>::iterator curitty = drawstyleHandlesRefCounts.find((*sitty).second);
560 int count = (*curitty).second;
564 VectorHandle ref = (*curitty).first;
565 drawstyleHandles.erase(sitty++);
566 drawstyleHandlesRefCounts.erase(curitty++);
567 drawstyleHandles_lastit_valid = drawstyleHandlesRefCounts_lastit_valid = false;
568 destroyDrawStyleHandle(ref);
576 int OsdVector::getImageRef(ImageIndex index)
578 surfaces_mutex.lock();
580 if (images_ref.find(index) == images_ref.end())
586 return images_ref[index];
589 surfaces_mutex.unlock();
592 void OsdVector::incrementDrawStyleHandleRefCount(VectorHandle index)
594 if (!drawstyleHandlesRefCounts_lastit_valid || (drawstyleHandlesRefCounts_lastit->first != index))
596 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(index);
597 if (drawstyleHandlesRefCounts_lastit == drawstyleHandlesRefCounts.end())
599 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.insert(std::pair<VectorHandle, int>(index, 0)).first;
603 drawstyleHandlesRefCounts_lastit->second++;
604 drawstyleHandlesRefCounts_lastit_valid = true;
607 void OsdVector::decrementDrawStyleHandleRefCount(VectorHandle index)
609 if (!drawstyleHandlesRefCounts_lastit_valid || (drawstyleHandlesRefCounts_lastit->first != index))
611 drawstyleHandlesRefCounts_lastit_valid = false;
612 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(index);
615 if (drawstyleHandlesRefCounts_lastit != drawstyleHandlesRefCounts.end())
617 drawstyleHandlesRefCounts_lastit_valid = true;
618 drawstyleHandlesRefCounts_lastit->second--;
622 VectorHandle OsdVector::getDrawStyleHandle(const DrawStyle& c)
624 surfaces_mutex.lock();
625 VectorHandle style_handle = 0;
631 if (!drawstyleHandles_lastit_valid || (drawstyleHandles_lastit->first != c))
633 drawstyleHandles_lastit_valid = false;
634 drawstyleHandles_lastit = drawstyleHandles.find(c);
637 if (drawstyleHandles_lastit == drawstyleHandles.end())
639 surfaces_mutex.unlock();
640 style_handle = createDrawStyleHandle(c);
641 surfaces_mutex.lock();
642 drawstyleHandles_lastit = drawstyleHandles.insert(std::pair<DrawStyle, VectorHandle>(c, style_handle)).first;
646 style_handle = drawstyleHandles_lastit->second;
648 //Now check if the handle is valid
649 if (!drawstyleHandlesRefCounts_lastit_valid || (*drawstyleHandlesRefCounts_lastit).first != style_handle)
651 drawstyleHandlesRefCounts_lastit_valid = false;
652 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(style_handle);
655 if (drawstyleHandlesRefCounts_lastit == drawstyleHandlesRefCounts.end())
657 //invalid handle recreate
658 surfaces_mutex.unlock();
659 style_handle = createDrawStyleHandle(c);
660 surfaces_mutex.lock();
661 drawstyleHandles_lastit->second = style_handle;
663 else drawstyleHandlesRefCounts_lastit_valid = true;
666 drawstyleHandles_lastit_valid = true;
667 incrementDrawStyleHandleRefCount(style_handle);
668 surfaces_mutex.unlock();
673 void OsdVector::dumpStyles()
677 std::map<DrawStyle, VectorHandle>::iterator i;
678 for(i = drawstyleHandles.begin(); i != drawstyleHandles.end(); i++)
680 const DrawStyle* test = &(i->first);
681 Log::getInstance()->log("OsdVector", Log::DEBUG, "DumpStyles: %p %i", test , i->second);
684 std::map<VectorHandle, int>::iterator i2;
685 for (i2 = drawstyleHandlesRefCounts.begin(); i2 != drawstyleHandlesRefCounts.end(); i2++)
687 Log::getInstance()->log("OsdVector", Log::DEBUG, "DumpStylesRef: %i %i", i2->first, i2->second);
692 LoadIndex OsdVector::getTVMediaRef(TVMediaInfo& tvmedia, ImageIndex& image)
694 ImageIndex image_handle = 0;
695 LoadIndex loadindex = 0;
696 surfaces_mutex.lock();
698 if (tvmedias.find(tvmedia) == tvmedias.end())
700 loadindex = loadTVMedia(tvmedia);
704 image_handle = tvmedias[tvmedia];
706 if (images_ref.find(image_handle) == images_ref.end())
708 //invalid handle recreate
709 loadindex = loadTVMedia(tvmedia);
714 incImageRef(image_handle);
718 /*tvmedias[tvmedia]=createTVMedia(tvmedia,width,height);
719 incImageRef(image_handle);*/
720 image = image_handle;
721 surfaces_mutex.unlock();
725 LoadIndex OsdVector::loadTVMedia(TVMediaInfo& tvmedia)
729 if (tvmedias_load.find(tvmedia) == tvmedias_load.end())
731 switch (tvmedia.getType())
734 index = VDR::getInstance()->loadTVMediaRecThumb(tvmedia);
739 index = ((long long) tvmedia.getPrimaryID()) << 32LL;
740 reader.addStaticImage(tvmedia.getPrimaryID());
744 index = VDR::getInstance()->loadTVMediaEventThumb(tvmedia);
748 index = VDR::getInstance()->loadChannelLogo(tvmedia);
752 index = VDR::getInstance()->loadTVMedia(tvmedia);
756 if (tvmedia.getType() != 4 && tvmedia.getStaticFallback() > -1)
758 reader.informFallback(index, tvmedia.getStaticFallback());
761 tvmedias_load[tvmedia] = index;
762 tvmedias_load_inv[index] = tvmedia;
766 index = tvmedias_load[tvmedia];
769 incLoadIndexRef(index);
774 void OsdVector::informPicture(LoadIndex index, ImageIndex imageIndex)
776 //Beware for thread safety
777 ImageIndex image_index = 0;
779 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Picture for request id %llx arrived %x", index, imageIndex);
780 surfaces_mutex.lock();
781 TVMediaInfo tvmedia = tvmedias_load_inv[index];
785 std::map<LoadIndex, int>::iterator itty = loadindex_ref.find(index);
786 image_index = tvmedias[tvmedia] = imageIndex;
787 tvmedias_loaded[index] = image_index;
789 if (itty == loadindex_ref.end() || (*itty).second == 0)
791 // we do not want the picture anymore . Really...
792 // fill images_ref in to not irritate the garbage collector
793 if (images_ref.find(image_index) == images_ref.end())
795 images_ref[image_index] = 0;
800 incImageRef(image_index); // hold one index until all loadings refs are gone;
804 surfaces_mutex.unlock();
808 ImageIndex OsdVector::getJpegRef(const char* fileName, int *width,int *height)
810 ImageIndex image_handle=0;
811 if (jpegs.find(fileName)==jpegs.end())
813 image_handle=jpegs[fileName]=createJpeg(fileName,width,height);
815 image_handle=jpegs[fileName];
818 if (images_ref.find(image_handle)==images_ref.end()) {
819 //invalid handle recreate
820 image_handle=jpegs[fileName]=createJpeg(fileName,width,height);
823 incImageRef(image_handle);
828 ImageIndex OsdVector::getMonoBitmapRef(void* base, int width, int height)
830 ImageIndex image_handle;
831 surfaces_mutex.lock();
833 if (monobitmaps.find(base) == monobitmaps.end())
835 surfaces_mutex.unlock();
836 image_handle = createMonoBitmap(base, width, height);
837 surfaces_mutex.lock();
838 monobitmaps[base] = image_handle;
842 image_handle = monobitmaps[base];
844 if (images_ref.find(image_handle) == images_ref.end())
846 //invalid handle recreate
847 surfaces_mutex.unlock();
848 image_handle = createMonoBitmap(base, width, height);
849 surfaces_mutex.lock();
850 monobitmaps[base] = image_handle;
854 incImageRef(image_handle);
855 surfaces_mutex.unlock();
859 ImageIndex OsdVector::getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
861 ImageIndex image_handle;
862 image_handle = createImagePalette(width, height, image_data, palette_data);
863 surfaces_mutex.lock();
864 palettepics.push_back(image_handle);
865 incImageRef(image_handle);
866 surfaces_mutex.unlock();
870 OsdVector::PictureReader::~PictureReader()
872 decoders_lock.lock();
874 while (decoders.size())
876 PictureDecoder* dec = decoders.front();
877 decoders.pop_front();
881 decoders_lock.unlock();
884 void OsdVector::PictureReader::init()
889 void OsdVector::PictureReader::shutdown()
894 void OsdVector::PictureReader::addDecoder(PictureDecoder* decoder)
896 decoders_lock.lock();
898 decoders.push_front(decoder);
899 decoders_lock.unlock();
902 void OsdVector::PictureReader::removeDecoder(PictureDecoder* decoder)
904 decoders_lock.lock();
905 std::list<PictureDecoder*>::iterator itty = decoders.begin();
907 while (itty != decoders.end())
909 if ((*itty) == decoder)
911 decoders.erase(itty);
918 Log::getInstance()->log("OsdVector", Log::DEBUG, "removeDecoder");
921 decoders_lock.unlock();
924 void OsdVector::PictureReader::threadMethod()
926 OsdVector* osdvector = dynamic_cast<OsdVector*>(Osd::getInstance());
927 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Start Picture Reader");
931 if (!threadIsActive())
933 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia End Picture Reader");
943 decoders_lock.lock();
944 std::list<PictureDecoder*>::iterator itty = decoders.begin();
946 while (itty != decoders.end())
948 if ((*itty)->getDecodedPicture(pictinf))
951 osdvector->createPicture(pictinf);
957 if (processReceivedPictures())
962 decoders_lock.unlock();
965 //Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Sleep Picture Reader");
967 struct timespec target_time;
968 getClockRealTime(&target_time);
970 target_time.tv_nsec += 1000000LL * 10;
972 if (target_time.tv_nsec > 999999999)
974 target_time.tv_nsec -= 1000000000L;
975 target_time.tv_sec += 1;
979 threadWaitForSignalTimed(&target_time);
981 //Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Sleep end Picture Reader");
985 void OsdVector::PictureReader::invalidateLoadIndex(LoadIndex index)
987 pict_lock_incoming.lock();
988 invalid_loadindex.insert(index);
989 pict_lock_incoming.unlock();
992 void OsdVector::PictureReader::informFallback(LoadIndex index, int fallback)
994 pict_lock_incoming.lock();
995 inform_fallback[index] = fallback;
996 pict_lock_incoming.unlock();
999 void OsdVector::PictureReader::receivePicture(VDR_ResponsePacket* vresp)
1001 pict_lock_incoming.lock();
1002 pict_incoming.push(vresp);
1003 pict_lock_incoming.unlock();
1008 void OsdVector::PictureReader::addStaticImage(unsigned int id)
1010 pict_lock_incoming.lock();
1011 pict_incoming_static.push(id);
1012 invalid_loadindex.erase(((long long) id) << 32LL);
1013 pict_lock_incoming.unlock();
1019 #pragma warning(disable : 4703)
1022 bool OsdVector::PictureReader::processReceivedPictures()
1024 bool decoded = false;
1026 pict_lock_incoming.lock();
1028 if (pict_incoming.size())
1030 VDR_ResponsePacket* vresp = pict_incoming.front();
1031 pict_incoming.pop();
1032 std::set<LoadIndex>::iterator setpos = invalid_loadindex.find(vresp->getStreamID());
1034 if (setpos != invalid_loadindex.end())
1037 invalid_loadindex.erase(setpos);
1040 pict_lock_incoming.unlock();
1042 if (!valid) // we do not want it anymore skip it;
1048 // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Pictures arrived VDR %x %d %d",
1049 // vresp->getStreamID(),vresp->getUserDataLength(),vresp->getFlag());
1050 bool decode = false;
1055 if (vresp->getFlag() != 2)
1057 userdata = vresp->getUserData();
1058 length = vresp->getUserDataLength();
1065 pict_lock_incoming.lock();
1067 if (inform_fallback.find(vresp->getStreamID()) != inform_fallback.end())
1069 fallback = inform_fallback[vresp->getStreamID()];
1072 pict_lock_incoming.unlock();
1074 if (fallback >= 0 && ((OsdVector*)Osd::getInstance())->getStaticImageData(fallback, &userdata, &length))
1083 std::list<PictureDecoder*>::iterator itty = decoders.begin();
1085 while (itty != decoders.end())
1087 userdata = (*itty)->decodePicture(vresp->getStreamID(), userdata, length, freed);
1098 if (!decoded && userdata && freed)
1104 pict_lock_incoming.lock();
1105 inform_fallback.erase(vresp->getStreamID());
1106 pict_lock_incoming.unlock();
1107 //else osd->informPicture(vresp->getStreamID(), 0);
1110 else if (pict_incoming_static.size())
1112 unsigned int static_id = pict_incoming_static.front();
1113 pict_incoming_static.pop();
1114 std::set<LoadIndex>::iterator setpos = invalid_loadindex.find(((long long) static_id) << 32LL);
1116 if (setpos != invalid_loadindex.end())
1119 invalid_loadindex.erase(setpos);
1122 pict_lock_incoming.unlock();
1124 if (!valid) // we do not want it anymore skip it;
1132 if (((OsdVector*)Osd::getInstance())->getStaticImageData(static_id, &userdata, &length))
1134 std::list<PictureDecoder*>::iterator itty = decoders.begin();
1136 while (itty != decoders.end())
1138 if (!(*itty)->decodePicture(((long long) static_id) << 32LL, userdata, length, false))
1150 pict_lock_incoming.unlock();
1153 if (pict_incoming.size() || pict_incoming_static.size()) return true;