[WiP/PoC] Odroid multiscreen with XPRA

Share here your ideas for new projects
Post Reply
User avatar
mad_ady
Posts: 6874
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 241 times
Been thanked: 178 times
Contact:

[WiP/PoC] Odroid multiscreen with XPRA

Unread post by mad_ady » Wed Jul 17, 2019 10:21 pm

The following is a project I've worked on, but wasn't fully completed because I couldn't get the performance I wanted. I post it in this incomplete form to maybe help/inspire others. I have some ideas for improving performance that draw from this project, but may likely be a different one. Details at the end.

================================
If you're using a computer for day-to-day work you probably want to use the biggest screen you can get your hands on. People who have used two screens have problems adjusting back to one. The Odroid community keeps asking from time to time when will a two-screen odroid be released. (this was written before the H2)

Older members will remember that the XU3 had a HDMI and a Display Port that could be used simultaneously, but the XU3 was expensive and the Display Port could not be used with any adaptors, which limited its use.

For about a year I've been thinking of a way to turn a second (cheaper) Odroid into a secondary display, but in a way where I can drag windows from one side to the other, not just move the mouse across with Synergy. I had planned on using xdmx (https://www.x.org/releases/X11R7.6/doc/ ... mx.1.xhtml) which is a distributed window manager that can move windows across different X servers (with impressive results), but I abandoned the idea when it kept crashing (to be fair, the project was not maintained for at least 10 years).

So, another crazy idea sprung into my mind - using xpra (https://xpra.org/) in a way it wasn't designed to be used…


Xpra standard usage

Xpra is a tool designed to allow you to start an X11 application decoupled from your current graphical server. It resembles "screen" or "tmux" in the way that you can start an application on a virtual X11 server and it will keep running even if you disconnect from it. Xpra has clients for Linux, Mac, HTML and even Windows, allowing easy sharing of running desktop apps.

The way you normally use it is to start a Xpra virtual display server-side and attach whatever applications you want in it:

Code: Select all

$ sudo apt-get install xpra

$ xpra start :100

$ xpra list

$ DISPLAY=:100 xeyes &

$ DISPLAY=:100 xterm &
Then you can attach to that display, either via ssh or over TCP (plain or with ssl) from a client and you can integrate those apps in your desktop session:

Code: Select all

$ xpra attach ssh/user@server/100
You can also use the desktop client to connect to a local/remote session by running xpra_launcher.


You can get basic usage information from here: https://xpra.org/trac/wiki/Usage



When your client disconnects, the applications keep running and you can re-attach to them from somewhere else.


Normally Xpra uses h264 compression of the video data and tries to adapt itself to network conditions. It can also forward clipboard and audio.


As a standalone product it can help you share running applications between different systems.


If xpra refuses to start and complains that Failed to create bus connection: No such file or directory, you can start it with:

Code: Select all

$ xpra start :100 --systemd-run=no --start-via-proxy=no
If it still refuses to start as a non-privileged user you may be running into this bug: https://bugs.debian.org/cgi-bin/bugrepo ... bug=863891 that you can fix with editing /etc/xpra/conf.d/55_server_x11.conf and setting this absolute path to Xorg:

Code: Select all

$ sudo vi /etc/xpra/conf.d/55_server_x11.conf

…

# Selecting virtual X server:

xvfb = /usr/lib/xorg/Xorg -noreset -novtswitch -nolisten tcp +extension GLX +extension RANDR +extension RENDER -auth $XAUTHORITY -logfile ${XPRA_LOG_DIR}/Xorg.${DISPLAY}.log -configdir ${HOME}/.xpra/xorg.conf.d -config /etc/xpra/xorg.conf
Xpra development is ahead of what is packaged in the Ubuntu distro, so you may avoid headaches by installing the latest version instead of the distro supplied one. To do so you would run the following (long) commands:

Code: Select all

$ sudo apt-get install xserver-xorg-video-dummy libpangox-1.0-0 python-opengl libpango1.0-0 freeglut3 xserver-xorg-input-void python-gtkglext1 libgtkglext1 ssh-askpass libglu1-mesa python-gi-cairo python-lz4 python-lzo python-rencode python-pillow cython pkg-config libx11-dev libxrandr-dev libxtst-dev libxkbfile-dev libxcomposite-dev libxdamage-dev python-all-dev python-gobject-2-dev python-gtk2-dev xvfb

$ sudo apt-get remove xpra

$ wget https://xpra.org/src/xpra-2.4.tar.xz

$ unxz xpra-2.4.tar.xz

$ tar xvf xpra-2.4.tar

$ cd xpra-2.4

$ sudo python2 ./setup.py install
The following steps assume you're running Xpra 2.4 or later, to avoid confusion.


The idea

The plan is to make use of xpra's features and create a shared virtual desktop session that spans the width of two (or potentially more) monitors. We will use the xpra client to attach to this session from both Odroids. This will give us a duplicated left half view of a desktop - hardly of any use. But if we use xdotool to programmatically move the desktop window to the left on the right monitor (confusing, I know) you'll end up with the illusion of a dual-monitor setup.

Of course, it will need synergy for mouse/keyboard integration, and performance will suffer a bit (that turned out to be an understatement).


Preliminary setup

In order to get started you'll need two Odroids - one more powerful that runs the desktop apps (XU4 or better is recommended), and one that acts as a "dumb" network display (C0/C1). Regarding networking - both devices should be connected to the same gigabit switch (100Mbps may affect performance) and should have fixed IP addresses (either static or through DHCP) and hostnames. In my example I will use identical monitors, but the scripts can be adjusted to work with monitors of different resolutions.


In my setup I'm going to use:

Odroid XU4 running Ubuntu 18.04 (desktop image) named "xu4-left", with IP 192.168.228.203, connected to a monitor with 1680x1050 resolution. This Odroid has a USB sound card and also a keyboard/mouse attached.

Odroid C1 running Ubuntu 18.04 (desktop image) named "c1-right" with IP 192.168.228.19 connected to a monitor with 1680x1050 resolution.


Your first step should be to make sure both devices can run their desktop optimally on their own at the monitor's resolution. For example you can install @memeka's bionic repository (viewtopic.php?f=95&t=31565) for XU4 and update ffmpeg and mpv (though it's not mandatory).


Take your time to set the correct IPs and hostnames (adjust as needed):

Code: Select all

xu4-left$ sudo cat /etc/hostname

xu4-left

xu4-left$ sudo vi /etc/hosts

127.0.0.1 localhost xu4-left

192.168.228.19 c1-right

c1-right$ sudo cat /etc/hostname

c1-right

c1-right$ sudo vi /etc/hosts

127.0.0.1 localhost c1-right

192.168.228.203 xu4-left

Getting synergy to work

Installing synergy is thankfully an easy thing in Ubuntu 18.04. Simply run:

Code: Select all

xu4-left$ sudo apt-get install synergy

c1-right$ sudo apt-get install synergy
Once installed you need to start one side as server (where the keyboard and mouse are connected) and the other as client. You can run the synergy wizard by running the synergy command on each computer:

Code: Select all

xu4-left$ synergy

c1-right$ synergy
On both systems select Edit -> Settings and uncheck "Use SSL encryption". Make sure each system has the correct name in "Screen name".


On the server (xu4-left) select "Server" mode, select "Configure Server…" and: 

Drag and drop a new screen (to the right of xu4-left) and name it c1-right

Apply and Start

File -> Save configuration as ~odroid/.synergy.conf

A sample config file can be downloaded from here: //todo


On the client (c1-right) select "Client" mode, unset "Auto config" and type in the server IP: 192.168.228.203 (xu4-left). Apply and start

You should now be able to move the cursor from one system to the other through synergy.


You should now experiment by starting synergy client/server from the command line on both systems to validate that it works (after restarting the desktop session):

Code: Select all

xu4-left$ synergys -c /home/odroid/.synergy.conf

c1-right$ synergyc xu4-left

Abusing Xpra to get a second screen

Once synergy and X11 works as desired, is time to set up the dual screens. We will first set both boards to start in text mode:

Code: Select all

xu4-left$ sudo systemctl set-default multi-user.target

c1-right$ sudo systemctl set-default multi-user.target
Next, download the xpra and x11 startup scripts from my github page:

Code: Select all

c1-right$ sudo apt-get install xdotool

c1-right$ git clone https://github.com/mad-ady/xpra-multiscreen.git

c1-right$ cd xpra-multiscreen/right

c1-right$ sudo cp -av * /

xu4-left$ git clone https://github.com/mad-ady/xpra-multiscreen.git

xu4-left$ cd xpra-multiscreen/left

xu4-left$ sudo cp -av * /
You will also need to create a password file for xpra with the same password/shared secret on both systems. This password is used by the client to authenticate to the server. The following commands will assign a random 15 character password:

Code: Select all

xu4-left$ sudo apt-get install pwgen

xu4-left$ pwgen 15 1 | tee /home/odroid/.xpra.pass

xu4-left$ scp /home/odroid/.xpra.pass odroid@c1-right:.
You can now start the services on both systems (the start order is not important):

Code: Select all

xu4-left$ sudo service xpra start

xu4-left$ sudo service xorg start

c1-right$ sudo service xorg start
When xpra starts it will start a virtual X11 server (:100) which will have the combined resolution of both physical screens. It also sets up authentication for the connection and set video compression settings. Next it will start a regular Mate desktop session inside this display (:100) as the odroid user. You may customize /etc/systemd/system/xpra.service on the xu4-left system to change things like resolution or session user. You will probably have to adjust /usr/local/bin/start-x-screen*.sh  on both systems to set username, IP, resolution.


The X11 service starts a local X11 server on display :0 (the same way lightdm starts it) on each system. When X11 starts, it executes commands from ~/.xinitrc (and since it starts as root, the full path is /root/.xinitrc). The commands executed are listed below:

Code: Select all

xu4-left$ sudo cat /root/.xinitrc

exec su -c '/usr/local/bin/start-x-screen0.sh' odroid

c1-right$ sudo cat /root/.xinitrc

exec /bin/su -c /usr/local/bin/start-x-screen1.sh - odroid

The left "server" odroid starts the synergy server and then tries to attach to the xpra server in a loop (to recover automatically in case of disconnection).

The right "client" odroid starts the synergy client and instructs it to connect to the server and also attaches to the xpra server in a loop. In addition to this, once attached, it needs to move the xpra window containing the desktop to the left by the same amount as the left screen's resolution (so that what is already displayed by the left monitor is not displayed on the right one too). This is done so that the two views are overlapping and the left screen shows only the left side and the right screen shows the right side. You can see that the script is cheating and if there is no offset defined it reads the x-axis resolution on the right screen and assumes it's the same for the left screen (handy if you have identical monitors).


You can now enable the services and reboot and you should be greeted by a dual-screen setup!

//todo: Fake xinerama


Security considerations

The setup described above is recommended to be used in a home LAN, single user environment. It doesn't use encryption over the network in order to max out performance. It also doesn't have a user login prompt because it bypasses lightdm, but you can still add a bit of security by starting the screensaver on session start-up.


//leftover information which may no longer be relevant

** start xpra with a wide screen

[BOTH]$ sudo apt-get install xpra xdotool

apt-get install python-numpy


Menu -> Control Center -> Startup Applications -> Add -> 

Name: Resize desktop

Command: /usr/bin/xrandr -s 3360x1050


Marco fix:

root@c1-dev:~# ln -s /usr/bin/marco /usr/bin/\'marco\'

root@c1-dev:~# ls -l /usr/bin/\'marco\'

lrwxrwxrwx 1 root root 14 Jul 30 12:49 /usr/bin/'marco' -> /usr/bin/marco

================================

So - did it work? Yes, but it was somewhat unstable - sometimes xpra would take a while to respond and one or both monitors would disconnect and reconnect again after a while. Performance was painfully low - I'd get about 1-2 fps on both monitors. There was a noticeable lag in window actions too (don't remember if mouse was laggy or not). This is likely because of xpra, because it uses x264 to do video encoding, and doesn't use acceleration. I tried sending unencoded data, but performance didn't improve. I hoped to get ~30fps on the xu4, while having the C1 have lower fps, but I couldn't manage.

At least you could drag and drop a window from one monitor to the other - if you dropped it between monitors and dragged it again from the other monitor, once the mouse moved over.

What else? I had issues with X11's resolution when starting manually instead of from lightdm. On 18.04 the screen resolution was fine, but X11 would draw only 1280x720. On 16.04 it was better.

Regarding improvements - I think moving to vnc might speed things up. Starting a regular X11 session (with lightdm) on the master, using xrandr to extend the virtual desktop size and using x11vnc to expose the right side of the desktop to the right monitor. The challenge is to keep the desktop from scrolling when moving the mouse on a screen edge...
These users thanked the author mad_ady for the post (total 2):
joy (Mon Jul 22, 2019 7:14 am) • odroid (Mon Jul 22, 2019 7:02 pm)

joy
Posts: 908
Joined: Fri Oct 02, 2015 1:44 pm
languages_spoken: english
ODROIDs: ODROID-C1+, XU4, X
Has thanked: 16 times
Been thanked: 52 times
Contact:

Re: [WiP/PoC] Odroid multiscreen with XPRA

Unread post by joy » Mon Jul 22, 2019 7:16 am

Awesome!
Thank you for sharing detailed instruction. :)
I will try it!

User avatar
mad_ady
Posts: 6874
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 241 times
Been thanked: 178 times
Contact:

Re: [WiP/PoC] Odroid multiscreen with XPRA

Unread post by mad_ady » Mon Jul 22, 2019 1:37 pm

Let me know if you get stuck somewhere. I last played with it about 6 months ago.
There was another issue that bugged me - sometimes when the second monitor would connect to the xpra session, it would change (lower) the desktop session resolution. I couldn't figure out why...

Maybe switching to vnc will solve the issues...

User avatar
mad_ady
Posts: 6874
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 241 times
Been thanked: 178 times
Contact:

Re: [WiP/PoC] Odroid multiscreen with XPRA

Unread post by mad_ady » Mon Sep 16, 2019 7:26 pm

Update: vnc did solve some issues and improved performance. I did a new write up and I'm polishing it before publishing it. :D
These users thanked the author mad_ady for the post:
odroid (Tue Sep 17, 2019 9:03 am)

User avatar
mad_ady
Posts: 6874
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 241 times
Been thanked: 178 times
Contact:

Re: [WiP/PoC] Odroid multiscreen with XPRA

Unread post by mad_ady » Fri Sep 20, 2019 4:24 pm


User avatar
odroid
Site Admin
Posts: 32704
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 213 times
Been thanked: 367 times
Contact:

Re: [WiP/PoC] Odroid multiscreen with XPRA

Unread post by odroid » Fri Sep 20, 2019 5:05 pm

Great! Rob will ping you soon. :D
Have a nice weekend.
These users thanked the author odroid for the post:
mad_ady (Fri Sep 20, 2019 5:14 pm)

User avatar
mad_ady
Posts: 6874
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 241 times
Been thanked: 178 times
Contact:

Re: [WiP/PoC] Odroid multiscreen with XPRA

Unread post by mad_ady » Fri Sep 20, 2019 5:14 pm

I pinged him sooner :P

nidhiwani
Posts: 1
Joined: Sat Oct 12, 2019 4:05 pm
languages_spoken: english
ODROIDs: laptop
Has thanked: 0
Been thanked: 1 time
Contact:

Re: [WiP/PoC] Odroid multiscreen with XPRA

Unread post by nidhiwani » Sat Oct 12, 2019 4:06 pm

Great Post.Thank You :)
These users thanked the author nidhiwani for the post:
mad_ady (Sat Oct 12, 2019 5:08 pm)

Post Reply

Return to “The Ideas”

Who is online

Users browsing this forum: No registered users and 0 guests