Add AudioEngine with new implementation
Change-Id: I5eebe662ecbce9814ed3e763db56df9be737d11f Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
@@ -93,13 +93,17 @@ QT_BEGIN_NAMESPACE
|
||||
\endcode
|
||||
*/
|
||||
|
||||
QSampleCache::QSampleCache()
|
||||
: m_networkAccessManager(0)
|
||||
QSampleCache::QSampleCache(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_networkAccessManager(0)
|
||||
, m_mutex(QMutex::Recursive)
|
||||
, m_capacity(0)
|
||||
, m_usage(0)
|
||||
, m_loadingRefCount(0)
|
||||
{
|
||||
m_loadingThread.setObjectName(QLatin1String("QSampleCache::LoadingThread"));
|
||||
connect(&m_loadingThread, SIGNAL(finished()), this, SIGNAL(isLoadingChanged()));
|
||||
connect(&m_loadingThread, SIGNAL(started()), this, SIGNAL(isLoadingChanged()));
|
||||
}
|
||||
|
||||
QNetworkAccessManager& QSampleCache::networkAccessManager()
|
||||
@@ -128,10 +132,31 @@ QSampleCache::~QSampleCache()
|
||||
delete m_networkAccessManager;
|
||||
}
|
||||
|
||||
void QSampleCache::loadingRelease()
|
||||
{
|
||||
QMutexLocker locker(&m_loadingMutex);
|
||||
m_loadingRefCount--;
|
||||
if (m_loadingRefCount == 0) {
|
||||
if (m_loadingThread.isRunning())
|
||||
m_loadingThread.exit();
|
||||
}
|
||||
}
|
||||
|
||||
bool QSampleCache::isLoading() const
|
||||
{
|
||||
return m_loadingThread.isRunning();
|
||||
}
|
||||
|
||||
QSample* QSampleCache::requestSample(const QUrl& url)
|
||||
{
|
||||
//lock and add first to make sure live loadingThread will not be killed during this function call
|
||||
m_loadingMutex.lock();
|
||||
m_loadingRefCount++;
|
||||
m_loadingMutex.unlock();
|
||||
|
||||
if (!m_loadingThread.isRunning())
|
||||
m_loadingThread.start();
|
||||
|
||||
#ifdef QT_SAMPLECACHE_DEBUG
|
||||
qDebug() << "QSampleCache: request sample [" << url << "]";
|
||||
#endif
|
||||
@@ -250,6 +275,8 @@ void QSample::loadIfNecessary()
|
||||
if (m_state == QSample::Error || m_state == QSample::Creating) {
|
||||
m_state = QSample::Loading;
|
||||
QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection);
|
||||
} else {
|
||||
qobject_cast<QSampleCache*>(m_parent)->loadingRelease();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,6 +394,7 @@ void QSample::decoderError()
|
||||
#endif
|
||||
cleanup();
|
||||
m_state = QSample::Error;
|
||||
qobject_cast<QSampleCache*>(m_parent)->loadingRelease();
|
||||
emit error();
|
||||
}
|
||||
|
||||
@@ -380,6 +408,7 @@ void QSample::onReady()
|
||||
m_audioFormat = m_waveDecoder->audioFormat();
|
||||
cleanup();
|
||||
m_state = QSample::Ready;
|
||||
qobject_cast<QSampleCache*>(m_parent)->loadingRelease();
|
||||
emit ready();
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class QSampleCache;
|
||||
class QWaveDecoder;
|
||||
|
||||
// Lives in application thread
|
||||
class QSample : public QObject
|
||||
class Q_MULTIMEDIA_EXPORT QSample : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -127,17 +127,23 @@ private:
|
||||
int m_ref;
|
||||
};
|
||||
|
||||
class QSampleCache
|
||||
class Q_MULTIMEDIA_EXPORT QSampleCache : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
friend class QSample;
|
||||
|
||||
QSampleCache();
|
||||
QSampleCache(QObject *parent = 0);
|
||||
~QSampleCache();
|
||||
|
||||
QSample* requestSample(const QUrl& url);
|
||||
void setCapacity(qint64 capacity);
|
||||
|
||||
bool isLoading() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void isLoadingChanged();
|
||||
|
||||
private:
|
||||
QMap<QUrl, QSample*> m_samples;
|
||||
QSet<QSample*> m_staleSamples;
|
||||
@@ -152,6 +158,10 @@ private:
|
||||
bool notifyUnreferencedSample(QSample* sample);
|
||||
void removeUnreferencedSample(QSample* sample);
|
||||
void unloadSample(QSample* sample);
|
||||
|
||||
void loadingRelease();
|
||||
int m_loadingRefCount;
|
||||
QMutex m_loadingMutex;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user