diff --git a/src/manager.cpp b/src/manager.cpp index 73ef2833c2f61846f7318d8c3da5a758e152a7f9..7589759b91a0f25cfcc1e1fee8fb1d70f2bb4e96 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -615,6 +615,9 @@ void Manager::ManagerPimpl::addWaitingCall(const std::string& id) { std::lock_guard<std::mutex> m(waitingCallsMutex_); + // Enable incoming call beep if needed. + if (audiodriver_ and waitingCalls_.empty() and not currentCall_.empty()) + audiodriver_->playIncomingCallNotification(true); waitingCalls_.insert(id); } @@ -623,6 +626,8 @@ Manager::ManagerPimpl::removeWaitingCall(const std::string& id) { std::lock_guard<std::mutex> m(waitingCallsMutex_); waitingCalls_.erase(id); + if (audiodriver_ and waitingCalls_.empty()) + audiodriver_->playIncomingCallNotification(false); } void diff --git a/src/media/audio/audiolayer.cpp b/src/media/audio/audiolayer.cpp index 3f7e3f874b9c1a7786533e59fb45d9dc2c9f82ab..dd8648023515663c4bc587337840fa752f5c2779 100644 --- a/src/media/audio/audiolayer.cpp +++ b/src/media/audio/audiolayer.cpp @@ -164,21 +164,17 @@ AudioLayer::putUrgent(AudioBuffer& buffer) void AudioLayer::notifyIncomingCall() { - if (!Manager::instance().incomingCallsWaiting()) + if (not playIncomingCallBeep_) return; auto now = std::chrono::system_clock::now(); // Notify maximum once every 5 seconds - if ((now - lastNotificationTime_) < std::chrono::seconds(5)) + if (now < lastNotificationTime_ + std::chrono::seconds(5)) return; lastNotificationTime_ = now; - // Enable notification only if more than one call - if (!Manager::instance().hasCurrentCall()) - return; - Tone tone("440/160", getSampleRate()); size_t nbSample = tone.getSize(); AudioBuffer buf(nbSample, AudioFormat::MONO()); diff --git a/src/media/audio/audiolayer.h b/src/media/audio/audiolayer.h index 79ad74d36b24c13277d3fec0c38693f356b56b47..86562bee8cd7cfa138bdc2c76c0c399a24178ea9 100644 --- a/src/media/audio/audiolayer.h +++ b/src/media/audio/audiolayer.h @@ -53,7 +53,7 @@ typedef struct SpeexEchoState_ SpeexEchoState; #define COREAUDIO_API_STR "coreaudio" #define PORTAUDIO_API_STR "portaudio" -#define PCM_DEFAULT "default" // Default ALSA plugin +#define PCM_DEFAULT "default" // Default ALSA plugin #define PCM_DSNOOP "plug:dsnoop" // Alsa plugin for microphone sharing #define PCM_DMIX_DSNOOP "dmix/dsnoop" // Audio profile using Alsa dmix/dsnoop @@ -117,6 +117,12 @@ public: */ void putUrgent(AudioBuffer& buffer); + /** + * Start/Stop playing the incoming call notification sound (beep) + * while playing back audio (typically during an ongoing call). + */ + void playIncomingCallNotification(bool play) { playIncomingCallBeep_.exchange(play); } + /** * Flush main buffer */ @@ -179,7 +185,7 @@ public: AudioFormat getFormat() const { return audioFormat_; } /** - * Emit an audio notification on incoming calls + * Emit an audio notification (beep) on incoming calls */ void notifyIncomingCall(); @@ -295,10 +301,15 @@ protected: private: void checkAEC(); + // Set to "true" to play the incoming call notification (beep) + // when the playback is on (typically when there is already an + // active call). + std::atomic_bool playIncomingCallBeep_ {false}; /** * Time of the last incoming call notification */ - std::chrono::system_clock::time_point lastNotificationTime_; + std::chrono::system_clock::time_point lastNotificationTime_ { + std::chrono::system_clock::time_point::min()}; }; } // namespace jami