From 5f33d7bea3fd3dd441aff499576826a02e8e5be2 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 22 Jul 2014 18:24:22 +0200 Subject: Only call pa_cvolme set on stream creation if volume explicitly set. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Streams without a custom volume set use suitable volume selected by the PulseAudio server. This is usually the correct choice, since then stream-restore module can apply old volume to the stream. Also with Sailfish explicitly setting the volume to streams breaks system volume. Change-Id: I75f5bf4e7aaafb4bd55510f5ac4ddf03767d494b Done-with: Juho Hämäläinen Reviewed-by: Andrew den Exter --- src/plugins/pulseaudio/qaudiooutput_pulse.cpp | 28 ++++++++++++++++++++------- src/plugins/pulseaudio/qaudiooutput_pulse.h | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp index 64a080663..a5c7cf192 100644 --- a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp +++ b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp @@ -159,6 +159,7 @@ QPulseAudioOutput::QPulseAudioOutput(const QByteArray &device) , m_audioBuffer(0) , m_resuming(false) , m_volume(1.0) + , m_customVolumeRequired(false) { connect(m_tickTimer, SIGNAL(timeout()), SLOT(userFeed())); } @@ -306,13 +307,25 @@ bool QPulseAudioOutput::open() pa_stream_set_latency_update_callback(m_stream, outputStreamLatencyCallback, this); pa_volume_t paVolume; - if (qFuzzyCompare(m_volume, 0.0)) { - paVolume = PA_VOLUME_MUTED; - m_volume = 0.0; - } else { - paVolume = qFloor(m_volume * PA_VOLUME_NORM + 0.5); + + /* streams without a custom volume set are expected to already have a + * sensible volume set by Pulse, so we don't set it explicitly. + * + * explicit setting also breaks volume handling on sailfish, where each + * stream's volume is set separately inside pulseaudio, with the + * exception of streams that already have a volume set (i.e. if we set + * it here, we'd ignore system volume). + */ + if (m_customVolumeRequired) { + if (qFuzzyCompare(m_volume, 0.0)) { + paVolume = PA_VOLUME_MUTED; + m_volume = 0.0; + } else { + paVolume = qFloor(m_volume * PA_VOLUME_NORM + 0.5); + } + + pa_cvolume_set(&m_chVolume, m_spec.channels, paVolume); } - pa_cvolume_set(&m_chVolume, m_spec.channels, paVolume); if (m_bufferSize <= 0 && m_category == LOW_LATENCY_CATEGORY_NAME) { m_bufferSize = bytesPerSecond * LowLatencyBufferSizeMs / qint64(1000); @@ -325,7 +338,7 @@ bool QPulseAudioOutput::open() requestedBuffer.prebuf = (uint32_t)-1; requestedBuffer.tlength = m_bufferSize; - if (pa_stream_connect_playback(m_stream, m_device.data(), (m_bufferSize > 0) ? &requestedBuffer : NULL, (pa_stream_flags_t)0, &m_chVolume, NULL) < 0) { + if (pa_stream_connect_playback(m_stream, m_device.data(), (m_bufferSize > 0) ? &requestedBuffer : NULL, (pa_stream_flags_t)0, m_customVolumeRequired ? &m_chVolume : NULL, NULL) < 0) { qWarning() << "pa_stream_connect_playback() failed!"; pa_stream_unref(m_stream); m_stream = 0; @@ -636,6 +649,7 @@ void QPulseAudioOutput::setVolume(qreal vol) { if (vol >= 0.0 && vol <= 1.0) { if (!qFuzzyCompare(m_volume, vol)) { + m_customVolumeRequired = true; m_volume = vol; if (m_opened) { QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.h b/src/plugins/pulseaudio/qaudiooutput_pulse.h index fea151ba2..d6c7cffe3 100644 --- a/src/plugins/pulseaudio/qaudiooutput_pulse.h +++ b/src/plugins/pulseaudio/qaudiooutput_pulse.h @@ -142,6 +142,7 @@ private: QString m_category; qreal m_volume; + bool m_customVolumeRequired; pa_cvolume m_chVolume; pa_sample_spec m_spec; }; -- cgit v1.2.3