Low Latency RTP streaming with TX


#1

Hi All

The thing I’m trying to do is stream audio to my phone with very low latency 500ms is to slow im hoping for something <50ms.

So after some research, I have decided to try TX. I get the error
pi@raspberrypi:~ $ tx -h 127.0.0.1
trx © Copyright 2014 Mark Hills <[markxwax.org](mailt: markxwax.org)>
ALSA lib pcm_dmix.c:990:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
snd_pcm_open: Invalid argument

Any help would be greatly appreciated.
Thanks
Jon


Here is how I got it up to this stage.

I started with I read.

lb.raspberrypi.org/forums/viewtopic.php?t=185507

  1. Make sure you compile against this implementation / version of ortp

========================================================
I did this.

  1. I changed the opus encoder / decoder to int16 from float - due to my audio devices was simple
    16 bit cheep stuf.
    changes to tx.c rx.c and device.c
    ==================================
    I didn’t do this because I have the pisound

I download tx for here

www.pogo.org.uk/~mark/trx/releases/trx-0.3.tar.gz

tar -xvf trx-0.3.tar.gz
sudo apt-get install libasound2-dev
sudo apt-cache search opus
sudo apt-get install libopus-dev
sudo make install
sudo install -d /usr/local/bin
sudo install rx tx /usr/local/bin

There is a small error in the doco

I think

pcm.!default { type plug slave.pcm { type dmix ipc_key 2867 slave { pcm “hw:Loopback,0,0” rate 48000 format S16_LE channels 2 period_size 1024 buffer_size 8192 } }

should be

pcm.!default { type plug slave.pcm { type dmix ipc_key 2867 slave { pcm “hw:Loopback,0,0” rate 48000 format S16_LE channels 2 period_size 1024 buffer_size 8192 } }}

pi@raspberrypi:~ $ sudo su
root@raspberrypi:/home/pi# modprobe snd-aloop
pi@raspberrypi:~ $ aplay -vv test.wav
Playing WAVE ‘test.wav’ : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
Plug PCM: Direct Stream Mixing PCM
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 8192
period_size : 1024
period_time : 21333
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1024
period_event : 0
start_threshold : 8192
stop_threshold : 8192
silence_threshold: 0
silence_size : 0
boundary : 1073741824
Hardware PCM card 2 ‘Loopback’ device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 8192
period_size : 1024
period_time : 21333
tstamp_mode : ENABLE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1024
period_event : 0
start_threshold : 1
stop_threshold : 1073741824
silence_threshold: 0
silence_size : 1073741824
boundary : 1073741824
appl_ptr : 0
hw_ptr : 0
######### + | 21%

#+ | 00%
pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: pisound [pisound], device 0: PS-06A5GMK snd-soc-dummy-dai-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 2: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
pi@raspberrypi:~ $ cat .asoundrc
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
pcm.!default {
type plug
slave.pcm {
type dmix
ipc_key 2867
slave {
pcm “hw:Loopback,0,0”
rate 48000
format S16_LE
channels 2
period_size 1024
buffer_size 8192
}
}
}
pcm.hubcap {
type plug
slave {
pcm “hw:Loopback,1,0”
rate 48000
format S16_LE
}
}
pi@raspberrypi:~ $ tx -h 192.168.43.246
trx © Copyright 2014 Mark Hills <[markxwax.org](mailt: markxwax.org)>
ALSA lib pcm_dmix.c:990:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
snd_pcm_open: Invalid argument
pi@raspberrypi:~ $ ping 192.168.43.246
PING 192.168.43.246 (192.168.43.246) 56(84) bytes of data.
64 bytes from 192.168.43.246: icmp_seq=1 ttl=64 time=7.04 ms
64 bytes from 192.168.43.246: icmp_seq=2 ttl=64 time=5.85 ms
pi@raspberrypi:~ $ tx -h 127.0.0.1
trx © Copyright 2014 Mark Hills <[markxwax.org](mailt: markxwax.org)>
ALSA lib pcm_dmix.c:990:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
snd_pcm_open: Invalid argument


#2

Hey,

The error given means that the audio device tx tries to use provides only ‘playback’ capability, while it needs to ‘capture’ audio to stream over the network.

Do you want to stream whatever comes in to Pisound’s input over this software? Looks like the config here is trying to set up a virtual audio device that would capture ‘desktop’ sounds and send it over the net, but in case you just want Pisound’s input to be streamed, what you have to do is to give a -d argument to tx to select Pisound as the device.

Try something like this:

tx -h 192.168.43.246 -d hw:1,0
or
tx -h 192.168.43.246 -d hw:pisound

Let us know how it works and whether this is the scenario you are after :slight_smile:


#3

Thanks for the help

I did a bit more reading, you’re correct I was mistaken and was trying to send the desktops sound.

This is not what I’m after, I want to get analog in and send out RTP (because I think its the fastest) sent to a phone with minimum latency, I have an internal network so I can control the quantity of this.

My new config looks like

pi@raspberrypi:~ $ cat .asoundrc
pcm.!default {
	type hw
	card 1
}

ctl.!default {
	type hw
	card 1
}

pi@raspberrypi:~ $  arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: pisound [pisound], device 0: PS-06A5GMK snd-soc-dummy-dai-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

pi@raspberrypi:~ $ tx -h 192.168.43.246 -d hw:pisound
trx (C) Copyright 2014 Mark Hills <mark@xwax.org>
snd_pcm_hw_params_set_format: Invalid argument

Do I need to load the ALSA driver?

snd_pcm_hw_params_set_format: Invalid argument

I have a more general question, Given the problem, low latency streaming to a phone am I going about it in a reasonable way? Is there a better more standard way of doing this?

Thanks for the help
Jon


#4

This may mean the software is trying to get some format which is not natively supported by Pisound. You should explicitly make it use either 16, 24 or 32 bits per sample, exactly 2 channels audio, and sampling rate must be one of 48000, 96000 or 192000.

It is possible to set up ALSA plugins that automatically transcode requested audio format to the closest one that is supported by hardware, but it’s most efficient to use format supporte natively directly.

Not sure what is the most ‘standard’ way of doing this, but there’s also netJACK. However I haven’t used it myself.


#5

Hi again.

I recompiled the C code and forced
https://lb.raspberrypi.org/forums/viewtopic.php?t=185507
The summery is changing float to int for 16bit audio
r = opus_decode(decoder, packet, len, pcm, samples, 0);
// r = opus_decode_float(decoder, packet, len, pcm, samples, 0);

So then I steamed over UDP another standard PI without a pisound.

I worked but the quality was very poor. I noticed that on the receiving pi without the pisound there were warning about not having access to the scheduler something about RT.

Does the pisound software installation do some tweaks to make RT kernel work?

I have ordered another pisound for the receiver and will test it out when it arrives. If I can get that to work well then I will try and port the C code to Android.

Thanks again for the help
Jon