OpenSL ES: lazy initialization of QAudioInput's supported formats.

Change-Id: I51cdd35a944c990ce7df999bcb6063342e98c62d
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
Yoann Lopes
2014-03-11 12:31:34 +01:00
committed by The Qt Project
parent c24c3b171f
commit a6e0dd525a
2 changed files with 11 additions and 4 deletions

View File

@@ -55,6 +55,7 @@ Q_GLOBAL_STATIC(QOpenSLESEngine, openslesEngine);
QOpenSLESEngine::QOpenSLESEngine() QOpenSLESEngine::QOpenSLESEngine()
: m_engineObject(0) : m_engineObject(0)
, m_engine(0) , m_engine(0)
, m_checkedInputFormats(false)
{ {
SLresult result; SLresult result;
@@ -66,8 +67,6 @@ QOpenSLESEngine::QOpenSLESEngine()
result = (*m_engineObject)->GetInterface(m_engineObject, SL_IID_ENGINE, &m_engine); result = (*m_engineObject)->GetInterface(m_engineObject, SL_IID_ENGINE, &m_engine);
CheckError("Failed to get engine interface"); CheckError("Failed to get engine interface");
checkSupportedInputFormats();
} }
QOpenSLESEngine::~QOpenSLESEngine() QOpenSLESEngine::~QOpenSLESEngine()
@@ -118,15 +117,20 @@ QList<QByteArray> QOpenSLESEngine::availableDevices(QAudio::Mode mode) const
QList<int> QOpenSLESEngine::supportedChannelCounts(QAudio::Mode mode) const QList<int> QOpenSLESEngine::supportedChannelCounts(QAudio::Mode mode) const
{ {
if (mode == QAudio::AudioInput) if (mode == QAudio::AudioInput) {
if (!m_checkedInputFormats)
const_cast<QOpenSLESEngine *>(this)->checkSupportedInputFormats();
return m_supportedInputChannelCounts; return m_supportedInputChannelCounts;
else } else {
return QList<int>() << 1 << 2; return QList<int>() << 1 << 2;
}
} }
QList<int> QOpenSLESEngine::supportedSampleRates(QAudio::Mode mode) const QList<int> QOpenSLESEngine::supportedSampleRates(QAudio::Mode mode) const
{ {
if (mode == QAudio::AudioInput) { if (mode == QAudio::AudioInput) {
if (!m_checkedInputFormats)
const_cast<QOpenSLESEngine *>(this)->checkSupportedInputFormats();
return m_supportedInputSampleRates; return m_supportedInputSampleRates;
} else { } else {
return QList<int>() << 8000 << 11025 << 12000 << 16000 << 22050 return QList<int>() << 8000 << 11025 << 12000 << 16000 << 22050
@@ -177,6 +181,8 @@ void QOpenSLESEngine::checkSupportedInputFormats()
if (inputFormatIsSupported(format)) if (inputFormatIsSupported(format))
m_supportedInputChannelCounts.append(2); m_supportedInputChannelCounts.append(2);
} }
m_checkedInputFormats = true;
} }
bool QOpenSLESEngine::inputFormatIsSupported(SLDataFormat_PCM format) bool QOpenSLESEngine::inputFormatIsSupported(SLDataFormat_PCM format)

View File

@@ -75,6 +75,7 @@ private:
QList<int> m_supportedInputChannelCounts; QList<int> m_supportedInputChannelCounts;
QList<int> m_supportedInputSampleRates; QList<int> m_supportedInputSampleRates;
bool m_checkedInputFormats;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE