mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 14:10:40 +02:00
use QEnableSharedFromThis
This commit is contained in:
parent
dbd46fc4b8
commit
81489ea6c4
3 changed files with 4 additions and 26 deletions
|
@ -150,7 +150,7 @@ bool AudioInjector::inject(bool(AudioInjectorManager::*injection)(AudioInjectorP
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if (!_options.localOnly) {
|
if (!_options.localOnly) {
|
||||||
auto injectorManager = DependencyManager::get<AudioInjectorManager>();
|
auto injectorManager = DependencyManager::get<AudioInjectorManager>();
|
||||||
if (!(*injectorManager.*injection)(getThisPointer())) {
|
if (!(*injectorManager.*injection)(sharedFromThis())) {
|
||||||
success = false;
|
success = false;
|
||||||
finishNetworkInjection();
|
finishNetworkInjection();
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ bool AudioInjector::injectLocally() {
|
||||||
|
|
||||||
// call this function on the AudioClient's thread
|
// call this function on the AudioClient's thread
|
||||||
// this will move the local buffer's thread to the LocalInjectorThread
|
// this will move the local buffer's thread to the LocalInjectorThread
|
||||||
success = _localAudioInterface->outputLocalInjector(getThisPointer());
|
success = _localAudioInterface->outputLocalInjector(sharedFromThis());
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
qCDebug(audio) << "AudioInjector::injectLocally could not output locally via _localAudioInterface";
|
qCDebug(audio) << "AudioInjector::injectLocally could not output locally via _localAudioInterface";
|
||||||
|
@ -475,25 +475,9 @@ AudioInjectorPointer AudioInjector::playSoundAndDelete(const QByteArray& buffer,
|
||||||
|
|
||||||
AudioInjectorPointer AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options) {
|
AudioInjectorPointer AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options) {
|
||||||
AudioInjectorPointer injector = AudioInjectorPointer(new AudioInjector(buffer, options));
|
AudioInjectorPointer injector = AudioInjectorPointer(new AudioInjector(buffer, options));
|
||||||
injector->setThisPointer(injector);
|
|
||||||
|
|
||||||
if (!injector->inject(&AudioInjectorManager::threadInjector)) {
|
if (!injector->inject(&AudioInjectorManager::threadInjector)) {
|
||||||
qWarning() << "AudioInjector::playSound failed to thread injector";
|
qWarning() << "AudioInjector::playSound failed to thread injector";
|
||||||
}
|
}
|
||||||
return injector;
|
return injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjectorPointer AudioInjector::getThisPointer() {
|
|
||||||
std::lock_guard<std::mutex> lock(_refLock);
|
|
||||||
QSharedPointer<AudioInjector> this_ref(_self);
|
|
||||||
if (this_ref.isNull()) {
|
|
||||||
this_ref = QSharedPointer<AudioInjector>(this);
|
|
||||||
_self = this_ref.toWeakRef();
|
|
||||||
}
|
|
||||||
return this_ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AudioInjector::setThisPointer(AudioInjectorPointer self) {
|
|
||||||
std::lock_guard<std::mutex> lock(_refLock);
|
|
||||||
_self = self.toWeakRef();
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ AudioInjectorState& operator|= (AudioInjectorState& lhs, AudioInjectorState rhs)
|
||||||
|
|
||||||
// In order to make scripting cleaner for the AudioInjector, the script now holds on to the AudioInjector object
|
// In order to make scripting cleaner for the AudioInjector, the script now holds on to the AudioInjector object
|
||||||
// until it dies.
|
// until it dies.
|
||||||
class AudioInjector : public QObject {
|
class AudioInjector : public QObject, public QEnableSharedFromThis<AudioInjector> {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AudioInjector(const Sound& sound, const AudioInjectorOptions& injectorOptions);
|
AudioInjector(const Sound& sound, const AudioInjectorOptions& injectorOptions);
|
||||||
|
@ -79,9 +79,6 @@ public:
|
||||||
static AudioInjectorPointer playSound(SharedSoundPointer sound, const float volume,
|
static AudioInjectorPointer playSound(SharedSoundPointer sound, const float volume,
|
||||||
const float stretchFactor, const glm::vec3 position);
|
const float stretchFactor, const glm::vec3 position);
|
||||||
|
|
||||||
AudioInjectorPointer getThisPointer();
|
|
||||||
void setThisPointer(AudioInjectorPointer self);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void restart();
|
void restart();
|
||||||
|
|
||||||
|
@ -127,9 +124,6 @@ private:
|
||||||
AudioHRTF _localHRTF;
|
AudioHRTF _localHRTF;
|
||||||
AudioFOA _localFOA;
|
AudioFOA _localFOA;
|
||||||
friend class AudioInjectorManager;
|
friend class AudioInjectorManager;
|
||||||
|
|
||||||
QWeakPointer<AudioInjector> _self;
|
|
||||||
mutable std::mutex _refLock;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(AudioInjectorPointer)
|
Q_DECLARE_METATYPE(AudioInjectorPointer)
|
||||||
|
|
|
@ -181,7 +181,7 @@ bool AudioInjectorManager::restartFinishedInjector(AudioInjectorPointer injector
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// add the injector to the queue with a send timestamp of now
|
// add the injector to the queue with a send timestamp of now
|
||||||
_injectors.emplace(usecTimestampNow(), injector->getThisPointer());
|
_injectors.emplace(usecTimestampNow(), injector);
|
||||||
|
|
||||||
// notify our wait condition so we can inject two frames for this injector immediately
|
// notify our wait condition so we can inject two frames for this injector immediately
|
||||||
_injectorReady.notify_one();
|
_injectorReady.notify_one();
|
||||||
|
|
Loading…
Reference in a new issue