You are not logged in.

#1 2021-08-29 16:03:38

jneem
Member
Registered: 2011-07-14
Posts: 13

High CPU usage with pulseaudio + gstreamer

When using audio in a gstreamer-based application, both the application and pulseaudio show high CPU usage. For example, when running

gst-launch-1.0 -v autoaudiosrc ! audio/x-raw,rate=48000,channels=1 ! wavenc ! filesink location="output.wav"

top shows 23% CPU usage for pulseaudio and 18% for gst-launch-1.0. On the other hand, recording with

parecord --channels=1 -d alsa_input.pci-0000_00_1f.3.analog-stereo --rate=48000 out.wav

results in basically undetectable CPU usage (< 0.3%). I've verified that both commands are using the same recording source: here is the output of "pacmd list-source-outputs" while running the "gst-launch" command:

1 source output(s) available.
    index: 52
	driver: <protocol-native.c>
	flags: START_CORKED 
	state: RUNNING
	source: 2 <alsa_input.pci-0000_00_1f.3.analog-stereo>
	volume: mono: 65536 / 100% / 0.00 dB
	        balance 0.00
	muted: no
	current latency: 0.00 ms
	requested latency: 10.00 ms
	sample spec: s16le 1ch 48000Hz
	channel map: mono
	             Mono
	resample method: copy
	owner module: 14
	client: 216 <gst-launch-1.0>
	properties:
		media.name = "Record Stream"
		application.name = "gst-launch-1.0"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "35"
		application.process.id = "54087"
		application.process.user = "jneeman"
		application.process.host = "origami"
		application.process.binary = "gst-launch-1.0"
		application.language = "en_US.UTF-8"
		window.x11.display = ":0"
		application.process.machine_id = "ee5f05f6a839443a93f07f6c0aa27702"
		application.process.session_id = "1"
		module-stream-restore.id = "source-output-by-application-name:gst-launch-1.0"

and here is the output of "pacmd list-source-outputs" when running "parecord"

1 source output(s) available.
    index: 40
	driver: <protocol-native.c>
	flags: 
	state: RUNNING
	source: 2 <alsa_input.pci-0000_00_1f.3.analog-stereo>
	volume: mono: 65536 / 100% / 0.00 dB
	        balance 0.00
	muted: no
	current latency: 0.00 ms
	requested latency: n/a
	sample spec: s16le 1ch 48000Hz
	channel map: mono
	             Mono
	resample method: copy
	owner module: 14
	client: 194 <parecord>
	properties:
		media.format = "WAV (Microsoft)"
		application.name = "parecord"
		media.name = "out.wav"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "35"
		application.process.id = "52904"
		application.process.user = "jneeman"
		application.process.host = "origami"
		application.process.binary = "pacat"
		application.language = "en_US.UTF-8"
		window.x11.display = ":0"
		application.process.machine_id = "ee5f05f6a839443a93f07f6c0aa27702"
		application.process.session_id = "1"
		module-stream-restore.id = "source-output-by-application-name:parecord"

I notice that they differ in "requested latency", but is 10ms unreasonably low for that?

Offline

#2 2021-09-02 19:09:15

jneem
Member
Registered: 2011-07-14
Posts: 13

Re: High CPU usage with pulseaudio + gstreamer

I managed to improve the situation a little by uninstalling pulseaudio and installing pipewire instead. That reduced the CPU load by a factor or 2 or 3 when using gst-launch. It's still an order of magnitude higher than parecord, though.

Offline

Board footer

Powered by FluxBB