Fix for QSoundEffect crash bug

When multiple QSoundEffect instances play the same wav source file
simultaneously, the system would crash due to some instances not
waiting for the underlying pulse audio stream to complete its
setup logic. QSoundEffect now waits for the stream to attain the
correct state before playing the sound.

Change-Id: Ib5a1e6bc3f1cc314054f9cdc89c10100ad546721
Reviewed-by: Ling Hu <ling.hu@nokia.com>
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
Mithra Pattison
2012-01-06 12:54:26 +10:00
committed by Qt by Nokia
parent 6b67a11032
commit 13d75ce063
3 changed files with 3 additions and 2 deletions

View File

@@ -567,7 +567,7 @@ void QSoundEffectPrivate::play()
return; return;
PulseDaemonLocker locker; PulseDaemonLocker locker;
if (!m_sampleReady || !m_pulseStream || m_stopping || m_emptying) { if (!m_pulseStream || m_status != QSoundEffect::Ready || m_stopping || m_emptying) {
#ifdef QT_PA_DEBUG #ifdef QT_PA_DEBUG
qDebug() << this << "play deferred"; qDebug() << this << "play deferred";
#endif #endif
@@ -794,6 +794,7 @@ void QSoundEffectPrivate::playSample()
qDebug() << this << "playSample"; qDebug() << this << "playSample";
#endif #endif
Q_ASSERT(m_pulseStream); Q_ASSERT(m_pulseStream);
Q_ASSERT(pa_stream_get_state(m_pulseStream) == PA_STREAM_READY);
pa_operation_unref(pa_stream_cork(m_pulseStream, 0, 0, 0)); pa_operation_unref(pa_stream_cork(m_pulseStream, 0, 0, 0));
} }

View File

@@ -123,7 +123,7 @@ void tst_QSound::testStop()
void tst_QSound::testStaticPlay() void tst_QSound::testStaticPlay()
{ {
// Check that you hear sound with static play also. // Check that you hear sound with static play also.
const QString testFileName = QStringLiteral("test2.wav"); const QString testFileName = QStringLiteral("test.wav");
const QString fullPath = QFINDTESTDATA(testFileName); const QString fullPath = QFINDTESTDATA(testFileName);
QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName)); QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName));