mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 16:52:10 +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
|
// move the localOutput to the same thread as the local injector buffer
|
||||||
localOutput->moveToThread(injector->getLocalBuffer()->thread());
|
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;
|
qDebug() << "Starting QAudioOutput for local injector" << localOutput;
|
||||||
|
|
||||||
localOutput->start(injector->getLocalBuffer());
|
localOutput->start(injector->getLocalBuffer());
|
||||||
|
|
|
@ -52,20 +52,21 @@ AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOpt
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjector::~AudioInjector() {
|
void AudioInjector::setIsFinished(bool isFinished) {
|
||||||
if (_localBuffer) {
|
_isFinished = isFinished;
|
||||||
_localBuffer->stop();
|
|
||||||
|
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() {
|
void AudioInjector::injectAudio() {
|
||||||
|
|
||||||
if (!_isStarted) {
|
if (!_isStarted) {
|
||||||
|
@ -252,8 +253,7 @@ void AudioInjector::injectToMixer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_isFinished = true;
|
setIsFinished(true);
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::stop() {
|
void AudioInjector::stop() {
|
||||||
|
@ -261,8 +261,7 @@ void AudioInjector::stop() {
|
||||||
|
|
||||||
if (_options.localOnly) {
|
if (_options.localOnly) {
|
||||||
// we're only a local injector, so we can say we are finished right away too
|
// we're only a local injector, so we can say we are finished right away too
|
||||||
_isFinished = true;
|
setIsFinished(true);
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ public:
|
||||||
AudioInjector(QObject* parent);
|
AudioInjector(QObject* parent);
|
||||||
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||||
AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions);
|
AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions);
|
||||||
~AudioInjector();
|
|
||||||
|
|
||||||
bool isFinished() const { return _isFinished; }
|
bool isFinished() const { return _isFinished; }
|
||||||
|
|
||||||
int getCurrentSendPosition() const { return _currentSendPosition; }
|
int getCurrentSendPosition() const { return _currentSendPosition; }
|
||||||
|
|
||||||
AudioInjectorLocalBuffer* getLocalBuffer() const { return _localBuffer; }
|
AudioInjectorLocalBuffer* getLocalBuffer() const { return _localBuffer; }
|
||||||
|
@ -43,9 +43,9 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void injectAudio();
|
void injectAudio();
|
||||||
void stop();
|
void stop();
|
||||||
void setOptions(AudioInjectorOptions& options);
|
void setOptions(AudioInjectorOptions& options) { _options = options; }
|
||||||
void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; }
|
void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; }
|
||||||
float getLoudness() const;
|
float getLoudness() const { return _loudness; }
|
||||||
bool isPlaying() const { return !_isFinished; }
|
bool isPlaying() const { return !_isFinished; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -57,6 +57,8 @@ private:
|
||||||
void injectToMixer();
|
void injectToMixer();
|
||||||
void injectLocally();
|
void injectLocally();
|
||||||
|
|
||||||
|
void setIsFinished(bool isFinished);
|
||||||
|
|
||||||
QByteArray _audioData;
|
QByteArray _audioData;
|
||||||
AudioInjectorOptions _options;
|
AudioInjectorOptions _options;
|
||||||
bool _shouldStop = false;
|
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 the right slots and signals for AudioInjector and thread cleanup
|
||||||
connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit);
|
connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit);
|
||||||
connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);
|
connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);
|
||||||
connect(injectorThread, &QThread::destroyed, this, &AudioScriptingInterface::threadDead);
|
|
||||||
|
|
||||||
injectorThread->start();
|
injectorThread->start();
|
||||||
|
|
||||||
|
@ -68,7 +67,3 @@ AudioInjector* AudioScriptingInterface::invokedPlaySound(Sound* sound, const Aud
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioScriptingInterface::threadDead() {
|
|
||||||
qDebug() << "The audio thread has gone down";
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,9 +31,6 @@ signals:
|
||||||
void mutedByMixer();
|
void mutedByMixer();
|
||||||
void environmentMuted();
|
void environmentMuted();
|
||||||
|
|
||||||
public slots:
|
|
||||||
void threadDead();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
AudioInjector* invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
AudioInjector* invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue