diff --git a/assignment-client/src/AgentScriptingInterface.h b/assignment-client/src/AgentScriptingInterface.h index cd5aa5ad659..1146c4006ba 100644 --- a/assignment-client/src/AgentScriptingInterface.h +++ b/assignment-client/src/AgentScriptingInterface.h @@ -40,7 +40,7 @@ */ class AgentScriptingInterface : public QObject { Q_OBJECT - Q_PROPERTY(bool isAvatar READ isAvatar WRITE setIsAvatar) + Q_PROPERTY(bool isAvatar READ getIsAvatar WRITE setIsAvatar) Q_PROPERTY(bool isPlayingAvatarSound READ isPlayingAvatarSound) Q_PROPERTY(bool isListeningToAudioStream READ isListeningToAudioStream WRITE setIsListeningToAudioStream) Q_PROPERTY(bool isNoiseGateEnabled READ isNoiseGateEnabled WRITE setIsNoiseGateEnabled) @@ -77,15 +77,15 @@ public slots: /*@jsdoc * Checks whether the script is emulating an avatar. - * @function Agent.isAvatar + * @function Agent.getIsAvatar * @returns {boolean} true if the script is emulating an avatar, otherwise false. * @example Check whether the agent is emulating an avatar. * (function () { - * print("Agent is avatar: " + Agent.isAvatar()); + * print("Agent is avatar: " + Agent.getIsAvatar()); * print("Agent is avatar: " + Agent.isAvatar); // Same result. * }()); */ - bool isAvatar() const { return _agent->isAvatar(); } + bool getIsAvatar() const { return _agent->isAvatar(); } /*@jsdoc * Plays a sound from the position and with the orientation of the emulated avatar's head. No sound is played unless diff --git a/libraries/recording/src/recording/RecordingScriptingInterface.cpp b/libraries/recording/src/recording/RecordingScriptingInterface.cpp index 05cfa8b851e..c6c4d5cd244 100644 --- a/libraries/recording/src/recording/RecordingScriptingInterface.cpp +++ b/libraries/recording/src/recording/RecordingScriptingInterface.cpp @@ -38,27 +38,33 @@ using namespace recording; static const QString HFR_EXTENSION = "hfr"; RecordingScriptingInterface::RecordingScriptingInterface() { + Locker(_mutex); _player = DependencyManager::get(); _recorder = DependencyManager::get(); } bool RecordingScriptingInterface::isPlaying() const { + Locker(_mutex); return _player->isPlaying(); } bool RecordingScriptingInterface::isPaused() const { + Locker(_mutex); return _player->isPaused(); } float RecordingScriptingInterface::playerElapsed() const { + Locker(_mutex); return _player->position(); } float RecordingScriptingInterface::playerLength() const { + Locker(_mutex); return _player->length(); } void RecordingScriptingInterface::playClip(NetworkClipLoaderPointer clipLoader, const QString& url, const ScriptValue& callback) { + Locker(_mutex); _player->queueClip(clipLoader->getClip()); if (callback.isFunction()) { @@ -69,10 +75,7 @@ void RecordingScriptingInterface::playClip(NetworkClipLoaderPointer clipLoader, } void RecordingScriptingInterface::loadRecording(const QString& url, const ScriptValue& callback) { - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "loadRecording", Q_ARG(const QString&, url), Q_ARG(const ScriptValue&, callback)); - return; - } + Locker(_mutex); auto clipLoader = DependencyManager::get()->getClipLoader(url); @@ -131,15 +134,12 @@ void RecordingScriptingInterface::startPlaying() { return; } + Locker(_mutex); _player->play(); } void RecordingScriptingInterface::setPlayerVolume(float volume) { - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "setPlayerVolume", Q_ARG(float, volume)); - return; - } - + Locker(_mutex); _player->setVolume(std::min(std::max(volume, 0.0f), 1.0f)); } @@ -152,6 +152,8 @@ void RecordingScriptingInterface::setPlayerTime(float time) { BLOCKING_INVOKE_METHOD(this, "setPlayerTime", Q_ARG(float, time)); return; } + + Locker(_mutex); _player->seek(time); } @@ -160,11 +162,7 @@ void RecordingScriptingInterface::setPlayFromCurrentLocation(bool playFromCurren } void RecordingScriptingInterface::setPlayerLoop(bool loop) { - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "setPlayerLoop", Q_ARG(bool, loop)); - return; - } - + Locker(_mutex); _player->loop(loop); } @@ -185,10 +183,7 @@ void RecordingScriptingInterface::setPlayerUseSkeletonModel(bool useSkeletonMode } void RecordingScriptingInterface::pausePlayer() { - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "pausePlayer"); - return; - } + Locker(_mutex); _player->pause(); } @@ -197,6 +192,8 @@ void RecordingScriptingInterface::stopPlaying() { BLOCKING_INVOKE_METHOD(this, "stopPlaying"); return; } + + Locker(_mutex); _player->stop(); } @@ -214,11 +211,7 @@ void RecordingScriptingInterface::startRecording() { return; } - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "startRecording"); - return; - } - + Locker(_mutex); _recorder->start(); } @@ -228,11 +221,7 @@ void RecordingScriptingInterface::stopRecording() { return; } - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "stopRecording"); - return; - } - + Locker(_mutex); _recorder->stop(); _lastClip = _recorder->getClip(); _lastClip->seek(0); @@ -247,12 +236,7 @@ QString RecordingScriptingInterface::getDefaultRecordingSaveDirectory() { } void RecordingScriptingInterface::saveRecording(const QString& filename) { - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "saveRecording", - Q_ARG(QString, filename)); - return; - } - + Locker(_mutex); if (!_lastClip) { qWarning() << "There is no recording to save"; return; @@ -267,14 +251,7 @@ bool RecordingScriptingInterface::saveRecordingToAsset(const ScriptValue& getCli return false; } - if (QThread::currentThread() != thread()) { - bool result; - BLOCKING_INVOKE_METHOD(this, "saveRecordingToAsset", - Q_RETURN_ARG(bool, result), - Q_ARG(const ScriptValue&, getClipAtpUrl)); - return result; - } - + Locker(_mutex); if (!_lastClip) { qWarning() << "There is no recording to save"; return false; @@ -316,6 +293,8 @@ void RecordingScriptingInterface::loadLastRecording() { return; } + Locker(_mutex); + if (!_lastClip) { qCDebug(scriptengine) << "There is no recording to load"; return; diff --git a/libraries/recording/src/recording/RecordingScriptingInterface.h b/libraries/recording/src/recording/RecordingScriptingInterface.h index 42dc665706f..4cc8a990cd1 100644 --- a/libraries/recording/src/recording/RecordingScriptingInterface.h +++ b/libraries/recording/src/recording/RecordingScriptingInterface.h @@ -357,6 +357,8 @@ public slots: using Locker = std::unique_lock; using Flag = std::atomic; + Mutex _mutex; + QSharedPointer _player; QSharedPointer _recorder;