blob: b82d31d206c832206dc7f53be3ab453c8f63a29b [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#include <assert.h>
20#include <string.h>
21
Pierre Ossman86350622015-11-10 13:02:12 +010022#include <rfb/CConnection.h>
Pierre Ossman9f273e92015-11-09 16:34:54 +010023#include <rfb/DecodeManager.h>
24#include <rfb/Decoder.h>
25
26#include <rfb/LogWriter.h>
27
28#include <rdr/Exception.h>
29
30using namespace rfb;
31
32static LogWriter vlog("DecodeManager");
33
34DecodeManager::DecodeManager(CConnection *conn) :
35 conn(conn)
36{
37 memset(decoders, 0, sizeof(decoders));
38}
39
40DecodeManager::~DecodeManager()
41{
42 for (size_t i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++)
43 delete decoders[i];
44}
45
46void DecodeManager::decodeRect(const Rect& r, int encoding,
47 ModifiablePixelBuffer* pb)
48{
49 assert(pb != NULL);
50
51 if (!Decoder::supported(encoding)) {
52 vlog.error("Unknown encoding %d", encoding);
53 throw rdr::Exception("Unknown encoding");
54 }
55
56 if (!decoders[encoding]) {
Pierre Ossman86350622015-11-10 13:02:12 +010057 decoders[encoding] = Decoder::createDecoder(encoding);
Pierre Ossman9f273e92015-11-09 16:34:54 +010058 if (!decoders[encoding]) {
59 vlog.error("Unknown encoding %d", encoding);
60 throw rdr::Exception("Unknown encoding");
61 }
62 }
Pierre Ossman86350622015-11-10 13:02:12 +010063 decoders[encoding]->readRect(r, conn->getInStream(), conn->cp, pb);
Pierre Ossman9f273e92015-11-09 16:34:54 +010064}