mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 11:33:44 +02:00
wait on AudioInjectors when shutting down interface
This commit is contained in:
parent
f8874daab6
commit
663167d684
5 changed files with 23 additions and 8 deletions
|
@ -451,7 +451,7 @@ Application::~Application() {
|
|||
_audio.thread()->wait();
|
||||
|
||||
// kill any audio injectors that are still around
|
||||
|
||||
AudioScriptingInterface::getInstance().stopAllInjectors();
|
||||
|
||||
_octreeProcessor.terminate();
|
||||
_voxelHideShowThread.terminate();
|
||||
|
|
|
@ -26,6 +26,7 @@ AudioInjector::AudioInjector(QObject* parent) :
|
|||
_sound(NULL),
|
||||
_options(),
|
||||
_shouldStop(false),
|
||||
_isFinished(false),
|
||||
_currentSendPosition(0)
|
||||
{
|
||||
}
|
||||
|
@ -34,6 +35,7 @@ AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorO
|
|||
_sound(sound),
|
||||
_options(injectorOptions),
|
||||
_shouldStop(false),
|
||||
_isFinished(false),
|
||||
_currentSendPosition(0)
|
||||
{
|
||||
}
|
||||
|
@ -161,5 +163,6 @@ void AudioInjector::injectAudio() {
|
|||
}
|
||||
}
|
||||
|
||||
_isFinished = true;
|
||||
emit finished();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
AudioInjector(QObject* parent);
|
||||
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||
|
||||
bool isFinished() const { return _isFinished; }
|
||||
int getCurrentSendPosition() const { return _currentSendPosition; }
|
||||
public slots:
|
||||
void injectAudio();
|
||||
|
@ -39,6 +40,7 @@ private:
|
|||
Sound* _sound;
|
||||
AudioInjectorOptions _options;
|
||||
bool _shouldStop;
|
||||
bool _isFinished;
|
||||
int _currentSendPosition;
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,18 @@ AudioScriptingInterface& AudioScriptingInterface::getInstance() {
|
|||
}
|
||||
|
||||
void AudioScriptingInterface::stopAllInjectors() {
|
||||
|
||||
QList<QPointer<AudioInjector> >::iterator injector = _activeInjectors.begin();
|
||||
while (injector != _activeInjectors.end()) {
|
||||
if (!injector->isNull()) {
|
||||
injector->data()->stop();
|
||||
|
||||
while (injector->data() && !injector->data()->isFinished()) {
|
||||
// wait for this injector to go down
|
||||
}
|
||||
}
|
||||
|
||||
injector = _activeInjectors.erase(injector);
|
||||
}
|
||||
}
|
||||
|
||||
AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
|
||||
|
@ -42,7 +53,7 @@ AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjec
|
|||
|
||||
injectorThread->start();
|
||||
|
||||
_activeInjectors.insert(injector);
|
||||
_activeInjectors.append(QPointer<AudioInjector>(injector));
|
||||
|
||||
return injector;
|
||||
}
|
||||
|
@ -58,8 +69,5 @@ bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) {
|
|||
}
|
||||
|
||||
void AudioScriptingInterface::injectorStopped() {
|
||||
qDebug() << "Removing" << sender() << "from active injectors";
|
||||
qDebug() << _activeInjectors.size();
|
||||
_activeInjectors.remove(static_cast<AudioInjector*>(sender()));
|
||||
qDebug() << _activeInjectors.size();
|
||||
_activeInjectors.removeAll(QPointer<AudioInjector>(reinterpret_cast<AudioInjector*>(sender())));
|
||||
}
|
|
@ -12,6 +12,8 @@
|
|||
#ifndef hifi_AudioScriptingInterface_h
|
||||
#define hifi_AudioScriptingInterface_h
|
||||
|
||||
#include <qpointer.h>
|
||||
|
||||
#include "AudioInjector.h"
|
||||
#include "Sound.h"
|
||||
|
||||
|
@ -32,7 +34,7 @@ public slots:
|
|||
|
||||
private:
|
||||
AudioScriptingInterface() {};
|
||||
QSet<AudioInjector*> _activeInjectors;
|
||||
QList< QPointer<AudioInjector> > _activeInjectors;
|
||||
|
||||
};
|
||||
#endif // hifi_AudioScriptingInterface_h
|
||||
|
|
Loading…
Reference in a new issue