Implement optional per-frame CRC calculation to save bandwidth
Current implementation is very CPU-efficient as it's not processing
JPEG-encoded data received from V4L2 at all.
This patch implements an optional mode where for each frame that's about
to be sent a CRC32 is calculated and if this client has already received
it before, the transmission is skipped. This of course adds some
noticeable CPU load (proportional to the frame rate requested and the
encoded JPEG size); on AST2500 it's taking about 10 % CPU when showing a
relatively complex GUI login screen with 15 FPS.
Reducing required bandwidth to 0 for static images helps a lot when
using IP KVM via poor connections, e.g. provided by cellular network
operators or some hotels, so can be beneficial for certain common
usecases.
The next optimisation to try is to dynamically alter the frame rate,
automatically ramping it up as soon as the changes start happening and
lowering after a period of inactivity; it's not yet clear if V4L2 allows
this.
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Change-Id: I74b887cf83b5c8676f5792412805de08e1a54f32
diff --git a/ikvm_server.cpp b/ikvm_server.cpp
index 7be99e4..804eb39 100644
--- a/ikvm_server.cpp
+++ b/ikvm_server.cpp
@@ -7,6 +7,8 @@
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
+#include <boost/crc.hpp>
+
namespace ikvm
{
@@ -54,6 +56,8 @@
server->ptrAddEvent = Input::pointerEvent;
processTime = (1000000 / video.getFrameRate()) - 100;
+
+ calcFrameCRC = args.getCalcFrameCRC();
}
Server::~Server()
@@ -93,6 +97,7 @@
char* data = video.getData();
rfbClientIteratorPtr it;
rfbClientPtr cl;
+ int64_t frame_crc = -1;
if (!data || pendingResize)
{
@@ -121,6 +126,26 @@
{
continue;
}
+
+ if (calcFrameCRC)
+ {
+ if (frame_crc == -1)
+ {
+ /* JFIF header contains some varying data so skip it for
+ * checksum calculation */
+ frame_crc = boost::crc<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF,
+ true, true>(data + 0x30,
+ video.getFrameSize() - 0x30);
+ }
+
+ if (cd->last_crc == frame_crc)
+ {
+ continue;
+ }
+
+ cd->last_crc = frame_crc;
+ }
+
cd->needUpdate = false;
if (cl->enableLastRectEncoding)