diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 7ee696693d..953da03d24 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -16,8 +16,9 @@ #include #include -#include #include +#include +#include #include #include #include @@ -43,7 +44,7 @@ Agent::Agent(NLPacket& packet) : DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false)) { DependencyManager::get()->setPacketSender(&_entityEditSender); - + auto assetClient = DependencyManager::set(); QThread* assetThread = new QThread; @@ -54,6 +55,8 @@ Agent::Agent(NLPacket& packet) : DependencyManager::set(); DependencyManager::set(); + + DependencyManager::set(); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); @@ -396,6 +399,9 @@ void Agent::aboutToFinish() { DependencyManager::destroy(); assetThread->quit(); assetThread->wait(); + + // cleanup the AudioInjectorManager (and any still running injectors) + DependencyManager::set(); } void Agent::sendPingRequests() { diff --git a/examples/tests/injectorTest.js b/examples/tests/injectorTest.js index d383b7ef9a..171186c91e 100644 --- a/examples/tests/injectorTest.js +++ b/examples/tests/injectorTest.js @@ -11,7 +11,7 @@ var soundURL = "http://hifi-public.s3.amazonaws.com/birarda/medium-crowd.wav"; var audioOptions = { - position: MyAvatar.position, + position: { x: 0.0, y: 0.0, z: 0.0 }, volume: 0.5 }; diff --git a/libraries/audio/src/AudioInjectorManager.cpp b/libraries/audio/src/AudioInjectorManager.cpp index a441f679d6..4770371e48 100644 --- a/libraries/audio/src/AudioInjectorManager.cpp +++ b/libraries/audio/src/AudioInjectorManager.cpp @@ -76,25 +76,28 @@ void AudioInjectorManager::run() { _injectorReady.wait_for(lock, std::chrono::microseconds(difference)); } - // loop through the injectors in the map and send whatever frames need to go out - auto front = _injectors.front(); - while (_injectors.size() > 0 && front.first <= usecTimestampNow()) { - // either way we're popping this injector off - get a copy first - auto injector = front.second; - _injectors.pop(); - - if (!injector.isNull()) { - // this is an injector that's ready to go, have it send a frame now - auto nextCallDelta = injector->injectNextFrame(); + if (_injectors.size() > 0) { + // loop through the injectors in the map and send whatever frames need to go out + auto front = _injectors.front(); + while (_injectors.size() > 0 && front.first <= usecTimestampNow()) { + // either way we're popping this injector off - get a copy first + auto injector = front.second; + _injectors.pop(); - if (nextCallDelta > 0 && !injector->isFinished()) { - // re-enqueue the injector with the correct timing - _injectors.push({ usecTimestampNow() + nextCallDelta, injector }); + if (!injector.isNull()) { + // this is an injector that's ready to go, have it send a frame now + auto nextCallDelta = injector->injectNextFrame(); + + if (nextCallDelta > 0 && !injector->isFinished()) { + // re-enqueue the injector with the correct timing + _injectors.push({ usecTimestampNow() + nextCallDelta, injector }); + } } + + front = _injectors.front(); } - - front = _injectors.front(); } + } else { // we have no current injectors, wait until we get at least one before we do anything _injectorReady.wait(lock); @@ -110,6 +113,11 @@ void AudioInjectorManager::run() { static const int MAX_INJECTORS_PER_THREAD = 50; // calculated based on AudioInjector while loop time, with sufficient padding bool AudioInjectorManager::threadInjector(AudioInjector* injector) { + if (_shouldStop) { + qDebug() << "AudioInjectorManager::threadInjector asked to thread injector but is shutting down."; + return false; + } + // guard the injectors vector with a mutex std::unique_lock lock(_injectorsMutex); @@ -140,12 +148,14 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) { } void AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) { - // guard the injectors vector with a mutex - std::unique_lock lock(_injectorsMutex); - - // add the injector to the queue with a send timestamp of now - _injectors.emplace(usecTimestampNow(), InjectorQPointer { injector }); - - // notify our wait condition so we can inject two frames for this injector immediately - _injectorReady.notify_one(); + if (!_shouldStop) { + // guard the injectors vector with a mutex + std::unique_lock lock(_injectorsMutex); + + // add the injector to the queue with a send timestamp of now + _injectors.emplace(usecTimestampNow(), InjectorQPointer { injector }); + + // notify our wait condition so we can inject two frames for this injector immediately + _injectorReady.notify_one(); + } }