Only call pa_cvolme set on stream creation if volume explicitly set.
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 <juho.hamalainen@tieto.com> Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
This commit is contained in:
committed by
Robin Burchell
parent
1c5ea9561a
commit
5f33d7bea3
@@ -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();
|
||||
|
||||
@@ -142,6 +142,7 @@ private:
|
||||
QString m_category;
|
||||
|
||||
qreal m_volume;
|
||||
bool m_customVolumeRequired;
|
||||
pa_cvolume m_chVolume;
|
||||
pa_sample_spec m_spec;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user