Quantcast
Channel: Scarygliders » Linux Tips & Tricks
Viewing all articles
Browse latest Browse all 10

Get audio with your xrdp/x11rdp connections, LAN or Remote! Updated! Windows Clients!

$
0
0

Okay so I did a bit of research, and found a method of forwarding audio from your remote RDP Linux desktops.

The methods work for RDP connections on your local LAN, and also for connections to remote systems via ssh tunnels.

Here's how…

2012-04-19 Article Updated

Changelog:

  • Added a section for how to get audio on Windows Clients from the linux RDP target

Prerequisites

  • The client system needs PulseAudio – client and server – installed.  These days it's installed by default if you've installed a full desktop Debian/Ubuntu distribution. Update : Also works for Windows, which also needs PulseAudio – see new section for Windows below!

 

  • The target system needs the PulseAudio client libraries installed. No need for the PulseAudio server, although this is probably already installed if you've installed the Gnome Desktop and/or Unity.

 

 

 

A) Local LAN RDP connections…

 

Here's the basic setup; a client system and the target system running Xrdp/X11rdp.

The client system's IP address is 192.168.1.9.

The target systems's IP address is 192.168.1.254.

 

 

 

 

The system you're going to listen to audio on is the rdp client, but it's the PulseAudio server. The RDP target system will send all audio data to the PulseAudio server running on your client machine.

1) On the Client System

Ensure the PulseAudio TCP native protocol module is set up on your client system.

Open up a terminal window on your local system, and type the following;

pacmd list-modules | grep module-native-protocol-tcp

If the response is blank, then this module is not loaded. To load it, type the following;

pactl load-module module-native-protocol-tcp auth-ip-acl="<ip address or network range>"

Where <ip address or network range> can be a single ip address – for example 192.168.1.254 – or a network range such as 192.168.1.0/24. The former will limit access to the PulseAudio server running on your client system. The latter will grant PulseAudio server access to all systems on that network. You can also specify a list of IP addresses separated with a semicolon. For example; "192.168.1.101;192.168.1.102;192.168.1.254", which would limit access to the systems on the LAN with those addresses.

Once you've loaded this module successfully, you'll see a number returned – this is the module ID number. You can unload the module if you wish to try different configurations, by typing pactl unload-module <ID number> .

2) On the Target RDP System

In the user's ~/.xsession file, add this line BEFORE any lines which start your gnome or unity-2D session…

export PULSE_SERVER=<ip address of your client machine>

 

So for example, my client machine's address is 192.168.1.9. The line would read export PULSE_SERVER=192.168.1.9

Save the .xsession file.

 

Here's what my .xsession file looks like;

 

export PULSE_SERVER=192.168.1.9:4713
gnome-session --session=gnome-fallback
 

3) Connect via RDP

From your client machine, use your favorite RDP client to connect to the target RDP system as usual.

Any audio output from programs running in the RDP session should now automatically be heard on your client system.

Also, if you right-click on the audio icon on your desktop (I'm using the gnome-classic desktop for my RDP sessions), then click on Sound Preferences, you can control the audio output of the RDP session, just as if the sound hardware were on the RDP target machine :)

 

Here's a screenshot of a gnome-classic session running on rdesktop. I brought up the Sound Preferences and clicked the Hardware tab. Thanks to Pulseaudio's magic, the sound card on my client machine appears – as if it's installed on the RDP server.

Magic, I say. Magic!

I'm running RhythmBox in that session as I type this, and the audio's coming through just fine ;)

 

 

 

And that's it for audio on RDP for the local LAN. Next up is doing the same on a truly remote system…

B) Audio on RDP on remote connections…

The method is similar to the above for LAN connections, except that we're going to be doing this through ssh tunnels.

 

Prerequisites

  • The client system needs PulseAudio – client and server – installed.  These days it's installed by default if you've installed a full desktop Debian/Ubuntu distribution.

 

  • The target system needs the PulseAudio client libraries installed. No need for the PulseAudio server, although this is probably already installed if you've installed the Gnome Desktop and/or Unity.

 

 

1) On the Client System

We'll need an SSH tunnel between the client machine, and your target machine.

If you don't know how that's done, I suggest you read the article I wrote recently on how to do exactly that ;)

For the purposes of this article, I'm going to form an ssh tunnel between my client, and a machine on my LAN at 192.168.1.254 – the principle is exactly the same, and I've tried this on a remote VPS system too.

 

I've tried this procedure on a remote machine over the internet (a VPS), and the sound was choppy when playing sound from Google Chrome (a YouTube video. I don't know if that's a result of a bursty connection or what, so, your results may vary – your results for this might be brilliant, or just as bad as the result I achieved, so, be warned.

When I ran Rhythmbox though and played a radio station, the sound came through just fine.

Also, when I ran Gnome Terminal and caused an "audible bell" by pressing backspace when no characters were left to delete, the sound was choppy.

So, basically mixed results for remote audio over the internet – Your Mileage May Vary, etc etc

 

As with the LAN scenario, ensure the PulseAudio TCP native protocol module is set up on your client system.

Open up a terminal window on your local system, and type the following;

pacmd list-modules | grep module-native-protocol-tcp

If the response is blank, then this module is not loaded. To load it, type the following;

pactl load-module module-native-protocol-tcp auth-ip-acl="127.0.0.1"

Since we're going to use an SSH tunnel for this, all we need is access allowed on the locahost interface. You can, if you're going to be accessing RDP systems on the local LAN as well as remote, say "127.0.0.1;<ip address or range>" as we did above, though.

 

2) On the Target RDP System

In the user's ~/.xsession file, add this line BEFORE the line(s) which start your gnome or unity-2D session…

export PULSE_SERVER=<localhost:4713>

We'll be using SSH to tunnel port 4713 from the target RDP system to your local client system, so audio will play on that local client system.
Save the .xsession file.
 
Here's what my .xsession file looks like;
 
export PULSE_SERVER=localhost:4713
gnome-session --session=gnome-fallback
 

3) Form the SSH tunnel connection between your client system and the SSH target system.

 

 

 

 

 

 

 
If your remote ssh target system is also the RDP server;
 
ssh -c arcfour -R localhost:4713:localhost:4713 -L3390:localhost:3389 <ip address of ssh target system>
 
We just set up two tunnels. The first one handles the PulseAudio connection, the second handles the RDP connection.
 
So in my case;
 
ssh -c arcfour -R localhost:4713:localhost:4713 -L3390:localhost:3389 192.168.1.254
 
 
If your RDP server sits on a LAN behind your ssh server;
ssh -c arcfour -R localhost:4713:<ip address of RDP server>:4713 -L localhost:3390:<ip address of RDP server>:3389 <ip address of ssh target system>

 

4) Connect to your RDP server via the ssh tunnel

 
I'm using rdesktop -a16 -g 1820x900 localhost:3390 for my connection as an example.
 
Sound should now be routed through your SSH tunnel to your PulseAudio server on your local client. :)
 

 
 
 
 
 
 
Again, here's an RDP screenshot of my LAN session, tunneled via SSH, with Sound Preferences and Rhythmbox running…
 
 
 
 
 
 
 
 
 
 
 
 
 
And I tried the same with a truly remote system. The same method with a VPS I have. Rhythmbox sent its output via the ssh tunnel to my local PulseAudio server. The sound was perfect.
 
I guess it's down to how the program in use sends it's output.
 
 
 
 
 
 
 

And now for Windows clients :D

That's right, you read it right – you can get audio working from your Linux RDP server to your Windows RDP client machine, Like A Boss. Here's how…

A) Local LAN RDP connections…

 

 

Same basic scenario as above.

I have a Linux target RDP server on my LAN at 192.168.1.249

I have a Windows client on the LAN at 192.168.1.10

 

 

 

 

 

 

1) On the Windows client system…

 
You can obtain Windows PulseAudio binaries, from the FreeDesktop website here.
 
Click on the link saying "A Zipfile containing preview binaries…" and save the file somewhere.
 

""

 
 
 
 
 
 
 
Extract the files in the zip archive to somewhere on your drive. I'm going to extract to C:\PulseAudio.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Next you have to configure PulseAudio to accept connections on the LAN. Now, you'll need a text editor which can handle Unix newline characters – Notepad won't. I've installed a free editor called Notepad++ .
 
Open up the file C:\PulseAudio\etc\pulse\default.pa
 
 
 
 
 
 
 
 
Locate the line in the file saying #load-module module-null-sink
 
Add the following underneath it:
 
load-module module-native-protocol-tcp listen=0.0.0.0 auth-anonymous=1
 
NOTE: This means the PulseAudio server running on your client machine will accept connections from anywhere on your local LAN. You can reconfigure this by using the options I described above in the Linux Client section to limit who can connect from where.
 
Save the file.
 
 
 
 
 
 
 
 
Open the file C:\PulseAudio\etc\pulse\daemon.conf
 
Scroll down to the very end of the file.
 
 
 
 
 
 
 
 
 
 
 
 
 
At the end of the file, add the following line:
 
exit-idle-time = -1
 
This will instruct the PulseAudio daemon not to shut down – otherwise by default it would shut down after 20 minutes of no audio being sent to it.
 
Save the file and exit the editor.
 
 
 
 
 
 
Next up, start a Command Line session. Windows 7 users will need to do this as Administrator.
 
Change to the PulseAudio bin directory: cd c:\PulseAudio\bin
 
Start PulseAudio with the following parameters:
 
pulseaudio.exe -p "C:\PulseAudio\lib\pulse-1.1\modules" -nF "C:\PulseAudio\etc\pulse\default.pa"
 
You may have to do this twice, first time around.
 
 
 
 
 
The very first run of PulseAudio just stopped.
 
I pressed the Up Arrow key and then tried running the command again, this time the PulseAudio Daemon loaded.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
On Windows 7, the Windows Firewall Alert box popped up, asking you what you want to do.
 
Click on Allow access, because naturally, we need to be able to send sound data to your client machine ;)
 
You now have a PulseAudio server running on your Windows client machine :)
 
 
 
 
 
 
 
 
2) On your RDP target machine…
 
 
 
Edit the .xsession file in the home directory of the target user you will log in as, on the target RDP system.
 
Add the following line at the very top, before any other lines:
 
export PULSE_SERVER=192.168.1.10:4713
 
See the screenshot for clarification. Save the file and exit the editor.
 
 
 
 
3) Connect via Terminal Services Client to your RDP target machine
 
""
 
 
 
 
 
 
 
 
 
 
You don't need to do anything special for the RDP client configuration – just set your ip address and Display settings if you wish, then connect.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
After logging in, notice that, if I hover the mouse cursor over the Volume icon in my specially customized Gnome Classic desktop, it says "WaveOut on Microsoft Sound Mapper" !!
 
Never thought I'd see anything like that on a Linux Desktop – tee hee!
 
Now go and run something which produces audio, and rejoice when sound is heard from your Windows client machine's loudspeakers :D
 
 
 
 
 
 
 
 
 
 
 
 
I fired up Firefox and started playing something from YouTube – grooving along as I type this ;)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
And thanks to the magic of PulseAudio, sound preferences work from the RDP server too – you can change volume from there and even sound balance works :)
 
 
 
 
 
 
 
 
 
And that's it for a LAN connection – but what about an RDP session to a remote RDP server? As the Linux section above, this can be achieved via an SSH tunnel…
 
 
 

B) Audio on RDP on remote connections…

We'll need an SSH tunnel between the client machine, and your target machine.

If you don't know how that's done, I suggest you read the article I wrote recently on how to do exactly that ;)

For the purposes of this article, I'm going to form an ssh tunnel between my client, and a machine on my LAN at 192.168.1.254 – the principle is exactly the same as if the RDP server was at a remote location over the internet, and I've tried this on a remote VPS system too.

 
 
I'm assuming you've installed PulseAudio onto your Windows client system as outlined above, and it's configured as above, so let's skip that bit and go straight for the SSH jugular…
 

1) Configure puTTY On the Client System…

 
Load up puTTY and create a new session as follows:
 

 

 

 

 

Configure a Session Name and enter the Host IP address.

 

 

 

 

 

 

 

 

 
 
 
 
 
 
 
Configure the first tunnel for the RDP data;
 
Make sure the Local radio-button is selected as shown.
 
Source port is 3391 (Windows uses 3390 already).
 
Destination is localhost:3389.
 
Click Add.
 
 
 
 
 
 
 
 
 
 
 
 
 
Configure another tunnel for the PulseAudio data.
 
Make sure Remote radio-button is selected, as shown.
 
Source should be 4713
 
Destination should be localhost:4713
 
Click on Add.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
The tunnels configuration should look something like as shown.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Oh, and remember to go back to Session, and save the configuration, otherwise you'll have to do this all over again next time ;)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2) On the remote RDP server system…
 
 
Edit the .xsession file in the target user's home directory on the target RDP system, such that the first line reads;
 
export PULSE_SERVER=localhost:4713
 
Save and exit.
 
 
 
 
3) Connect via puTTY/SSH…
 
 

 

 

Connect to the remote system via puTTY, using the session details you saved from above.

The two tunnels should now be active. Let's see…

 

 

 

4) Connect to an RDP session…

 

 

 

 

 

This time round, we're connecting to localhost:3391 – that's the RDP tunnel formed by the puTTY connection.

 

 

 

 

 

 

 

 

 

 

 

Good, the RDP tunnel is working, so let's log in…

 

 

 

 

 

 

 

 

 

 

And bingo! The PulseAudio tunnel is working!

Play something and it should work – it did for me :)

 

 

 

 

 

 

 

 

Lastly, here's the SSH tunnel to my VPS. The above setup worled on that too, and audio was playing fine – you may get some distortion on a truly remote system if you're running the PulseAudio control panel like I am on the remote machine.

 

 

 

 

 

And that's it!    :)

 

 

Please let me know how you got on with this!

 

 

 

 

 

The post Get audio with your xrdp/x11rdp connections, LAN or Remote! Updated! Windows Clients! appeared first on Scarygliders.


Viewing all articles
Browse latest Browse all 10

Trending Articles