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"); |
| 172 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
195 if (_processThreadPtr) | 173 if (_processThreadPtr) |
196 { | |
197 _processThreadPtr->DeRegisterModule(&_monitorModule); | 174 _processThreadPtr->DeRegisterModule(&_monitorModule); |
198 } | 175 #endif |
199 { | 176 { |
200 rtc::CritScope cs(&_critSect); | 177 rtc::CritScope cs(&_critSect); |
201 if (file_recorder_) { | 178 if (file_recorder_) { |
202 file_recorder_->RegisterModuleFileCallback(NULL); | 179 file_recorder_->RegisterModuleFileCallback(NULL); |
203 file_recorder_->StopRecording(); | 180 file_recorder_->StopRecording(); |
204 } | 181 } |
205 if (file_call_recorder_) { | 182 if (file_call_recorder_) { |
206 file_call_recorder_->RegisterModuleFileCallback(NULL); | 183 file_call_recorder_->RegisterModuleFileCallback(NULL); |
207 file_call_recorder_->StopRecording(); | 184 file_call_recorder_->StopRecording(); |
208 } | 185 } |
209 if (file_player_) { | 186 if (file_player_) { |
210 file_player_->RegisterModuleFileCallback(NULL); | 187 file_player_->RegisterModuleFileCallback(NULL); |
211 file_player_->StopPlayingFile(); | 188 file_player_->StopPlayingFile(); |
212 } | 189 } |
213 } | 190 } |
214 } | 191 } |
215 | 192 |
216 int32_t | 193 int32_t |
217 TransmitMixer::SetEngineInformation(ProcessThread& processThread, | 194 TransmitMixer::SetEngineInformation(ProcessThread& processThread, |
218 Statistics& engineStatistics, | 195 Statistics& engineStatistics, |
219 ChannelManager& channelManager) | 196 ChannelManager& channelManager) |
220 { | 197 { |
221 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 198 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
222 "TransmitMixer::SetEngineInformation()"); | 199 "TransmitMixer::SetEngineInformation()"); |
223 | 200 |
224 _processThreadPtr = &processThread; | 201 _processThreadPtr = &processThread; |
225 _engineStatisticsPtr = &engineStatistics; | 202 _engineStatisticsPtr = &engineStatistics; |
226 _channelManagerPtr = &channelManager; | 203 _channelManagerPtr = &channelManager; |
227 | 204 |
| 205 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
228 _processThreadPtr->RegisterModule(&_monitorModule); | 206 _processThreadPtr->RegisterModule(&_monitorModule); |
229 | 207 #endif |
230 return 0; | 208 return 0; |
231 } | 209 } |
232 | 210 |
233 int32_t | 211 int32_t |
234 TransmitMixer::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) | 212 TransmitMixer::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) |
235 { | 213 { |
236 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 214 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
237 "TransmitMixer::RegisterVoiceEngineObserver()"); | 215 "TransmitMixer::RegisterVoiceEngineObserver()"); |
238 rtc::CritScope cs(&_callbackCritSect); | 216 rtc::CritScope cs(&_callbackCritSect); |
239 | 217 |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 audioproc_->set_stream_key_pressed(key_pressed); | 1048 audioproc_->set_stream_key_pressed(key_pressed); |
1071 | 1049 |
1072 int err = audioproc_->ProcessStream(&_audioFrame); | 1050 int err = audioproc_->ProcessStream(&_audioFrame); |
1073 if (err != 0) { | 1051 if (err != 0) { |
1074 LOG(LS_ERROR) << "ProcessStream() error: " << err; | 1052 LOG(LS_ERROR) << "ProcessStream() error: " << err; |
1075 assert(false); | 1053 assert(false); |
1076 } | 1054 } |
1077 | 1055 |
1078 // Store new capture level. Only updated when analog AGC is enabled. | 1056 // Store new capture level. Only updated when analog AGC is enabled. |
1079 _captureLevel = agc->stream_analog_level(); | 1057 _captureLevel = agc->stream_analog_level(); |
1080 | |
1081 rtc::CritScope cs(&_critSect); | |
1082 // Triggers a callback in OnPeriodicProcess(). | |
1083 _saturationWarning |= agc->stream_is_saturated(); | |
1084 } | 1058 } |
1085 | 1059 |
1086 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION | 1060 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
1087 void TransmitMixer::TypingDetection(bool keyPressed) | 1061 void TransmitMixer::TypingDetection(bool keyPressed) |
1088 { | 1062 { |
1089 // We let the VAD determine if we're using this feature or not. | 1063 // We let the VAD determine if we're using this feature or not. |
1090 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) { | 1064 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) { |
1091 return; | 1065 return; |
1092 } | 1066 } |
1093 | 1067 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { | 1112 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { |
1139 swap_stereo_channels_ = enable; | 1113 swap_stereo_channels_ = enable; |
1140 } | 1114 } |
1141 | 1115 |
1142 bool TransmitMixer::IsStereoChannelSwappingEnabled() { | 1116 bool TransmitMixer::IsStereoChannelSwappingEnabled() { |
1143 return swap_stereo_channels_; | 1117 return swap_stereo_channels_; |
1144 } | 1118 } |
1145 | 1119 |
1146 } // namespace voe | 1120 } // namespace voe |
1147 } // namespace webrtc | 1121 } // namespace webrtc |
OLD | NEW |