mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 07:43:57 +02:00
handle blocked AudioInjectorManager for restart
This commit is contained in:
parent
d764ff2e87
commit
ab5c8e072f
5 changed files with 22 additions and 16 deletions
|
@ -9,7 +9,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var soundURL = "atp:44a83a788ccfd2924e35c902c34808b24dbd0309d000299ce01a355f91cf8115.wav";
|
||||
var soundURL = "http://hifi-public.s3.amazonaws.com/birarda/medium-crowd.wav";
|
||||
var audioOptions = {
|
||||
position: MyAvatar.position,
|
||||
volume: 0.5
|
||||
|
|
|
@ -85,8 +85,17 @@ void AudioInjector::setupInjection() {
|
|||
}
|
||||
|
||||
void AudioInjector::restart() {
|
||||
// grab the AudioInjectorManager
|
||||
auto injectorManager = DependencyManager::get<AudioInjectorManager>();
|
||||
|
||||
if (thread() != QThread::currentThread()) {
|
||||
QMetaObject::invokeMethod(this, "restart");
|
||||
QMetaObject::invokeMethod(this, "restart");
|
||||
|
||||
if (!_options.localOnly) {
|
||||
// notify the AudioInjectorManager to wake up in case it's waiting for new injectors
|
||||
injectorManager->notifyInjectorReadyCondition();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -100,18 +109,16 @@ void AudioInjector::restart() {
|
|||
_shouldStop = false;
|
||||
_state = State::NotFinished;
|
||||
|
||||
qDebug() << "Emitting restartedWhileFinished to inject audio again to restart an injector";
|
||||
|
||||
// call inject audio to start injection over again
|
||||
setupInjection();
|
||||
|
||||
// if we're a local injector call inject locally to start injecting again
|
||||
if (_options.localOnly) {
|
||||
injectLocally();
|
||||
} else {
|
||||
// wake the AudioInjectorManager back up if it's stuck waiting
|
||||
injectorManager->restartFinishedInjector(this);
|
||||
}
|
||||
|
||||
// emit our restarted signal, for network injectors this allows the AudioInjectorManager to start considering us again
|
||||
emit restartedWhileFinished();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,15 +76,16 @@ public slots:
|
|||
|
||||
signals:
|
||||
void finished();
|
||||
void restartedWhileFinished();
|
||||
|
||||
void restarting();
|
||||
|
||||
private slots:
|
||||
void finish();
|
||||
|
||||
private:
|
||||
void setupInjection();
|
||||
uint64_t injectNextFrame();
|
||||
bool injectLocally();
|
||||
|
||||
void finish();
|
||||
|
||||
QByteArray _audioData;
|
||||
AudioInjectorOptions _options;
|
||||
std::atomic<State> _state { State::NotFinished };
|
||||
|
|
|
@ -117,7 +117,6 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
|||
injector->moveToThread(_thread);
|
||||
|
||||
// handle a restart once the injector has finished
|
||||
connect(injector, &AudioInjector::restartedWhileFinished, this, &AudioInjectorManager::restartFinishedInjector);
|
||||
|
||||
// add the injector to the queue with a send timestamp of now
|
||||
_injectors.emplace(usecTimestampNow(), InjectorQPointer { injector });
|
||||
|
@ -134,9 +133,7 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
|||
}
|
||||
}
|
||||
|
||||
void AudioInjectorManager::restartFinishedInjector() {
|
||||
auto injector = qobject_cast<AudioInjector*>(sender());
|
||||
|
||||
void AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) {
|
||||
// guard the injectors vector with a mutex
|
||||
std::unique_lock<std::mutex> lock(_injectorsMutex);
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ private slots:
|
|||
void run();
|
||||
private:
|
||||
bool threadInjector(AudioInjector* injector);
|
||||
void restartFinishedInjector();
|
||||
void restartFinishedInjector(AudioInjector* injector);
|
||||
void notifyInjectorReadyCondition() { _injectorReady.notify_one(); }
|
||||
|
||||
AudioInjectorManager() {};
|
||||
AudioInjectorManager(const AudioInjectorManager&) = delete;
|
||||
|
|
Loading…
Reference in a new issue