From d302611c6517f90d5cda217917da76679f073182 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 24 Nov 2021 16:42:03 +0000 Subject: [PATCH] Bug fix: Prevent vector handle ref counts going negative Disable function OsdVector::getImageRef Rename LoadIndex LoadingIndex Rename images_ref vhi_refcounts Reorganise osdvector.h to identify things private to that class --- imageomx.cc | 4 +- imageomx.h | 4 +- imageomx2.cc | 2 +- imageomx2.h | 2 +- osdvector.cc | 141 ++++++++++++++++++++++++----------------------- osdvector.h | 126 ++++++++++++++++++++++-------------------- osdwinvector.cc | 4 +- surfacevector.cc | 10 ++-- 8 files changed, 153 insertions(+), 140 deletions(-) diff --git a/imageomx.cc b/imageomx.cc index 23a5784..6be066e 100644 --- a/imageomx.cc +++ b/imageomx.cc @@ -258,7 +258,7 @@ int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length) -unsigned char* ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem) +unsigned char* ImageOMX::decodePicture(LoadingIndex index, unsigned char * buffer, unsigned int length, bool freemem) { if (pictInfValid) return buffer; // does support only one image at a Time; // LogNT::getInstance()->debug(TAG, @@ -297,7 +297,7 @@ unsigned char* ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, } -bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char* /* buffer */, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video) +bool ImageOMX::intDecodePicture(LoadingIndex index, unsigned char* /* buffer */, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video) { static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX}; diff --git a/imageomx.h b/imageomx.h index e2df77f..ce722aa 100644 --- a/imageomx.h +++ b/imageomx.h @@ -47,7 +47,7 @@ class ImageOMX : public OsdVector::PictureDecoder void init(); void shutdown(); - unsigned char* decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem); + unsigned char* decodePicture(LoadingIndex index, unsigned char * buffer, unsigned int length, bool freemem); bool getDecodedPicture(struct OsdVector::PictureInfo& pict_inf); void freeReference(void * ref); @@ -57,7 +57,7 @@ class ImageOMX : public OsdVector::PictureDecoder static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* bulibaver); - bool intDecodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, EGLPictureCreator* egl_pict, VideoOMX *video); + bool intDecodePicture(LoadingIndex index, unsigned char * buffer, unsigned int length, EGLPictureCreator* egl_pict, VideoOMX *video); void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver); void ReturnFillOMXBuffer(OMX_BUFFERHEADERTYPE* buffer); diff --git a/imageomx2.cc b/imageomx2.cc index 7eaffdb..2601bdf 100644 --- a/imageomx2.cc +++ b/imageomx2.cc @@ -73,7 +73,7 @@ void ImageOMX2::reinit() init(); } -unsigned char* ImageOMX2::decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem) noexcept +unsigned char* ImageOMX2::decodePicture(LoadingIndex index, unsigned char* buffer, unsigned int length, bool freemem) noexcept { // This function needs to return NULL if successful, buffer if not. diff --git a/imageomx2.h b/imageomx2.h index 8f8fb63..ef85a75 100644 --- a/imageomx2.h +++ b/imageomx2.h @@ -64,7 +64,7 @@ class ImageOMX2 : public OsdVector::PictureDecoder void init(); void shutdown(); - unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem) noexcept; + unsigned char* decodePicture(LoadingIndex index, unsigned char* buffer, unsigned int length, bool freemem) noexcept; bool getDecodedPicture(struct OsdVector::PictureInfo& pict_inf); void freeReference(void*) {}; diff --git a/osdvector.cc b/osdvector.cc index e34fac5..e7311ed 100644 --- a/osdvector.cc +++ b/osdvector.cc @@ -41,7 +41,7 @@ class MagickDecoder: public OsdVector::PictureDecoder public: MagickDecoder(OsdVector::PictureReader* treader): OsdVector::PictureDecoder(treader) {pictInfValid = false;}; - unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem); + unsigned char* decodePicture(LoadingIndex index, unsigned char* buffer, unsigned int length, bool freemem); bool getDecodedPicture( struct OsdVector::PictureInfo& pict_inf); @@ -52,7 +52,7 @@ class MagickDecoder: public OsdVector::PictureDecoder bool pictInfValid; }; -unsigned char* MagickDecoder::decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem) +unsigned char* MagickDecoder::decodePicture(LoadingIndex index, unsigned char* buffer, unsigned int length, bool freemem) { if (pictInfValid) return buffer; // does support only one image at a Time; @@ -172,7 +172,7 @@ Surface* OsdVector::createNewSurface() void OsdVector::Blank() { - // do nothing? remove this one? + // FIXME do nothing? remove this one? } int OsdVector::restore() @@ -188,7 +188,7 @@ int OsdVector::restore() } //also clear all handles, they are now invalid, no need to release them - images_ref.clear(); + vhi_refcounts.clear(); monobitmaps.clear(); //jpegs.clear(); drawstyleHandles.clear(); @@ -258,14 +258,14 @@ void OsdVector::drawSurfaces() // update any images loaded in the mean time if ((*commands).instr == DrawImageLoading) { - LoadIndex loadindex = (*commands).target.loadindex; + LoadingIndex loadindex = (*commands).target.loadindex; if (tvmedias_loaded.find(loadindex) != tvmedias_loaded.end()) { (*commands).instr = DrawImage; (*commands).target.image = tvmedias_loaded[loadindex];; incImageRef((*commands).target.image); - removeLoadIndexRef(loadindex); + removeLoadingIndexRef(loadindex); } } @@ -325,14 +325,14 @@ void OsdVector::updateOrAddSurface(const SurfaceVector* surf, float x, float y, { if (command.instr == DrawImageLoading) { - LoadIndex loadindex = command.target.loadindex; + LoadingIndex loadindex = command.target.loadindex; if (tvmedias_loaded.find(loadindex) != tvmedias_loaded.end()) { command.instr = DrawImage; command.target.image = tvmedias_loaded[loadindex]; incImageRef(command.target.image); - removeLoadIndexRef(loadindex); + removeLoadingIndexRef(loadindex); } } } @@ -379,8 +379,8 @@ void OsdVector::decrementAllRefCounts(std::vector& commands) VectorHandleImage imageHandle = command.getImageHandle(); if (imageHandle) removeImageRef(imageHandle); - LoadIndex li = command.getLoadIndex(); - if (li) removeLoadIndexRef(li); + LoadingIndex li = command.getLoadingIndex(); + if (li) removeLoadingIndexRef(li); } } @@ -395,29 +395,29 @@ void OsdVector::incrementAllRefCounts(std::vector& commands) VectorHandleImage imageHandle = command.getImageHandle(); if (imageHandle) incImageRef(imageHandle); - LoadIndex li = command.getLoadIndex(); - if (li) incLoadIndexRef(li); + LoadingIndex li = command.getLoadingIndex(); + if (li) incLoadingIndexRef(li); } } void OsdVector::incImageRef(VectorHandleImage handle) { - if (images_ref.find(handle) == images_ref.end()) + if (vhi_refcounts.find(handle) == vhi_refcounts.end()) { - images_ref[handle] = 1; + vhi_refcounts[handle] = 1; } else { - images_ref[handle]++; + vhi_refcounts[handle]++; } } void OsdVector::removeImageRef(const VectorHandleImage handle) { - images_ref[handle]--; + vhi_refcounts[handle]--; } -int OsdVector::getLoadIndexRef(LoadIndex index) +int OsdVector::getLoadingIndexRef(LoadingIndex index) { surfaces_mutex.lock(); @@ -433,7 +433,7 @@ int OsdVector::getLoadIndexRef(LoadIndex index) surfaces_mutex.unlock(); } -void OsdVector::incLoadIndexRef(LoadIndex index) +void OsdVector::incLoadingIndexRef(LoadingIndex index) { if (loadindex_ref.find(index) == loadindex_ref.end()) { @@ -445,18 +445,23 @@ void OsdVector::incLoadIndexRef(LoadIndex index) } } -void OsdVector::removeLoadIndexRef(const LoadIndex ref) +void OsdVector::removeLoadingIndexRef(const LoadingIndex ref) { loadindex_ref[ref]--; if (loadindex_ref[ref] == 0) { //now check, if it is already loaded - std::map::iterator itty = tvmedias_loaded.find(ref); + std::map::iterator itty = tvmedias_loaded.find(ref); if ( itty != tvmedias_loaded.end()) { - removeImageRef((*itty).second); // remove lock + // removeImageRef((*itty).second); // remove lock + /* + * I'm not sure exactly how all this works but removing this line of code prevents + * reference counts in vhi_refcounts from going negative. Therefore I suspect the above + * line is wrong. Will test for a while. + */ } tvmedias_loaded.erase(ref); @@ -464,7 +469,7 @@ void OsdVector::removeLoadIndexRef(const LoadIndex ref) tvmedias_load.erase(tvmedias_load_inv[ref]); tvmedias_load_inv.erase(ref); - reader.invalidateLoadIndex(ref); + reader.invalidateLoadingIndex(ref); } } @@ -476,14 +481,14 @@ void OsdVector::cleanupOrphanedRefs() while (mitty != monobitmaps.end()) { - std::map::iterator curitty = images_ref.find((*mitty).second); + std::map::iterator curitty = vhi_refcounts.find((*mitty).second); int count = (*curitty).second; if (count == 0) { VectorHandleImage handle = (*curitty).first; monobitmaps.erase(mitty++); - images_ref.erase(curitty++); + vhi_refcounts.erase(curitty++); destroyImageRef(handle); } else ++mitty; @@ -491,12 +496,12 @@ void OsdVector::cleanupOrphanedRefs() /*map::iterator jitty=jpegs.begin(); while (jitty!=jpegs.end()) { - map::iterator curitty=images_ref.find((*jitty).second); + map::iterator curitty=vhi_refcounts.find((*jitty).second); int count=(*curitty).second; if (count==0) { VectorHandleImage handle=(*curitty).first; jpegs.erase(jitty++); - images_ref.erase(curitty++); + vhi_refcounts.erase(curitty++); destroyImageRef(handle); } else ++jitty; }*/ @@ -505,25 +510,25 @@ void OsdVector::cleanupOrphanedRefs() while (titty != tvmedias.end()) { - std::map::iterator curitty = images_ref.find((*titty).second); + std::map::iterator curitty = vhi_refcounts.find((*titty).second); int count = (*curitty).second; if (count == 0) { VectorHandleImage handle = (*curitty).first; tvmedias.erase(titty++); - images_ref.erase(curitty); + vhi_refcounts.erase(curitty); destroyImageRef(handle); } else ++titty; } - std::map::iterator litty = tvmedias_load.begin(); + std::map::iterator litty = tvmedias_load.begin(); while (litty != tvmedias_load.end()) { - std::map::iterator curitty = loadindex_ref.find((*litty).second); + std::map::iterator curitty = loadindex_ref.find((*litty).second); int count = (*curitty).second; if (count == 0) @@ -539,29 +544,29 @@ void OsdVector::cleanupOrphanedRefs() while (pitty != palettepics.end()) { - std::map::iterator curitty = images_ref.find((*pitty)); + std::map::iterator curitty = vhi_refcounts.find((*pitty)); int count = (*curitty).second; if (count == 0) { VectorHandleImage handle = (*curitty).first; palettepics.erase(pitty++); - images_ref.erase(curitty++); + vhi_refcounts.erase(curitty++); destroyImageRef(handle); } else ++pitty; } - std::map::iterator citty = images_ref.begin(); + std::map::iterator citty = vhi_refcounts.begin(); - while (citty != images_ref.end()) + while (citty != vhi_refcounts.end()) { int count = (*citty).second; if (count == 0) { VectorHandleImage handle = (*citty).first; - images_ref.erase(citty++); + vhi_refcounts.erase(citty++); destroyImageRef(handle); } else ++citty; @@ -589,21 +594,21 @@ void OsdVector::cleanupOrphanedRefs() } } -int OsdVector::getImageRef(VectorHandleImage handle) -{ - surfaces_mutex.lock(); - - if (images_ref.find(handle) == images_ref.end()) - { - return -1; - } - else - { - return images_ref[handle]; - } - - surfaces_mutex.unlock(); -} +//int OsdVector::getImageRef(VectorHandleImage handle) +//{ +// surfaces_mutex.lock(); +// +// if (vhi_refcounts.find(handle) == vhi_refcounts.end()) +// { +// return -1; +// } +// else +// { +// return vhi_refcounts[handle]; +// } +// +// surfaces_mutex.unlock(); +//} void OsdVector::incrementDrawStyleHandleRefCount(VectorHandle index) { @@ -705,21 +710,21 @@ void OsdVector::dumpStyles() } #endif -LoadIndex OsdVector::getTVMediaRef(TVMediaInfo& tvmedia, VectorHandleImage& handle) +LoadingIndex OsdVector::getTVMediaRef(TVMediaInfo& tvmedia, VectorHandleImage& handle) { VectorHandleImage localHandle = 0; - LoadIndex loadindex = 0; + LoadingIndex loadindex = 0; surfaces_mutex.lock(); if (tvmedias.find(tvmedia) == tvmedias.end()) // if not found, return a loadIndex from loadTVMedia(tvmedia) { loadindex = loadTVMedia(tvmedia); } - else // if found, return a real imageIndex. incImageRef(localHandle). EXCEPT: If it's not found in images_ref (???) in which case do same as above. + else // if found, return a real imageIndex. incImageRef(localHandle). EXCEPT: If it's not found in vhi_refcounts (???) in which case do same as above. { localHandle = tvmedias[tvmedia]; - if (images_ref.find(localHandle) == images_ref.end()) + if (vhi_refcounts.find(localHandle) == vhi_refcounts.end()) { //invalid handle recreate loadindex = loadTVMedia(tvmedia); @@ -738,9 +743,9 @@ LoadIndex OsdVector::getTVMediaRef(TVMediaInfo& tvmedia, VectorHandleImage& hand return loadindex; } -LoadIndex OsdVector::loadTVMedia(TVMediaInfo& tvmedia) // insert a tvmedia for loading +LoadingIndex OsdVector::loadTVMedia(TVMediaInfo& tvmedia) // insert a tvmedia for loading { - LoadIndex index = 0; + LoadingIndex index = 0; if (tvmedias_load.find(tvmedia) == tvmedias_load.end()) // if not found in tvmedias_load { @@ -782,12 +787,12 @@ LoadIndex OsdVector::loadTVMedia(TVMediaInfo& tvmedia) // insert a tvme index = tvmedias_load[tvmedia]; } - incLoadIndexRef(index); + incLoadingIndexRef(index); return index; } -void OsdVector::informPicture(LoadIndex index, VectorHandleImage handle) +void OsdVector::informPicture(LoadingIndex index, VectorHandleImage handle) { //Beware for thread safety VectorHandleImage localHandle = 0; @@ -798,17 +803,17 @@ void OsdVector::informPicture(LoadIndex index, VectorHandleImage handle) if (handle) { - std::map::iterator itty = loadindex_ref.find(index); + std::map::iterator itty = loadindex_ref.find(index); localHandle = tvmedias[tvmedia] = handle; tvmedias_loaded[index] = localHandle; if (itty == loadindex_ref.end() || (*itty).second == 0) { // we do not want the picture anymore . Really... - // fill images_ref in to not irritate the garbage collector - if (images_ref.find(localHandle) == images_ref.end()) + // fill vhi_refcounts in to not irritate the garbage collector + if (vhi_refcounts.find(localHandle) == vhi_refcounts.end()) { - images_ref[localHandle] = 0; + vhi_refcounts[localHandle] = 0; } } else @@ -854,7 +859,7 @@ VectorHandleImage OsdVector::getJpegRef(const char* fileName, int *width,int *he image_handle=jpegs[fileName]; *width=0; *height=0; - if (images_ref.find(image_handle)==images_ref.end()) { + if (vhi_refcounts.find(image_handle)==vhi_refcounts.end()) { //invalid handle recreate image_handle=jpegs[fileName]=createJpeg(fileName,width,height); } @@ -880,7 +885,7 @@ VectorHandleImage OsdVector::getMonoBitmapRef(void* base, int width, int height) { image_handle = monobitmaps[base]; - if (images_ref.find(image_handle) == images_ref.end()) + if (vhi_refcounts.find(image_handle) == vhi_refcounts.end()) { //invalid handle recreate surfaces_mutex.unlock(); @@ -1035,7 +1040,7 @@ void OsdVector::PictureReader::threadMethod() } } -void OsdVector::PictureReader::invalidateLoadIndex(LoadIndex index) +void OsdVector::PictureReader::invalidateLoadingIndex(LoadingIndex index) { pict_lock_incoming.lock(); invalid_loadindex.insert(index); @@ -1047,7 +1052,7 @@ void OsdVector::PictureReader::invalidateLoadIndex(LoadIndex index) // Doesn't look like it, but if it does get the 4 lines below } -void OsdVector::PictureReader::informFallback(LoadIndex index, int fallback) +void OsdVector::PictureReader::informFallback(LoadingIndex index, int fallback) { pict_lock_incoming.lock(); inform_fallback[index] = fallback; @@ -1096,7 +1101,7 @@ bool OsdVector::PictureReader::processReceivedPictures() { VDR_ResponsePacket* vresp = pict_incoming.front(); pict_incoming.pop(); - std::set::iterator setpos = invalid_loadindex.find(vresp->getStreamID()); + std::set::iterator setpos = invalid_loadindex.find(vresp->getStreamID()); if (setpos != invalid_loadindex.end()) { @@ -1178,7 +1183,7 @@ bool OsdVector::PictureReader::processReceivedPictures() { unsigned int static_id = pict_incoming_static.front(); pict_incoming_static.pop(); - std::set::iterator setpos = invalid_loadindex.find(((long long) static_id) << 32LL); + std::set::iterator setpos = invalid_loadindex.find(((long long) static_id) << 32LL); if (setpos != invalid_loadindex.end()) { diff --git a/osdvector.h b/osdvector.h index 4b7ae5f..b3b20cc 100644 --- a/osdvector.h +++ b/osdvector.h @@ -71,7 +71,7 @@ enum Corner }; typedef VectorHandle VectorHandleImage; -typedef unsigned long long LoadIndex; +typedef unsigned long long LoadingIndex; class SVGCommand { @@ -89,7 +89,7 @@ class SVGCommand return nc; }; - inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, Corner corner = TopLeft) + inline static SVGCommand PaintImageLoading(LoadingIndex load_in, float ix, float iy, float iw, float ih, Corner corner = TopLeft) { SVGCommand nc; nc.instr = DrawImageLoading; @@ -181,7 +181,7 @@ class SVGCommand else return target.image; }; - LoadIndex getLoadIndex() + LoadingIndex getLoadingIndex() { if (instr != DrawImageLoading) return 0; else return target.loadindex; @@ -197,7 +197,7 @@ class SVGCommand wchar_t textchar; VectorHandleImage image; unsigned int ttchar; - LoadIndex loadindex; + LoadingIndex loadindex; } target; }; @@ -234,24 +234,24 @@ class OsdVector : public Osd, public MessageReceiver virtual float getFontHeight() = 0; virtual float getCharWidth(wchar_t c) = 0; float* getCharWidthArray() {return byte_char_width;}; - - //virtual VectorHandleImage getJpegRef(const char* fileName, int *width,int *height); - virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia, VectorHandleImage& handle); - virtual VectorHandleImage getMonoBitmapRef(void* base, int width, int height); - virtual VectorHandleImage getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data); - + virtual void getScreenSize(int& width, int& height) = 0; + virtual void getRealScreenSize(int& width, int& height) = 0; virtual bool getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length) = 0; + // Used only by OsdVector and SurfaceVector void removeImageRef(const VectorHandleImage ref); - void removeLoadIndexRef(const LoadIndex ref); + void removeLoadingIndexRef(const LoadingIndex ref); VectorHandle getDrawStyleHandle(const DrawStyle& c); - virtual void decrementDrawStyleHandleRefCount(VectorHandle ref); - virtual void getScreenSize(int& width, int& height) = 0; - virtual void getRealScreenSize(int& width, int& height) = 0; + void decrementDrawStyleHandleRefCount(VectorHandle ref); + LoadingIndex getTVMediaRef(TVMediaInfo& tvmedia, VectorHandleImage& handle); + //virtual VectorHandleImage getJpegRef(const char* fileName, int *width,int *height); + virtual VectorHandleImage getMonoBitmapRef(void* base, int width, int height); + virtual VectorHandleImage getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data); + // should be only called from control thread - void informPicture(LoadIndex index, VectorHandleImage handle); + void informPicture(LoadingIndex index, VectorHandleImage handle); void processMessage(Message* m); @@ -270,7 +270,7 @@ class OsdVector : public Osd, public MessageReceiver PictType type; ULONG width; ULONG height; - LoadIndex lindex; + LoadingIndex lindex; union { const void* image; @@ -290,7 +290,7 @@ class OsdVector : public Osd, public MessageReceiver virtual ~PictureDecoder() {}; // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true; - virtual unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem = true) = 0; + virtual unsigned char* decodePicture(LoadingIndex index, unsigned char* buffer, unsigned int length, bool freemem = true) = 0; virtual bool getDecodedPicture(struct PictureInfo& pict_inf) = 0; virtual void freeReference(void* ref) = 0; @@ -316,8 +316,8 @@ class OsdVector : public Osd, public MessageReceiver void receivePicture(VDR_ResponsePacket* vresp); void addStaticImage(unsigned int id); - void invalidateLoadIndex(LoadIndex index); - void informFallback(LoadIndex index, int fallback); + void invalidateLoadingIndex(LoadingIndex index); + void informFallback(LoadingIndex index, int fallback); protected: @@ -333,8 +333,8 @@ class OsdVector : public Osd, public MessageReceiver std::queue pict_incoming; std::queue pict_incoming_static; std::list decoders; - std::map inform_fallback; - std::set invalid_loadindex; + std::map inform_fallback; + std::set invalid_loadindex; bool picture_update; }; @@ -346,53 +346,16 @@ class OsdVector : public Osd, public MessageReceiver PictureReader reader; - std::map images_ref; - std::map monobitmaps; - //map jpegs; - std::map tvmedias; - std::list palettepics; - std::map loadindex_ref; - std::map tvmedias_load; - std::map tvmedias_load_inv; - std::map tvmedias_loaded; - - std::map drawstyleHandles; - std::map::iterator drawstyleHandles_lastit; - bool drawstyleHandles_lastit_valid{}; - - std::map drawstyleHandlesRefCounts; - std::map::iterator drawstyleHandlesRefCounts_lastit; - bool drawstyleHandlesRefCounts_lastit_valid{}; - - std::list surfaces; - using SurfacesIterator = std::list::iterator; - - std::mutex surfaces_mutex; - float byte_char_width[256]{}; - void incImageRef(VectorHandleImage handle); - int getImageRef(VectorHandleImage handle); - virtual void destroyImageRef(VectorHandleImage handle) = 0; - void incLoadIndexRef(LoadIndex index); - int getLoadIndexRef(LoadIndex index); + virtual void destroyImageRef(VectorHandleImage handle) = 0; //virtual VectorHandleImage createJpeg(const char* fileName, int *width,int *height)=0; virtual VectorHandleImage createMonoBitmap(void* base, int width, int height) = 0; virtual VectorHandleImage createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data) = 0; virtual void createPicture(struct PictureInfo& pict_inf) = 0; - - virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia); - virtual VectorHandle createDrawStyleHandle(const DrawStyle& c) = 0; - void incrementDrawStyleHandleRefCount(VectorHandle index); virtual void destroyDrawStyleHandle(VectorHandle index) = 0; - - - void decrementAllRefCounts(std::vector& commands); - void incrementAllRefCounts(std::vector& commands); - void cleanupOrphanedRefs(); - virtual void drawSetTrans(SurfaceInfo& sc) = 0; virtual void executeDrawCommand(SVGCommand& command) = 0; @@ -401,6 +364,51 @@ class OsdVector : public Osd, public MessageReceiver #if DEV void dumpStyles(); #endif + + // See what we can make private in OsdVector + private: + + // Methods that only seem to be called internally + void incImageRef(VectorHandleImage handle); + void incLoadingIndexRef(LoadingIndex index); + int getLoadingIndexRef(LoadingIndex index); + void decrementAllRefCounts(std::vector& commands); + void incrementAllRefCounts(std::vector& commands); + void cleanupOrphanedRefs(); + void incrementDrawStyleHandleRefCount(VectorHandle index); + LoadingIndex loadTVMedia(TVMediaInfo& tvmedia); + + // int getImageRef(VectorHandleImage handle); // Not used anywhere + + + + // All the below are data structures only touched by this base class OsdVector + + std::map tvmedias; + std::map monobitmaps; + //map jpegs; + std::list palettepics; + + std::map vhi_refcounts; // This appears to cover all 3 (4) of the above types + + std::map loadindex_ref; + std::map tvmedias_load; + std::map tvmedias_load_inv; + std::map tvmedias_loaded; + + + std::map drawstyleHandles; + std::map::iterator drawstyleHandles_lastit; + bool drawstyleHandles_lastit_valid{}; + + std::map drawstyleHandlesRefCounts; + std::map::iterator drawstyleHandlesRefCounts_lastit; + bool drawstyleHandlesRefCounts_lastit_valid{}; + + std::list surfaces; + using SurfacesIterator = std::list::iterator; + std::mutex surfaces_mutex; + }; #endif diff --git a/osdwinvector.cc b/osdwinvector.cc index 51504eb..67de968 100644 --- a/osdwinvector.cc +++ b/osdwinvector.cc @@ -51,7 +51,7 @@ public: WICPictDecoder(OsdVector::PictureReader* treader, OsdWinVector *posd); virtual ~WICPictDecoder(); - unsigned char *decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem); + unsigned char *decodePicture(LoadingIndex index, unsigned char * buffer, unsigned int length, bool freemem); bool getDecodedPicture(struct OsdVector::PictureInfo& pict_inf); @@ -80,7 +80,7 @@ WICPictDecoder::~WICPictDecoder() wicfactory->Release(); } -unsigned char * WICPictDecoder::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem) +unsigned char * WICPictDecoder::decodePicture(LoadingIndex index, unsigned char * buffer, unsigned int length, bool freemem) { if (pictInfValid) return buffer; // does support only one image at a Time; diff --git a/surfacevector.cc b/surfacevector.cc index 1da632b..ca1c6ba 100644 --- a/surfacevector.cc +++ b/surfacevector.cc @@ -45,8 +45,8 @@ SurfaceVector::~SurfaceVector() VectorHandleImage handle = command.getImageHandle(); if (handle) osd->removeImageRef(handle); - LoadIndex li = command.getLoadIndex(); - if (li) osd->removeLoadIndexRef(li); + LoadingIndex li = command.getLoadingIndex(); + if (li) osd->removeLoadingIndexRef(li); } } @@ -262,7 +262,7 @@ void SurfaceVector::drawTVMedia(TVMediaInfo& tvmedia, float x, float y, float w { command_mutex.lock(); VectorHandleImage handle = 0; - LoadIndex load_index = osd->getTVMediaRef(tvmedia, handle); + LoadingIndex load_index = osd->getTVMediaRef(tvmedia, handle); if (width != 0 && height != 0) { @@ -404,9 +404,9 @@ int SurfaceVector::removeCommands(float x, float y, float width, float height) if (handle) osd->removeImageRef(handle); - LoadIndex li = (*itty).getLoadIndex(); + LoadingIndex li = (*itty).getLoadingIndex(); - if (li) osd->removeLoadIndexRef(li); + if (li) osd->removeLoadingIndexRef(li); if (!remove) { -- 2.39.2