Introduction

This document describes how to use VNC server on a CCpilot display.

Overview

Virtual Network Computing, VNC, allows someone to remotely view and control a computer, or in this case a display. Each of our CCpilot displays can be extended with a VNC server which means you may remotely connect and control the display from a VNC Client. The VNC server has been developed to be a standalone service, without use of Qt or other services.

The screen mirroring module contains tar archives for each of our i.MX8 devices. The tar packages contain the following:

  • VNC binary (ccvncserver, with LibVNCServer linked statically)

  • Start script (start-ccvncserver.sh) that selects the touch scaling and options for the display

  • Systemd service file for auto start

Glossary

Word/Abbrevation

Explanation

VNC

Virtual Network Computing

fps

Frames Per Second

client

The device that want to see the content of another device on screen

server

The device that will send its content over the network to a client

DRM/KMS

Linux Direct Rendering Manager / Kernel Mode Setting, the display controller interface the server reads the screen from

Blitter (G2D)

The 2D graphics hardware of the i.MX SoC, used to copy the screen and draw overlay planes

Overlay plane

A hardware layer on top of the main screen, for example video shown with kmssink

JPEG

Picture compression used by the Tight encoding; the server can encode it in hardware

CCVNC server

CrossControl has made a VNC server implementation based on the open-source library LibVNCServer. This server will forward mouse clicks from a VNC client to multi touch events on the display.

The server requires CC Linux 5.1 or later and runs as root (the systemd service does this).

How the screen is captured

The server reads the screen from the display controller (DRM/KMS), so it works with any application that shows its picture through KMS, for example Qt with eglfs_kms or a Wayland compositor such as Weston. It does not need a special Qt graphics integration. It does not keep DRM master and waits if nothing is shown yet, so it can be started before or after the application or compositor. If DRM capture is not possible the server falls back to /dev/fb0.

  • Pixel formats. The screen buffer must be 32 bit XRGB8888, ARGB8888, XBGR8888 or ABGR8888. Linear buffers always work. Vivante tiled and super-tiled buffers (Weston) are copied and untiled by the 2D blitter, so they need it.

  • Overlay planes (for example kmssink video) are drawn into the picture by the 2D blitter with the position, scaling, colour conversion and alpha used by the display. Supported plane formats are linear XRGB8888, ARGB8888, XBGR8888, ABGR8888, RGB565, YUYV, UYVY, NV12 and NV21, at most 4 planes. Other formats and tiled planes are left out. Plane alpha, rotation and YUV colour range are ignored. Use --drm-info to list the planes.

  • 2D blitter copy. The screen is first copied by the blitter into cacheable memory, which the CPU can read much faster than the display memory. If the blitter is not available the screen is read directly (--read-method=neon32 forces this), but then tiled screens and overlay planes cannot be shown.

  • Change detection. The server only reads the screen after a page flip, or at least every 0.5 s. Changed areas are found with a CRC32 hash of the screen (no copy of the previous frame is kept) and sent as up to 8 rectangles. Programs that draw directly into the framebuffer without page flips (fbdevsink) are found by the timed looks, which follow --fps while the screen changes.

Hardware JPEG encoder

With --encoder=hw-rect the changed screen areas are JPEG-encoded by the hardware encoder of the SoC (mxc-jpeg, V4L2) instead of by the CPU. This gives a higher frame rate and a lower CPU load. It is used for clients that use the Tight encoding with JPEG. Other clients, 256-colour clients, and all clients if no hardware encoder is found, are served in software.

  • The JPEG quality and chroma subsampling follow the quality setting of the client. Lossless settings (zlib, ZRLE) do not use JPEG and are much slower. Set the client quality to 6 or 7 for the best frame rate. Lower quality settings give smaller JPEGs and less network load.

  • Every changed rectangle is sent as JPEG, also flat user interface areas and text, and grayscale client settings are sent as colour. Use --encoder=sw if that is not wanted.

  • The hardware encoder sometimes produces a damaged JPEG. The server checks every JPEG before sending it and encodes it again at a slightly lower quality, or in software, when needed.

  • --hw-pipeline (experimental) is for screens that change completely at a high frame rate. It encodes the next frame before the client asks for it.

Command line options

The different CCpilot display types use the same software but needs some specific options to be able to handle the difference in screen sizes. The following command line options are available:

Option

Description

--port=<n>

Port number to connect to. Default 5900.

--passwd=<pw>

Password to view server content. Default: no password.

--viewonly

No input from client to server possible.

--verbose

Turn on VNC server logging and print the changed areas.

--fps=<n>

Highest number of screen captures per second. Default 2 (the start script uses 10). Higher FPS makes interaction more responsive but with increased CPU and network load.

--x-scale=<n>, --y-scale=<n>

Scaling of the touch coordinates. Default 125. See the start script.

--invert

Invert x/y scaling.

--single-touch

For displays without multi touch.

--touch-device=<dev>

Touch device to be used. Default /dev/input/touchscreen0.

--rotate=<0|90|180|270>

Rotation of the screen when being sent to the client. Default 0.

--encoder=<sw|hw-rect>

sw (default) encodes in software, hw-rect uses the hardware JPEG encoder.

--read-threads=<1-8>

Threads used to read and compare the screen. Default 2.

--jpeg-quality=<1-100>

Force the hardware JPEG quality instead of following the client.

--jpeg-input=<auto|yuv444|yuv422|yuv420|bgr|bgra>

Chroma format given to the hardware encoder. Default auto follows the client. bgr and bgra give wrong colours in some clients and are only for comparison.

--jpeg-device=<dev>

V4L2 JPEG encoder device. Default is to find it.

--hw-min-area=<pixels>

Rectangles smaller than this are encoded in software. Default 0.

--hw-threads=<0-4>

Threads that encode the rectangles of an update while the main thread sends them. Default 2, 0 encodes in the sending thread.

--hw-strip-area=<pixels>

Encode rectangles of at least this many pixels as two strips. Default 0 (off).

--hw-pipeline

Experimental, needs --hw-threads of 1 or more. Encode the next frame before the client asks. Default off.

--read-method=<name>

How the screen memory is read: g2d (default with DRM capture) copies it with the blitter first, or read directly with neon32, memcpy, neon64, neon64-prefetch or u64.

--vblank-sync=<auto|on|off>

Copy a screen buffer only after the next vblank, to avoid half-drawn frames from GPU compositors such as Weston. auto (default) does this for tiled screens. Adds up to one refresh of delay.

--full-scan

Read the screen every frame instead of only after a page flip.

--no-crc

Find changed areas by comparing with a copy of the previous frame instead of CRC32 hashes.

The following options are for diagnostics and troubleshooting:

Option

Description

--drm-info

List the CRTCs and planes (format, size, modifier, position) and which plane is captured, then exit. Run it when something is missing from the picture.

--profile

Print timing statistics every 2 seconds. See Measuring performance.

--bench-read

Measure the screen read speed for all methods and thread counts, then exit.

--g2d-check

Compare the blitter copies with a direct read and report differences in --profile.

--jpeg-verify=<prefix>

Decode every hardware JPEG before it is sent. A bad one is logged and saved as <prefix>-<n>.jpg (first 20). Uses a lot of CPU, not for normal use.

--dump-frame=<prefix>

Every 5 seconds write <prefix>-snapshot.ppm (the screen copy) and <prefix>-vnc.ppm (what is sent), to find where a picture error comes from.

--dump-region=<x,y,w,h>

With --dump-frame: write the files when something in this region changes instead of every 5 seconds.

To connect to the VNC server in the CC display you will need to start a VNC client/viewer on your remote device and connect to the CC display with the IP address. You should see the display screen mirrored on your VNC client and be able to control the display from the VNC client. TigerVNC, TurboVNC, TightVNC and Remmina have been tested.

Installation on i.MX8 devices

CCVNC server can be installed on the target in two different ways.

Supported devices

i.MX8:

  • CCPilot V510

  • CCPilot V700

  • CCPilot V705

  • CCPilot V710

  • CCPilot V1000

  • CCPilot V1200

  • CCPilot V1090

  • CCPilot V1290

RAUC bundle

For production use the CCVNC server should be installed on the target using a RAUC bundle.
Reference the CC Linux - Using RAUC documentation on the support web site for more information about how to generate a RAUC bundle.

Installing it manually for development/testing

During development or testing of the CCVNC server it can be installed on the target manually by unlocking appfs and manually unpacking the tarball, tar.gz, under appfs.

Unlock /appfs for development/testing

  1. Open an ssh session to the target:

    ssh ccs@<IP-ADDRESS>
    
  2. Change write permissions of /appfs:

    sudo mount -o remount,rw /appfs
    
  3. Check which version partition /appfs is mounted to:

    rauc status
    
  4. Unmount /appfs:

    sudo umount /appfs
    
  5. Format the partition:

    sudo mkfs.ext4 /dev/<PARTITION>
    
  6. Remount /appfs:

    sudo mount /dev/<PARTITION> /appfs
    

Unpacking tarball

  1. Download the tarball, ccvncserver-ccl51__imx8.tar.gz (for example ccvncserver-ccl51_2.0_imx8.tar.gz), from the support site under: Software & Solution -> Screen sharing -> Downloads -> Device downloads -> <TARGET>

  2. Transfer the tar.gz package to device:

    scp ccvncserver-ccl51_<VERSION>_imx8.tar.gz ccs@<IP-ADDRESS>:/tmp
    
  3. Open an ssh session to the target:

    ssh ccs@<IP-ADDRESS>
    
  4. Change directory to /tmp:

    cd /tmp
    
  5. Run the following code to unpack it:

    sudo tar xzf ccvncserver-ccl51_<VERSION>_imx8.tar.gz -C /appfs
    
  6. CCVNC server will not automatically start at boot. See Example usage.

Example usage

After unpacking the tar.gz package the VNC server will not start automatically. See below for how to enable auto start of the server. Once the service has been started it will run the script /appfs/vncserver/start-ccvncserver.sh, which starts the VNC server as root.

The script reads the display resolution from the device EEPROM (ccsettingsconsole), or from the framebuffer if the EEPROM has no resolution, and selects the touch scaling for 800x480 (V700), 1280x800 (V1X00) and 1920x1080 displays. It starts the server with the hardware JPEG encoder at 10 fps:

/appfs/vncserver/ccvncserver --fps 10 --x-scale <X_SCALE> --y-scale <Y_SCALE> --encoder=hw-rect

To enable or disable the VNC server at boot use

sudo systemctl enable ccvncserver
sudo systemctl disable ccvncserver

To change FPS or other options, edit /appfs/vncserver/start-ccvncserver.sh and restart the service or reboot the device:

sudo systemctl restart ccvncserver

For smoother video (camera streams of 30 fps, animations) raise FPS in the script. The CPU load goes up with it, so check it on the target. To add a password and change the port, add for example --passwd <password> --port 5901 to the command line in the script.

Measuring performance

Run the server with --profile to print timing statistics every 2 seconds. Times are average/maximum milliseconds. The most useful lines are:

  • capture: frames per second, page flips per second of the screen (capture should follow it) and time per frame.

  • hwjpeg: JPEGs per second, size and time to encode. hwjpeg damaged is only printed if a damaged JPEG was found and repaired.

  • vnc: updates per second and time to send each. client shows the time between two updates (gap).

  • time spent: where the sending thread spends its time. A high share waiting for the client means that the viewer or the network is the limit, not the server.

  • tcp: throughput, round trip time and how long the connection was limited by the client’s receive window or send buffer.

  • g2d: blitter copy times, and with overlay planes the overlay_* timers.

If something is missing from the picture, run ccvncserver --drm-info to list the planes and which one is captured. For picture errors, --dump-frame shows whether the error comes from the screen copy or from the change detection and encoding.

Known limitations:

CCpilot X900 & X1200

The CCpilot X900 and X1200 does currently not support a VNC connection using CCVNC server. Alternative approach is to use Qt and the built-in “VNC” platform as covered in the QT VNC platform plugin section.

CCpilot VS

Wayland works good but EGLFS doesn’t work as expected. The mouse clicks behaves odd when running Qt-apps.

All i.MX8 and i.MX9 devices

  • The server needs root, because it reads the screen through DRM/KMS and DMA-BUF. The service runs as root.

  • The 2D blitter library (libg2d) is needed for tiled screens (Weston) and overlay planes. Without it only linear buffers are read, directly, and overlay planes are not shown.

  • Plane alpha, plane rotation and the YUV colour range of overlay planes are not handled, and tiled overlay planes are left out.

  • A video producer that commits frames as fast as it can (kmssink sync=false on a non-live source) limits the capture to about 20 fps. Cameras and live sources are not affected.

  • A hardware cursor that only moves is shown at the next capture, up to 0.5 s later on a quiet screen.

  • In-place drawing without page flips (fbdevsink) can tear briefly and costs more CPU. Use --fps 30 for a 30 fps source.

  • With --encoder=hw-rect every changed area is sent as JPEG, and the picture is not lossless. A client set to lossless encodings (zlib, ZRLE) is much slower. Use --encoder=sw for grayscale or palette clients.

  • Qt applications no longer need to be started with eglfs_viv and QT_QPA_EGLFS_FORCE888. The screen is captured through DRM/KMS, so eglfs_kms and Wayland compositors work.

Qt VNC platform plugin

An alternative approach instead of using the CCVNC server is to use the Qt platform plugin “vnc”. A Qt application can be started with the flag “-platform vnc” to start a VNC server session. This will render graphics to a VNC offscreen buffer instead of the display screen and all graphics will be sent over the network. The drawback with this approach is that the Qt application must be restarted in VNC mode and the display screen will be black during this time. But if this is an acceptable behaviour during a service session, the performance is superior in this approach compared to running the CCVNC server.

VNC Client

Currently the displays do not support using a VNC client, i.e. viewing/interacting with a remote computer from a CCpilot display.

Security considerations

  • Some customers have had problems with the default VNC port (5900). There is a possibility that this port number attracts a huge number of login tries if a display is public accessible on the Internet. That amount of data traffic can slow down the communication and might also add a traffic cost.

  • Change the server to use a different VNC port number to avoid easy detection from malicious botnets and similar.

  • A password is always recommended before allowing a client to attach to the display.

  • Only enable VNC server for a limited time, during a service session, and not enabled by default.

License

The CCVNC server builds on libvnc which uses a GPL v2 license and this software will also use GPL v2 license.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

A written offer to get the source code will be included in the downloadable package.