diff --git a/src/voice_engine/main/interface/voe_audio_processing.h b/src/voice_engine/main/interface/voe_audio_processing.h index f4742dcf4..0d21f622b 100644 --- a/src/voice_engine/main/interface/voe_audio_processing.h +++ b/src/voice_engine/main/interface/voe_audio_processing.h @@ -187,6 +187,12 @@ public: // Gets the current typing detection status. virtual int GetTypingDetectionStatus(bool& enabled) = 0; + // Reports the lower of: + // * Time in seconds since the last typing event. + // * Time in seconds since the typing detection was enabled. + // Returns error if typing detection is disabled. + virtual int TimeSinceLastTyping(int &seconds) = 0; + protected: VoEAudioProcessing() {} virtual ~VoEAudioProcessing() {} diff --git a/src/voice_engine/main/source/transmit_mixer.cc b/src/voice_engine/main/source/transmit_mixer.cc index cd1e2acc8..9fc9f4fff 100644 --- a/src/voice_engine/main/source/transmit_mixer.cc +++ b/src/voice_engine/main/source/transmit_mixer.cc @@ -183,6 +183,7 @@ TransmitMixer::TransmitMixer(const WebRtc_UWord32 instanceId) : _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION _timeActive(0), + _timeSinceLastTyping(0), _penaltyCounter(0), _typingNoiseWarning(0), #endif @@ -1384,6 +1385,16 @@ int TransmitMixer::TypingDetection() else _timeActive = 0; + // Keep track if time since last typing event + if (keyPressed) + { + _timeSinceLastTyping = 0; + } + else + { + ++_timeSinceLastTyping; + } + if (keyPressed && (_audioFrame._vadActivity == AudioFrame::kVadActive) && (_timeActive < 10)) { @@ -1419,6 +1430,18 @@ int TransmitMixer::GetMixingFrequency() return (_mixingFrequency); } +#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION +int TransmitMixer::TimeSinceLastTyping(int &seconds) +{ + // We check in VoEAudioProcessingImpl that this is only called when + // typing detection is active. + + // Round to whole seconds + seconds = (_timeSinceLastTyping + 50) / 100; + return(0); +} +#endif + } // namespace voe } // namespace webrtc diff --git a/src/voice_engine/main/source/transmit_mixer.h b/src/voice_engine/main/source/transmit_mixer.h index d65bb805d..271686d4c 100644 --- a/src/voice_engine/main/source/transmit_mixer.h +++ b/src/voice_engine/main/source/transmit_mixer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -148,6 +148,11 @@ public: // FileCallback void RecordFileEnded(const WebRtc_Word32 id); +#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION +public: // Typing detection + int TimeSinceLastTyping(int &seconds); +#endif + private: TransmitMixer(const WebRtc_UWord32 instanceId); @@ -197,6 +202,7 @@ private: // owns #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION WebRtc_Word32 _timeActive; + WebRtc_Word32 _timeSinceLastTyping; WebRtc_Word32 _penaltyCounter; WebRtc_UWord32 _typingNoiseWarning; #endif diff --git a/src/voice_engine/main/source/voe_audio_processing_impl.cc b/src/voice_engine/main/source/voe_audio_processing_impl.cc index 7303f4840..eddc23ecb 100644 --- a/src/voice_engine/main/source/voe_audio_processing_impl.cc +++ b/src/voice_engine/main/source/voe_audio_processing_impl.cc @@ -14,6 +14,7 @@ #include "channel.h" #include "critical_section_wrapper.h" #include "trace.h" +#include "transmit_mixer.h" #include "voe_errors.h" #include "voice_engine_impl.h" @@ -1031,6 +1032,40 @@ int VoEAudioProcessingImpl::GetTypingDetectionStatus(bool& enabled) { #endif } + +int VoEAudioProcessingImpl::TimeSinceLastTyping(int &seconds) { + WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_instanceId, -1), + "TimeSinceLastTyping()"); + ANDROID_NOT_SUPPORTED(_engineStatistics); + IPHONE_NOT_SUPPORTED(); + +#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION + if (!_engineStatistics.Initialized()) { + _engineStatistics.SetLastError(VE_NOT_INITED, kTraceError); + return -1; + } + // Check if typing detection is enabled + bool enabled = _audioProcessingModulePtr->voice_detection()->is_enabled(); + if (enabled) + { + _transmitMixerPtr->TimeSinceLastTyping(seconds); + return 0; + } + else + { + _engineStatistics.SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, + "SetTypingDetectionStatus is not enabled"); + return -1; + } +#else + _engineStatistics.SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, + "SetTypingDetectionStatus is not supported"); + return -1; +#endif + +} + + #endif // #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API } // namespace webrtc diff --git a/src/voice_engine/main/source/voe_audio_processing_impl.h b/src/voice_engine/main/source/voe_audio_processing_impl.h index 0c49bf43b..9598da40b 100644 --- a/src/voice_engine/main/source/voe_audio_processing_impl.h +++ b/src/voice_engine/main/source/voe_audio_processing_impl.h @@ -89,6 +89,8 @@ class VoEAudioProcessingImpl virtual int GetTypingDetectionStatus(bool& enabled); + virtual int TimeSinceLastTyping(int &seconds); + protected: VoEAudioProcessingImpl(); virtual ~VoEAudioProcessingImpl();