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 <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/audio/utility/audio_frame_operations.h" | 15 #include "webrtc/audio/utility/audio_frame_operations.h" |
16 #include "webrtc/base/format_macros.h" | 16 #include "webrtc/base/format_macros.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/system_wrappers/include/event_wrapper.h" | 18 #include "webrtc/system_wrappers/include/event_wrapper.h" |
19 #include "webrtc/system_wrappers/include/trace.h" | 19 #include "webrtc/system_wrappers/include/trace.h" |
20 #include "webrtc/voice_engine/channel.h" | 20 #include "webrtc/voice_engine/channel.h" |
21 #include "webrtc/voice_engine/channel_manager.h" | 21 #include "webrtc/voice_engine/channel_manager.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 namespace webrtc { | 26 namespace webrtc { |
27 namespace voe { | 27 namespace voe { |
28 | 28 |
29 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION | |
29 // TODO(ajm): The thread safety of this is dubious... | 30 // TODO(ajm): The thread safety of this is dubious... |
30 void | 31 void TransmitMixer::OnPeriodicProcess() |
31 TransmitMixer::OnPeriodicProcess() | |
32 { | 32 { |
33 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 33 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
34 "TransmitMixer::OnPeriodicProcess()"); | 34 "TransmitMixer::OnPeriodicProcess()"); |
35 | 35 |
36 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION | |
37 bool send_typing_noise_warning = false; | 36 bool send_typing_noise_warning = false; |
38 bool typing_noise_detected = false; | 37 bool typing_noise_detected = false; |
39 { | 38 { |
40 rtc::CritScope cs(&_critSect); | 39 rtc::CritScope cs(&_critSect); |
41 if (_typingNoiseWarningPending) { | 40 if (_typingNoiseWarningPending) { |
42 send_typing_noise_warning = true; | 41 send_typing_noise_warning = true; |
43 typing_noise_detected = _typingNoiseDetected; | 42 typing_noise_detected = _typingNoiseDetected; |
44 _typingNoiseWarningPending = false; | 43 _typingNoiseWarningPending = false; |
45 } | 44 } |
46 } | 45 } |
(...skipping 10 matching lines...) Expand all Loading... | |
57 } else { | 56 } else { |
58 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 57 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
59 "TransmitMixer::OnPeriodicProcess() => " | 58 "TransmitMixer::OnPeriodicProcess() => " |
60 "CallbackOnError(VE_TYPING_NOISE_OFF_WARNING)"); | 59 "CallbackOnError(VE_TYPING_NOISE_OFF_WARNING)"); |
61 _voiceEngineObserverPtr->CallbackOnError( | 60 _voiceEngineObserverPtr->CallbackOnError( |
62 -1, | 61 -1, |
63 VE_TYPING_NOISE_OFF_WARNING); | 62 VE_TYPING_NOISE_OFF_WARNING); |
64 } | 63 } |
65 } | 64 } |
66 } | 65 } |
66 } | |
67 #endif // WEBRTC_VOICE_ENGINE_TYPING_DETECTION | 67 #endif // WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
68 | 68 |
69 bool saturationWarning = false; | |
70 { | |
71 // Modify |_saturationWarning| under lock to avoid conflict with write op | |
72 // in ProcessAudio and also ensure that we don't hold the lock during the | |
73 // callback. | |
74 rtc::CritScope cs(&_critSect); | |
75 saturationWarning = _saturationWarning; | |
76 if (_saturationWarning) | |
77 _saturationWarning = false; | |
78 } | |
79 | |
80 if (saturationWarning) | |
81 { | |
82 rtc::CritScope cs(&_callbackCritSect); | |
83 if (_voiceEngineObserverPtr) | |
84 { | |
85 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | |
86 "TransmitMixer::OnPeriodicProcess() =>" | |
87 " CallbackOnError(VE_SATURATION_WARNING)"); | |
88 _voiceEngineObserverPtr->CallbackOnError(-1, VE_SATURATION_WARNING); | |
89 } | |
90 } | |
91 } | |
92 | |
93 | |
94 void TransmitMixer::PlayNotification(int32_t id, | 69 void TransmitMixer::PlayNotification(int32_t id, |
95 uint32_t durationMs) | 70 uint32_t durationMs) |
96 { | 71 { |
97 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 72 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
98 "TransmitMixer::PlayNotification(id=%d, durationMs=%d)", | 73 "TransmitMixer::PlayNotification(id=%d, durationMs=%d)", |
99 id, durationMs); | 74 id, durationMs); |
100 | 75 |
101 // Not implement yet | 76 // Not implement yet |
102 } | 77 } |
103 | 78 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 TransmitMixer::Destroy(TransmitMixer*& mixer) | 144 TransmitMixer::Destroy(TransmitMixer*& mixer) |
170 { | 145 { |
171 if (mixer) | 146 if (mixer) |
172 { | 147 { |
173 delete mixer; | 148 delete mixer; |
174 mixer = NULL; | 149 mixer = NULL; |
175 } | 150 } |
176 } | 151 } |
177 | 152 |
178 TransmitMixer::TransmitMixer(uint32_t instanceId) : | 153 TransmitMixer::TransmitMixer(uint32_t instanceId) : |
179 _monitorModule(this), | |
180 // Avoid conflict with other channels by adding 1024 - 1026, | 154 // Avoid conflict with other channels by adding 1024 - 1026, |
181 // won't use as much as 1024 channels. | 155 // won't use as much as 1024 channels. |
182 _filePlayerId(instanceId + 1024), | 156 _filePlayerId(instanceId + 1024), |
183 _fileRecorderId(instanceId + 1025), | 157 _fileRecorderId(instanceId + 1025), |
184 _fileCallRecorderId(instanceId + 1026), | 158 _fileCallRecorderId(instanceId + 1026), |
159 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION | |
160 _monitorModule(this), | |
161 #endif | |
185 _instanceId(instanceId) | 162 _instanceId(instanceId) |
186 { | 163 { |
187 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), | 164 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), |
188 "TransmitMixer::TransmitMixer() - ctor"); | 165 "TransmitMixer::TransmitMixer() - ctor"); |
189 } | 166 } |
190 | 167 |
191 TransmitMixer::~TransmitMixer() | 168 TransmitMixer::~TransmitMixer() |
192 { | 169 { |
193 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), | 170 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), |
194 "TransmitMixer::~TransmitMixer() - dtor"); | 171 "TransmitMixer::~TransmitMixer() - dtor"); |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1070 audioproc_->set_stream_key_pressed(key_pressed); | 1047 audioproc_->set_stream_key_pressed(key_pressed); |
1071 | 1048 |
1072 int err = audioproc_->ProcessStream(&_audioFrame); | 1049 int err = audioproc_->ProcessStream(&_audioFrame); |
1073 if (err != 0) { | 1050 if (err != 0) { |
1074 LOG(LS_ERROR) << "ProcessStream() error: " << err; | 1051 LOG(LS_ERROR) << "ProcessStream() error: " << err; |
1075 assert(false); | 1052 assert(false); |
1076 } | 1053 } |
1077 | 1054 |
1078 // Store new capture level. Only updated when analog AGC is enabled. | 1055 // Store new capture level. Only updated when analog AGC is enabled. |
1079 _captureLevel = agc->stream_analog_level(); | 1056 _captureLevel = agc->stream_analog_level(); |
1080 | |
1081 rtc::CritScope cs(&_critSect); | |
tommi
2017/02/28 11:46:43
look, we can haz one less locks!
| |
1082 // Triggers a callback in OnPeriodicProcess(). | |
1083 _saturationWarning |= agc->stream_is_saturated(); | |
1084 } | 1057 } |
1085 | 1058 |
1086 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION | 1059 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
1087 void TransmitMixer::TypingDetection(bool keyPressed) | 1060 void TransmitMixer::TypingDetection(bool keyPressed) |
1088 { | 1061 { |
1089 // We let the VAD determine if we're using this feature or not. | 1062 // We let the VAD determine if we're using this feature or not. |
1090 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) { | 1063 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) { |
1091 return; | 1064 return; |
1092 } | 1065 } |
1093 | 1066 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { | 1111 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { |
1139 swap_stereo_channels_ = enable; | 1112 swap_stereo_channels_ = enable; |
1140 } | 1113 } |
1141 | 1114 |
1142 bool TransmitMixer::IsStereoChannelSwappingEnabled() { | 1115 bool TransmitMixer::IsStereoChannelSwappingEnabled() { |
1143 return swap_stereo_channels_; | 1116 return swap_stereo_channels_; |
1144 } | 1117 } |
1145 | 1118 |
1146 } // namespace voe | 1119 } // namespace voe |
1147 } // namespace webrtc | 1120 } // namespace webrtc |
OLD | NEW |