mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 16:14:01 +02:00
Extend the test for number of active injectors to apply to injector restarts.
This commit is contained in:
parent
04bd32e008
commit
5d9ee84e63
3 changed files with 26 additions and 11 deletions
|
@ -104,7 +104,9 @@ void AudioInjector::restart() {
|
|||
|
||||
// reset state to start sending from beginning again
|
||||
_nextFrame = 0;
|
||||
_frameTimer->invalidate();
|
||||
if (_frameTimer) {
|
||||
_frameTimer->invalidate();
|
||||
}
|
||||
_hasSentFirstFrame = false;
|
||||
|
||||
// check our state to decide if we need extra handling for the restart request
|
||||
|
@ -122,7 +124,9 @@ void AudioInjector::restart() {
|
|||
injectLocally();
|
||||
} else {
|
||||
// wake the AudioInjectorManager back up if it's stuck waiting
|
||||
injectorManager->restartFinishedInjector(this);
|
||||
if (!injectorManager->restartFinishedInjector(this)) {
|
||||
_state = State::Finished; // we're not playing, so reset the state used by isPlaying.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,16 @@ void AudioInjectorManager::run() {
|
|||
|
||||
static const int MAX_INJECTORS_PER_THREAD = 40; // calculated based on AudioInjector time to send frame, with sufficient padding
|
||||
|
||||
bool AudioInjectorManager::wouldExceedLimits() { // Should be called inside of a lock.
|
||||
if (_injectors.size() >= MAX_INJECTORS_PER_THREAD) {
|
||||
qDebug() << "AudioInjectorManager::threadInjector could not thread AudioInjector - at max of"
|
||||
<< MAX_INJECTORS_PER_THREAD << "current audio injectors.";
|
||||
return true;
|
||||
}
|
||||
qDebug() << "current injectors:" << _injectors.size();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
||||
if (_shouldStop) {
|
||||
qDebug() << "AudioInjectorManager::threadInjector asked to thread injector but is shutting down.";
|
||||
|
@ -138,8 +148,9 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
|||
// guard the injectors vector with a mutex
|
||||
Lock lock(_injectorsMutex);
|
||||
|
||||
// check if we'll be able to thread this injector (do we have < max concurrent injectors)
|
||||
if (_injectors.size() < MAX_INJECTORS_PER_THREAD) {
|
||||
if (wouldExceedLimits()) {
|
||||
return false;
|
||||
} else {
|
||||
if (!_thread) {
|
||||
createThread();
|
||||
}
|
||||
|
@ -156,23 +167,22 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
|||
_injectorReady.notify_one();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// unable to thread this injector, at the max
|
||||
qDebug() << "AudioInjectorManager::threadInjector could not thread AudioInjector - at max of"
|
||||
<< MAX_INJECTORS_PER_THREAD << "current audio injectors.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) {
|
||||
bool AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) {
|
||||
if (!_shouldStop) {
|
||||
// guard the injectors vector with a mutex
|
||||
Lock lock(_injectorsMutex);
|
||||
|
||||
if (wouldExceedLimits()) {
|
||||
return false;
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -50,8 +50,9 @@ private:
|
|||
using Lock = std::unique_lock<Mutex>;
|
||||
|
||||
bool threadInjector(AudioInjector* injector);
|
||||
void restartFinishedInjector(AudioInjector* injector);
|
||||
bool restartFinishedInjector(AudioInjector* injector);
|
||||
void notifyInjectorReadyCondition() { _injectorReady.notify_one(); }
|
||||
bool wouldExceedLimits();
|
||||
|
||||
AudioInjectorManager() {};
|
||||
AudioInjectorManager(const AudioInjectorManager&) = delete;
|
||||
|
|
Loading…
Reference in a new issue