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*"); int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) : AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
_thread(NULL),
_sound(sound), _sound(sound),
_volume(injectorOptions.volume), _volume(injectorOptions.volume),
_shouldLoopback(injectorOptions.shouldLoopback), _shouldLoopback(injectorOptions.shouldLoopback),
@ -26,21 +27,24 @@ AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions)
_orientation(injectorOptions.orientation), _orientation(injectorOptions.orientation),
_loopbackAudioInterface(injectorOptions.loopbackAudioInterface) _loopbackAudioInterface(injectorOptions.loopbackAudioInterface)
{ {
_thread = new QThread();
// we want to live on our own thread // we want to live on our own thread
moveToThread(&_thread); moveToThread(_thread);
} }
void AudioInjector::threadSound(Sound* sound, AudioInjectorOptions injectorOptions) { void AudioInjector::threadSound(Sound* sound, AudioInjectorOptions injectorOptions) {
AudioInjector injector(sound, injectorOptions); AudioInjector* injector = new AudioInjector(sound, injectorOptions);
// start injecting when the injector thread starts // 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 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; const uchar MAX_INJECTOR_VOLUME = 0xFF;

View file

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