Delegate decoder object management to a separate class
Done in preparation for multi-core decoding. Keeps the complexity
out of the other classes. This also moves ownership of the
framebuffer in to CConnection. It's the CConnection object that is
aware of the threads and how to synchronise with them. Therefore
the ownership of the framebuffer must also be there to make sure
it isn't deleted whilst threads are working.
diff --git a/tests/encperf.cxx b/tests/encperf.cxx
index d93c771..06c878d 100644
--- a/tests/encperf.cxx
+++ b/tests/encperf.cxx
@@ -38,7 +38,6 @@
#include <rfb/CConnection.h>
#include <rfb/CMsgReader.h>
-#include <rfb/Decoder.h>
#include <rfb/UpdateTracker.h>
#include <rfb/EncodeManager.h>
@@ -104,8 +103,6 @@
protected:
rdr::FileInStream *in;
- rfb::Decoder *decoders[rfb::encodingMax + 1];
- rfb::ManagedPixelBuffer pb;
rfb::SimpleUpdateTracker updates;
class SConn *sc;
};
@@ -165,22 +162,12 @@
CConn::CConn(const char *filename)
{
- int i;
-
decodeTime = 0.0;
encodeTime = 0.0;
in = new rdr::FileInStream(filename);
setStreams(in, NULL);
- memset(decoders, 0, sizeof(decoders));
- for (i = 0; i < rfb::encodingMax; i++) {
- if (!rfb::Decoder::supported(i))
- continue;
-
- decoders[i] = rfb::Decoder::createDecoder(i, this);
- }
-
// Need to skip the initial handshake and ServerInit
setState(RFBSTATE_NORMAL);
// That also means that the reader and writer weren't setup
@@ -191,23 +178,15 @@
pf.parse(format);
setPixelFormat(pf);
- pb.setPF((bool)translate ? fbPF : pf);
-
sc = new SConn();
- sc->cp.setPF(pb.getPF());
+ sc->cp.setPF((bool)translate ? fbPF : pf);
sc->setEncodings(sizeof(encodings) / sizeof(*encodings), encodings);
}
CConn::~CConn()
{
- int i;
-
delete sc;
-
delete in;
-
- for (i = 0; i < rfb::encodingMax; i++)
- delete decoders[i];
}
void CConn::getStats(double& ratio, unsigned long long& bytes,
@@ -220,7 +199,7 @@
{
CConnection::setDesktopSize(w, h);
- pb.setSize(cp.width, cp.height);
+ setFramebuffer(new rfb::ManagedPixelBuffer(sc->cp.pf(), cp.width, cp.height));
}
void CConn::setCursor(int, int, const rfb::Point&, void*, void*)
@@ -230,17 +209,23 @@
void CConn::framebufferUpdateStart()
{
updates.clear();
+ startCpuCounter();
}
void CConn::framebufferUpdateEnd()
{
rfb::UpdateInfo ui;
- rfb::Region clip(pb.getRect());
+ rfb::PixelBuffer* pb = getFramebuffer();
+ rfb::Region clip(pb->getRect());
+
+ endCpuCounter();
+
+ decodeTime += getCpuCounter();
updates.getUpdateInfo(&ui, clip);
startCpuCounter();
- sc->writeUpdate(ui, &pb);
+ sc->writeUpdate(ui, pb);
endCpuCounter();
encodeTime += getCpuCounter();
@@ -248,14 +233,7 @@
void CConn::dataRect(const rfb::Rect &r, int encoding)
{
- if (!decoders[encoding])
- throw rdr::Exception("Unknown encoding");
-
- startCpuCounter();
- decoders[encoding]->readRect(r, &pb);
- endCpuCounter();
-
- decodeTime += getCpuCounter();
+ CConnection::dataRect(r, encoding);
if (encoding != rfb::encodingCopyRect) // FIXME
updates.add_changed(rfb::Region(r));