diff --git a/src/manager.cpp b/src/manager.cpp index 4721b59968dfd63bb7b1cafbd008906e2a893534..c877dbd8ea4989e064439114f46cfd9bb185a884 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2208,13 +2208,13 @@ Manager::playRingtone(const std::string& accountID) ringback(); } -AudioLoop* +std::shared_ptr<AudioLoop> Manager::getTelephoneTone() { return pimpl_->toneCtrl_.getTelephoneTone(); } -AudioLoop* +std::shared_ptr<AudioLoop> Manager::getTelephoneFile() { return pimpl_->toneCtrl_.getTelephoneFile(); diff --git a/src/manager.h b/src/manager.h index 6ff5b0af2d2ce56663ac48a50f16895e2403e48c..dc555e18573dd9d799043835b4909a9c5c0f9abe 100644 --- a/src/manager.h +++ b/src/manager.h @@ -680,13 +680,13 @@ class Manager { * Retrieve the current telephone tone * @return AudioLoop* The audio tone or 0 if no tone (init before calling this function) */ - AudioLoop* getTelephoneTone(); + std::shared_ptr<AudioLoop> getTelephoneTone(); /** * Retrieve the current telephone file * @return AudioLoop* The audio file or 0 if the wav is stopped */ - AudioLoop* getTelephoneFile(); + std::shared_ptr<AudioLoop> getTelephoneFile(); /** * @return true is there is one or many incoming call waiting diff --git a/src/media/audio/alsa/alsalayer.cpp b/src/media/audio/alsa/alsalayer.cpp index ddb244372b6e82df68e12f6a3ad355435eead0b9..928e20cbea97875984f212c2542d34e843820c0d 100644 --- a/src/media/audio/alsa/alsalayer.cpp +++ b/src/media/audio/alsa/alsalayer.cpp @@ -756,7 +756,7 @@ void AlsaLayer::ringtone() if (!ringtoneHandle_) return; - AudioLoop *file_tone = Manager::instance().getTelephoneFile(); + auto file_tone = Manager::instance().getTelephoneFile(); int ringtoneAvailFrames = 0; if (not safeUpdate(ringtoneHandle_, ringtoneAvailFrames)) diff --git a/src/media/audio/audiolayer.cpp b/src/media/audio/audiolayer.cpp index 302ab23bbfad02eb68c45373146658ceab9e4b3d..63205d5658ed16b2ffc0f00f1d15e4587a241724 100644 --- a/src/media/audio/audiolayer.cpp +++ b/src/media/audio/audiolayer.cpp @@ -122,7 +122,7 @@ void AudioLayer::notifyIncomingCall() const AudioBuffer& AudioLayer::getToRing(AudioFormat format, size_t writableSamples) { ringtoneBuffer_.resize(0); - AudioLoop *fileToPlay = Manager::instance().getTelephoneFile(); + auto fileToPlay = Manager::instance().getTelephoneFile(); if (fileToPlay) { auto fileformat = fileToPlay->getFormat(); bool resample = format.sample_rate != fileformat.sample_rate; @@ -167,9 +167,7 @@ const AudioBuffer& AudioLayer::getToPlay(AudioFormat format, size_t writableSamp return playbackBuffer_; } - // FIXME: not thread safe! we only lock the mutex when we get the - // pointer, we have no guarantee that it will stay safe to use - if (AudioLoop* toneToPlay = Manager::instance().getTelephoneTone()) { + if (auto toneToPlay = Manager::instance().getTelephoneTone()) { playbackBuffer_.setFormat(format); playbackBuffer_.resize(writableSamples); toneToPlay->getNext(playbackBuffer_, playbackGain_); // retrive only n_channels diff --git a/src/media/audio/jack/jacklayer.cpp b/src/media/audio/jack/jacklayer.cpp index 3c502bd2ad13bb10b6370cac270a1135635e15eb..50f862001780c82829d6ba9b97f27393dd10a749 100644 --- a/src/media/audio/jack/jacklayer.cpp +++ b/src/media/audio/jack/jacklayer.cpp @@ -103,8 +103,8 @@ void JackLayer::fillWithVoice(AudioBuffer &buffer, size_t samplesAvail) void JackLayer::fillWithToneOrRingtone(AudioBuffer &buffer) { buffer.resize(hardwareBufferSize_); - AudioLoop *tone = Manager::instance().getTelephoneTone(); - AudioLoop *file_tone = Manager::instance().getTelephoneFile(); + auto tone = Manager::instance().getTelephoneTone(); + auto file_tone = Manager::instance().getTelephoneFile(); // In case of a dtmf, the pointers will be set to nullptr once the dtmf length is // reached. For this reason we need to fill audio buffer with zeros if pointer is nullptr diff --git a/src/media/audio/sound/tonelist.cpp b/src/media/audio/sound/tonelist.cpp index 4654b93dc9151781397ab81ec7612ff06decd7a2..1a6321cba2c1775dc6a489ec4df3c425ccc9dc21 100644 --- a/src/media/audio/sound/tonelist.cpp +++ b/src/media/audio/sound/tonelist.cpp @@ -114,22 +114,22 @@ TelephoneTone::setSampleRate(unsigned int sampleRate) buildTones(sampleRate); } -Tone* +std::shared_ptr<Tone> TelephoneTone::getCurrentTone() { if (currentTone_ < Tone::TONE_DIALTONE or currentTone_ >= Tone::TONE_NULL) return nullptr; - return &tones_[currentTone_]; + return tones_[currentTone_]; } void TelephoneTone::buildTones(unsigned int sampleRate) { - tones_[Tone::TONE_DIALTONE] = Tone(toneZone[countryId_][Tone::TONE_DIALTONE], sampleRate); - tones_[Tone::TONE_BUSY] = Tone(toneZone[countryId_][Tone::TONE_BUSY], sampleRate); - tones_[Tone::TONE_RINGTONE] = Tone(toneZone[countryId_][Tone::TONE_RINGTONE], sampleRate); - tones_[Tone::TONE_CONGESTION] = Tone(toneZone[countryId_][Tone::TONE_CONGESTION], sampleRate); + tones_[Tone::TONE_DIALTONE] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_DIALTONE], sampleRate); + tones_[Tone::TONE_BUSY] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_BUSY], sampleRate); + tones_[Tone::TONE_RINGTONE] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_RINGTONE], sampleRate); + tones_[Tone::TONE_CONGESTION] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_CONGESTION], sampleRate); } } // namespace ring diff --git a/src/media/audio/sound/tonelist.h b/src/media/audio/sound/tonelist.h index f84a9526fee33580bf8b7be06e402df1d3704d86..9e9dc98069363b9cfbf723d99a1ac29690db5e78 100644 --- a/src/media/audio/sound/tonelist.h +++ b/src/media/audio/sound/tonelist.h @@ -49,7 +49,7 @@ class TelephoneTone { void setCurrentTone(Tone::TONEID toneId); void setSampleRate(unsigned int sampleRate); - Tone* getCurrentTone(); + std::shared_ptr<Tone> getCurrentTone(); private: NON_COPYABLE(TelephoneTone); @@ -59,7 +59,7 @@ class TelephoneTone { void buildTones(unsigned int sampleRate); COUNTRYID countryId_; - std::array<Tone, Tone::TONE_NULL> tones_; + std::array<std::shared_ptr<Tone>, Tone::TONE_NULL> tones_; Tone::TONEID currentTone_; }; diff --git a/src/media/audio/tonecontrol.cpp b/src/media/audio/tonecontrol.cpp index 6b433ee2482bdd4d6a246835e01efdc001cd04fa..4efce0ec308fc62122372b9588e82282c4e0d716 100644 --- a/src/media/audio/tonecontrol.cpp +++ b/src/media/audio/tonecontrol.cpp @@ -51,7 +51,7 @@ ToneControl::setSampleRate(unsigned rate) telephoneTone_->setSampleRate(rate); } -AudioLoop* +std::shared_ptr<AudioLoop> ToneControl::getTelephoneTone() { std::lock_guard<std::mutex> lk(mutex_); @@ -60,11 +60,11 @@ ToneControl::getTelephoneTone() return nullptr; } -AudioLoop* +std::shared_ptr<AudioLoop> ToneControl::getTelephoneFile(void) { std::lock_guard<std::mutex> lk(mutex_); - return audioFile_.get(); + return audioFile_; } bool diff --git a/src/media/audio/tonecontrol.h b/src/media/audio/tonecontrol.h index b8b47f110dea23873c9cf2547993d83b20da14a7..e7b0a0fb410729d6380c1b04094034871f75abb8 100644 --- a/src/media/audio/tonecontrol.h +++ b/src/media/audio/tonecontrol.h @@ -44,8 +44,8 @@ class ToneControl { ~ToneControl(); void setSampleRate(unsigned rate); - AudioLoop* getTelephoneTone(); - AudioLoop* getTelephoneFile(void); + std::shared_ptr<AudioLoop> getTelephoneTone(); + std::shared_ptr<AudioLoop> getTelephoneFile(void); bool setAudioFile(const std::string& file); void stopAudioFile(); void stop(); @@ -58,7 +58,7 @@ class ToneControl { std::mutex mutex_; // protect access to following members unsigned sampleRate_; std::unique_ptr<TelephoneTone> telephoneTone_; - std::unique_ptr<AudioFile> audioFile_; + std::shared_ptr<AudioFile> audioFile_; }; } // namespace ring