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> |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 29 | #include <rdr/MemOutStream.h> |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 30 | |
| 31 | using namespace rfb; |
| 32 | |
| 33 | static LogWriter vlog("DecodeManager"); |
| 34 | |
| 35 | DecodeManager::DecodeManager(CConnection *conn) : |
| 36 | conn(conn) |
| 37 | { |
| 38 | memset(decoders, 0, sizeof(decoders)); |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 39 | bufferStream = new rdr::MemOutStream(); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | DecodeManager::~DecodeManager() |
| 43 | { |
| 44 | for (size_t i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++) |
| 45 | delete decoders[i]; |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 46 | delete bufferStream; |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void DecodeManager::decodeRect(const Rect& r, int encoding, |
| 50 | ModifiablePixelBuffer* pb) |
| 51 | { |
| 52 | assert(pb != NULL); |
| 53 | |
| 54 | if (!Decoder::supported(encoding)) { |
| 55 | vlog.error("Unknown encoding %d", encoding); |
| 56 | throw rdr::Exception("Unknown encoding"); |
| 57 | } |
| 58 | |
| 59 | if (!decoders[encoding]) { |
Pierre Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame] | 60 | decoders[encoding] = Decoder::createDecoder(encoding); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 61 | if (!decoders[encoding]) { |
| 62 | vlog.error("Unknown encoding %d", encoding); |
| 63 | throw rdr::Exception("Unknown encoding"); |
| 64 | } |
| 65 | } |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 66 | |
| 67 | bufferStream->clear(); |
| 68 | decoders[encoding]->readRect(r, conn->getInStream(), |
| 69 | conn->cp, bufferStream); |
| 70 | decoders[encoding]->decodeRect(r, bufferStream->data(), |
| 71 | bufferStream->length(), |
| 72 | conn->cp, pb); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 73 | } |