Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 1 | /* Copyright 2015 Pierre Ossman for Cendio AB |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __RFB_DECODEMANAGER_H__ |
| 20 | #define __RFB_DECODEMANAGER_H__ |
| 21 | |
Pierre Ossman | 504afa2 | 2015-11-12 12:21:58 +0100 | [diff] [blame] | 22 | #include <list> |
| 23 | |
| 24 | #include <os/Thread.h> |
| 25 | |
Pierre Ossman | 1412789 | 2015-11-12 13:17:42 +0100 | [diff] [blame] | 26 | #include <rfb/Region.h> |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 27 | #include <rfb/encodings.h> |
| 28 | |
Pierre Ossman | 504afa2 | 2015-11-12 12:21:58 +0100 | [diff] [blame] | 29 | namespace os { |
| 30 | class Condition; |
| 31 | class Mutex; |
| 32 | } |
| 33 | |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 34 | namespace rdr { class MemOutStream; } |
| 35 | |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 36 | namespace rfb { |
| 37 | class CConnection; |
| 38 | class Decoder; |
| 39 | class ModifiablePixelBuffer; |
| 40 | class Rect; |
| 41 | |
| 42 | class DecodeManager { |
| 43 | public: |
| 44 | DecodeManager(CConnection *conn); |
| 45 | ~DecodeManager(); |
| 46 | |
| 47 | void decodeRect(const Rect& r, int encoding, |
| 48 | ModifiablePixelBuffer* pb); |
| 49 | |
Pierre Ossman | 504afa2 | 2015-11-12 12:21:58 +0100 | [diff] [blame] | 50 | void flush(); |
| 51 | |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 52 | private: |
| 53 | CConnection *conn; |
| 54 | Decoder *decoders[encodingMax+1]; |
Pierre Ossman | 504afa2 | 2015-11-12 12:21:58 +0100 | [diff] [blame] | 55 | |
| 56 | struct QueueEntry { |
| 57 | bool active; |
| 58 | Rect rect; |
| 59 | int encoding; |
| 60 | Decoder* decoder; |
| 61 | const ConnParams* cp; |
| 62 | ModifiablePixelBuffer* pb; |
| 63 | rdr::MemOutStream* bufferStream; |
Pierre Ossman | 1412789 | 2015-11-12 13:17:42 +0100 | [diff] [blame] | 64 | Region affectedRegion; |
Pierre Ossman | 504afa2 | 2015-11-12 12:21:58 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | std::list<rdr::MemOutStream*> freeBuffers; |
| 68 | std::list<QueueEntry*> workQueue; |
| 69 | |
| 70 | os::Mutex* queueMutex; |
| 71 | os::Condition* producerCond; |
| 72 | os::Condition* consumerCond; |
| 73 | |
| 74 | private: |
| 75 | class DecodeThread : public os::Thread { |
| 76 | public: |
| 77 | DecodeThread(DecodeManager* manager); |
| 78 | ~DecodeThread(); |
| 79 | |
| 80 | void stop(); |
| 81 | |
| 82 | protected: |
| 83 | void worker(); |
| 84 | DecodeManager::QueueEntry* findEntry(); |
| 85 | |
| 86 | private: |
| 87 | DecodeManager* manager; |
| 88 | |
| 89 | bool stopRequested; |
| 90 | }; |
| 91 | |
| 92 | std::list<DecodeThread*> threads; |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 93 | }; |
| 94 | } |
| 95 | |
| 96 | #endif |