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