2 Copyright 2021 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/>.
29 #include <condition_variable>
32 #include "osdvectortypes.h"
33 #include "osdvector.h"
39 class VDR_ResponsePacket;
46 virtual ~PictureDecoder() {}
48 // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
49 virtual unsigned char* decodePicture(LoadingIndex index, unsigned char* buffer, unsigned int length, bool freemem = true) = 0;
51 virtual bool getDecodedPicture(struct PictureInfo& pict_inf) = 0;
52 virtual void freeReference(void* ref) = 0;
54 virtual void init() {};
55 virtual void shutdown() {};
61 ImageStatic createStatic(int sa_id);
62 ImageGeneric createGeneric();
63 ImageRecFolder createRecFolder(const char* recFileName);
64 ImageRecThumb createRecThumb(const char* recFileName);
65 ImageEventThumb createEventThumb(u4 channel, u4 event);
66 ImageChannelLogo createChannelLogo(u4 channel, int sa_id = -1);
70 static ImageLoader* getInstance();
74 void ensureLoaded(Image& image);
75 void ensureLoaded(ImageGeneric& imageGeneric);
76 void decodeStatic(Image& t);
77 void downloadDone(VDR_ResponsePacket* vresp);
78 bool pictureRendered(LoadingIndex index, OsdImage& oimage);
79 void garbageCollect();
81 void addDecoder(PictureDecoder* decoder);
82 void removeDecoder(PictureDecoder* decoder);
87 static ImageLoader* instance;
91 std::vector<Image> mImages; // Master vector of Image objects
92 std::mutex mImagesLock;
94 struct PictureReaderWorkItem
96 VDR_ResponsePacket* vresp{};
101 std::queue<PictureReaderWorkItem> pictureReaderWork;
102 std::mutex pictureReaderWorkLock;
104 void pictureReaderThreadMethod();
105 std::mutex pictureReaderThreadMutex;
106 std::thread pictureReaderThread;
107 bool pictureReaderThreadRun{};
108 bool pictureReaderThreadQuit{};
109 std::condition_variable pictureReaderThreadCond;
110 std::mutex pictureReaderCondSigtex; // Careful with this, lock for minimal time
112 std::mutex decoders_lock;
113 std::list<PictureDecoder*> decoders;
115 Image loadingIndexToImage(LoadingIndex index);
116 void pictureReaderProcessOne();