More thorough handling of VideoResourceType.

Add proper application pid for VideoResource upon resource object
creation. Also handle VideoResource when removing resource client.

Change-Id: I1c19c875c2d7d3d29aa9426b092081e3fdf47588
This commit is contained in:
Juho Hämäläinen
2015-03-04 12:09:42 +02:00
committed by Martin Jones
parent e9c2cce662
commit 9a188059eb

View File

@@ -127,25 +127,34 @@ void ResourcePolicyInt::removeClient(ResourcePolicyImpl *client)
#ifdef RESOURCE_DEBUG #ifdef RESOURCE_DEBUG
qDebug() << "##### Remove client " << client << " : " << i.value().id; qDebug() << "##### Remove client " << client << " : " << i.value().id;
#endif #endif
if (i.value().status == GrantedResource) // First release clients resources, if any
--m_acquired; release(client);
m_clients.erase(i);
if (i.value().videoEnabled) {
--m_video;
if (m_video == 0) {
m_resourceSet->deleteResource(ResourcePolicy::VideoPlaybackType);
m_resourceSet->update();
}
} }
if (m_acquired == 0 && m_status != Initial) { m_clients.erase(i);
#ifdef RESOURCE_DEBUG #ifdef RESOURCE_DEBUG
qDebug() << "##### Remove client, acquired = 0, release"; qDebug() << "##### Removed client " << client;
#endif #endif
m_resourceSet->release();
m_status = Initial;
} }
} }
bool ResourcePolicyInt::isVideoEnabled(const ResourcePolicyImpl *client) const bool ResourcePolicyInt::isVideoEnabled(const ResourcePolicyImpl *client) const
{ {
QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client); QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client);
if (i != m_clients.constEnd()) if (i != m_clients.constEnd()) {
#ifdef RESOURCE_DEBUG
qDebug() << "##### isVideoEnabled(" << i.value().id << ") -> " << i.value().videoEnabled;
#endif
return i.value().videoEnabled; return i.value().videoEnabled;
}
return false; return false;
} }
@@ -159,11 +168,17 @@ void ResourcePolicyInt::setVideoEnabled(const ResourcePolicyImpl *client, bool v
if (videoEnabled == i.value().videoEnabled) if (videoEnabled == i.value().videoEnabled)
return; return;
#ifdef RESOURCE_DEBUG
qDebug() << "##### setVideoEnabled(" << i.value().id << ", " << videoEnabled << ")";
#endif
if (videoEnabled) { if (videoEnabled) {
if (m_video > 0) { if (m_video > 0) {
i.value().videoEnabled = true; i.value().videoEnabled = true;
} else { } else {
m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType); ResourcePolicy::VideoResource *videoResource = new ResourcePolicy::VideoResource();
videoResource->setProcessID(QCoreApplication::applicationPid());
m_resourceSet->addResourceObject(videoResource);
update = true; update = true;
} }
++m_video; ++m_video;
@@ -177,7 +192,12 @@ void ResourcePolicyInt::setVideoEnabled(const ResourcePolicyImpl *client, bool v
} }
} }
if (update) #ifdef RESOURCE_DEBUG
qDebug() << "##### setVideoEnabled m_video " << m_video;
if (update) qDebug() << " Calling update()";
#endif
if (update && m_status != Initial)
m_resourceSet->update(); m_resourceSet->update();
} }