blob: 1a974ea4add55b85bf8be1dd67e06028ed220f5a [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 Ossman9f273e92015-11-09 16:34:54 +010026#include <rfb/encodings.h>
27
Pierre Ossman504afa22015-11-12 12:21:58 +010028namespace os {
29 class Condition;
30 class Mutex;
31}
32
Pierre Ossman80b42092015-11-10 17:17:34 +010033namespace rdr { class MemOutStream; }
34
Pierre Ossman9f273e92015-11-09 16:34:54 +010035namespace rfb {
36 class CConnection;
37 class Decoder;
38 class ModifiablePixelBuffer;
39 class Rect;
40
41 class DecodeManager {
42 public:
43 DecodeManager(CConnection *conn);
44 ~DecodeManager();
45
46 void decodeRect(const Rect& r, int encoding,
47 ModifiablePixelBuffer* pb);
48
Pierre Ossman504afa22015-11-12 12:21:58 +010049 void flush();
50
Pierre Ossman9f273e92015-11-09 16:34:54 +010051 private:
52 CConnection *conn;
53 Decoder *decoders[encodingMax+1];
Pierre Ossman504afa22015-11-12 12:21:58 +010054
55 struct QueueEntry {
56 bool active;
57 Rect rect;
58 int encoding;
59 Decoder* decoder;
60 const ConnParams* cp;
61 ModifiablePixelBuffer* pb;
62 rdr::MemOutStream* bufferStream;
63 };
64
65 std::list<rdr::MemOutStream*> freeBuffers;
66 std::list<QueueEntry*> workQueue;
67
68 os::Mutex* queueMutex;
69 os::Condition* producerCond;
70 os::Condition* consumerCond;
71
72 private:
73 class DecodeThread : public os::Thread {
74 public:
75 DecodeThread(DecodeManager* manager);
76 ~DecodeThread();
77
78 void stop();
79
80 protected:
81 void worker();
82 DecodeManager::QueueEntry* findEntry();
83
84 private:
85 DecodeManager* manager;
86
87 bool stopRequested;
88 };
89
90 std::list<DecodeThread*> threads;
Pierre Ossman9f273e92015-11-09 16:34:54 +010091 };
92}
93
94#endif