diff --git a/libraries/audio/src/AudioInjectorManager.cpp b/libraries/audio/src/AudioInjectorManager.cpp index 2327bda0e7..f6f4dc58bf 100644 --- a/libraries/audio/src/AudioInjectorManager.cpp +++ b/libraries/audio/src/AudioInjectorManager.cpp @@ -79,6 +79,11 @@ void AudioInjectorManager::run() { if (_injectors.size() > 0) { // loop through the injectors in the map and send whatever frames need to go out auto front = _injectors.top(); + + // create an InjectorQueue to hold injectors to be queued + // this allows us to call processEvents even if a single injector wants to be re-queued immediately + InjectorQueue holdingQueue; + while (_injectors.size() > 0 && front.first <= usecTimestampNow()) { // either way we're popping this injector off - get a copy first auto injector = front.second; @@ -89,8 +94,8 @@ void AudioInjectorManager::run() { auto nextCallDelta = injector->injectNextFrame(); if (nextCallDelta >= 0 && !injector->isFinished()) { - // re-enqueue the injector with the correct timing - _injectors.emplace(usecTimestampNow() + nextCallDelta, injector); + // enqueue the injector with the correct timing in our holding queue + holdingQueue.emplace(usecTimestampNow() + nextCallDelta, injector); } } @@ -101,6 +106,12 @@ void AudioInjectorManager::run() { break; } } + + // if there are injectors in the holding queue, push them to our persistent queue now + while (!holdingQueue.empty()) { + _injectors.push(holdingQueue.top()); + holdingQueue.pop(); + } } } else {