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 void 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 (!screenShot(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());
155 Surface* OsdVector::createNewSurface()
157 return new SurfaceVector(this);
160 void OsdVector::Blank()
162 // do nothing? remove this one?
165 int OsdVector::restore()
167 // First clear the contents of all registered surfaces
168 surfaces_mutex.lock();
170 //Now go through all surfaces and clear them
171 for (auto& surface : surfaces)
173 surface.commands.clear();
174 surface.commands.reserve(2048);
177 //also clear all handles, they are now invalid, no need to release them
181 drawstyleHandles.clear();
182 drawstyleHandlesRefCounts.clear();
183 drawstyleHandles_lastit_valid = drawstyleHandlesRefCounts_lastit_valid = false;
187 loadindex_ref.clear();
188 tvmedias_load.clear();
189 tvmedias_load_inv.clear();
190 tvmedias_loaded.clear();
192 surfaces_mutex.unlock();
196 void OsdVector::drawSurfaces()
198 surfaces_mutex.lock();
199 std::list<SurfaceInfo*> todraw; //First figure out if a surfaces is below another surface
200 std::list<SurfaceInfo>::iterator itty1 = surfaces.begin();
202 while (itty1 != surfaces.end())
204 std::list<SurfaceInfo>::iterator itty2 = itty1;
208 while (itty2 != surfaces.end())
210 SurfaceInfo& ref1 = *itty1;
211 SurfaceInfo& ref2 = *itty2;
213 if (ref1.x >= ref2.x && ref1.y >= ref2.y
214 && (ref1.x + ref1.w) <= (ref2.x + ref2.w)
215 && (ref1.y + ref1.h) <= (ref2.y + ref2.h) )
224 if (!hidden) // we are not hidden, perfect
226 todraw.push_back(&(*itty1));
233 getScreenSize(swidth, sheight);
234 //Now go through all surfaces and draw them
235 std::list<SurfaceInfo*>::iterator curdraw = todraw.begin();
237 while (curdraw != todraw.end())
239 drawSetTrans(*(*curdraw));
240 std::vector<SVGCommand>::iterator commands = (*(*curdraw)).commands.begin();
241 std::vector<SVGCommand>::iterator end = (*(*curdraw)).commands.end();
243 while (commands != end)
245 // update any images loaded in the mean time
246 if ((*commands).instr == DrawImageLoading)
248 LoadIndex loadindex = (*commands).target.loadindex;
250 if (tvmedias_loaded.find(loadindex) != tvmedias_loaded.end())
252 (*commands).instr = DrawImage;
253 (*commands).target.image = tvmedias_loaded[loadindex];;
254 incImageRef((*commands).target.image);
255 removeLoadIndexRef(loadindex);
260 // Now check if the command is on screen!
261 if (!(*commands).Outside(0, 0, swidth, sheight))
263 executeDrawCommand(*commands);
272 surfaces_mutex.unlock();
275 void OsdVector::updateOrAddSurface(const SurfaceVector* surf, float x, float y, float height, float width, std::vector<SVGCommand>& commands)
277 std::lock_guard<std::mutex> lg(surfaces_mutex);
281 Log::getInstance()->log("OsdVector", Log::CRAZY, "updateOrAddSurface, surfaces.length %i", surfaces.size());
285 // First determine it is already in our system
286 for(si = surfaces.begin(); si != surfaces.end(); si++)
288 if (si->surface == surf)
290 // If the surface given (surf) is already in our surfaces vector, reset our SurfaceInfo->commands vector
291 decrementAllRefCounts(si->commands);
292 si->commands.clear();
297 // if not found, make a new SurfaceInfo
298 if (si == surfaces.end())
301 new_sc.surface = surf;
306 si = surfaces.insert(si, new_sc);
309 // update any images loaded in the mean time
311 for (SVGCommand& command : commands)
313 if (command.instr == DrawImageLoading)
315 LoadIndex loadindex = command.target.loadindex;
317 if (tvmedias_loaded.find(loadindex) != tvmedias_loaded.end())
319 command.instr = DrawImage;
320 command.target.image = tvmedias_loaded[loadindex];
321 incImageRef(command.target.image);
322 removeLoadIndexRef(loadindex);
327 si->commands = commands; // Copy surf->commands to our SurfaceInfo->commands
328 incrementAllRefCounts(si->commands);
330 cleanupOrphanedRefs();
333 Log::getInstance()->log("OsdVector", Log::CRAZY, "After UOAS:");
338 void OsdVector::removeSurface(const SurfaceVector* surf)
340 std::lock_guard<std::mutex> lg(surfaces_mutex);
341 for (auto i = surfaces.begin(); i != surfaces.end(); i++)
343 if (i->surface == surf)
345 decrementAllRefCounts(i->commands);
353 void OsdVector::decrementAllRefCounts(std::vector<SVGCommand>& commands)
355 for (SVGCommand& command : commands)
357 VectorHandle handle = command.getHandle();
358 if (handle != 0) // command might not have a handle
359 decrementDrawStyleHandleRefCount(handle);
361 ImageIndex ii = command.getImageIndex();
362 if (ii) removeImageRef(ii);
364 LoadIndex li = command.getLoadIndex();
365 if (li) removeLoadIndexRef(li);
369 void OsdVector::incrementAllRefCounts(std::vector<SVGCommand>& commands)
371 for (SVGCommand& command : commands)
373 VectorHandle handle = command.getHandle();
374 if (handle != 0) // command might not have a handle
375 incrementDrawStyleHandleRefCount(handle);
377 ImageIndex ii = command.getImageIndex();
378 if (ii) incImageRef(ii);
380 LoadIndex li = command.getLoadIndex();
381 if (li) incLoadIndexRef(li);
385 void OsdVector::incImageRef(ImageIndex index)
387 if (images_ref.find(index) == images_ref.end())
389 images_ref[index] = 1;
397 void OsdVector::removeImageRef(const ImageIndex ref)
402 int OsdVector::getLoadIndexRef(LoadIndex index)
404 surfaces_mutex.lock();
406 if (loadindex_ref.find(index) == loadindex_ref.end())
412 return loadindex_ref[index];
415 surfaces_mutex.unlock();
418 void OsdVector::incLoadIndexRef(LoadIndex index)
420 if (loadindex_ref.find(index) == loadindex_ref.end())
422 loadindex_ref[index] = 1;
426 loadindex_ref[index]++;
430 void OsdVector::removeLoadIndexRef(const LoadIndex ref)
432 loadindex_ref[ref]--;
434 if (loadindex_ref[ref] == 0)
436 //now check, if it is already loaded
437 std::map<LoadIndex, ImageIndex>::iterator itty = tvmedias_loaded.find(ref);
439 if ( itty != tvmedias_loaded.end())
441 removeImageRef((*itty).second); // remove lock
444 tvmedias_loaded.erase(ref);
445 // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia removeLoadIndexRef %d %llx",tvmedias_load.size(),ref);
446 tvmedias_load.erase(tvmedias_load_inv[ref]);
447 tvmedias_load_inv.erase(ref);
449 reader.invalidateLoadIndex(ref);
453 void OsdVector::cleanupOrphanedRefs()
455 // Do some garbage collection
457 std::map<void*, ImageIndex>::iterator mitty = monobitmaps.begin();
459 while (mitty != monobitmaps.end())
461 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*mitty).second);
462 int count = (*curitty).second;
466 ImageIndex ref = (*curitty).first;
467 monobitmaps.erase(mitty++);
468 images_ref.erase(curitty++);
469 destroyImageRef(ref);
474 /*map<string,ImageIndex>::iterator jitty=jpegs.begin();
475 while (jitty!=jpegs.end()) {
476 map<ImageIndex,int>::iterator curitty=images_ref.find((*jitty).second);
477 int count=(*curitty).second;
479 ImageIndex ref=(*curitty).first;
480 jpegs.erase(jitty++);
481 images_ref.erase(curitty++);
482 destroyImageRef(ref);
486 std::map<TVMediaInfo, ImageIndex>::iterator titty = tvmedias.begin();
488 while (titty != tvmedias.end())
490 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*titty).second);
491 int count = (*curitty).second;
495 ImageIndex ref = (*curitty).first;
496 tvmedias.erase(titty++);
497 images_ref.erase(curitty);
498 destroyImageRef(ref);
504 std::map<TVMediaInfo, LoadIndex>::iterator litty = tvmedias_load.begin();
506 while (litty != tvmedias_load.end())
508 std::map<LoadIndex, int>::iterator curitty = loadindex_ref.find((*litty).second);
509 int count = (*curitty).second;
513 tvmedias_load_inv.erase((*litty).second);
514 tvmedias_loaded.erase((*litty).second);
515 tvmedias_load.erase(litty++);
520 std::list<ImageIndex>::iterator pitty = palettepics.begin();
522 while (pitty != palettepics.end())
524 std::map<ImageIndex, int>::iterator curitty = images_ref.find((*pitty));
525 int count = (*curitty).second;
529 ImageIndex ref = (*curitty).first;
530 palettepics.erase(pitty++);
531 images_ref.erase(curitty++);
532 destroyImageRef(ref);
537 std::map<ImageIndex, int>::iterator citty = images_ref.begin();
539 while (citty != images_ref.end())
541 int count = (*citty).second;
545 ImageIndex ref = (*citty).first;
546 images_ref.erase(citty++);
547 destroyImageRef(ref);
553 std::map<DrawStyle, VectorHandle>::iterator sitty = drawstyleHandles.begin();
555 while (sitty != drawstyleHandles.end())
557 std::map<VectorHandle, int>::iterator curitty = drawstyleHandlesRefCounts.find((*sitty).second);
558 int count = (*curitty).second;
562 VectorHandle ref = (*curitty).first;
563 drawstyleHandles.erase(sitty++);
564 drawstyleHandlesRefCounts.erase(curitty++);
565 drawstyleHandles_lastit_valid = drawstyleHandlesRefCounts_lastit_valid = false;
566 destroyDrawStyleHandle(ref);
574 int OsdVector::getImageRef(ImageIndex index)
576 surfaces_mutex.lock();
578 if (images_ref.find(index) == images_ref.end())
584 return images_ref[index];
587 surfaces_mutex.unlock();
590 void OsdVector::incrementDrawStyleHandleRefCount(VectorHandle index)
592 if (!drawstyleHandlesRefCounts_lastit_valid || (drawstyleHandlesRefCounts_lastit->first != index))
594 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(index);
595 if (drawstyleHandlesRefCounts_lastit == drawstyleHandlesRefCounts.end())
597 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.insert(std::pair<VectorHandle, int>(index, 0)).first;
601 drawstyleHandlesRefCounts_lastit->second++;
602 drawstyleHandlesRefCounts_lastit_valid = true;
605 void OsdVector::decrementDrawStyleHandleRefCount(VectorHandle index)
607 if (!drawstyleHandlesRefCounts_lastit_valid || (drawstyleHandlesRefCounts_lastit->first != index))
609 drawstyleHandlesRefCounts_lastit_valid = false;
610 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(index);
613 if (drawstyleHandlesRefCounts_lastit != drawstyleHandlesRefCounts.end())
615 drawstyleHandlesRefCounts_lastit_valid = true;
616 drawstyleHandlesRefCounts_lastit->second--;
620 VectorHandle OsdVector::getDrawStyleHandle(const DrawStyle& c)
622 surfaces_mutex.lock();
623 VectorHandle style_handle = 0;
629 if (!drawstyleHandles_lastit_valid || (drawstyleHandles_lastit->first != c))
631 drawstyleHandles_lastit_valid = false;
632 drawstyleHandles_lastit = drawstyleHandles.find(c);
635 if (drawstyleHandles_lastit == drawstyleHandles.end())
637 surfaces_mutex.unlock();
638 style_handle = createDrawStyleHandle(c);
639 surfaces_mutex.lock();
640 drawstyleHandles_lastit = drawstyleHandles.insert(std::pair<DrawStyle, VectorHandle>(c, style_handle)).first;
644 style_handle = drawstyleHandles_lastit->second;
646 //Now check if the handle is valid
647 if (!drawstyleHandlesRefCounts_lastit_valid || (*drawstyleHandlesRefCounts_lastit).first != style_handle)
649 drawstyleHandlesRefCounts_lastit_valid = false;
650 drawstyleHandlesRefCounts_lastit = drawstyleHandlesRefCounts.find(style_handle);
653 if (drawstyleHandlesRefCounts_lastit == drawstyleHandlesRefCounts.end())
655 //invalid handle recreate
656 surfaces_mutex.unlock();
657 style_handle = createDrawStyleHandle(c);
658 surfaces_mutex.lock();
659 drawstyleHandles_lastit->second = style_handle;
661 else drawstyleHandlesRefCounts_lastit_valid = true;
664 drawstyleHandles_lastit_valid = true;
665 incrementDrawStyleHandleRefCount(style_handle);
666 surfaces_mutex.unlock();
671 void OsdVector::dumpStyles()
673 std::map<DrawStyle, VectorHandle>::iterator i;
674 for(i = drawstyleHandles.begin(); i != drawstyleHandles.end(); i++)
676 const DrawStyle* test = &(i->first);
677 Log::getInstance()->log("OsdVector", Log::DEBUG, "DumpStyles: %p %i", test , i->second);
680 std::map<VectorHandle, int>::iterator i2;
681 for (i2 = drawstyleHandlesRefCounts.begin(); i2 != drawstyleHandlesRefCounts.end(); i2++)
683 Log::getInstance()->log("OsdVector", Log::DEBUG, "DumpStylesRef: %i %i", i2->first, i2->second);
688 LoadIndex OsdVector::getTVMediaRef(TVMediaInfo& tvmedia, ImageIndex& image)
690 ImageIndex image_handle = 0;
691 LoadIndex loadindex = 0;
692 surfaces_mutex.lock();
694 if (tvmedias.find(tvmedia) == tvmedias.end())
696 loadindex = loadTVMedia(tvmedia);
700 image_handle = tvmedias[tvmedia];
702 if (images_ref.find(image_handle) == images_ref.end())
704 //invalid handle recreate
705 loadindex = loadTVMedia(tvmedia);
710 incImageRef(image_handle);
714 /*tvmedias[tvmedia]=createTVMedia(tvmedia,width,height);
715 incImageRef(image_handle);*/
716 image = image_handle;
717 surfaces_mutex.unlock();
721 LoadIndex OsdVector::loadTVMedia(TVMediaInfo& tvmedia)
725 if (tvmedias_load.find(tvmedia) == tvmedias_load.end())
727 switch (tvmedia.getType())
730 index = VDR::getInstance()->loadTVMediaRecThumb(tvmedia);
735 index = ((long long) tvmedia.getPrimaryID()) << 32LL;
736 reader.addStaticImage(tvmedia.getPrimaryID());
740 index = VDR::getInstance()->loadTVMediaEventThumb(tvmedia);
744 index = VDR::getInstance()->loadChannelLogo(tvmedia);
748 index = VDR::getInstance()->loadTVMedia(tvmedia);
752 if (tvmedia.getType() != 4 && tvmedia.getStaticFallback() > -1)
754 reader.informFallback(index, tvmedia.getStaticFallback());
757 tvmedias_load[tvmedia] = index;
758 tvmedias_load_inv[index] = tvmedia;
762 index = tvmedias_load[tvmedia];
765 incLoadIndexRef(index);
770 void OsdVector::informPicture(LoadIndex index, ImageIndex imageIndex)
772 //Beware for thread safety
773 ImageIndex image_index = 0;
775 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Picture for request id %llx arrived %x", index, imageIndex);
776 surfaces_mutex.lock();
777 TVMediaInfo tvmedia = tvmedias_load_inv[index];
781 std::map<LoadIndex, int>::iterator itty = loadindex_ref.find(index);
782 image_index = tvmedias[tvmedia] = imageIndex;
783 tvmedias_loaded[index] = image_index;
785 if (itty == loadindex_ref.end() || (*itty).second == 0)
787 // we do not want the picture anymore . Really...
788 // fill images_ref in to not irritate the garbage collector
789 if (images_ref.find(image_index) == images_ref.end())
791 images_ref[image_index] = 0;
796 incImageRef(image_index); // hold one index until all loadings refs are gone;
800 surfaces_mutex.unlock();
804 ImageIndex OsdVector::getJpegRef(const char* fileName, int *width,int *height)
806 ImageIndex image_handle=0;
807 if (jpegs.find(fileName)==jpegs.end())
809 image_handle=jpegs[fileName]=createJpeg(fileName,width,height);
811 image_handle=jpegs[fileName];
814 if (images_ref.find(image_handle)==images_ref.end()) {
815 //invalid handle recreate
816 image_handle=jpegs[fileName]=createJpeg(fileName,width,height);
819 incImageRef(image_handle);
824 ImageIndex OsdVector::getMonoBitmapRef(void* base, int width, int height)
826 ImageIndex image_handle;
827 surfaces_mutex.lock();
829 if (monobitmaps.find(base) == monobitmaps.end())
831 surfaces_mutex.unlock();
832 image_handle = createMonoBitmap(base, width, height);
833 surfaces_mutex.lock();
834 monobitmaps[base] = image_handle;
838 image_handle = monobitmaps[base];
840 if (images_ref.find(image_handle) == images_ref.end())
842 //invalid handle recreate
843 surfaces_mutex.unlock();
844 image_handle = createMonoBitmap(base, width, height);
845 surfaces_mutex.lock();
846 monobitmaps[base] = image_handle;
850 incImageRef(image_handle);
851 surfaces_mutex.unlock();
855 ImageIndex OsdVector::getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
857 ImageIndex image_handle;
858 image_handle = createImagePalette(width, height, image_data, palette_data);
859 surfaces_mutex.lock();
860 palettepics.push_back(image_handle);
861 incImageRef(image_handle);
862 surfaces_mutex.unlock();
866 OsdVector::PictureReader::~PictureReader()
868 decoders_lock.lock();
870 while (decoders.size())
872 PictureDecoder* dec = decoders.front();
873 decoders.pop_front();
877 decoders_lock.unlock();
880 void OsdVector::PictureReader::init()
885 void OsdVector::PictureReader::shutdown()
890 void OsdVector::PictureReader::addDecoder(PictureDecoder* decoder)
892 decoders_lock.lock();
894 decoders.push_front(decoder);
895 decoders_lock.unlock();
898 void OsdVector::PictureReader::removeDecoder(PictureDecoder* decoder)
900 decoders_lock.lock();
901 std::list<PictureDecoder*>::iterator itty = decoders.begin();
903 while (itty != decoders.end())
905 if ((*itty) == decoder)
907 decoders.erase(itty);
914 Log::getInstance()->log("OsdVector", Log::DEBUG, "removeDecoder");
917 decoders_lock.unlock();
920 void OsdVector::PictureReader::threadMethod()
922 OsdVector* osdvector = dynamic_cast<OsdVector*>(Osd::getInstance());
923 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Start Picture Reader");
927 if (!threadIsActive())
929 Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia End Picture Reader");
939 decoders_lock.lock();
940 std::list<PictureDecoder*>::iterator itty = decoders.begin();
942 while (itty != decoders.end())
944 if ((*itty)->getDecodedPicture(pictinf))
947 osdvector->createPicture(pictinf);
953 if (processReceivedPictures())
958 decoders_lock.unlock();
961 //Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Sleep Picture Reader");
963 struct timespec target_time;
964 getClockRealTime(&target_time);
966 target_time.tv_nsec += 1000000LL * 10;
968 if (target_time.tv_nsec > 999999999)
970 target_time.tv_nsec -= 1000000000L;
971 target_time.tv_sec += 1;
975 threadWaitForSignalTimed(&target_time);
977 //Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Sleep end Picture Reader");
981 void OsdVector::PictureReader::invalidateLoadIndex(LoadIndex index)
983 pict_lock_incoming.lock();
984 invalid_loadindex.insert(index);
985 pict_lock_incoming.unlock();
988 void OsdVector::PictureReader::informFallback(LoadIndex index, int fallback)
990 pict_lock_incoming.lock();
991 inform_fallback[index] = fallback;
992 pict_lock_incoming.unlock();
995 void OsdVector::PictureReader::receivePicture(VDR_ResponsePacket* vresp)
997 pict_lock_incoming.lock();
998 pict_incoming.push(vresp);
999 pict_lock_incoming.unlock();
1004 void OsdVector::PictureReader::addStaticImage(unsigned int id)
1006 pict_lock_incoming.lock();
1007 pict_incoming_static.push(id);
1008 invalid_loadindex.erase(((long long) id) << 32LL);
1009 pict_lock_incoming.unlock();
1015 #pragma warning(disable : 4703)
1018 bool OsdVector::PictureReader::processReceivedPictures()
1020 bool decoded = false;
1022 pict_lock_incoming.lock();
1024 if (pict_incoming.size())
1026 VDR_ResponsePacket* vresp = pict_incoming.front();
1027 pict_incoming.pop();
1028 std::set<LoadIndex>::iterator setpos = invalid_loadindex.find(vresp->getStreamID());
1030 if (setpos != invalid_loadindex.end())
1033 invalid_loadindex.erase(setpos);
1036 pict_lock_incoming.unlock();
1038 if (!valid) // we do not want it anymore skip it;
1044 // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Pictures arrived VDR %x %d %d",
1045 // vresp->getStreamID(),vresp->getUserDataLength(),vresp->getFlag());
1046 bool decode = false;
1051 if (vresp->getFlag() != 2)
1053 userdata = vresp->getUserData();
1054 length = vresp->getUserDataLength();
1061 pict_lock_incoming.lock();
1063 if (inform_fallback.find(vresp->getStreamID()) != inform_fallback.end())
1065 fallback = inform_fallback[vresp->getStreamID()];
1068 pict_lock_incoming.unlock();
1070 if (fallback >= 0 && ((OsdVector*)Osd::getInstance())->getStaticImageData(fallback, &userdata, &length))
1079 std::list<PictureDecoder*>::iterator itty = decoders.begin();
1081 while (itty != decoders.end())
1083 userdata = (*itty)->decodePicture(vresp->getStreamID(), userdata, length, freed);
1094 if (!decoded && userdata && freed)
1100 pict_lock_incoming.lock();
1101 inform_fallback.erase(vresp->getStreamID());
1102 pict_lock_incoming.unlock();
1103 //else osd->informPicture(vresp->getStreamID(), 0);
1106 else if (pict_incoming_static.size())
1108 unsigned int static_id = pict_incoming_static.front();
1109 pict_incoming_static.pop();
1110 std::set<LoadIndex>::iterator setpos = invalid_loadindex.find(((long long) static_id) << 32LL);
1112 if (setpos != invalid_loadindex.end())
1115 invalid_loadindex.erase(setpos);
1118 pict_lock_incoming.unlock();
1120 if (!valid) // we do not want it anymore skip it;
1128 if (((OsdVector*)Osd::getInstance())->getStaticImageData(static_id, &userdata, &length))
1130 std::list<PictureDecoder*>::iterator itty = decoders.begin();
1132 while (itty != decoders.end())
1134 if (!(*itty)->decodePicture(((long long) static_id) << 32LL, userdata, length, false))
1146 pict_lock_incoming.unlock();
1149 if (pict_incoming.size() || pict_incoming_static.size()) return true;