Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is audio playback via ALSA supported in Qt5?

Tags:

c++

qt

qt5

alsa

I have a small C++ Qt program that uses a QAudioOutput instance to emit sound. It compiles & runs fine using Qt 4.8.5.

However, in Qt 5.0, 5.1, and 5.2, my application compiles, but does not work. I get the following error message while the constructor of the QAudioOutput instance is running:

Unable to create a connection to the pulseaudio context.

Also, the constructor does not return, so my program hangs.

I do not have pulseaudio running. ALSA is working fine, and this is what my program uses when compiled with Qt 4.8.5.

Inspecting the Qt5 “plugins/audio” directory, there is only “libqtmedia_pulse.so” there, the name of which suggests that it depends on pulseaudio.

My questions:

  • Is there still a backend for output to ALSA (without pulseaudio) in Qt 5+ ?
  • If yes, how do I make sure it is built? I do not see any configure options for that.
  • It appears to be a bug that the constructor of QAudioOutput hangs my app. Where can I report that?
like image 453
reddish Avatar asked Nov 14 '13 18:11

reddish


1 Answers

From Qt documentation wiki on Multimedia Backends:

Here is the list of the current audio backends:

Windows Multimedia
CoreAudio (Mac OS / iOS)
PulseAudio (Unix)
Alsa (Unix)
OpenSL ES (Android)
QNX

Only PulseAudio, CoreAudio, and QNX backends are actual plugins. The other backends are “#ifdef’ed” in the related classes.

So basically ALSA is not a plugin but must be selected when you configure Qt (if you build your own, which I assume you are).

From Qt documentation wiki on building Qt5 from git:

Qt Multimedia

You’ll need at least alsa-lib (>= 1.0.15) and gstreamer (>=0.10.24, but <1.0 for now [lists.qt-project.org]) with the base-plugins package.

Ubuntu/Debian:

sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

When configuring Qt I have lost count over the times when some feature was not compiled in because of missing dependencies. So make absolutely 100% sure that all dependencies are installed properly, and that all your configuration options are valid with the current configuration program (available options change even between minor versions)! Remember to look closely at output from build process (collect output in a file and search through it after build completes for any messages with "skipping" or "error" or such keywords.

OTOH, if you did not build your own Qt then I have no clue and you should disregard this answer.

like image 145
Lennart Rolland Avatar answered Nov 04 '22 17:11

Lennart Rolland