Skip to content

Networking audio

f4exb edited this page Feb 19, 2019 · 10 revisions

Introduction

This page deals with sending audio to distant clients through the network. The network in question is a LAN this does not cover contacting clients over the Internet. With proper NAT and firewall setup this could be possible but first you have to make sure it works on the LAN. This also covers plenty of interesting use cases within the house like listening to your favorite local QSO on your mobile phone in the bathroom 😄.

The preferred transport and protocol is RTP over UDP.

The audio preferences menu

Details of the settings are covered here: https://github.com/f4exb/sdrangel/blob/master/sdrgui/audio.md The concerned settings are 5 to 14. The settings to consider more particularly are:

  • Address (11): this is the "remote" address i.e. the address of the network interface on the client that will receive the stream
  • Port (12): this is the port at which the client listens
  • Stream parameters (5, 8, 9): these settings result in a format described in RTP/SDP form at (10). The actual stream sample rate is the audio sample rate (5) divided by the decimation factor (6). For proper operation the sample rate given in (5) should match the sample rate of the audio device.
  • You will want to check the RTP flag (14) to transmit using RTP protocol

Receiving the stream in a client application

You may use VLC, cvlc or MX Player for example. MX player is recommended on Android clients. All these applications will read a .sdp file as input. This is a text file that describes the stream. For example:

c=IN IP4 192.168.1.3
m=audio 9998 RTP/AVP 96 
a=rtpmap:96 L16/48000/1
  • 192.168.1.3 is the IPv4 address of the interface that receives the stream.
  • 9998 is the port that receives the stream
  • 96 is the RTP payload type. You will find a list of these type codes here: https://en.wikipedia.org/wiki/RTP_audio_video_profile 96 to 128 are "dynamic" types. 96 is the usual number for audio dynamic types
  • L16/48000/1 is a description of the stream format and can be found in the audio preferences dialog at (10):
    • L16 is for "Linear PCM 16-bit audio". These are 16 bit signed samples without any compression
    • 48000 is the sample rate
    • 1 is the number of channels

To reduce the network bandwidth usage you may use PCMA or PCMU that uses 8 bit samples in a single channel and should be sent at 8000 Hz sample rate to respect the standard. Therefore the stream rate is 64 kbits/s. You may use decimation (control 6 of the audio preferences dialog) to achieve the desired sample rate from a given audio sample rate (control 5 of the audio preferences dialog).

For PCMA or PCMU the .sdp file can be constructed as in this example:

c=IN IP4 192.168.1.3
m=audio 9998 RTP/AVP 8 
a=rtpmap:8 PCMA/8000

RTP payload types:

  • PCMA: 8
  • PCMU: 0

Note that single channel is implicit and therefore the number of channels (/1) is optional.

Receiving the stream in a browser with WebRTC

Using a WebRTC server it is possible to play back the stream directly in the browser. We will discuss interfacing with the Janus WebRTC server

Install Janus server

Prerequisites

You will need to install a few prerequisite packages. In Ubuntu/Debian you do this with:

sudo apt-get install libmicrohttpd-dev libjansson-dev libssl-dev libnice-dev libsrtp2-dev libglib2.0-dev libcurl4-openssl-dev libconfig-dev pkg-config gengetopt libtool automake

Data channels are not needed for audio/video but are useful to stream (future) FFT spectrum. usrsctp is needed for that purpose and is only available in source form. So you will need to compile and install it in the system.

git clone https://github.com/sctplab/usrsctp
cd usrsctp
./bootstrap
./configure --prefix=/usr
make -j4 
sudo make install

Note that I normally hate the sudo make install but for the sake of simplicity we will install usrsctp system wide.

Build, install

Clone the Janus git repository:

git clone https://github.com/meetecho/janus-gateway.git
cd janus-gateway

Build and install:

sh autogen.sh
./configure --prefix=/opt/install/janus
make -j4
make install

Run the server

Start Janus server at default port 8088:

/opt/install/janus/bin/janus

Test it by opening your browser at http://127.0.0.1:8088/janus/info You should get back server information in JSON format

Later (in "production" mode) you may want to run Janus server using supervisor or a system service. We will not cover this here.

Configure Janus server

Janus configuration files are located in /opt/install/janus/etc/janus (assuming Janus was installed in /opt/install/janus as described above).

You will have to modify janus.transport.http.jcfg to enable HTTPS on port 8089 (for example) by uncommenting these lines:

	https = true					# Whether to enable HTTPS (default=no)
	secure_port = 8089				# Web server HTTPS port, if enabled

Note that the client will have to access this port via https and as the certificate is self signed it may have to be accepted once. To do this from the client browser access to https://192.168.1.3:8089/janus/info assuming 192.168.1.3 is the address of the network interface at which the Janus server listens and accept the "insecure" certificate. This is something you will have to do if you cannot start the demos (you get a "Probably a network error, is the server down?" message box).

Then you will have to add an endpoint for SDRangel stream by adding this in the janus.plugin.streaming.jcfg file:

sdrangel-audio: {
    type = "rtp"
    id = 16
    description = "SDRangel live audio"
    audio = true
    video = false
    audioport = 9998
    audiopt = 8
    audiortpmap = "PCMA/8000/1"
}

Here we will use PCMA note that PCMU is also possible.

  • id is an arbitrary number
  • port 9998 is the port to which the stream will be directed
  • audiopt 8 corresponds to the RTP payload (PCMA is 8 and PCMU is 0)
  • audiortpmap PCMA/8000/1 is RTP stream mapping in SDP format. The same is found on the a=rtpmap line of the .sdp file

Serve Janus demo

First cd to the demo folder. From the root of the cloned janus-gateway repository do cd http.

We will use the Janus streaming demo to receive the stream from SDRangel therefore we will need a http server to access the demo from the browser. Note that browsers accept WebRTC negotiation on https only. We will use the nodejs server to do so. It may be installed with npm like this sudo npm install http-server -g.

In order to be able to use https we will need self signed certificates that can be created with openssl like this: openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem. Just hit enter at all prompts.

You can now start the http server in https mode with: http-server -S -C cert.pem.

Configure SDRangel audio

In the audio preferences dialog select the audio interface to which the audio you want to send is directed. Most of the time this will be the system default but you may want to do more complicated things with virtual devices and we will not cover this here.

The audio preferences dialog:

Audio prferences dialog

  • You need to send the stream using RTP protocol (14).
  • The sample rate must be 8000 Hz so if your system default device runs at 48000 Hz (5) you will need to decimate the sample rate by 6. This is done with (8)
  • You have to use PCMA or PCMU format. You select it with (9)
  • The resulting SDP format string (10) has to be PCMA/8000/1 if you have chosen PCMA when configuring the Janus endpoint earlier. Note that you may have chosen PCMU the important thing is that it matches the Janus endpoint configuration.
  • The address (11) must be the IPv4 address of your network interface and not the localhost (127.0.0.1)
  • The port (12) is the one specified in the Janus endpoint configuration done earlier

Now that you are all set just hit the "UDP" button (13). In the Janus log it should display a line confirming the connection.

Receive the audio stream in the browser

  • In the Janus Demos drop down list select Streaming
  • In the opened page click on Start
  • In the Streams list drop down menu select SDRangel live audio
  • Click on the Watch or listen button
Clone this wiki locally