[QSoundBuffer] Replace isReady() with state() states
The two-state "isReady" is not enough for checking if loading was already requested. This also makes it abvious we're accepting load() after error. Change-Id: I8181f99e8b36be484ec791862941b5b2ec78eb1f Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
@@ -58,7 +58,7 @@ StaticSoundBufferAL::StaticSoundBufferAL(QObject *parent, const QUrl &url, QSamp
|
|||||||
m_ref(1),
|
m_ref(1),
|
||||||
m_url(url),
|
m_url(url),
|
||||||
m_alBuffer(0),
|
m_alBuffer(0),
|
||||||
m_isReady(false),
|
m_state(Creating),
|
||||||
m_sample(0),
|
m_sample(0),
|
||||||
m_sampleLoader(sampleLoader)
|
m_sampleLoader(sampleLoader)
|
||||||
{
|
{
|
||||||
@@ -79,10 +79,19 @@ StaticSoundBufferAL::~StaticSoundBufferAL()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSoundBuffer::State StaticSoundBufferAL::state() const
|
||||||
|
{
|
||||||
|
return m_state;
|
||||||
|
}
|
||||||
|
|
||||||
void StaticSoundBufferAL::load()
|
void StaticSoundBufferAL::load()
|
||||||
{
|
{
|
||||||
if (m_sample)
|
if (m_state == Loading || m_state == Ready)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_state = Loading;
|
||||||
|
emit stateChanged(m_state);
|
||||||
|
|
||||||
m_sample = m_sampleLoader->requestSample(m_url);
|
m_sample = m_sampleLoader->requestSample(m_url);
|
||||||
connect(m_sample, SIGNAL(error()), this, SLOT(decoderError()));
|
connect(m_sample, SIGNAL(error()), this, SLOT(decoderError()));
|
||||||
connect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady()));
|
connect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady()));
|
||||||
@@ -98,11 +107,6 @@ void StaticSoundBufferAL::load()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StaticSoundBufferAL::isReady() const
|
|
||||||
{
|
|
||||||
return m_isReady;
|
|
||||||
}
|
|
||||||
|
|
||||||
void StaticSoundBufferAL::bindToSource(ALuint alSource)
|
void StaticSoundBufferAL::bindToSource(ALuint alSource)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_alBuffer != 0);
|
Q_ASSERT(m_alBuffer != 0);
|
||||||
@@ -162,7 +166,8 @@ void StaticSoundBufferAL::sampleReady()
|
|||||||
m_sample->release();
|
m_sample->release();
|
||||||
m_sample = 0;
|
m_sample = 0;
|
||||||
|
|
||||||
m_isReady = true;
|
m_state = Ready;
|
||||||
|
emit stateChanged(m_state);
|
||||||
emit ready();
|
emit ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +181,8 @@ void StaticSoundBufferAL::decoderError()
|
|||||||
m_sample->release();
|
m_sample->release();
|
||||||
m_sample = 0;
|
m_sample = 0;
|
||||||
|
|
||||||
|
m_state = Error;
|
||||||
|
emit stateChanged(m_state);
|
||||||
emit error();
|
emit error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,9 @@ public:
|
|||||||
StaticSoundBufferAL(QObject *parent, const QUrl &url, QSampleCache *sampleLoader);
|
StaticSoundBufferAL(QObject *parent, const QUrl &url, QSampleCache *sampleLoader);
|
||||||
~StaticSoundBufferAL();
|
~StaticSoundBufferAL();
|
||||||
|
|
||||||
|
State state() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void load() Q_DECL_OVERRIDE;
|
void load() Q_DECL_OVERRIDE;
|
||||||
bool isReady() const Q_DECL_OVERRIDE;
|
|
||||||
|
|
||||||
void bindToSource(ALuint alSource) Q_DECL_OVERRIDE;
|
void bindToSource(ALuint alSource) Q_DECL_OVERRIDE;
|
||||||
void unbindFromSource(ALuint alSource) Q_DECL_OVERRIDE;
|
void unbindFromSource(ALuint alSource) Q_DECL_OVERRIDE;
|
||||||
@@ -92,7 +93,7 @@ private:
|
|||||||
long m_ref;
|
long m_ref;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
ALuint m_alBuffer;
|
ALuint m_alBuffer;
|
||||||
bool m_isReady;
|
State m_state;
|
||||||
QSample *m_sample;
|
QSample *m_sample;
|
||||||
QSampleCache *m_sampleLoader;
|
QSampleCache *m_sampleLoader;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ bool QDeclarativeAudioSample::isLoaded() const
|
|||||||
{
|
{
|
||||||
if (!m_soundBuffer)
|
if (!m_soundBuffer)
|
||||||
return false;
|
return false;
|
||||||
return m_soundBuffer->isReady();
|
return m_soundBuffer->state() == QSoundBuffer::Ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -163,13 +163,12 @@ bool QDeclarativeAudioSample::isLoaded() const
|
|||||||
*/
|
*/
|
||||||
void QDeclarativeAudioSample::load()
|
void QDeclarativeAudioSample::load()
|
||||||
{
|
{
|
||||||
if (isLoaded())
|
|
||||||
return;
|
|
||||||
if (!m_soundBuffer) {
|
if (!m_soundBuffer) {
|
||||||
m_preloaded = true;
|
m_preloaded = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_soundBuffer->load();
|
if (m_soundBuffer->state() != QSoundBuffer::Loading && m_soundBuffer->state() != QSoundBuffer::Ready)
|
||||||
|
m_soundBuffer->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QDeclarativeAudioSample::setPreloaded(bool preloaded)
|
void QDeclarativeAudioSample::setPreloaded(bool preloaded)
|
||||||
@@ -218,7 +217,7 @@ void QDeclarativeAudioSample::init()
|
|||||||
} else {
|
} else {
|
||||||
m_soundBuffer =
|
m_soundBuffer =
|
||||||
qobject_cast<QDeclarativeAudioEngine*>(parent())->engine()->getStaticSoundBuffer(m_url);
|
qobject_cast<QDeclarativeAudioEngine*>(parent())->engine()->getStaticSoundBuffer(m_url);
|
||||||
if (m_soundBuffer->isReady()) {
|
if (m_soundBuffer->state() == QSoundBuffer::Ready) {
|
||||||
emit loadedChanged();
|
emit loadedChanged();
|
||||||
} else {
|
} else {
|
||||||
connect(m_soundBuffer, SIGNAL(ready()), this, SIGNAL(loadedChanged()));
|
connect(m_soundBuffer, SIGNAL(ready()), this, SIGNAL(loadedChanged()));
|
||||||
|
|||||||
@@ -41,11 +41,22 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QSoundBuffer : public QObject
|
class QSoundBuffer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool isReady() const = 0;
|
enum State
|
||||||
|
{
|
||||||
|
Creating,
|
||||||
|
Loading,
|
||||||
|
Error,
|
||||||
|
Ready
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual State state() const = 0;
|
||||||
|
|
||||||
virtual void load() = 0;
|
virtual void load() = 0;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
void stateChanged(State state);
|
||||||
void ready();
|
void ready();
|
||||||
void error();
|
void error();
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ void QSoundInstance::prepareNewVariation()
|
|||||||
detach();
|
detach();
|
||||||
|
|
||||||
m_bindBuffer = playVar->sampleObject()->soundBuffer();
|
m_bindBuffer = playVar->sampleObject()->soundBuffer();
|
||||||
if (m_bindBuffer->isReady()) {
|
if (m_bindBuffer->state() == QSoundBuffer::Ready) {
|
||||||
Q_ASSERT(m_soundSource);
|
Q_ASSERT(m_soundSource);
|
||||||
m_soundSource->bindBuffer(m_bindBuffer);
|
m_soundSource->bindBuffer(m_bindBuffer);
|
||||||
m_isReady = true;
|
m_isReady = true;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ void QSoundSourcePrivate::release()
|
|||||||
void QSoundSourcePrivate::bindBuffer(QSoundBuffer* soundBuffer)
|
void QSoundSourcePrivate::bindBuffer(QSoundBuffer* soundBuffer)
|
||||||
{
|
{
|
||||||
unbindBuffer();
|
unbindBuffer();
|
||||||
Q_ASSERT(soundBuffer->isReady());
|
Q_ASSERT(soundBuffer->state() == QSoundBuffer::Ready);
|
||||||
m_bindBuffer = qobject_cast<QSoundBufferPrivateAL*>(soundBuffer);
|
m_bindBuffer = qobject_cast<QSoundBufferPrivateAL*>(soundBuffer);
|
||||||
m_bindBuffer->bindToSource(m_alSource);
|
m_bindBuffer->bindToSource(m_alSource);
|
||||||
m_isReady = true;
|
m_isReady = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user