mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-13 22:27:13 +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;
|
||||
if (!_options.localOnly) {
|
||||
auto injectorManager = DependencyManager::get<AudioInjectorManager>();
|
||||
if (!(*injectorManager.*injection)(getThisPointer())) {
|
||||
if (!(*injectorManager.*injection)(sharedFromThis())) {
|
||||
success = false;
|
||||
finishNetworkInjection();
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ bool AudioInjector::injectLocally() {
|
|||
|
||||
// call this function on the AudioClient's thread
|
||||
// this will move the local buffer's thread to the LocalInjectorThread
|
||||
success = _localAudioInterface->outputLocalInjector(getThisPointer());
|
||||
success = _localAudioInterface->outputLocalInjector(sharedFromThis());
|
||||
|
||||
if (!success) {
|
||||
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 injector = AudioInjectorPointer(new AudioInjector(buffer, options));
|
||||
injector->setThisPointer(injector);
|
||||
|
||||
if (!injector->inject(&AudioInjectorManager::threadInjector)) {
|
||||
qWarning() << "AudioInjector::playSound failed to thread 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
|
||||
// until it dies.
|
||||
class AudioInjector : public QObject {
|
||||
class AudioInjector : public QObject, public QEnableSharedFromThis<AudioInjector> {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioInjector(const Sound& sound, const AudioInjectorOptions& injectorOptions);
|
||||
|
@ -79,9 +79,6 @@ public:
|
|||
static AudioInjectorPointer playSound(SharedSoundPointer sound, const float volume,
|
||||
const float stretchFactor, const glm::vec3 position);
|
||||
|
||||
AudioInjectorPointer getThisPointer();
|
||||
void setThisPointer(AudioInjectorPointer self);
|
||||
|
||||
public slots:
|
||||
void restart();
|
||||
|
||||
|
@ -127,9 +124,6 @@ private:
|
|||
AudioHRTF _localHRTF;
|
||||
AudioFOA _localFOA;
|
||||
friend class AudioInjectorManager;
|
||||
|
||||
QWeakPointer<AudioInjector> _self;
|
||||
mutable std::mutex _refLock;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(AudioInjectorPointer)
|
||||
|
|
|
@ -181,7 +181,7 @@ bool AudioInjectorManager::restartFinishedInjector(AudioInjectorPointer injector
|
|||
return false;
|
||||
} else {
|
||||
// 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
|
||||
_injectorReady.notify_one();
|
||||
|
|
Loading…
Reference in a new issue