blob: dec7a6cbf351ceeb7574579becfde176c480fd52 [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 Ossman80b42092015-11-10 17:17:34 +010034namespace rdr { class MemOutStream; }
35
Pierre Ossman9f273e92015-11-09 16:34:54 +010036namespace 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 Ossman504afa22015-11-12 12:21:58 +010050 void flush();
51
Pierre Ossman9f273e92015-11-09 16:34:54 +010052 private:
53 CConnection *conn;
54 Decoder *decoders[encodingMax+1];
Pierre Ossman504afa22015-11-12 12:21:58 +010055
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 Ossman14127892015-11-12 13:17:42 +010064 Region affectedRegion;
Pierre Ossman504afa22015-11-12 12:21:58 +010065 };
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 Ossman9f273e92015-11-09 16:34:54 +010093 };
94}
95
96#endif