1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix audio singleton implementation

This commit is contained in:
Nils Fenner 2016-01-09 13:12:39 +01:00
parent ad3326b95d
commit 82dfe0f704
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
2 changed files with 8 additions and 27 deletions

View File

@ -56,8 +56,6 @@
#include "audiofilterer.h"
#endif
Audio* Audio::instance{nullptr};
/**
@class AudioPlayer
@ -267,16 +265,12 @@ void AudioMeterListener::doListen()
}
/**
Returns the singleton's instance. Will construct on first call.
Returns the singleton instance.
*/
Audio& Audio::getInstance()
{
if (!instance)
{
instance = new Audio();
instance->startAudioThread();
}
return *instance;
static Audio instance;
return instance;
}
AudioMeterListener* Audio::createAudioMeterListener() const
@ -289,18 +283,6 @@ AudioMeterListener* Audio::createAudioMeterListener() const
Audio::Audio()
: d(new AudioPrivate)
{
}
Audio::~Audio()
{
delete d;
}
/**
Start the audio thread for capture and playback.
*/
void Audio::startAudioThread()
{
moveToThread(d->audioThread);
@ -308,7 +290,11 @@ void Audio::startAudioThread()
d->audioThread->start();
else
qWarning("Audio thread already started -> ignored.");
}
Audio::~Audio()
{
delete d;
}
/**
@ -541,7 +527,7 @@ The first and last argument are ignored, but allow direct compatibility with tox
void Audio::playGroupAudioQueued(void*,int group, int peer, const int16_t* data,
unsigned samples, uint8_t channels, unsigned sample_rate, void* core)
{
QMetaObject::invokeMethod(instance, "playGroupAudio", Qt::BlockingQueuedConnection,
QMetaObject::invokeMethod(&Audio::getInstance(), "playGroupAudio", Qt::BlockingQueuedConnection,
Q_ARG(int,group), Q_ARG(int,peer), Q_ARG(const int16_t*,data),
Q_ARG(unsigned,samples), Q_ARG(uint8_t,channels), Q_ARG(unsigned,sample_rate));
emit static_cast<Core*>(core)->groupPeerAudioPlaying(group, peer);

View File

@ -50,8 +50,6 @@ public:
static Audio& getInstance();
public:
void startAudioThread();
AudioMeterListener* createAudioMeterListener() const;
qreal outputVolume();
@ -100,9 +98,6 @@ private:
Audio();
~Audio();
private:
static Audio* instance;
private:
AudioPrivate* d;
};