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_args.cpp b/ikvm_args.cpp
index ad5b4f7..21373aa 100644
--- a/ikvm_args.cpp
+++ b/ikvm_args.cpp
@@ -8,15 +8,17 @@
 namespace ikvm
 {
 
-Args::Args(int argc, char* argv[]) : frameRate(30), commandLine(argc, argv)
+Args::Args(int argc, char* argv[]) : frameRate(30), calcFrameCRC{false},
+                                     commandLine(argc, argv)
 {
     int option;
-    const char* opts = "f:h:k:p:v:";
+    const char* opts = "f:h:k:p:v:c";
     struct option lopts[] = {{"frameRate", 1, 0, 'f'},
                              {"help", 0, 0, 'h'},
                              {"keyboard", 1, 0, 'k'},
                              {"mouse", 1, 0, 'p'},
                              {"videoDevice", 1, 0, 'v'},
+                             {"calcCRC", 0, 0, 'c'},
                              {0, 0, 0, 0}};
 
     while ((option = getopt_long(argc, argv, opts, lopts, NULL)) != -1)
@@ -40,6 +42,9 @@
             case 'v':
                 videoPath = std::string(optarg);
                 break;
+            case 'c':
+                calcFrameCRC = true;
+                break;
         }
     }
 }
@@ -54,6 +59,7 @@
     fprintf(stderr, "-k device              HID keyboard gadget device\n");
     fprintf(stderr, "-p device              HID mouse gadget device\n");
     fprintf(stderr, "-v device              V4L2 device\n");
+    fprintf(stderr, "-c, --calcCRC          Calculate CRC for each frame to save bandwidth\n");
     rfbUsage();
 }