From 67050f5cd22629df4580ee1d70b40c9422acbc9c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 25 Oct 2013 10:34:58 -0700 Subject: [PATCH] fix Assignment ctor from data to properly parse payload --- assignment-client/src/Agent.cpp | 33 ++++++++++++++--------------- domain-server/src/DomainServer.cpp | 2 +- libraries/shared/src/Assignment.cpp | 3 ++- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 5b778b0552..baf04372d2 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -159,26 +159,25 @@ void Agent::run() { // find the audio-mixer in the NodeList so we can inject audio at it Node* audioMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); + if (audioMixer && audioMixer->getActiveSocket()) { emit willSendAudioDataCallback(); + } + + int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * INJECT_INTERVAL_USECS) - usecTimestampNow(); + if (usecToSleep > 0) { + usleep(usecToSleep); + } + + if (audioMixer && audioMixer->getActiveSocket() && scriptedAudioInjector.hasSamplesToInject()) { + // we have an audio mixer and samples to inject, send those off + scriptedAudioInjector.injectAudio(NodeList::getInstance()->getNodeSocket(), audioMixer->getActiveSocket()); - if (scriptedAudioInjector.hasSamplesToInject()) { - int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * INJECT_INTERVAL_USECS) - usecTimestampNow(); - if (usecToSleep > 0) { - usleep(usecToSleep); - } - - scriptedAudioInjector.injectAudio(NodeList::getInstance()->getNodeSocket(), audioMixer->getActiveSocket()); - - // clear out the audio injector so that it doesn't re-send what we just sent - scriptedAudioInjector.clear(); - } - } else if (audioMixer) { - int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * INJECT_INTERVAL_USECS) - usecTimestampNow(); - if (usecToSleep > 0) { - usleep(usecToSleep); - } - + // clear out the audio injector so that it doesn't re-send what we just sent + scriptedAudioInjector.clear(); + } + + if (audioMixer && !audioMixer->getActiveSocket()) { // don't have an active socket for the audio-mixer, ping it now NodeList::getInstance()->pingPublicAndLocalSocketsForInactiveNode(audioMixer); } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 8f02c30b4c..d91d020a22 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -724,7 +724,7 @@ int DomainServer::run() { Assignment* assignmentToDeploy = deployableAssignmentForRequest(requestAssignment); if (assignmentToDeploy) { - + // give this assignment out, either the type matches or the requestor said they will take any int numHeaderBytes = populateTypeAndVersion(broadcastPacket, PACKET_TYPE_CREATE_ASSIGNMENT); int numAssignmentBytes = assignmentToDeploy->packToBuffer(broadcastPacket + numHeaderBytes); diff --git a/libraries/shared/src/Assignment.cpp b/libraries/shared/src/Assignment.cpp index 223488e4c5..07e96e4963 100644 --- a/libraries/shared/src/Assignment.cpp +++ b/libraries/shared/src/Assignment.cpp @@ -90,6 +90,7 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) : if (dataBuffer[numBytesRead] != '\0') { // read the pool from the data buffer setPool((const char*) dataBuffer + numBytesRead); + numBytesRead += strlen(_pool) + sizeof('\0'); } else { // skip past the null pool and null out our pool setPool(NULL); @@ -192,7 +193,7 @@ int Assignment::packToBuffer(unsigned char* buffer) { numPackedBytes += NUM_BYTES_RFC4122_UUID; } - if (_pool) { + if (hasPool()) { // pack the pool for this assignment, it exists int numBytesNullTerminatedPool = strlen(_pool) + sizeof('\0'); memcpy(buffer + numPackedBytes, _pool, numBytesNullTerminatedPool);