Showing the changes to libraries/script-engine/src/AudioScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -31,44 +31,41 @@ AudioScriptingInterface::AudioScriptingInterface() : · 30 unmodified lines | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | ScriptAudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) { | 33 | ScriptAudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) { |
| 34 | AudioInjector* injector = NULL; | 34 | if (QThread::currentThread() != thread()) { |
| 35 | QMetaObject::invokeMethod(this, "invokedPlaySound", Qt::BlockingQueuedConnection, | 35 | ScriptAudioInjector* injector = NULL; |
| 36 | Q_RETURN_ARG(AudioInjector*, injector), | 36 | |
| 37 | Q_ARG(Sound*, sound), Q_ARG(const AudioInjectorOptions&, injectorOptions)); | 37 | QMetaObject::invokeMethod(this, "playSound", Qt::BlockingQueuedConnection, |
| 38 | if (injector) { | 38 | Q_RETURN_ARG(ScriptAudioInjector*, injector), |
| 39 | return new ScriptAudioInjector(injector); | 39 | Q_ARG(Sound*, sound), Q_ARG(const AudioInjectorOptions&, injectorOptions)); |
| 40 | } else { | 40 | return injector; |
| 41 | return NULL; | ||
| 42 | } | 41 | } |
| 43 | } | 42 | |
| 44 | |||
| 45 | AudioInjector* AudioScriptingInterface::invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions) { | ||
| 46 | if (sound) { | 43 | if (sound) { |
| 47 | // stereo option isn't set from script, this comes from sound metadata or filename | 44 | // stereo option isn't set from script, this comes from sound metadata or filename |
| 48 | AudioInjectorOptions optionsCopy = injectorOptions; | 45 | AudioInjectorOptions optionsCopy = injectorOptions; |
| 49 | optionsCopy.stereo = sound->isStereo(); | 46 | optionsCopy.stereo = sound->isStereo(); |
| 50 | 47 | ||
| 51 | QThread* injectorThread = new QThread(); | 48 | QThread* injectorThread = new QThread(); |
| 52 | injectorThread->setObjectName("Audio Injector Thread"); | 49 | injectorThread->setObjectName("Audio Injector Thread"); |
| 53 | 50 | ||
| 54 | AudioInjector* injector = new AudioInjector(sound, optionsCopy); | 51 | AudioInjector* injector = new AudioInjector(sound, optionsCopy); |
| 55 | injector->setLocalAudioInterface(_localAudioInterface); | 52 | injector->setLocalAudioInterface(_localAudioInterface); |
| 56 | 53 | ||
| 57 | injector->moveToThread(injectorThread); | 54 | injector->moveToThread(injectorThread); |
| 58 | 55 | ||
| 59 | // start injecting when the injector thread starts | 56 | // start injecting when the injector thread starts |
| 60 | connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio); | 57 | connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio); |
| 61 | 58 | ||
| 62 | // connect the right slots and signals for AudioInjector and thread cleanup | 59 | // connect the right slots and signals for AudioInjector and thread cleanup |
| 63 | connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit); | 60 | connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit); |
| 64 | connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater); | 61 | connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater); |
| 65 | 62 | ||
| 66 | injectorThread->start(); | 63 | injectorThread->start(); |
| 67 | 64 | ||
| 68 | return injector; | 65 | return new ScriptAudioInjector(injector); |
| 69 | 66 | ||
| 70 | } else { | 67 | } else { |
| 71 | qDebug() << "AudioScriptingInterface::playSound called with null Sound object."; | 68 | qDebug() << "AudioScriptingInterface::playSound called with null Sound object."; |
| 72 | return NULL; | 69 | return NULL; |
| 73 | } | 70 | } |
| 74 | } | 71 | } |