repair AudioInjector threading

This commit is contained in:
Stephen Birarda 2014-01-02 13:35:56 -08:00
parent 3a45fb8533
commit 8cc4a33ad3
2 changed files with 11 additions and 7 deletions

View file

@ -19,6 +19,7 @@
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
_thread(NULL),
_sound(sound),
_volume(injectorOptions.volume),
_shouldLoopback(injectorOptions.shouldLoopback),
@ -26,21 +27,24 @@ AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions)
_orientation(injectorOptions.orientation),
_loopbackAudioInterface(injectorOptions.loopbackAudioInterface)
{
_thread = new QThread();
// we want to live on our own thread
moveToThread(&_thread);
moveToThread(_thread);
}
void AudioInjector::threadSound(Sound* sound, AudioInjectorOptions injectorOptions) {
AudioInjector injector(sound, injectorOptions);
AudioInjector* injector = new AudioInjector(sound, injectorOptions);
// start injecting when the injector thread starts
connect(&injector._thread, SIGNAL(started()), &injector, SLOT(injectAudio()));
connect(injector->_thread, SIGNAL(started()), injector, SLOT(injectAudio()));
// connect the right slots and signals so that the AudioInjector is killed once the injection is complete
connect(&injector, SIGNAL(finished()), &injector._thread, SLOT(quit()));
connect(&injector, SIGNAL(finished()), &injector, SLOT(deleteLater()));
connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater()));
connect(injector, SIGNAL(finished()), injector->_thread, SLOT(quit()));
connect(injector->_thread, SIGNAL(finished()), injector->_thread, SLOT(deleteLater()));
injector._thread.start();
injector->_thread->start();
}
const uchar MAX_INJECTOR_VOLUME = 0xFF;

View file

@ -40,7 +40,7 @@ public:
private:
AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions);
QThread _thread;
QThread* _thread;
Sound* _sound;
float _volume;
uchar _shouldLoopback;