m_elapsedTime(0),
m_processedBytes(0),
m_availableBuffers(BUFFER_COUNT),
- m_eventMask(SL_PLAYEVENT_HEADATEND)
+ m_eventMask(SL_PLAYEVENT_HEADATEND),
+ m_startRequiresInit(true)
{
#ifndef ANDROID
m_streamType = -1;
void QOpenSLESAudioOutput::start(QIODevice *device)
{
Q_ASSERT(device);
- destroyPlayer();
-
- m_pullMode = true;
-
if (!preparePlayer())
return;
+ m_pullMode = true;
m_audioSource = device;
setState(QAudio::ActiveState);
setError(QAudio::NoError);
// Change the state to playing.
// We need to do this after filling the buffers or processedBytes might get corrupted.
- if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
- setError(QAudio::FatalError);
- destroyPlayer();
- }
+ startPlayer();
}
QIODevice *QOpenSLESAudioOutput::start()
{
- destroyPlayer();
-
- m_pullMode = false;
-
if (!preparePlayer())
return Q_NULLPTR;
+ m_pullMode = false;
m_audioSource = new SLIODevicePrivate(this);
m_audioSource->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
// Change the state to playing
- if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
- setError(QAudio::FatalError);
- destroyPlayer();
- }
+ startPlayer();
setState(QAudio::IdleState);
return m_audioSource;
if (m_state == QAudio::StoppedState)
return;
- destroyPlayer();
+ stopPlayer();
setError(QAudio::NoError);
}
if (m_state != QAudio::StoppedState)
return;
+ m_startRequiresInit = true;
m_bufferSize = value;
}
void QOpenSLESAudioOutput::setFormat(const QAudioFormat &format)
{
+ m_startRequiresInit = true;
m_format = format;
}
return;
}
+ m_startRequiresInit = true;
m_streamType = streamType;
m_category = category;
#endif // ANDROID
bool QOpenSLESAudioOutput::preparePlayer()
{
+ if (m_startRequiresInit)
+ destroyPlayer();
+ else
+ return true;
+
SLEngineItf engine = QOpenSLESEngine::instance()->slEngine();
if (!engine) {
qWarning() << "No engine";
m_clockStamp.restart();
setError(QAudio::NoError);
+ m_startRequiresInit = false;
return true;
}
void QOpenSLESAudioOutput::destroyPlayer()
{
- setState(QAudio::StoppedState);
-
- // We need to change the state manually...
- if (m_playItf)
- (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_STOPPED);
-
- if (m_bufferQueueItf && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Clear(m_bufferQueueItf))
- qWarning() << "Unable to clear buffer";
+ if (m_state != QAudio::StoppedState)
+ stopPlayer();
if (m_playerObject) {
(*m_playerObject)->Destroy(m_playerObject);
m_playItf = Q_NULLPTR;
m_volumeItf = Q_NULLPTR;
m_bufferQueueItf = Q_NULLPTR;
+ m_startRequiresInit = true;
+}
+
+void QOpenSLESAudioOutput::stopPlayer()
+{
+ setState(QAudio::StoppedState);
+
+ // We need to change the state manually...
+ if (m_playItf)
+ (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_STOPPED);
+
+ if (m_bufferQueueItf && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Clear(m_bufferQueueItf))
+ qWarning() << "Unable to clear buffer";
+}
+
+void QOpenSLESAudioOutput::startPlayer()
+{
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ }
}
qint64 QOpenSLESAudioOutput::writeData(const char *data, qint64 len)