From 713d2ee626df8e18d16c605d913f342efa482334 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 7 Oct 2019 18:07:14 +0200 Subject: [PATCH] Ref T730, Ref T739 avoid timer stopping issue during shutdown * use timer with parent * avoid QObject::~QObject: Timers cannot be stopped from another thread * see https://discordapp.com/channels/539048679160676382/623947987822837779/630521007056224286 --- .../afv/audio/callsignsampleprovider.cpp | 23 +++++++++++-------- .../afv/audio/callsignsampleprovider.h | 6 ++--- .../sampleprovider/simplecompressoreffect.cpp | 20 ++++++++++------ .../sampleprovider/simplecompressoreffect.h | 6 ++--- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/blackcore/afv/audio/callsignsampleprovider.cpp b/src/blackcore/afv/audio/callsignsampleprovider.cpp index ea641fd7c..bd194991d 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.cpp +++ b/src/blackcore/afv/audio/callsignsampleprovider.cpp @@ -13,6 +13,7 @@ #include "blacksound/sampleprovider/samples.h" #include "blacksound/audioutilities.h" #include "blackcore/afv/audio/receiversampleprovider.h" + #include #include @@ -32,6 +33,7 @@ namespace BlackCore { Q_ASSERT(audioFormat.channelCount() == 1); + this->setObjectName("CallsignSampleProvider"); m_mixer = new CMixingSampleProvider(this); m_crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), m_mixer); m_crackleSoundProvider->setLooping(true); @@ -57,8 +59,11 @@ namespace BlackCore m_mixer->addMixerInput(m_hfWhiteNoise); m_mixer->addMixerInput(m_voiceEq); - m_timer.setInterval(100); - connect(&m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed); + m_timer = new QTimer(this); + m_timer->setObjectName(this->objectName() + "m_timer"); + + m_timer->setInterval(100); + connect(m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed); } int CallsignSampleProvider::readSamples(QVector &samples, qint64 count) @@ -136,7 +141,7 @@ namespace BlackCore m_lastPacketLatch = audioDto.lastPacket; if (audioDto.lastPacket && !m_underflow) { CallsignDelayCache::instance().success(m_callsign); } m_lastSamplesAddedUtc = QDateTime::currentDateTimeUtc(); - if (!m_timer.isActive()) { m_timer.start(); } + if (!m_timer->isActive()) { m_timer->start(); } } void CallsignSampleProvider::addSilentSamples(const IAudioDto &audioDto) @@ -148,16 +153,16 @@ namespace BlackCore m_lastPacketLatch = audioDto.lastPacket; m_lastSamplesAddedUtc = QDateTime::currentDateTimeUtc(); - if (!m_timer.isActive()) { m_timer.start(); } + if (!m_timer->isActive()) { m_timer->start(); } } void CallsignSampleProvider::idle() { - m_timer.stop(); + m_timer->stop(); m_inUse = false; setEffects(); - m_callsign = QString(); - m_type = QString(); + m_callsign.clear(); + m_type.clear(); } QVector CallsignSampleProvider::decodeOpus(const QByteArray &opusData) @@ -184,7 +189,7 @@ namespace BlackCore { double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652); - if (crackleFactor < 0.0f) { crackleFactor = 0.0f; } + if (crackleFactor < 0.0f) { crackleFactor = 0.00f; } if (crackleFactor > 0.20f) { crackleFactor = 0.20f; } m_hfWhiteNoise->setGain(m_hfWhiteNoiseGainMin); @@ -198,7 +203,7 @@ namespace BlackCore { double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652); - if (crackleFactor < 0.0) { crackleFactor = 0.0; } + if (crackleFactor < 0.0) { crackleFactor = 0.0; } if (crackleFactor > 0.20) { crackleFactor = 0.20; } m_crackleSoundProvider->setGain(crackleFactor * 2); diff --git a/src/blackcore/afv/audio/callsignsampleprovider.h b/src/blackcore/afv/audio/callsignsampleprovider.h index c98a8d15e..2bb249791 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.h +++ b/src/blackcore/afv/audio/callsignsampleprovider.h @@ -81,10 +81,8 @@ namespace BlackCore QString m_type; bool m_inUse = false; - bool m_bypassEffects = false; - + bool m_bypassEffects = false; float m_distanceRatio = 1.0; - const CReceiverSampleProvider *m_receiver = nullptr; BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr; @@ -94,7 +92,7 @@ namespace BlackCore BlackSound::SampleProvider::CSimpleCompressorEffect *m_simpleCompressorEffect = nullptr; BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEq = nullptr; BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr; - QTimer m_timer; + QTimer *m_timer = nullptr; BlackSound::Codecs::COpusDecoder m_decoder; bool m_lastPacketLatch = false; diff --git a/src/blacksound/sampleprovider/simplecompressoreffect.cpp b/src/blacksound/sampleprovider/simplecompressoreffect.cpp index f33b3b669..89ea857d2 100644 --- a/src/blacksound/sampleprovider/simplecompressoreffect.cpp +++ b/src/blacksound/sampleprovider/simplecompressoreffect.cpp @@ -17,14 +17,18 @@ namespace BlackSound ISampleProvider(parent), m_sourceStream(source) { + + this->setObjectName("CSimpleCompressorEffect"); + m_timer = new QTimer(this); + m_timer->setObjectName(this->objectName() + ":m_timer"); + m_simpleCompressor.setAttack(5.0); m_simpleCompressor.setRelease(10.0); m_simpleCompressor.setSampleRate(48000.0); m_simpleCompressor.setThresh(16.0); m_simpleCompressor.setRatio(6.0); m_simpleCompressor.setMakeUpGain(16.0); - - m_timer.start(3000); + m_timer->start(3000); } int CSimpleCompressorEffect::readSamples(QVector &samples, qint64 count) @@ -33,14 +37,16 @@ namespace BlackSound if (m_enabled) { - for (int sample = 0; sample < samplesRead; sample += channels) + for (int sample = 0; sample < samplesRead; sample += m_channels) { double in1 = samples.at(sample); - double in2 = (channels == 1) ? 0 : samples.at(sample + 1); + double in2 = (m_channels == 1) ? 0 : samples.at(sample + 1); m_simpleCompressor.process(in1, in2); - samples[sample] = in1; - if (channels > 1) - samples[sample + 1] = in2; + samples[sample] = static_cast(in1); + if (m_channels > 1) + { + samples[sample + 1] = static_cast(in2); + } } } return samplesRead; diff --git a/src/blacksound/sampleprovider/simplecompressoreffect.h b/src/blacksound/sampleprovider/simplecompressoreffect.h index af878eda5..c025e7302 100644 --- a/src/blacksound/sampleprovider/simplecompressoreffect.h +++ b/src/blacksound/sampleprovider/simplecompressoreffect.h @@ -41,11 +41,11 @@ namespace BlackSound void setMakeUpGain(double gain); private: - QTimer m_timer; + QTimer *m_timer = nullptr; ISampleProvider *m_sourceStream = nullptr; - bool m_enabled = true; + bool m_enabled = true; + const int m_channels = 1; chunkware_simple::SimpleComp m_simpleCompressor; - const int channels = 1; }; } // ns } // ns