mirror of
https://github.com/overte-org/overte.git
synced 2025-06-24 05:40:29 +02:00
Merge pull request #7597 from Atlante45/fix/script-sound-hold-strong-ref
Fix audio injectors not working
This commit is contained in:
commit
40e53baa79
8 changed files with 44 additions and 35 deletions
|
@ -397,7 +397,7 @@ void Agent::processAgentAvatarAndAudio(float deltaTime) {
|
||||||
if (_numAvatarSoundSentBytes == soundByteArray.size()) {
|
if (_numAvatarSoundSentBytes == soundByteArray.size()) {
|
||||||
// we're done with this sound object - so set our pointer back to NULL
|
// we're done with this sound object - so set our pointer back to NULL
|
||||||
// and our sent bytes back to zero
|
// and our sent bytes back to zero
|
||||||
_avatarSound = NULL;
|
_avatarSound.clear();
|
||||||
_numAvatarSoundSentBytes = 0;
|
_numAvatarSoundSentBytes = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void run();
|
void run();
|
||||||
void playAvatarSound(Sound* avatarSound) { setAvatarSound(avatarSound); }
|
void playAvatarSound(SharedSoundPointer avatarSound) { setAvatarSound(avatarSound); }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void requestScript();
|
void requestScript();
|
||||||
|
@ -77,7 +77,7 @@ private:
|
||||||
MixedAudioStream _receivedAudioStream;
|
MixedAudioStream _receivedAudioStream;
|
||||||
float _lastReceivedAudioLoudness;
|
float _lastReceivedAudioLoudness;
|
||||||
|
|
||||||
void setAvatarSound(Sound* avatarSound) { _avatarSound = avatarSound; }
|
void setAvatarSound(SharedSoundPointer avatarSound) { _avatarSound = avatarSound; }
|
||||||
|
|
||||||
void sendAvatarIdentityPacket();
|
void sendAvatarIdentityPacket();
|
||||||
void sendAvatarBillboardPacket();
|
void sendAvatarBillboardPacket();
|
||||||
|
@ -85,7 +85,7 @@ private:
|
||||||
QString _scriptContents;
|
QString _scriptContents;
|
||||||
QTimer* _scriptRequestTimeout { nullptr };
|
QTimer* _scriptRequestTimeout { nullptr };
|
||||||
bool _isListeningToAudioStream = false;
|
bool _isListeningToAudioStream = false;
|
||||||
Sound* _avatarSound = nullptr;
|
SharedSoundPointer _avatarSound;
|
||||||
int _numAvatarSoundSentBytes = 0;
|
int _numAvatarSoundSentBytes = 0;
|
||||||
bool _isAvatar = false;
|
bool _isAvatar = false;
|
||||||
QTimer* _avatarIdentityTimer = nullptr;
|
QTimer* _avatarIdentityTimer = nullptr;
|
||||||
|
|
|
@ -32,8 +32,8 @@ AudioInjector::AudioInjector(QObject* parent) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
|
AudioInjector::AudioInjector(const Sound& sound, const AudioInjectorOptions& injectorOptions) :
|
||||||
_audioData(sound->getByteArray()),
|
_audioData(sound.getByteArray()),
|
||||||
_options(injectorOptions)
|
_options(injectorOptions)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
AudioInjector(QObject* parent);
|
AudioInjector(QObject* parent);
|
||||||
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
AudioInjector(const Sound& sound, const AudioInjectorOptions& injectorOptions);
|
||||||
AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions);
|
AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions);
|
||||||
|
|
||||||
bool isFinished() const { return _state == State::Finished; }
|
bool isFinished() const { return _state == State::Finished; }
|
||||||
|
|
|
@ -27,22 +27,18 @@
|
||||||
#include "AudioLogging.h"
|
#include "AudioLogging.h"
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
|
|
||||||
static int soundMetaTypeId = qRegisterMetaType<Sound*>();
|
QScriptValue soundSharedPointerToScriptValue(QScriptEngine* engine, const SharedSoundPointer& in) {
|
||||||
|
return engine->newQObject(new SoundScriptingInterface(in), QScriptEngine::ScriptOwnership);
|
||||||
QScriptValue soundSharedPointerToScriptValue(QScriptEngine* engine, SharedSoundPointer const& in) {
|
|
||||||
return engine->newQObject(in.data());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void soundSharedPointerFromScriptValue(const QScriptValue& object, SharedSoundPointer &out) {
|
void soundSharedPointerFromScriptValue(const QScriptValue& object, SharedSoundPointer& out) {
|
||||||
out = SharedSoundPointer(qobject_cast<Sound*>(object.toQObject()));
|
if (auto soundInterface = qobject_cast<SoundScriptingInterface*>(object.toQObject())) {
|
||||||
|
out = soundInterface->getSound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue soundPointerToScriptValue(QScriptEngine* engine, Sound* const& in) {
|
SoundScriptingInterface::SoundScriptingInterface(SharedSoundPointer sound) : _sound(sound) {
|
||||||
return engine->newQObject(in);
|
QObject::connect(sound.data(), &Sound::ready, this, &SoundScriptingInterface::ready);
|
||||||
}
|
|
||||||
|
|
||||||
void soundPointerFromScriptValue(const QScriptValue &object, Sound* &out) {
|
|
||||||
out = qobject_cast<Sound*>(object.toQObject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sound::Sound(const QUrl& url, bool isStereo) :
|
Sound::Sound(const QUrl& url, bool isStereo) :
|
||||||
|
|
|
@ -20,18 +20,16 @@
|
||||||
|
|
||||||
class Sound : public Resource {
|
class Sound : public Resource {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(bool downloaded READ isReady)
|
|
||||||
Q_PROPERTY(float duration READ getDuration)
|
|
||||||
public:
|
public:
|
||||||
Sound(const QUrl& url, bool isStereo = false);
|
Sound(const QUrl& url, bool isStereo = false);
|
||||||
|
|
||||||
bool isStereo() const { return _isStereo; }
|
bool isStereo() const { return _isStereo; }
|
||||||
bool isReady() const { return _isReady; }
|
bool isReady() const { return _isReady; }
|
||||||
float getDuration() { return _duration; }
|
float getDuration() const { return _duration; }
|
||||||
|
|
||||||
|
|
||||||
const QByteArray& getByteArray() { return _byteArray; }
|
const QByteArray& getByteArray() const { return _byteArray; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ready();
|
void ready();
|
||||||
|
@ -50,13 +48,28 @@ private:
|
||||||
|
|
||||||
typedef QSharedPointer<Sound> SharedSoundPointer;
|
typedef QSharedPointer<Sound> SharedSoundPointer;
|
||||||
|
|
||||||
|
class SoundScriptingInterface : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(bool downloaded READ isReady)
|
||||||
|
Q_PROPERTY(float duration READ getDuration)
|
||||||
|
|
||||||
|
public:
|
||||||
|
SoundScriptingInterface(SharedSoundPointer sound);
|
||||||
|
SharedSoundPointer getSound() { return _sound; }
|
||||||
|
|
||||||
|
bool isReady() const { return _sound->isReady(); }
|
||||||
|
float getDuration() { return _sound->getDuration(); }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void ready();
|
||||||
|
|
||||||
|
private:
|
||||||
|
SharedSoundPointer _sound;
|
||||||
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(SharedSoundPointer)
|
Q_DECLARE_METATYPE(SharedSoundPointer)
|
||||||
QScriptValue soundSharedPointerToScriptValue(QScriptEngine* engine, SharedSoundPointer const& in);
|
QScriptValue soundSharedPointerToScriptValue(QScriptEngine* engine, const SharedSoundPointer& in);
|
||||||
void soundSharedPointerFromScriptValue(const QScriptValue& object, SharedSoundPointer &out);
|
void soundSharedPointerFromScriptValue(const QScriptValue& object, SharedSoundPointer& out);
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Sound*)
|
|
||||||
QScriptValue soundPointerToScriptValue(QScriptEngine* engine, Sound* const& in);
|
|
||||||
void soundPointerFromScriptValue(const QScriptValue& object, Sound* &out);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_Sound_h
|
#endif // hifi_Sound_h
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
void registerAudioMetaTypes(QScriptEngine* engine) {
|
void registerAudioMetaTypes(QScriptEngine* engine) {
|
||||||
qScriptRegisterMetaType(engine, injectorOptionsToScriptValue, injectorOptionsFromScriptValue);
|
qScriptRegisterMetaType(engine, injectorOptionsToScriptValue, injectorOptionsFromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, soundSharedPointerToScriptValue, soundSharedPointerFromScriptValue);
|
qScriptRegisterMetaType(engine, soundSharedPointerToScriptValue, soundSharedPointerFromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, soundPointerToScriptValue, soundPointerFromScriptValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioScriptingInterface& AudioScriptingInterface::getInstance() {
|
AudioScriptingInterface& AudioScriptingInterface::getInstance() {
|
||||||
|
@ -31,13 +30,14 @@ AudioScriptingInterface::AudioScriptingInterface() :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptAudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) {
|
ScriptAudioInjector* AudioScriptingInterface::playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
ScriptAudioInjector* injector = NULL;
|
ScriptAudioInjector* injector = NULL;
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, "playSound", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(this, "playSound", Qt::BlockingQueuedConnection,
|
||||||
Q_RETURN_ARG(ScriptAudioInjector*, injector),
|
Q_RETURN_ARG(ScriptAudioInjector*, injector),
|
||||||
Q_ARG(Sound*, sound), Q_ARG(const AudioInjectorOptions&, injectorOptions));
|
Q_ARG(SharedSoundPointer, sound),
|
||||||
|
Q_ARG(const AudioInjectorOptions&, injectorOptions));
|
||||||
return injector;
|
return injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// this method is protected to stop C++ callers from calling, but invokable from script
|
// this method is protected to stop C++ callers from calling, but invokable from script
|
||||||
Q_INVOKABLE ScriptAudioInjector* playSound(Sound* sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions());
|
Q_INVOKABLE ScriptAudioInjector* playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions());
|
||||||
|
|
||||||
Q_INVOKABLE void setStereoInput(bool stereo);
|
Q_INVOKABLE void setStereoInput(bool stereo);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue