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 | #include <assert.h> |
| 20 | #include <string.h> |
| 21 | |
Pierre Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame^] | 22 | #include <rfb/CConnection.h> |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 23 | #include <rfb/DecodeManager.h> |
| 24 | #include <rfb/Decoder.h> |
| 25 | |
| 26 | #include <rfb/LogWriter.h> |
| 27 | |
| 28 | #include <rdr/Exception.h> |
| 29 | |
| 30 | using namespace rfb; |
| 31 | |
| 32 | static LogWriter vlog("DecodeManager"); |
| 33 | |
| 34 | DecodeManager::DecodeManager(CConnection *conn) : |
| 35 | conn(conn) |
| 36 | { |
| 37 | memset(decoders, 0, sizeof(decoders)); |
| 38 | } |
| 39 | |
| 40 | DecodeManager::~DecodeManager() |
| 41 | { |
| 42 | for (size_t i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++) |
| 43 | delete decoders[i]; |
| 44 | } |
| 45 | |
| 46 | void 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 Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame^] | 57 | decoders[encoding] = Decoder::createDecoder(encoding); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 58 | if (!decoders[encoding]) { |
| 59 | vlog.error("Unknown encoding %d", encoding); |
| 60 | throw rdr::Exception("Unknown encoding"); |
| 61 | } |
| 62 | } |
Pierre Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame^] | 63 | decoders[encoding]->readRect(r, conn->getInStream(), conn->cp, pb); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 64 | } |