5

I need (almost) real-time audio capturing on Linux with gstreamer. My problem is that I cannot reduce the latency below ~210ms. I tried a simple loopback from mic to headphone:

gst-launch-1.0 pulsesrc ! alsasink
gst-launch-1.0 alsasrc ! alsasink

Both produced the same delay. The latency-time property of alsasrc did not help (it did add the given latency). I could produce the effect I need with

pactl load-module module-loopback latency_msec=1

But I could not figure out whether it is possible to set the device latency for the pulsesrc plug-in of gstreamer. I guess, if it is possible, I should add something to the stream-properties, but could not figure out what (I searched for it here) and how.

Is it possible to set this device latency for any gstreamer sources, and if yes, how?

gertom
  • 51
  • 1
  • 2
  • some of these audio libraries ( jack ) offer a real-time option during install ... did you see such an option ? ... its not the default as it transfers priority over to audio processing to the detriment of non-audio processes – Scott Stensland Feb 03 '17 at 17:01
  • 1
    Maybe you want to test the latency at the ALSA level and see if this is maybe more of an ALSA question than a GStreamer one? http://www.alsa-project.org/main/index.php/Test_latency.c – mpr Feb 06 '17 at 21:08
  • I see also that there's a `buffer-time` property on alsasrc that you may want to try. The default value is 200000 microseconds which looks suspiciously like the latency you're seeing.. – mpr Feb 06 '17 at 21:10
  • 2
    I'm sure that the system is able to work low-latency, as the `pactl` worked and the alsa latency test prog also reports about 2ms latencies. But neither setting the `buffer-time` (I've also found it earlier) or `latency-time` alsasrc properties have the desired effect. (With low `buffer-time` the loopback sound starts glitching, and the `latency-time` can increase but cannot reduce the latency.) – gertom Feb 08 '17 at 08:30
  • look like gstreamer have too much delay. I actually confirmed that pulse audio have 1ms delay but the best that gstreamer provide is 100ms – Pazel1374 Dec 28 '21 at 22:59

2 Answers2

2

Using pulsesink instead of alsasink may solve the problem. Try this:

gst-launch-1.0 -v alsasrc buffer-time=35000 !  pulsesink
0

About as close as you can get to zero latency over network is about 20ms. This example produces the same RTP stream as you would get from a VoIP call with max ptime of 20 in the Session Description protocol. The first pipeline is the speaker and the second pipeline is the listener. I haven't tested this with lower latencies or to a local sink pad for that matter, but the setting does exist for your purpose.

speaker

gst-launch alsasrc name=mic provide-clock=true actual-buffer-time=20000 do-timestamp=true buffer-time=20000 \
mic. \
! alawenc \
! rtppcmapay max-ptime=20000000 \
! udpsink host=192.168.1.2 port=5000

listener

gst-launch udpsrc port=5000 caps="application/x-rtp, media=(string)audio, clock-rate=(int)8000, encoding-name=(string)PCMA" \
! rtppcmadepay \
! audio/x-alaw, rate=8000, channels=1 \
! alawdec \
! alsasink buffer-time=80000
Community
  • 1
  • 1
Josiah DeWitt
  • 1,594
  • 13
  • 15