blob: 058d824057bf496aa736ebeb46629b57a1349934 [file] [log] [blame]
Pierre Ossman9f273e92015-11-09 16:34:54 +01001/* 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 Ossman504afa22015-11-12 12:21:58 +010022#include <list>
23
24#include <os/Thread.h>
25
Pierre Ossman14127892015-11-12 13:17:42 +010026#include <rfb/Region.h>
Pierre Ossman9f273e92015-11-09 16:34:54 +010027#include <rfb/encodings.h>
28
Pierre Ossman504afa22015-11-12 12:21:58 +010029namespace os {
30 class Condition;
31 class Mutex;
32}
33
Pierre Ossman05604652015-11-17 09:37:57 +010034namespace rdr {
Steve Kondik1f5d4b12017-07-08 02:00:49 -070035 struct Exception;
Pierre Ossman05604652015-11-17 09:37:57 +010036 class MemOutStream;
37}
Pierre Ossman80b42092015-11-10 17:17:34 +010038
Pierre Ossman9f273e92015-11-09 16:34:54 +010039namespace rfb {
40 class CConnection;
41 class Decoder;
42 class ModifiablePixelBuffer;
Steve Kondik1f5d4b12017-07-08 02:00:49 -070043 struct Rect;
Pierre Ossman9f273e92015-11-09 16:34:54 +010044
45 class DecodeManager {
46 public:
47 DecodeManager(CConnection *conn);
48 ~DecodeManager();
49
50 void decodeRect(const Rect& r, int encoding,
51 ModifiablePixelBuffer* pb);
52
Pierre Ossman504afa22015-11-12 12:21:58 +010053 void flush();
54
Pierre Ossman9f273e92015-11-09 16:34:54 +010055 private:
Pierre Ossman05604652015-11-17 09:37:57 +010056 void setThreadException(const rdr::Exception& e);
57 void throwThreadException();
58
59 private:
Pierre Ossman9f273e92015-11-09 16:34:54 +010060 CConnection *conn;
61 Decoder *decoders[encodingMax+1];
Pierre Ossman504afa22015-11-12 12:21:58 +010062
63 struct QueueEntry {
64 bool active;
65 Rect rect;
66 int encoding;
67 Decoder* decoder;
Pierre Ossmanb14a6bc2018-06-18 15:44:26 +020068 const ServerParams* server;
Pierre Ossman504afa22015-11-12 12:21:58 +010069 ModifiablePixelBuffer* pb;
70 rdr::MemOutStream* bufferStream;
Pierre Ossman14127892015-11-12 13:17:42 +010071 Region affectedRegion;
Pierre Ossman504afa22015-11-12 12:21:58 +010072 };
73
74 std::list<rdr::MemOutStream*> freeBuffers;
75 std::list<QueueEntry*> workQueue;
76
77 os::Mutex* queueMutex;
78 os::Condition* producerCond;
79 os::Condition* consumerCond;
80
81 private:
82 class DecodeThread : public os::Thread {
83 public:
84 DecodeThread(DecodeManager* manager);
85 ~DecodeThread();
86
87 void stop();
88
89 protected:
90 void worker();
91 DecodeManager::QueueEntry* findEntry();
92
93 private:
94 DecodeManager* manager;
95
96 bool stopRequested;
97 };
98
99 std::list<DecodeThread*> threads;
Pierre Ossman05604652015-11-17 09:37:57 +0100100 rdr::Exception *threadException;
Pierre Ossman9f273e92015-11-09 16:34:54 +0100101 };
102}
103
104#endif