diff options
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r-- | src/multimedia/audio/qaudio.cpp | 22 | ||||
-rw-r--r-- | src/multimedia/audio/qaudio.h | 2 | ||||
-rw-r--r-- | src/multimedia/audio/qsoundeffect_pulse_p.cpp | 48 | ||||
-rw-r--r-- | src/multimedia/audio/qsoundeffect_pulse_p.h | 5 |
4 files changed, 48 insertions, 29 deletions
diff --git a/src/multimedia/audio/qaudio.cpp b/src/multimedia/audio/qaudio.cpp index d4f89e898..dea9a05a5 100644 --- a/src/multimedia/audio/qaudio.cpp +++ b/src/multimedia/audio/qaudio.cpp @@ -79,13 +79,18 @@ Q_CONSTRUCTOR_FUNCTION(qRegisterAudioMetaTypes) /*! \enum QAudio::State - \value ActiveState Audio data is being processed, this state is set after start() is called - and while audio data is available to be processed. - \value SuspendedState The audio device is in a suspended state, this state will only be entered - after suspend() is called. - \value StoppedState The audio device is closed, and is not processing any audio data - \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state - is set after start() is called and while no audio data is available to be processed. + \value ActiveState Audio data is being processed, this state is set after start() is called + and while audio data is available to be processed. + \value SuspendedState The audio stream is in a suspended state. Entered after suspend() is called + or when another stream takes control of the audio device. In the later case, + a call to resume will return control of the audio device to this stream. This + should usually only be done upon user request. + \value StoppedState The audio device is closed, and is not processing any audio data + \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state + is set after start() is called and while no audio data is available to be processed. + \value InterruptedState This stream is in a suspended state because another higher priority stream currently + has control of the audio device. Playback cannot resume until the higher priority + stream relinquishes control of the audio device. */ /*! @@ -285,6 +290,9 @@ QDebug operator<<(QDebug dbg, QAudio::State state) case QAudio::IdleState: dbg << "IdleState"; break; + case QAudio::InterruptedState: + dbg << "InterruptedState"; + break; } return dbg; } diff --git a/src/multimedia/audio/qaudio.h b/src/multimedia/audio/qaudio.h index 1c38e9f35..2603d71d1 100644 --- a/src/multimedia/audio/qaudio.h +++ b/src/multimedia/audio/qaudio.h @@ -55,7 +55,7 @@ class QString; namespace QAudio { enum Error { NoError, OpenError, IOError, UnderrunError, FatalError }; - enum State { ActiveState, SuspendedState, StoppedState, IdleState }; + enum State { ActiveState, SuspendedState, StoppedState, IdleState, InterruptedState }; enum Mode { AudioInput, AudioOutput }; enum Role { diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.cpp b/src/multimedia/audio/qsoundeffect_pulse_p.cpp index a4861d2a9..981d4c01f 100644 --- a/src/multimedia/audio/qsoundeffect_pulse_p.cpp +++ b/src/multimedia/audio/qsoundeffect_pulse_p.cpp @@ -73,20 +73,23 @@ inline pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format) spec.rate = format.sampleRate(); spec.channels = format.channelCount(); - - if (format.sampleSize() == 8) - spec.format = PA_SAMPLE_U8; - else if (format.sampleSize() == 16) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S16BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S16LE; break; - } - } - else if (format.sampleSize() == 32) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S32BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S32LE; break; + spec.format = PA_SAMPLE_INVALID; + const bool isBigEndian = (format.byteOrder() == QAudioFormat::BigEndian); + + if (format.sampleType() == QAudioFormat::UnSignedInt) { + if (format.sampleSize() == 8) + spec.format = PA_SAMPLE_U8; + } else if (format.sampleType() == QAudioFormat::SignedInt) { + if (format.sampleSize() == 16) { + spec.format = isBigEndian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE; + } else if (format.sampleSize() == 24) { + spec.format = isBigEndian ? PA_SAMPLE_S24BE : PA_SAMPLE_S24LE; + } else if (format.sampleSize() == 32) { + spec.format = isBigEndian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE; } + } else if (format.sampleType() == QAudioFormat::Float) { + if (format.sampleSize() == 32) + spec.format = isBigEndian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE; } return spec; @@ -190,7 +193,11 @@ private Q_SLOTS: pa_context_set_state_callback(m_context, context_state_callback, this); - if (pa_context_connect(m_context, 0, (pa_context_flags_t)0, 0) < 0) { + const QByteArray srvStrEnv = qgetenv("QT_PULSE_SERVER_STRING"); + const char *srvStr = srvStrEnv.isNull() ? 0 : srvStrEnv.constData(); + pa_context_flags_t flags = qEnvironmentVariableIsSet("QT_PULSE_NOAUTOSPAWN") ? PA_CONTEXT_NOAUTOSPAWN : (pa_context_flags_t)0; + + if (pa_context_connect(m_context, srvStr, flags, 0) < 0) { qWarning("PulseAudioService: pa_context_connect() failed"); pa_context_unref(m_context); unlock(); @@ -529,31 +536,34 @@ void QSoundEffectPrivate::setLoopCount(int loopCount) qreal QSoundEffectPrivate::volume() const { - QReadLocker locker(&m_volumeLock); + QMutexLocker locker(&m_volumeLock); return m_volume; } void QSoundEffectPrivate::setVolume(qreal volume) { - QWriteLocker locker(&m_volumeLock); + QMutexLocker locker(&m_volumeLock); if (qFuzzyCompare(m_volume, volume)) return; m_volume = qBound(qreal(0), volume, qreal(1)); + locker.unlock(); emit volumeChanged(); } bool QSoundEffectPrivate::isMuted() const { - QReadLocker locker(&m_volumeLock); + QMutexLocker locker(&m_volumeLock); return m_muted; } void QSoundEffectPrivate::setMuted(bool muted) { - QWriteLocker locker(&m_volumeLock); + m_volumeLock.lock(); m_muted = muted; + m_volumeLock.unlock(); + emit mutedChanged(); } @@ -878,7 +888,7 @@ int QSoundEffectPrivate::writeToStream(const void *data, int size) if (size < 1) return 0; - m_volumeLock.lockForRead(); + m_volumeLock.lock(); qreal volume = m_muted ? 0 : m_volume; m_volumeLock.unlock(); pa_free_cb_t writeDoneCb = stream_write_done_callback; diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.h b/src/multimedia/audio/qsoundeffect_pulse_p.h index 7be88c55a..268a99326 100644 --- a/src/multimedia/audio/qsoundeffect_pulse_p.h +++ b/src/multimedia/audio/qsoundeffect_pulse_p.h @@ -56,7 +56,7 @@ #include <QtCore/qobject.h> #include <QtCore/qdatetime.h> -#include <QtCore/qreadwritelock.h> +#include <QtCore/qmutex.h> #include <qmediaplayer.h> #include <pulse/pulseaudio.h> #include "qsamplecache_p.h" @@ -175,7 +175,8 @@ private: bool m_resourcesAvailable; - mutable QReadWriteLock m_volumeLock; + // Protects volume while PuseAudio is accessing it + mutable QMutex m_volumeLock; QMediaPlayerResourceSetInterface *m_resources; }; |