diff --git a/webrtc/engine_configurations.h b/webrtc/engine_configurations.h index bb28b75acc..8294c9afc8 100644 --- a/webrtc/engine_configurations.h +++ b/webrtc/engine_configurations.h @@ -65,8 +65,7 @@ #define WEBRTC_VOICE_ENGINE_NR // Near-end NS #define WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT -#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) && \ - !defined(WEBRTC_CHROMIUM_BUILD) +#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) #define WEBRTC_VOICE_ENGINE_TYPING_DETECTION // Typing detection #endif diff --git a/webrtc/voice_engine/include/voe_errors.h b/webrtc/voice_engine/include/voe_errors.h index 32f5c9b1e2..4ce0e5c725 100644 --- a/webrtc/voice_engine/include/voe_errors.h +++ b/webrtc/voice_engine/include/voe_errors.h @@ -88,6 +88,7 @@ #define VE_CANNOT_SET_SECONDARY_SEND_CODEC 8113 #define VE_CANNOT_GET_SECONDARY_SEND_CODEC 8114 #define VE_CANNOT_REMOVE_SECONDARY_SEND_CODEC 8115 +#define VE_TYPING_NOISE_OFF_WARNING 8116 // Errors causing limited functionality #define VE_RTCP_SOCKET_ERROR 9001 diff --git a/webrtc/voice_engine/transmit_mixer.cc b/webrtc/voice_engine/transmit_mixer.cc index f5ec7f6774..5e67e200e0 100644 --- a/webrtc/voice_engine/transmit_mixer.cc +++ b/webrtc/voice_engine/transmit_mixer.cc @@ -41,18 +41,26 @@ TransmitMixer::OnPeriodicProcess() "TransmitMixer::OnPeriodicProcess()"); #if defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) - if (_typingNoiseWarning) + if (_typingNoiseWarningPending) { CriticalSectionScoped cs(&_callbackCritSect); if (_voiceEngineObserverPtr) { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), - "TransmitMixer::OnPeriodicProcess() => " - "CallbackOnError(VE_TYPING_NOISE_WARNING)"); - _voiceEngineObserverPtr->CallbackOnError(-1, - VE_TYPING_NOISE_WARNING); + if (_typingNoiseDetected) { + WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), + "TransmitMixer::OnPeriodicProcess() => " + "CallbackOnError(VE_TYPING_NOISE_WARNING)"); + _voiceEngineObserverPtr->CallbackOnError(-1, + VE_TYPING_NOISE_WARNING); + } else { + WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), + "TransmitMixer::OnPeriodicProcess() => " + "CallbackOnError(VE_TYPING_NOISE_OFF_WARNING)"); + _voiceEngineObserverPtr->CallbackOnError( + -1, VE_TYPING_NOISE_OFF_WARNING); + } } - _typingNoiseWarning = false; + _typingNoiseWarningPending = false; } #endif @@ -189,7 +197,8 @@ TransmitMixer::TransmitMixer(uint32_t instanceId) : _timeActive(0), _timeSinceLastTyping(0), _penaltyCounter(0), - _typingNoiseWarning(false), + _typingNoiseWarningPending(false), + _typingNoiseDetected(false), _timeWindow(10), // 10ms slots accepted to count as a hit _costPerTyping(100), // Penalty added for a typing + activity coincide _reportingThreshold(300), // Threshold for _penaltyCounter @@ -1380,10 +1389,19 @@ int TransmitMixer::TypingDetection(bool keyPressed) if (_penaltyCounter > _reportingThreshold) { // Triggers a callback in OnPeriodicProcess(). - _typingNoiseWarning = true; + _typingNoiseWarningPending = true; + _typingNoiseDetected = true; } } + // If there is already a warning pending, do not change the state. + // Otherwise sets a warning pending if noise is off now but previously on. + if (!_typingNoiseWarningPending && _typingNoiseDetected) { + // Triggers a callback in OnPeriodicProcess(). + _typingNoiseWarningPending = true; + _typingNoiseDetected = false; + } + if (_penaltyCounter > 0) _penaltyCounter-=_penaltyDecay; diff --git a/webrtc/voice_engine/transmit_mixer.h b/webrtc/voice_engine/transmit_mixer.h index b7c7403a47..d795eac265 100644 --- a/webrtc/voice_engine/transmit_mixer.h +++ b/webrtc/voice_engine/transmit_mixer.h @@ -217,7 +217,8 @@ private: int32_t _timeActive; int32_t _timeSinceLastTyping; int32_t _penaltyCounter; - bool _typingNoiseWarning; + bool _typingNoiseWarningPending; + bool _typingNoiseDetected; // Tunable treshold values int _timeWindow; // nr of10ms slots accepted to count as a hit.