diff options
author | Wolf Bergenheim <ext-wolf.2.bergenheim@nokia.com> | 2010-02-19 10:38:19 +0200 |
---|---|---|
committer | Wolf Bergenheim <ext-wolf.2.bergenheim@nokia.com> | 2010-02-19 10:38:19 +0200 |
commit | da47faf6b036220e32e7ce90210530ba5ef9dc2b (patch) | |
tree | 07f2911f41f1ca504f42419e75d332d1994727ae | |
parent | a36aef2b7c5128785a60213a6607191a8bfb1ecf (diff) |
implemented the 'audio' features
-rw-r--r-- | libresourceqt/include/qt4/policy/audio-resource.h | 5 | ||||
-rw-r--r-- | libresourceqt/include/qt4/policy/resource-set.h | 10 | ||||
-rw-r--r-- | libresourceqt/src/audio-resource.cpp | 7 | ||||
-rw-r--r-- | libresourceqt/src/resource-engine.cpp | 76 | ||||
-rw-r--r-- | libresourceqt/src/resource-engine.h | 6 | ||||
-rw-r--r-- | libresourceqt/src/resource-set.cpp | 72 | ||||
-rw-r--r-- | resourceqt-client/client.cpp | 12 | ||||
-rw-r--r-- | tests/test-resource-engine/test-resource-engine.cpp | 9 |
8 files changed, 84 insertions, 113 deletions
diff --git a/libresourceqt/include/qt4/policy/audio-resource.h b/libresourceqt/include/qt4/policy/audio-resource.h index 1ba5f5a..a1c8443 100644 --- a/libresourceqt/include/qt4/policy/audio-resource.h +++ b/libresourceqt/include/qt4/policy/audio-resource.h @@ -36,9 +36,8 @@ private: QString streamName; QString streamValue; signals: - void pidChanged(quint32 newPid); - void audioGroupChanged(const QString &newGroup); - void streamTagChanged(const QString &name, const QString &value); + void audioPropertiesChanged(const QString &group, quint32 pid, + const QString &name, const QString &value); }; } diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h index fff63d1..c6012c1 100644 --- a/libresourceqt/include/qt4/policy/resource-set.h +++ b/libresourceqt/include/qt4/policy/resource-set.h @@ -226,9 +226,7 @@ private: bool initialized; bool pendingAcquire; bool pendingUpdate; - bool pendingAudioGroup; - bool pendingAudioStream; - bool pendingAudioPid; + bool pendingAudioProperties; private slots: void connectedHandler(); @@ -238,9 +236,9 @@ private slots: void handleResourcesLost(quint32); void handleResourcesBecameAvailable(quint32); - void handleAudioPidChange(quint32 newPid); - void handleAudioGroupChange(const QString &newGroup); - void handleAudioStreamTagChanged(const QString &name, const QString &value); + void handleAudioPropertiesChanged(const QString &group, quint32 pid, + const QString &name, const QString &value); + }; } diff --git a/libresourceqt/src/audio-resource.cpp b/libresourceqt/src/audio-resource.cpp index b8c049f..f3c345e 100644 --- a/libresourceqt/src/audio-resource.cpp +++ b/libresourceqt/src/audio-resource.cpp @@ -41,7 +41,7 @@ void AudioResource::setAudioGroup(const QString &newGroup) qDebug("this = %p", this); group = newGroup; qDebug() << "Audio group changed! New group is: " << newGroup; - emit audioGroupChanged(group); + emit audioPropertiesChanged(group, pid, streamName, streamValue); } quint32 AudioResource::processID() const @@ -52,7 +52,8 @@ quint32 AudioResource::processID() const void AudioResource::setProcessID(quint32 newPID) { pid = newPID; - emit pidChanged(pid); + qDebug("New PID = %u", pid); + emit audioPropertiesChanged(group, pid, streamName, streamValue); } QString AudioResource::streamTagName() const @@ -78,7 +79,7 @@ void AudioResource::setStreamTag(const QString &name, const QString &value) { streamName = name; streamValue = value; - emit streamTagChanged(name, value); + emit audioPropertiesChanged(group, pid, name, value); } ResourceType AudioResource::type() const diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp index f788439..014d2cc 100644 --- a/libresourceqt/src/resource-engine.cpp +++ b/libresourceqt/src/resource-engine.cpp @@ -388,65 +388,43 @@ bool ResourceEngine::updateResources() return true; } -bool ResourceEngine::registerAudioPid(quint32 pid) +bool ResourceEngine::registerAudioProperties(const QString &audioGroup, quint32 pid, + const QString &name, const QString &value) { - if(pid == 0) - return false; - - resmsg_t message; - memset(&message, 0, sizeof(resmsg_t)); - - message.audio.pid = pid; - - qDebug("audio pid %u", pid); - return sendAudioMessage(&message); -} - -bool ResourceEngine::registerAudioStreamTag(const QString &name, const QString &value) -{ - if(name.isEmpty() || name.isNull() || value.isEmpty() || value.isNull()) - return false; - resmsg_t message; memset(&message, 0, sizeof(resmsg_t)); + QByteArray groupBa, nameBa, valueBa; - QByteArray nameBa = name.toLatin1(); - QByteArray valueBa = value.toLatin1(); - message.audio.property.name = nameBa.data(); - message.audio.property.match.method = resmsg_method_equals; - message.audio.property.match.pattern = valueBa.data(); - - qDebug() << "audio stream tag " << name << ":" << value; - return sendAudioMessage(&message); -} - -bool ResourceEngine::registerAudioGroup(const QString &audioGroup) -{ - if(audioGroup.isEmpty() || audioGroup.isNull()) - return false; - - resmsg_t message; - memset(&message, 0, sizeof(resmsg_t)); - - QByteArray ba = audioGroup.toLatin1(); - message.audio.group = ba.data(); - - qDebug() << "audio group " << audioGroup; - return sendAudioMessage(&message); -} + if (pid != 0) { + message.audio.pid = pid; + qDebug("audio pid %u", pid); + } + if (!audioGroup.isEmpty() && !audioGroup.isNull()) { + resmsg_audio_t *audio; + groupBa = audioGroup.toLatin1(); + message.audio.group = groupBa.data(); + qDebug("audio group: %s", message.audio.group); + audio = &message.audio; + } + if (!name.isEmpty() && !name.isNull() && !value.isEmpty() && !value.isNull()) { + nameBa = name.toLatin1(); + valueBa = value.toLatin1(); + message.audio.property.name = nameBa.data(); + message.audio.property.match.method = resmsg_method_equals; + message.audio.property.match.pattern = valueBa.data(); + qDebug("audio stream tag is %s:%s", message.audio.property.name, message.audio.property.match.pattern); + } -bool ResourceEngine::sendAudioMessage(resmsg_t *message) -{ - message->audio.type = RESMSG_AUDIO; - message->audio.id = resourceSet->id(); - message->audio.reqno = ++requestId; + message.audio.type = RESMSG_AUDIO; + message.audio.id = resourceSet->id(); + message.audio.reqno = ++requestId; - message->audio.type = RESMSG_AUDIO; + message.audio.type = RESMSG_AUDIO; messageMap.insert(requestId, RESMSG_AUDIO); qDebug("audio %u:%u", resourceSet->id(), requestId); - int success = resproto_send_message(libresourceSet, message, statusCallbackHandler); + int success = resproto_send_message(libresourceSet, &message, statusCallbackHandler); if(!success) return false; diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h index 594a20b..6caaef7 100644 --- a/libresourceqt/src/resource-engine.h +++ b/libresourceqt/src/resource-engine.h @@ -35,9 +35,8 @@ public: bool releaseResources(); bool updateResources(); - bool registerAudioPid(quint32 pid); - bool registerAudioStreamTag(const QString &name, const QString &value); - bool registerAudioGroup(const QString &); + bool registerAudioProperties(const QString &audioGroup, quint32 pid, + const QString &name, const QString &value); void handleConnectionIsUp(); @@ -69,7 +68,6 @@ private: QMap<quint32, resmsg_type_t> messageMap; quint32 connectionMode; - bool sendAudioMessage(resmsg_t *message); }; } diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp index 00a0293..8d2668b 100644 --- a/libresourceqt/src/resource-set.cpp +++ b/libresourceqt/src/resource-set.cpp @@ -7,7 +7,7 @@ ResourceSet::ResourceSet(const QString &applicationClass, QObject * parent) : QObject(parent), resourceClass(applicationClass), resourceEngine(NULL), audioResource(NULL), autoRelease(false), alwaysReply(false), initialized(false), pendingAcquire(false), pendingUpdate(false), - pendingAudioGroup(true), pendingAudioStream(true), pendingAudioPid(true) + pendingAudioProperties(false) { identifier = (quint32)this; memset(resourceSet, 0, sizeof(QPointer<Resource *>)*NumberOfTypes); @@ -57,18 +57,17 @@ void ResourceSet::addResource(Resource *resource) if (resource->type() == AudioPlaybackType) { qDebug("audioResource... %p", resource); audioResource = static_cast<AudioResource *>(resource); - QObject::connect(audioResource, SIGNAL(pidChanged(quint32)), - this, SLOT(handleAudioPidChange(quint32))); - QObject::connect(audioResource, SIGNAL(audioGroupChanged(const QString &)), - this, SLOT(handleAudioGroupChange(QString))); - QObject::connect(audioResource, SIGNAL(streamTagChanged(const QString &, const QString &)), - this, SLOT(handleAudioStreamTagChanged(const QString &, const QString &))); - if(audioResource->streamTagIsSet()) - pendingAudioStream = true; - if(audioResource->audioGroupIsSet()) - pendingAudioGroup = true; - if(audioResource->processID() > 0) - pendingAudioPid = true; + QObject::connect(audioResource, + SIGNAL(audioPropertiesChanged(const QString &, quint32, + const QString &, const QString &)), + this, + SLOT(handleAudioPropertiesChanged(const QString &, quint32, + const QString &, const QString &))); + if(audioResource->streamTagIsSet() || audioResource->audioGroupIsSet() || + (audioResource->processID() > 0)) + { + pendingAudioProperties = true; + } } delete resourceSet[resource->type()]; resourceSet[resource->type()] = resource; @@ -204,10 +203,16 @@ bool ResourceSet::alwaysGetReply() void ResourceSet::connectedHandler() { - if (pendingAudioGroup) { + if (pendingAudioProperties) { qDebug() << "registering audio group: " << audioResource->audioGroup(); - resourceEngine->registerAudioGroup(audioResource->audioGroup()); - pendingAudioGroup = false; + qDebug() << "registering PID: " << audioResource->processID(); + qDebug() << "registering audio stream: " << audioResource->streamTagName() + << ":" << audioResource->streamTagValue(); + resourceEngine->registerAudioProperties(audioResource->audioGroup(), + audioResource->processID(), + audioResource->streamTagName(), + audioResource->streamTagValue()); + pendingAudioProperties = false; } if (pendingUpdate) { resourceEngine->updateResources(); @@ -289,38 +294,17 @@ void ResourceSet::handleResourcesBecameAvailable(quint32 availableResources) emit resourcesBecameAvailable(listOfResources); } -void ResourceSet::handleAudioPidChange(quint32 newPid) -{ - qDebug("Audio renderer PID = %u", newPid); - if (initialized && resourceEngine->isConnectedToManager()) { - qDebug("registering new PID"); - resourceEngine->registerAudioPid(newPid); - } - else { - qDebug("registering PID later..."); - pendingAudioPid = true; - } -} - -void ResourceSet::handleAudioGroupChange(const QString &newGroup) +void ResourceSet::handleAudioPropertiesChanged(const QString &group, quint32 pid, + const QString &name, const QString &value) { - qDebug() << "Audio group changed to: " << newGroup; + qDebug() << "Audio group is: " << group; + qDebug("Audio renderer PID = %u", pid); if (initialized && resourceEngine->isConnectedToManager()) { - qDebug("registering new audio group"); - resourceEngine->registerAudioGroup(newGroup); + qDebug("registering new audio settings"); + resourceEngine->registerAudioProperties(group, pid, name, value); } else { qDebug("registering new audio group LATER"); - pendingAudioGroup = true; - } -} - -void ResourceSet::handleAudioStreamTagChanged(const QString &name, const QString &value) -{ - if (initialized && resourceEngine->isConnectedToManager()) { - resourceEngine->registerAudioStreamTag(name, value); - } - else { - pendingAudioStream = true; + pendingAudioProperties = true; } } diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp index 1ac9519..6b99ff5 100644 --- a/resourceqt-client/client.cpp +++ b/resourceqt-client/client.cpp @@ -352,7 +352,7 @@ void Client::timerEvent(QTimerEvent*) printf("\t update\tupdate modified resource set after add or remove command\n"); printf("\t add reslist [-o]\tadd reosurce list, if -o provided, set as optional\n"); printf("\t remove reslist [-o]\tremove reosurce list, if -o provided, removed only optional flag\n"); - printf("\t audio pid <pid>|group <audio group>|tag <name:value>\tset audio properties"); + printf("\t audio pid <pid> | group <audio group> | tag <name> <value>\tset audio properties"); printf("\t show \tshow resources\n"); } else if (params[0] == "show") { @@ -435,9 +435,10 @@ void Client::timerEvent(QTimerEvent*) audioResource->setAudioGroup(params[2]); } else if (params[1] == "pid") { - bool ok; + bool ok=false; quint32 pid = (quint32)params[2].toInt(&ok, 10); if (ok && pid != 0) { + qDebug("Setting audio PID to %u", pid); audioResource->setProcessID(pid); } else { @@ -445,7 +446,12 @@ void Client::timerEvent(QTimerEvent*) } } else if (params[1] == "tag") { - audioResource->setStreamTag(params[2]); + if (params.count() < 4) { + printf("tag requires TWO parameters name and value. See help \n"); + } + else { + audioResource->setStreamTag(params[2], params[3]); + } } else { printf("Unknown audio command!\n"); diff --git a/tests/test-resource-engine/test-resource-engine.cpp b/tests/test-resource-engine/test-resource-engine.cpp index b80beec..4e21d87 100644 --- a/tests/test-resource-engine/test-resource-engine.cpp +++ b/tests/test-resource-engine/test-resource-engine.cpp @@ -284,7 +284,7 @@ int resproto_send_message(resset_t *resourceSet, resmsg_t *message, replyMessage.type = RESMSG_GRANT; if (acquireShouldSucceed) { - replyMessage.notify.resrc = RESMSG_AUDIO_PLAYBACK | RESMSG_AUDIO_RECORDING + replyMessage.notify.resrc = RESMSG_AUDIO_PLAYBACK | RESMSG_AUDIO_RECORDING | RESMSG_VIDEO_PLAYBACK | RESMSG_VIDEO_RECORDING; } else { @@ -320,3 +320,10 @@ static void verify_resproto_send_message(resset_t *resourceSet, resmsg_t *messag } } +char *resmsg_dump_message(resmsg_t *resmsg, + int indent, + char *buf, + int len) +{ + return "message"; +}
\ No newline at end of file |