From bf00740c92839865f3656fb4ee02b144f26b2012 Mon Sep 17 00:00:00 2001 From: "jiayl@webrtc.org" Date: Tue, 17 Sep 2013 18:09:20 +0000 Subject: [PATCH] Adds a new voice engine warning for the typing noise off state. The old VE_TYPING_NOISE_WARNING is unchanged and fired whenever typing noise is detected. The new VE_TYPING_NOISE_OFF_WARNING is fired when typing noise was detected and is gone now. This is necessary for converting the typing state to a PeerConnection stats. R=niklas.enbom@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2209004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4770 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/engine_configurations.h | 3 +- webrtc/voice_engine/include/voe_errors.h | 1 + webrtc/voice_engine/transmit_mixer.cc | 36 ++++++++++++++++++------ webrtc/voice_engine/transmit_mixer.h | 3 +- 4 files changed, 31 insertions(+), 12 deletions(-) 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.