mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 22:33:56 +02:00
better handling of cleanup for local injector
This commit is contained in:
parent
0498c5c708
commit
4894a5b414
5 changed files with 19 additions and 29 deletions
|
@ -980,9 +980,6 @@ bool AudioClient::outputLocalInjector(bool isStereo, qreal volume, AudioInjector
|
|||
// move the localOutput to the same thread as the local injector buffer
|
||||
localOutput->moveToThread(injector->getLocalBuffer()->thread());
|
||||
|
||||
// have it be cleaned up when that injector is done
|
||||
connect(injector, &AudioInjector::finished, localOutput, &QAudioOutput::stop);
|
||||
|
||||
qDebug() << "Starting QAudioOutput for local injector" << localOutput;
|
||||
|
||||
localOutput->start(injector->getLocalBuffer());
|
||||
|
|
|
@ -52,20 +52,21 @@ AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOpt
|
|||
|
||||
}
|
||||
|
||||
AudioInjector::~AudioInjector() {
|
||||
if (_localBuffer) {
|
||||
_localBuffer->stop();
|
||||
void AudioInjector::setIsFinished(bool isFinished) {
|
||||
_isFinished = isFinished;
|
||||
|
||||
if (_isFinished) {
|
||||
emit finished();
|
||||
|
||||
if (_localBuffer) {
|
||||
_localBuffer->stop();
|
||||
}
|
||||
|
||||
// cleanup the audio data so we aren't holding that memory unecessarily
|
||||
_audioData.resize(0);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInjector::setOptions(AudioInjectorOptions& options) {
|
||||
_options = options;
|
||||
}
|
||||
|
||||
float AudioInjector::getLoudness() {
|
||||
return _loudness;
|
||||
}
|
||||
|
||||
void AudioInjector::injectAudio() {
|
||||
|
||||
if (!_isStarted) {
|
||||
|
@ -252,8 +253,7 @@ void AudioInjector::injectToMixer() {
|
|||
}
|
||||
}
|
||||
|
||||
_isFinished = true;
|
||||
emit finished();
|
||||
setIsFinished(true);
|
||||
}
|
||||
|
||||
void AudioInjector::stop() {
|
||||
|
@ -261,8 +261,7 @@ void AudioInjector::stop() {
|
|||
|
||||
if (_options.localOnly) {
|
||||
// we're only a local injector, so we can say we are finished right away too
|
||||
_isFinished = true;
|
||||
emit finished();
|
||||
setIsFinished(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ public:
|
|||
AudioInjector(QObject* parent);
|
||||
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||
AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions);
|
||||
~AudioInjector();
|
||||
|
||||
bool isFinished() const { return _isFinished; }
|
||||
|
||||
int getCurrentSendPosition() const { return _currentSendPosition; }
|
||||
|
||||
AudioInjectorLocalBuffer* getLocalBuffer() const { return _localBuffer; }
|
||||
|
@ -43,9 +43,9 @@ public:
|
|||
public slots:
|
||||
void injectAudio();
|
||||
void stop();
|
||||
void setOptions(AudioInjectorOptions& options);
|
||||
void setOptions(AudioInjectorOptions& options) { _options = options; }
|
||||
void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; }
|
||||
float getLoudness() const;
|
||||
float getLoudness() const { return _loudness; }
|
||||
bool isPlaying() const { return !_isFinished; }
|
||||
|
||||
signals:
|
||||
|
@ -57,6 +57,8 @@ private:
|
|||
void injectToMixer();
|
||||
void injectLocally();
|
||||
|
||||
void setIsFinished(bool isFinished);
|
||||
|
||||
QByteArray _audioData;
|
||||
AudioInjectorOptions _options;
|
||||
bool _shouldStop = false;
|
||||
|
|
|
@ -57,7 +57,6 @@ AudioInjector* AudioScriptingInterface::invokedPlaySound(Sound* sound, const Aud
|
|||
// connect the right slots and signals for AudioInjector and thread cleanup
|
||||
connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit);
|
||||
connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);
|
||||
connect(injectorThread, &QThread::destroyed, this, &AudioScriptingInterface::threadDead);
|
||||
|
||||
injectorThread->start();
|
||||
|
||||
|
@ -68,7 +67,3 @@ AudioInjector* AudioScriptingInterface::invokedPlaySound(Sound* sound, const Aud
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioScriptingInterface::threadDead() {
|
||||
qDebug() << "The audio thread has gone down";
|
||||
}
|
||||
|
|
|
@ -31,9 +31,6 @@ signals:
|
|||
void mutedByMixer();
|
||||
void environmentMuted();
|
||||
|
||||
public slots:
|
||||
void threadDead();
|
||||
|
||||
private slots:
|
||||
AudioInjector* invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||
|
||||
|
|
Loading…
Reference in a new issue