From a6e0dd525a90733519fe0121e75595419cbaff79 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Tue, 11 Mar 2014 12:31:34 +0100 Subject: OpenSL ES: lazy initialization of QAudioInput's supported formats. Change-Id: I51cdd35a944c990ce7df999bcb6063342e98c62d Reviewed-by: Christian Stromme --- src/plugins/opensles/qopenslesengine.cpp | 14 ++++++++++---- src/plugins/opensles/qopenslesengine.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/plugins/opensles') diff --git a/src/plugins/opensles/qopenslesengine.cpp b/src/plugins/opensles/qopenslesengine.cpp index 056b51e26..68c324f67 100644 --- a/src/plugins/opensles/qopenslesengine.cpp +++ b/src/plugins/opensles/qopenslesengine.cpp @@ -55,6 +55,7 @@ Q_GLOBAL_STATIC(QOpenSLESEngine, openslesEngine); QOpenSLESEngine::QOpenSLESEngine() : m_engineObject(0) , m_engine(0) + , m_checkedInputFormats(false) { SLresult result; @@ -66,8 +67,6 @@ QOpenSLESEngine::QOpenSLESEngine() result = (*m_engineObject)->GetInterface(m_engineObject, SL_IID_ENGINE, &m_engine); CheckError("Failed to get engine interface"); - - checkSupportedInputFormats(); } QOpenSLESEngine::~QOpenSLESEngine() @@ -118,15 +117,20 @@ QList QOpenSLESEngine::availableDevices(QAudio::Mode mode) const QList QOpenSLESEngine::supportedChannelCounts(QAudio::Mode mode) const { - if (mode == QAudio::AudioInput) + if (mode == QAudio::AudioInput) { + if (!m_checkedInputFormats) + const_cast(this)->checkSupportedInputFormats(); return m_supportedInputChannelCounts; - else + } else { return QList() << 1 << 2; + } } QList QOpenSLESEngine::supportedSampleRates(QAudio::Mode mode) const { if (mode == QAudio::AudioInput) { + if (!m_checkedInputFormats) + const_cast(this)->checkSupportedInputFormats(); return m_supportedInputSampleRates; } else { return QList() << 8000 << 11025 << 12000 << 16000 << 22050 @@ -177,6 +181,8 @@ void QOpenSLESEngine::checkSupportedInputFormats() if (inputFormatIsSupported(format)) m_supportedInputChannelCounts.append(2); } + + m_checkedInputFormats = true; } bool QOpenSLESEngine::inputFormatIsSupported(SLDataFormat_PCM format) diff --git a/src/plugins/opensles/qopenslesengine.h b/src/plugins/opensles/qopenslesengine.h index 9f12ac65d..81d1f665b 100644 --- a/src/plugins/opensles/qopenslesengine.h +++ b/src/plugins/opensles/qopenslesengine.h @@ -75,6 +75,7 @@ private: QList m_supportedInputChannelCounts; QList m_supportedInputSampleRates; + bool m_checkedInputFormats; }; QT_END_NAMESPACE -- cgit v1.2.3