Jul 232013
 

Update

We have released dfreerdp (FreeRDP for the DirectFB backend) as a package for the Raspberry Pi. Please go to our new blog post to get it!

Intro

RDP is a convenient way to connect to Windows and also other operating systems with RDP host software, e.g. Linux. RDP transmits display information more efficiently than VLC, as it sees the structure of the screen and it’s elements. It also allows to transmit audio information both ways – playback and recording, share printers, drives, and more. As it is an extensible protocol, efficient video / multimedia playback can be implemented – and has been implemented, albeit apparently only in Windows Media Player.

The Raspberry Pi is a low-power device, with Full-HD (and audio) capable HDMI output.

FreeRDP is a mighty utility to connect to RDP servers, and utilize many of their possibilities. It even supports the video extensions for RDP (in RDP lingo: video redirection virtual channel extension) with ffmpeg. Don’t get your hope up too high right now, though: while theoretically feasible in software, it still would have to be written for both the Raspberry AND the host (it is not a “plug & forget” solution, but the software run on the server has to support it specifically).

The current state: A marriage made in heaven?

Not quite. FreeRDP is easily installed, and used from an X session. But it is … agonizingly slow. Audio playback is in a bad state.

The problem: X adds a very high overhead to any application, but even more so a graphics intensive, such as FreeRDP. Even super-charging the Raspberry Pi with overclocking, Class 10 SD cards, a beefy power supply, etc. will NOT solve this problem! An RDP client compiled specifically for Wayland might, but this is still some way off.

Solution

FreeRDP can be compiled to draw to the Direct Frame Buffer. This eliminates all of the overhead, which X would add. This is perfect for people really trying to use the Raspberry as Windows / RDP thin client. It will work in FullHD resolution (over the local network), with sufficient performance (and 16 bit color depth).

Kudos are in order to the Tao of Mac blog, which had the idea, and the instructions to get me up and running. You rock!

We will release a hardware & software package RDP client, based on the Raspberry, really soon now. If you’re interested, hit me up in the comments.

Step-by step instructions

With all that out of the way, let’s jump into the instructions!

Preparation

We suggest to use a Class 10 SD card, with ample space for the installation & build of the packages (8 GB Class 10 seems sensible). Install the newest Raspbian image, set up your locale and keyboard layout, aptitude update and aptitude upgrade.

Install the necessary packages:

aptitude install build-essential git-core cmake libssl-dev libx11-dev libxext-dev libxinerama-dev libxcursor-dev libxdamage-dev libxv-dev libxkbfile-dev libasound2-dev libcups2-dev libxml2 libxml2-dev libxrandr-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libavutil-dev libavcodec-dev libcunit1-dev libdirectfb-dev xmlto doxygen libxtst-dev

This should take quite a while.

Download the FreeRDP package (use a sensible location, we will be compiling there later. If in doubt, a sub-folder in your home folder is OK):

wget https://github.com/FreeRDP/FreeRDP/archive/1.0.2.tar.gz

You might also consider checking out the 1.0.3 pre-release version. It might turn stable in a couple of months.

Set up the build environment – this is analoguous to ./configure seen in many other compilations:

cmake -DCMAKE_BUILD_TYPE=Release  -DWITH_FFMPEG=OFF -DWITH_XINERAMA=OFF -DWITH_XCURSOR=OFF -DWITH_DIRECTFB=ON -DCMAKE_INSTALL_PREFIX=~/freerdp

A couple of hints for this:

  • You might want to adjust the –DCMAKE_INSTALL_PREFIX to something more suitable – if you compile as root, it will install the application and the libraries into the folder /root/freerdp otherwise.
    A good choice could be /usr – this way the binaries and libraries will be in the normal search path.
  • turning off FFMPEG means turning off virtual video extension. As discussed before, this is of limited use anyway, right now. But some experimenting might be interesting. FreeRDP also is built modularized on top of FFMPEG, so exchanging that for an omxplayer-like code thingy SHOULD be feasible.
  • Xinerama – is an X extension which allows X applications to span two or more displays a one large virtual display.

Check for the output of this command. It will tell you about skipped options and missed packages. It should find DirectFB amongst others (Found DirectFB: /usr/lib/arm-linux-gnueabihf/libdirectfb.so).

  • pulseaudio: this is a sound server, and another layer on ALSA. It is network capable. Users report varying mileage with pulseaudio and good playback quality. We have tested without the pulseaudio package, future tests will show whether there is an advantage in using it.
  • pcsc – this is for smart card support, most likely you will not need it
  • CUnit – a lightweight system for writing, administering and running unit tests in C – most likely you will not need this, either.

Compile the DirectFB RDP client:

cd client/DirectFB/
make

#optionally 
sudo make install

#for sound support
cd ../../channels/drdynvc
make
sudo make install
cd ../rdpsnd
make
sudo make install

This is all – but this will take quite a while (some hours).

Set up some configuration files

Edit your /etc/udev/rules.d/99-input.rules to be:

SUBSYSTEM=="input", GROUP="input", MODE="0660"
KERNEL=="tty[0-9]*", GROUP="root", MODE="0666"
KERNEL=="mice", MODE="0666"
KERNEL=="fb0", OWNER="root", MODE="0660"

The first line should aready be in the file, add the other three lines.

Optional, but recommended: Edit your /boot/config.txt to contain the following settings:

framebuffer_width=1920
framebuffer_height=1080
framebuffer_depth=16
# for other stuff
gpu_mem=128

arm_freq=800
disable_overscan=1
hdmi_drive=2
hdmi_ignore_edid=0xa5000080

This will

  • set your resolution as fixed [framebuffer_width, framebuffer_height] – be sure to adjust to your needs!
  • set bit depth to 16 – as we will connect to the RDP server using this depth for better performance.
  • ignore anything the monitor will tell the Raspberry – it might lead to blurry edges, otherwise [hdmi_ignore_edid=0xa5000080]
  • overclock the raspberry just a little [arm_freq=800]
  • disable the overscan – remove the black area around the display output on modern LCD monitors [disable_overscan=1]
  • set up the HDMI output to be a real HDMI output and carry audio – this will fix “no sound output” problems [hdmi_drive=2] don’t use this if you connect your Raspberry via DVI or VGA to the monitor

Edit /etc/fb.modes and add a new mode:

# Added as per taoofmac instructions
mode "1920x1080-24p"
   geometry 1920 1080 1920 1080 32
   timings 13468 148 638 36 4 44 5
endmode

You will have to adjust this if you use a different resolution than FullHD. The original article at Tao of Mac has some more resolution examples for you.

Create a new file /etc/directfbrc with the following contents:

system=fbdev
autoflip-window
desktop-buffer-mode=auto
vt-switching
graphics-vt
no-deinit-check
no-motion-compression
no-translucent-windows
memcpy=arm
mode=1920x1080
depth=16
dma
hardware
# for the moment, we need DirectFB's own cursor sprite
cursor

Reboot.

 

Usage

If you specified –DCMAKE_INSTALL_PREFIX to be /usr, you should be able to use FreeRDP DirectFB client without any path prefix, else just prepend your path:

dfreerdp -u "user name" -p secret_password_here -f -g 1920x1080 -x l -z --disable-full-window-drag  --gdi hw --plugin rdpsnd --data alsa --  host:port

Be sure to adjust this command:

  • “user name” should be your user name. If it contains a space, you should keep the quotation marks, else you can loose them.
  • secret_password_here should be your password, obviosly.
  • -g specifies the geometry. Adjust, as necessary.
  • -x = experience (l for LAN), will enable different bells and whistles. You might want to modify that, or use a more finegrained control of which features to enable, and which to disable
  • -z enable compression (useful)
  • –gdi hw – I’m not sure whether this is really necessary
  • –plugin rdpsnd –data alsa —  – this will enable remote sound output on the Raspberry. Drdynvc is said to have better quality, but I could not get it to work unfortunately. And, yes, the trailing double dashes are part of this option.
  • server:port – can be specified as domain or IP adress. The :port can be omitted, if you are connecting to the default RDP port (3389)

If you want sound output on the remote machine, use the –o switch.

 

FAQ

What about keyboard layout?

It will work exactly as you see your keyboard input on the Raspberry console itself. Even the Windows key should work. If your layout does not work on the Raspberry console, consider setting it up using raspi-config

Will this work over WLAN?

Sure it will. Just adjust your WiFi dongle for optimum throughput and latency (yes, literally change its position, tilt, etc. until you find the best performance spot!)

We recommend you the following packes for graphical / console adjustment of Wireless settings:

aptitude install wicd wicd-gtk wicd-curses

Will Skype work?

Not tested yet – enlighten us Smile This will need microphone redirection, too.

Will forwarding of devices work?

Not tested yet – inform us about usb printers, thumb drives, etc.

How can I test sound output on the Raspberry?

aplay /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav -v -V mono

Will performance over WAN networks be OK?

Yes, pretty much – sound output will suffer (a lot), but the GUI will still be quite usable. You might want to adjust the flags to disable some eye candy.

Why do the browsers “stutter” during scrolling?

In my understanding: Unfortunately browsers need a very high degree of control over their screen outputs, and thus they render it themselves, instead of letting Windows do it – RDP sees browser output as image, which is retransmitted when scrolling. Playing with image compression options might alleviate this problem a bit.

Will accessing Linux hosts over RDP work?

Not out of the box – you will need to install an X to RDP conversion software.

In a very quick and rough test, a connection set up by the Scarygliders X11 RDP O Matic as a server backend did not work reliably enough (it was installed on a Pentium IV Linux server). It might do so with some tuning.

Or another backend / solution might do the trick. Looking forward to your input Smile

 

Known problems

  • Flash (isn’t it always on some list?) – will deliver horrible audio performance, native players (Foobar2000) will be OK, though.
  • Video playback – don’t even dream of playing YouTube videos over an RDP connection … the time is not ready yet, the software not written. Care to join a noble cause?
  • WLAN performance will depend on WLAN throughput and latency. The orientation of your dongle – especially nano dongles – will be very important. It can be tuned to a decent performance state, though.
  • I can’t get the new / style switches to work with FreeRDP, fallback to the legacy – switches for now.
  • Sound output: only rdpsnd works, –plugin drdynvc –data tsmf:audio:alsa:plughw:0,0 — will not work – maybe this is a configuration issue, though and some other parameters need to be passed. Drdynvc is said to have better quality. The issue might be with servers with no sound card drivers installed. I did not find an easy solution to this, and I am looking forward to your suggestions.
  • Connection to Linux RDP server compiled with X11 RDP O Matic is not stable for me.

References & further reading

  • VK

    So are you planning to release distro for RasPi with “High-performance RDP” anytime soon?

    Br, VK

  • Pingback: Bookmarks for 6th August 2013 | Lednor.Com()

  • Brandon McRee

    yes, a pre-built system image would be awesome, I spent several hours working on getting a build and after the final step / reboot i get nothing but a blank screen

  • Ben

    any updates on a pre-built package?

    • pi3g

      It’s in the planning stages – as soon as we are finished with the TP-Link WiFi driver, we’ll attack this. Might take a couple of weeks.

      A hint to the people who seem to have trouble – we have compiled with the stable version 1.2.1, I believe, not the bleeding edge GIT revision.

      • Ben

        thank you!

  • wichate artsawang

    thank you!

    but I detect bug = “xfreerdp displays inverted colors”

    https://github.com/FreeRDP/FreeRDP/issues/297

  • Pingback: FreeRDP for DirectFB on the Raspberry Pi package – make your RDP session fly! » pi3g Blog()

  • McArthor Lee

    I test dfreerdp on a 900MHz rpi with a 1280×1024 17″ LCD.
    1. dfreerdp must be run with sudo, otherwise it will fail to load some frame buffer resource.
    2. “/f” argument should not be used because it has no effect. just use “/size:” (freerdp 1.1 branch) or “-g” (freerdp 1.0.x branch) to your screen resolution.
    3. dfreerdp draws some texture in the wrong color, and I feel no improvement compared with xfreerdp. what’s dfreerdp’s advantage? “drawing to frame buffer” is quite abstract. is there any performance comparison between dfreerdp and xfreerdp? or is there any specific situation where dfreerdp performs better than xfreerdp?

    • pi3g

      Thank you for your feedback.

      The main advantage for dfreerdp is the absence of the X Windows stack (client / server) which requires many context switches, and thus places an unnecessary high load on the Rpi.

      In my tests, with FullHD, performance seemed better with dfreerdp. We will try and investigate performance, maybe it can be recorded on video. Maybe we are wrong about this, we will see.

    • Johannes Bartsch

      Hi,
      I just installed freerdp on a rpi (sudo apt-get install freerdp).
      Using the console xfreerdp ….
      I get the message
      xf_pre_connect: failed to open display:
      Please check that the $DISPLAY enviroment variable is properly set.
      Please advise, what to do.
      many thanks
      Johannes

      • pi3g

        Hello Johannes,

        this is the stock package for Raspbian, not our dfreerdp package.

        Probably you are trying to use xfreerdp from the console (e.g. PuTTY session), not from a console under X Windows (which sets the $DISPLAY variable for you). You can set the $DISPLAY variable to call xfreerdp – but X must be running, please research this on the Internet. (I do not know the solution by heart, else I’d write it down for you here.)

        We are abandoning the dfreerdp package and will not provide further support for it, sorry.

        Max

  • Pingback: Remote Desktop ไป Windows ด้วย Raspberry Pi ใช้ DirectFB | Raspberry Pi Thailand()

  • Martin Lesser

    I have problems with AltGr-keys (@, € etc) in dfreerdp in ubuntu (12.04): locally they show up as expected but in programs on the remote desktop they are unavailable. In xfreerdp they work.
    I tested this with the self compiled version 1.0.2 and with the deb-package from your repository mentioned in another blog entry.
    Any ideas or help is welcome!

  • mister

    hi, I’m using dfreerdp and decided to make some fixes: at first there’is memory leak and some artifacts caused by DirectFB client incorrectly handled updated regions, second issue – some regions were filled with incorrect color, that caused by wrong RGB/GBR ordering in opaque_rect drawing.
    I created diffpatch that addresses that: http://www.paste.org/75336

    Note that it created & tested only under freerdp-1.0.2 on raspberry pi. Not sure if this patch is correct for elsewhere.

    • mister

      I forked freerdp stable-1.0 and commited my changes on github (all from my above message + something more), not sure if/when they will be approved, but my development is available here: https://github.com/mister-r/FreeRDP/tree/1.0-fixes4rpi or direct download link with sources to build: https://github.com/mister-r/FreeRDP/archive/1.0-fixes4rpi.zip

      BTW I found that best performance achieved without traffic compression (no -z flag) and with low encryption level (that means data from server to client are not encrypted at all) that can be enabled on sever with gpedit.msc -> computer configuration -> Administrative templates -> terminal services. Also I used broadband connection flag instead of lan (-x b), but not sure if it affected anything.

  • Ishmam Sharif

    have done all of this things . but when i use the command i can see a black screen only .after logging in from the host the black screen doesn’t go out .whats the problem?

Optimization WordPress Plugins & Solutions by W3 EDGE