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:");
339 // OSDOVG-ROD-EXPERIMENT
343 void OsdVector::removeSurface(const SurfaceVector* surf)
345 std::lock_guard<std::mutex> lg(surfaces_mutex); // FIXME - Can block here on shutdown if a timer is fired just as the wrong time
346 for (auto i = surfaces.begin(); i != surfaces.end(); i++)
348 if (i->surface == surf)
350 decrementAllRefCounts(i->commands);
358 void OsdVector::decrementAllRefCounts(std::vector<SVGCommand>& commands)
360 for (SVGCommand& command : commands)
362 VectorHandle handle = command.getHandle();
363 if (handle != 0) // command might not have a handle
364 decrementDrawStyleHandleRefCount(handle);
366 ImageIndex ii = command.getImageIndex();
367 if (ii) removeImageRef(ii);
369 LoadIndex li = command.getLoadIndex();
370 if (li) removeLoadIndexRef(li);
374 void OsdVector::incrementAllRefCounts(std::vector<SVGCommand>& commands)
376 for (SVGCommand& command : commands)
378 VectorHandle handle = command.getHandle();
379 if (handle != 0) // command might not have a handle
380 incrementDrawStyleHandleRefCount(handle);
382 ImageIndex ii = command.getImageIndex();
383 if (ii) incImageRef(ii);
385 LoadIndex li = command.getLoadIndex();
386 if (li) incLoadIndexRef(li);
390 void OsdVector::incImageRef(ImageIndex index)
392 if (images_ref.find(index) == images_ref.end())
394 images_ref[index] = 1;
402 void OsdVector::removeImageRef(const ImageIndex ref)
407 int OsdVector::getLoadIndexRef(LoadIndex index)
409 surfaces_mutex.lock();
411 if (loadindex_ref.find(index) == loadindex_ref.end())
417 return loadindex_ref[index];
420 surfaces_mutex.unlock();
423 void OsdVector::incLoadIndexRef(LoadIndex index)
425 if (loadindex_ref.find(index) == loadindex_ref.end())
427 loadindex_ref[index] = 1;
431 loadindex_ref[index]++;
435 void OsdVector::removeLoadIndexRef(const LoadIndex ref)
437 loadindex_ref[ref]--;
439 if (loadindex_ref[ref] == 0)
441 //now check, if it is already loaded
442 std::map<LoadIndex, ImageIndex>::iterator itty = tvmedias_loaded.find(ref);
444 if ( itty != tvmedias_loaded.end())
446 removeImageRef((*itty).second); // remove lock
449 tvmedias_loaded.erase(ref);
450 // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia removeLoadIndexRef %d %llx",tvmedias_load.size(),ref);
451 tvmedias_load.erase(tvmedias_load_inv[ref]);
452 tvmedias_load_inv.erase(ref);
454 reader.invalidateLoadIndex(ref);
458 void OsdVector::cleanupOrphanedRefs()
460 // Do some garbage collection
462 std::map<void*, ImageIndex>::iterator mitty = monobitmaps.begin();
464 while (mitty != monobitmaps.end())
466 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*mitty).second);
467 int count = (*curitty).second;
471 ImageIndex ref = (*curitty).first;
472 monobitmaps.erase(mitty++);
473 images_ref.erase(curitty++);
474 destroyImageRef(ref);
479 /*map<string,ImageIndex>::iterator jitty=jpegs.begin();
480 while (jitty!=jpegs.end()) {
481 map<ImageIndex,int>::iterator curitty=images_ref.find((*jitty).second);
482 int count=(*curitty).second;
484 ImageIndex ref=(*curitty).first;
485 jpegs.erase(jitty++);
486 images_ref.erase(curitty++);
487 destroyImageRef(ref);
491 std::map<TVMediaInfo, ImageIndex>::iterator titty = tvmedias.begin();
493 while (titty != tvmedias.end())
495 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*titty).second);
496 int count = (*curitty).second;
500 ImageIndex ref = (*curitty).first;
501 tvmedias.erase(titty++);
502 images_ref.erase(curitty);
503 destroyImageRef(ref);
509 std::map<TVMediaInfo, LoadIndex>::iterator litty = tvmedias_load.begin();
511 while (litty != tvmedias_load.end())
513 std::map<LoadIndex, int>::iterator curitty = loadindex_ref.find((*litty).second);
514 int count = (*curitty).second;
518 tvmedias_load_inv.erase((*litty).second);
519 tvmedias_loaded.erase((*litty).second);
520 tvmedias_load.erase(litty++);
525 std::list<ImageIndex>::iterator pitty = palettepics.begin();
527 while (pitty != palettepics.end())
529 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*pitty));
530 int count = (*curitty).second;
534 ImageIndex ref = (*curitty).first;
535 palettepics.erase(pitty++);
536 images_ref.erase(curitty++);
537 destroyImageRef(ref);
542 std::map<ImageIndex, int>::iterator citty = images_ref.begin();
544 while (citty != images_ref.end())
546 int count = (*citty).second;
550 ImageIndex ref = (*citty).first;
551 images_ref.erase(citty++);
552 destroyImageRef(ref);
558 std::map<DrawStyle, VectorHandle>::iterator sitty = drawstyleHandles.begin();
560 while (sitty != drawstyleHandles.end())
562 std::map<VectorHandle, int>::iterator curitty = drawstyleHandlesRefCounts.find((*sitty).second);
563 int count = (*curitty).second;
567 VectorHandle ref = (*curitty).first;
568 drawstyleHandles.erase(sitty++);
569 drawstyleHandlesRefCounts.erase(curitty++);
570 drawstyleHandles_lastit_valid = drawstyleHandlesRefCounts_lastit_valid = false;
571 destroyDrawStyleHandle(ref);
579 int OsdVector::getImageRef(ImageIndex index)
581 surfaces_mutex.lock();
583 if (images_ref.find(index) == images_ref.end())
589 return images_ref[index];
592 surfaces_mutex.unlock();
595 void OsdVector::incrementDrawStyleHandleRefCount(VectorHandle index)
597 if (!drawstyleHandlesRefCounts_lastit_valid || (drawstyleHandlesRefCounts_lastit->first != index))
599 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(index);
600 if (drawstyleHandlesRefCounts_lastit == drawstyleHandlesRefCounts.end())
602 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.insert(std::pair<VectorHandle, int>(index, 0)).first;
606 drawstyleHandlesRefCounts_lastit->second++;
607 drawstyleHandlesRefCounts_lastit_valid = true;
610 void OsdVector::decrementDrawStyleHandleRefCount(VectorHandle index)
612 if (!drawstyleHandlesRefCounts_lastit_valid || (drawstyleHandlesRefCounts_lastit->first != index))
614 drawstyleHandlesRefCounts_lastit_valid = false;
615 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(index);
618 if (drawstyleHandlesRefCounts_lastit != drawstyleHandlesRefCounts.end())
620 drawstyleHandlesRefCounts_lastit_valid = true;
621 drawstyleHandlesRefCounts_lastit->second--;
625 VectorHandle OsdVector::getDrawStyleHandle(const DrawStyle& c)
627 surfaces_mutex.lock();
628 VectorHandle style_handle = 0;
634 if (!drawstyleHandles_lastit_valid || (drawstyleHandles_lastit->first != c))
636 drawstyleHandles_lastit_valid = false;
637 drawstyleHandles_lastit = drawstyleHandles.find(c);
640 if (drawstyleHandles_lastit == drawstyleHandles.end())
642 surfaces_mutex.unlock();
643 style_handle = createDrawStyleHandle(c);
644 surfaces_mutex.lock();
645 drawstyleHandles_lastit = drawstyleHandles.insert(std::pair<DrawStyle, VectorHandle>(c, style_handle)).first;
649 style_handle = drawstyleHandles_lastit->second;
651 //Now check if the handle is valid
652 if (!drawstyleHandlesRefCounts_lastit_valid || (*drawstyleHandlesRefCounts_lastit).first != style_handle)
654 drawstyleHandlesRefCounts_lastit_valid = false;
655 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(style_handle);
658 if (drawstyleHandlesRefCounts_lastit == drawstyleHandlesRefCounts.end())
660 //invalid handle recreate
661 surfaces_mutex.unlock();
662 style_handle = createDrawStyleHandle(c);
663 surfaces_mutex.lock();
664 drawstyleHandles_lastit->second = style_handle;
666 else drawstyleHandlesRefCounts_lastit_valid = true;
669 drawstyleHandles_lastit_valid = true;
670 incrementDrawStyleHandleRefCount(style_handle);
671 surfaces_mutex.unlock();
676 void OsdVector::dumpStyles()
680 std::map<DrawStyle, VectorHandle>::iterator i;
681 for(i = drawstyleHandles.begin(); i != drawstyleHandles.end(); i++)
683 const DrawStyle* test = &(i->first);
684 Log::getInstance()->log("OsdVector", Log::DEBUG, "DumpStyles: %p %i", test , i->second);
687 std::map<VectorHandle, int>::iterator i2;
688 for (i2 = drawstyleHandlesRefCounts.begin(); i2 != drawstyleHandlesRefCounts.end(); i2++)
690 Log::getInstance()->log("OsdVector", Log::DEBUG, "DumpStylesRef: %i %i", i2->first, i2->second);
695 LoadIndex OsdVector::getTVMediaRef(TVMediaInfo& tvmedia, ImageIndex& image)
697 ImageIndex image_handle = 0;
698 LoadIndex loadindex = 0;
699 surfaces_mutex.lock();
701 if (tvmedias.find(tvmedia) == tvmedias.end())
703 loadindex = loadTVMedia(tvmedia);
707 image_handle = tvmedias[tvmedia];
709 if (images_ref.find(image_handle) == images_ref.end())
711 //invalid handle recreate
712 loadindex = loadTVMedia(tvmedia);
717 incImageRef(image_handle);
721 /*tvmedias[tvmedia]=createTVMedia(tvmedia,width,height);
722 incImageRef(image_handle);*/
723 image = image_handle;
724 surfaces_mutex.unlock();
728 LoadIndex OsdVector::loadTVMedia(TVMediaInfo& tvmedia)
732 if (tvmedias_load.find(tvmedia) == tvmedias_load.end())
734 switch (tvmedia.getType())
737 index = VDR::getInstance()->loadTVMediaRecThumb(tvmedia);
742 index = ((long long) tvmedia.getPrimaryID()) << 32LL;
743 reader.addStaticImage(tvmedia.getPrimaryID());
747 index = VDR::getInstance()->loadTVMediaEventThumb(tvmedia);
751 index = VDR::getInstance()->loadChannelLogo(tvmedia);
755 index = VDR::getInstance()->loadTVMedia(tvmedia);
759 if (tvmedia.getType() != 4 && tvmedia.getStaticFallback() > -1)
761 reader.informFallback(index, tvmedia.getStaticFallback());
764 tvmedias_load[tvmedia] = index;
765 tvmedias_load_inv[index] = tvmedia;
769 index = tvmedias_load[tvmedia];
772 incLoadIndexRef(index);
777 void OsdVector::informPicture(LoadIndex index, ImageIndex imageIndex)
779 //Beware for thread safety
780 ImageIndex image_index = 0;
782 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Picture for request id %llx arrived %x", index, imageIndex);
783 surfaces_mutex.lock();
784 TVMediaInfo tvmedia = tvmedias_load_inv[index];
788 std::map<LoadIndex, int>::iterator itty = loadindex_ref.find(index);
789 image_index = tvmedias[tvmedia] = imageIndex;
790 tvmedias_loaded[index] = image_index;
792 if (itty == loadindex_ref.end() || (*itty).second == 0)
794 // we do not want the picture anymore . Really...
795 // fill images_ref in to not irritate the garbage collector
796 if (images_ref.find(image_index) == images_ref.end())
798 images_ref[image_index] = 0;
803 incImageRef(image_index); // hold one index until all loadings refs are gone;
807 surfaces_mutex.unlock();
811 ImageIndex OsdVector::getJpegRef(const char* fileName, int *width,int *height)
813 ImageIndex image_handle=0;
814 if (jpegs.find(fileName)==jpegs.end())
816 image_handle=jpegs[fileName]=createJpeg(fileName,width,height);
818 image_handle=jpegs[fileName];
821 if (images_ref.find(image_handle)==images_ref.end()) {
822 //invalid handle recreate
823 image_handle=jpegs[fileName]=createJpeg(fileName,width,height);
826 incImageRef(image_handle);
831 ImageIndex OsdVector::getMonoBitmapRef(void* base, int width, int height)
833 ImageIndex image_handle;
834 surfaces_mutex.lock();
836 if (monobitmaps.find(base) == monobitmaps.end())
838 surfaces_mutex.unlock();
839 image_handle = createMonoBitmap(base, width, height);
840 surfaces_mutex.lock();
841 monobitmaps[base] = image_handle;
845 image_handle = monobitmaps[base];
847 if (images_ref.find(image_handle) == images_ref.end())
849 //invalid handle recreate
850 surfaces_mutex.unlock();
851 image_handle = createMonoBitmap(base, width, height);
852 surfaces_mutex.lock();
853 monobitmaps[base] = image_handle;
857 incImageRef(image_handle);
858 surfaces_mutex.unlock();
862 ImageIndex OsdVector::getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
864 ImageIndex image_handle;
865 image_handle = createImagePalette(width, height, image_data, palette_data);
866 surfaces_mutex.lock();
867 palettepics.push_back(image_handle);
868 incImageRef(image_handle);
869 surfaces_mutex.unlock();
873 OsdVector::PictureReader::~PictureReader()
875 decoders_lock.lock();
877 while (decoders.size())
879 PictureDecoder* dec = decoders.front();
880 decoders.pop_front();
884 decoders_lock.unlock();
887 void OsdVector::PictureReader::init()
892 void OsdVector::PictureReader::shutdown()
897 void OsdVector::PictureReader::addDecoder(PictureDecoder* decoder)
899 decoders_lock.lock();
901 decoders.push_front(decoder);
902 decoders_lock.unlock();
905 void OsdVector::PictureReader::removeDecoder(PictureDecoder* decoder)
907 decoders_lock.lock();
908 std::list<PictureDecoder*>::iterator itty = decoders.begin();
910 while (itty != decoders.end())
912 if ((*itty) == decoder)
914 decoders.erase(itty);
921 Log::getInstance()->log("OsdVector", Log::DEBUG, "removeDecoder");
924 decoders_lock.unlock();
927 void OsdVector::PictureReader::threadMethod()
929 OsdVector* osdvector = dynamic_cast<OsdVector*>(Osd::getInstance());
930 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Start Picture Reader");
934 if (!threadIsActive())
936 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia End Picture Reader");
946 decoders_lock.lock();
947 std::list<PictureDecoder*>::iterator itty = decoders.begin();
949 while (itty != decoders.end())
951 if ((*itty)->getDecodedPicture(pictinf))
954 osdvector->createPicture(pictinf);
960 if (processReceivedPictures())
965 decoders_lock.unlock();
968 //Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Sleep Picture Reader");
970 struct timespec target_time;
971 getClockRealTime(&target_time);
973 target_time.tv_nsec += 1000000LL * 10;
975 if (target_time.tv_nsec > 999999999)
977 target_time.tv_nsec -= 1000000000L;
978 target_time.tv_sec += 1;
982 threadWaitForSignalTimed(&target_time);
984 //Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Sleep end Picture Reader");
988 void OsdVector::PictureReader::invalidateLoadIndex(LoadIndex index)
990 pict_lock_incoming.lock();
991 invalid_loadindex.insert(index);
992 pict_lock_incoming.unlock();
995 void OsdVector::PictureReader::informFallback(LoadIndex index, int fallback)
997 pict_lock_incoming.lock();
998 inform_fallback[index] = fallback;
999 pict_lock_incoming.unlock();
1002 void OsdVector::PictureReader::receivePicture(VDR_ResponsePacket* vresp)
1004 pict_lock_incoming.lock();
1005 pict_incoming.push(vresp);
1006 pict_lock_incoming.unlock();
1011 void OsdVector::PictureReader::addStaticImage(unsigned int id)
1013 pict_lock_incoming.lock();
1014 pict_incoming_static.push(id);
1015 invalid_loadindex.erase(((long long) id) << 32LL);
1016 pict_lock_incoming.unlock();
1022 #pragma warning(disable : 4703)
1025 bool OsdVector::PictureReader::processReceivedPictures()
1027 bool decoded = false;
1029 pict_lock_incoming.lock();
1031 if (pict_incoming.size())
1033 VDR_ResponsePacket* vresp = pict_incoming.front();
1034 pict_incoming.pop();
1035 std::set<LoadIndex>::iterator setpos = invalid_loadindex.find(vresp->getStreamID());
1037 if (setpos != invalid_loadindex.end())
1040 invalid_loadindex.erase(setpos);
1043 pict_lock_incoming.unlock();
1045 if (!valid) // we do not want it anymore skip it;
1051 // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Pictures arrived VDR %x %d %d",
1052 // vresp->getStreamID(),vresp->getUserDataLength(),vresp->getFlag());
1053 bool decode = false;
1058 if (vresp->getFlag() != 2)
1060 userdata = vresp->getUserData();
1061 length = vresp->getUserDataLength();
1068 pict_lock_incoming.lock();
1070 if (inform_fallback.find(vresp->getStreamID()) != inform_fallback.end())
1072 fallback = inform_fallback[vresp->getStreamID()];
1075 pict_lock_incoming.unlock();
1077 if (fallback >= 0 && ((OsdVector*)Osd::getInstance())->getStaticImageData(fallback, &userdata, &length))
1086 std::list<PictureDecoder*>::iterator itty = decoders.begin();
1088 while (itty != decoders.end())
1090 userdata = (*itty)->decodePicture(vresp->getStreamID(), userdata, length, freed);
1101 if (!decoded && userdata && freed)
1107 pict_lock_incoming.lock();
1108 inform_fallback.erase(vresp->getStreamID());
1109 pict_lock_incoming.unlock();
1110 //else osd->informPicture(vresp->getStreamID(), 0);
1113 else if (pict_incoming_static.size())
1115 unsigned int static_id = pict_incoming_static.front();
1116 pict_incoming_static.pop();
1117 std::set<LoadIndex>::iterator setpos = invalid_loadindex.find(((long long) static_id) << 32LL);
1119 if (setpos != invalid_loadindex.end())
1122 invalid_loadindex.erase(setpos);
1125 pict_lock_incoming.unlock();
1127 if (!valid) // we do not want it anymore skip it;
1135 if (((OsdVector*)Osd::getInstance())->getStaticImageData(static_id, &userdata, &length))
1137 std::list<PictureDecoder*>::iterator itty = decoders.begin();
1139 while (itty != decoders.end())
1141 if (!(*itty)->decodePicture(((long long) static_id) << 32LL, userdata, length, false))
1153 pict_lock_incoming.unlock();
1156 if (pict_incoming.size() || pict_incoming_static.size()) return true;