Resource policy support for QSoundEffect.
Since sound effects are something short and mixed with other audio, do not acquire resources explicitly. Follow the resources availability information to determine when it is ok to play the sound effects. When client has registered itself to resource manager, client's streams are classified properly. If no higher priority client has acquired the resources, isAvailable() is true, and sound effects can be played. We do not explicitly acquire the resources, since then other clients with the same resource class would lose the resources, thus not possible to have second client play music with QMediaPlayer class while our client would just want to play simple sound effects. Change-Id: Ib5589349dca6900a8bee616b8ad77e7cb5ec9533 Done-with: Juho Hämäläinen <juho.hamalainen@tieto.com> Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
This commit is contained in:
committed by
Robin Burchell
parent
5f33d7bea3
commit
e316aa6491
@@ -61,6 +61,9 @@
|
|||||||
#include <pulse/ext-stream-restore.h>
|
#include <pulse/ext-stream-restore.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <private/qmediaresourcepolicy_p.h>
|
||||||
|
#include <private/qmediaresourceset_p.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
//#define QT_PA_DEBUG
|
//#define QT_PA_DEBUG
|
||||||
@@ -388,10 +391,26 @@ QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent):
|
|||||||
m_runningCount(0),
|
m_runningCount(0),
|
||||||
m_reloadCategory(false),
|
m_reloadCategory(false),
|
||||||
m_sample(0),
|
m_sample(0),
|
||||||
m_position(0)
|
m_position(0),
|
||||||
|
m_resourcesAvailable(false)
|
||||||
{
|
{
|
||||||
m_ref = new QSoundEffectRef(this);
|
m_ref = new QSoundEffectRef(this);
|
||||||
pa_sample_spec_init(&m_pulseSpec);
|
pa_sample_spec_init(&m_pulseSpec);
|
||||||
|
|
||||||
|
m_resources = QMediaResourcePolicy::createResourceSet<QMediaPlayerResourceSetInterface>();
|
||||||
|
Q_ASSERT(m_resources);
|
||||||
|
m_resourcesAvailable = m_resources->isAvailable();
|
||||||
|
connect(m_resources, SIGNAL(availabilityChanged(bool)), SLOT(handleAvailabilityChanged(bool)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void QSoundEffectPrivate::handleAvailabilityChanged(bool available)
|
||||||
|
{
|
||||||
|
m_resourcesAvailable = available;
|
||||||
|
#ifdef DEBUG_RESOURCE
|
||||||
|
qDebug() << Q_FUNC_INFO << "Resource availability changed " << m_resourcesAvailable;
|
||||||
|
#endif
|
||||||
|
if (!m_resourcesAvailable)
|
||||||
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSoundEffectPrivate::release()
|
void QSoundEffectPrivate::release()
|
||||||
@@ -437,6 +456,8 @@ void QSoundEffectPrivate::setCategory(const QString &category)
|
|||||||
|
|
||||||
QSoundEffectPrivate::~QSoundEffectPrivate()
|
QSoundEffectPrivate::~QSoundEffectPrivate()
|
||||||
{
|
{
|
||||||
|
QMediaResourcePolicy::destroyResourceSet(m_resources);
|
||||||
|
m_resources = 0;
|
||||||
m_ref->release();
|
m_ref->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,6 +646,14 @@ void QSoundEffectPrivate::setLoopsRemaining(int loopsRemaining)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QSoundEffectPrivate::play()
|
void QSoundEffectPrivate::play()
|
||||||
|
{
|
||||||
|
if (!m_resourcesAvailable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
playAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QSoundEffectPrivate::playAvailable()
|
||||||
{
|
{
|
||||||
#ifdef QT_PA_DEBUG
|
#ifdef QT_PA_DEBUG
|
||||||
qDebug() << this << "play";
|
qDebug() << this << "play";
|
||||||
|
|||||||
@@ -62,6 +62,9 @@
|
|||||||
#include <pulse/pulseaudio.h>
|
#include <pulse/pulseaudio.h>
|
||||||
#include "qsamplecache_p.h"
|
#include "qsamplecache_p.h"
|
||||||
|
|
||||||
|
#include <private/qmediaresourcepolicy_p.h>
|
||||||
|
#include <private/qmediaresourceset_p.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QSoundEffectRef;
|
class QSoundEffectRef;
|
||||||
@@ -119,7 +122,10 @@ private Q_SLOTS:
|
|||||||
void updateVolume();
|
void updateVolume();
|
||||||
void updateMuted();
|
void updateMuted();
|
||||||
|
|
||||||
|
void handleAvailabilityChanged(bool available);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void playAvailable();
|
||||||
void playSample();
|
void playSample();
|
||||||
|
|
||||||
void emptyStream();
|
void emptyStream();
|
||||||
@@ -164,6 +170,17 @@ private:
|
|||||||
QSample *m_sample;
|
QSample *m_sample;
|
||||||
int m_position;
|
int m_position;
|
||||||
QSoundEffectRef *m_ref;
|
QSoundEffectRef *m_ref;
|
||||||
|
|
||||||
|
enum ResourceStatus {
|
||||||
|
NoResources,
|
||||||
|
WaitingResources,
|
||||||
|
GrantedResources,
|
||||||
|
DeniedResources
|
||||||
|
};
|
||||||
|
ResourceStatus m_resourceStatus;
|
||||||
|
bool m_resourcesAvailable;
|
||||||
|
|
||||||
|
QMediaPlayerResourceSetInterface *m_resources;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
Reference in New Issue
Block a user