From 6dc19a0b10444f33acb1196f1ff85301cb29faea Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Mon, 12 Nov 2018 11:00:54 +0100 Subject: PulseAudio: Introduce QT_PA_CHANNEL_MAP for QAudioOutput MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced QT_PA_CHANNEL_MAP env var to define one of channel mapping definitions: ALSA = PA_CHANNEL_MAP_ALSA AUX = PA_CHANNEL_MAP_AUX WAVEEX = PA_CHANNEL_MAP_WAVEEX OSS = PA_CHANNEL_MAP_OSS and PA_CHANNEL_MAP_DEFAULT as default Usage QT_PA_CHANNEL_MAP=AUX ./app Also fixed a crash when the number of the channels is too high. Task-number: QTBUG-71710 Change-Id: I45f7f7499cb7db218d5dc7d2eb7764c835abf8f7 Reviewed-by: Otto Ryynänen Reviewed-by: Christian Stromme --- src/plugins/pulseaudio/qaudiooutput_pulse.cpp | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp index ea7a2be0c..b4bd1c55c 100644 --- a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp +++ b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp @@ -310,7 +310,34 @@ bool QPulseAudioOutput::open() if (!m_category.isNull()) pa_proplist_sets(propList, PA_PROP_MEDIA_ROLE, m_category.toLatin1().constData()); - m_stream = pa_stream_new_with_proplist(pulseEngine->context(), m_streamName.constData(), &m_spec, 0, propList); + static const auto mapName = qEnvironmentVariable("QT_PA_CHANNEL_MAP"); + pa_channel_map_def_t mapDef = PA_CHANNEL_MAP_DEFAULT; + if (mapName == QLatin1String("ALSA")) + mapDef = PA_CHANNEL_MAP_ALSA; + else if (mapName == QLatin1String("AUX")) + mapDef = PA_CHANNEL_MAP_AUX; + else if (mapName == QLatin1String("WAVEEX")) + mapDef = PA_CHANNEL_MAP_WAVEEX; + else if (mapName == QLatin1String("OSS")) + mapDef = PA_CHANNEL_MAP_OSS; + else if (!mapName.isEmpty()) + qWarning() << "Unknown pulse audio channel mapping definition:" << mapName; + + pa_channel_map m; + auto channelMap = pa_channel_map_init_extend(&m, m_spec.channels, mapDef); + if (!channelMap) + qWarning() << "QAudioOutput: pa_channel_map_init_extend() Could not initialize channel map"; + + m_stream = pa_stream_new_with_proplist(pulseEngine->context(), m_streamName.constData(), &m_spec, channelMap, propList); + if (!m_stream) { + qWarning() << "QAudioOutput: pa_stream_new_with_proplist() failed!"; + pulseEngine->unlock(); + setError(QAudio::OpenError); + setState(QAudio::StoppedState); + emit stateChanged(m_deviceState); + return false; + } + pa_proplist_free(propList); pa_stream_set_state_callback(m_stream, outputStreamStateCallback, this); -- cgit v1.2.3