| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/voice_engine/transmit_mixer.h" | 11 #include "webrtc/voice_engine/transmit_mixer.h" |
| 12 | 12 |
| 13 #include "webrtc/base/format_macros.h" | 13 #include "webrtc/base/format_macros.h" |
| 14 #include "webrtc/modules/utility/include/audio_frame_operations.h" | 14 #include "webrtc/modules/utility/include/audio_frame_operations.h" |
| 15 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 15 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 16 #include "webrtc/system_wrappers/include/event_wrapper.h" | 16 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 17 #include "webrtc/system_wrappers/include/logging.h" | 17 #include "webrtc/system_wrappers/include/logging.h" |
| 18 #include "webrtc/system_wrappers/include/trace.h" | 18 #include "webrtc/system_wrappers/include/trace.h" |
| 19 #include "webrtc/voice_engine/channel.h" | 19 #include "webrtc/voice_engine/channel.h" |
| 20 #include "webrtc/voice_engine/channel_manager.h" | 20 #include "webrtc/voice_engine/channel_manager.h" |
| 21 #include "webrtc/voice_engine/include/voe_external_media.h" | 21 #include "webrtc/voice_engine/include/voe_external_media.h" |
| 22 #include "webrtc/voice_engine/statistics.h" | 22 #include "webrtc/voice_engine/statistics.h" |
| 23 #include "webrtc/voice_engine/utility.h" | 23 #include "webrtc/voice_engine/utility.h" |
| 24 #include "webrtc/voice_engine/voe_base_impl.h" | 24 #include "webrtc/voice_engine/voe_base_impl.h" |
| 25 | 25 |
| 26 #define WEBRTC_ABS(a) (((a) < 0) ? -(a) : (a)) | |
| 27 | |
| 28 namespace webrtc { | 26 namespace webrtc { |
| 29 namespace voe { | 27 namespace voe { |
| 30 | 28 |
| 31 // TODO(ajm): The thread safety of this is dubious... | 29 // TODO(ajm): The thread safety of this is dubious... |
| 32 void | 30 void |
| 33 TransmitMixer::OnPeriodicProcess() | 31 TransmitMixer::OnPeriodicProcess() |
| 34 { | 32 { |
| 35 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 33 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
| 36 "TransmitMixer::OnPeriodicProcess()"); | 34 "TransmitMixer::OnPeriodicProcess()"); |
| 37 | 35 |
| 38 #if defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) | 36 #if defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) |
| 39 if (_typingNoiseWarningPending) | 37 bool send_typing_noise_warning = false; |
| 38 bool typing_noise_detected = false; |
| 40 { | 39 { |
| 40 CriticalSectionScoped cs(&_critSect); |
| 41 if (_typingNoiseWarningPending) { |
| 42 send_typing_noise_warning = true; |
| 43 typing_noise_detected = _typingNoiseDetected; |
| 44 _typingNoiseWarningPending = false; |
| 45 } |
| 46 } |
| 47 if (send_typing_noise_warning) { |
| 41 CriticalSectionScoped cs(&_callbackCritSect); | 48 CriticalSectionScoped cs(&_callbackCritSect); |
| 42 if (_voiceEngineObserverPtr) | 49 if (_voiceEngineObserverPtr) { |
| 43 { | 50 if (typing_noise_detected) { |
| 44 if (_typingNoiseDetected) { | |
| 45 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 51 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
| 46 "TransmitMixer::OnPeriodicProcess() => " | 52 "TransmitMixer::OnPeriodicProcess() => " |
| 47 "CallbackOnError(VE_TYPING_NOISE_WARNING)"); | 53 "CallbackOnError(VE_TYPING_NOISE_WARNING)"); |
| 48 _voiceEngineObserverPtr->CallbackOnError( | 54 _voiceEngineObserverPtr->CallbackOnError( |
| 49 -1, | 55 -1, |
| 50 VE_TYPING_NOISE_WARNING); | 56 VE_TYPING_NOISE_WARNING); |
| 51 } else { | 57 } else { |
| 52 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 58 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
| 53 "TransmitMixer::OnPeriodicProcess() => " | 59 "TransmitMixer::OnPeriodicProcess() => " |
| 54 "CallbackOnError(VE_TYPING_NOISE_OFF_WARNING)"); | 60 "CallbackOnError(VE_TYPING_NOISE_OFF_WARNING)"); |
| 55 _voiceEngineObserverPtr->CallbackOnError( | 61 _voiceEngineObserverPtr->CallbackOnError( |
| 56 -1, | 62 -1, |
| 57 VE_TYPING_NOISE_OFF_WARNING); | 63 VE_TYPING_NOISE_OFF_WARNING); |
| 58 } | 64 } |
| 59 } | 65 } |
| 60 _typingNoiseWarningPending = false; | |
| 61 } | 66 } |
| 62 #endif | 67 #endif |
| 63 | 68 |
| 64 bool saturationWarning = false; | 69 bool saturationWarning = false; |
| 65 { | 70 { |
| 66 // Modify |_saturationWarning| under lock to avoid conflict with write op | 71 // Modify |_saturationWarning| under lock to avoid conflict with write op |
| 67 // in ProcessAudio and also ensure that we don't hold the lock during the | 72 // in ProcessAudio and also ensure that we don't hold the lock during the |
| 68 // callback. | 73 // callback. |
| 69 CriticalSectionScoped cs(&_critSect); | 74 CriticalSectionScoped cs(&_critSect); |
| 70 saturationWarning = _saturationWarning; | 75 saturationWarning = _saturationWarning; |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION | 1277 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
| 1273 void TransmitMixer::TypingDetection(bool keyPressed) | 1278 void TransmitMixer::TypingDetection(bool keyPressed) |
| 1274 { | 1279 { |
| 1275 // We let the VAD determine if we're using this feature or not. | 1280 // We let the VAD determine if we're using this feature or not. |
| 1276 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) { | 1281 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) { |
| 1277 return; | 1282 return; |
| 1278 } | 1283 } |
| 1279 | 1284 |
| 1280 bool vadActive = _audioFrame.vad_activity_ == AudioFrame::kVadActive; | 1285 bool vadActive = _audioFrame.vad_activity_ == AudioFrame::kVadActive; |
| 1281 if (_typingDetection.Process(keyPressed, vadActive)) { | 1286 if (_typingDetection.Process(keyPressed, vadActive)) { |
| 1287 CriticalSectionScoped cs(&_critSect); |
| 1282 _typingNoiseWarningPending = true; | 1288 _typingNoiseWarningPending = true; |
| 1283 _typingNoiseDetected = true; | 1289 _typingNoiseDetected = true; |
| 1284 } else { | 1290 } else { |
| 1291 CriticalSectionScoped cs(&_critSect); |
| 1285 // If there is already a warning pending, do not change the state. | 1292 // If there is already a warning pending, do not change the state. |
| 1286 // Otherwise set a warning pending if last callback was for noise detected. | 1293 // Otherwise set a warning pending if last callback was for noise detected. |
| 1287 if (!_typingNoiseWarningPending && _typingNoiseDetected) { | 1294 if (!_typingNoiseWarningPending && _typingNoiseDetected) { |
| 1288 _typingNoiseWarningPending = true; | 1295 _typingNoiseWarningPending = true; |
| 1289 _typingNoiseDetected = false; | 1296 _typingNoiseDetected = false; |
| 1290 } | 1297 } |
| 1291 } | 1298 } |
| 1292 } | 1299 } |
| 1293 #endif | 1300 #endif |
| 1294 | 1301 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { | 1335 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { |
| 1329 swap_stereo_channels_ = enable; | 1336 swap_stereo_channels_ = enable; |
| 1330 } | 1337 } |
| 1331 | 1338 |
| 1332 bool TransmitMixer::IsStereoChannelSwappingEnabled() { | 1339 bool TransmitMixer::IsStereoChannelSwappingEnabled() { |
| 1333 return swap_stereo_channels_; | 1340 return swap_stereo_channels_; |
| 1334 } | 1341 } |
| 1335 | 1342 |
| 1336 } // namespace voe | 1343 } // namespace voe |
| 1337 } // namespace webrtc | 1344 } // namespace webrtc |
| OLD | NEW |