Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(917)

Side by Side Diff: voice_engine/transmit_mixer.cc

Issue 3019513002: Remove the VoiceEngineObserver callback interface. (Closed)
Patch Set: rebase + build error Created 3 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « voice_engine/transmit_mixer.h ('k') | voice_engine/voe_base_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "voice_engine/transmit_mixer.h" 11 #include "voice_engine/transmit_mixer.h"
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "audio/utility/audio_frame_operations.h" 15 #include "audio/utility/audio_frame_operations.h"
16 #include "rtc_base/format_macros.h" 16 #include "rtc_base/format_macros.h"
17 #include "rtc_base/location.h" 17 #include "rtc_base/location.h"
18 #include "rtc_base/logging.h" 18 #include "rtc_base/logging.h"
19 #include "system_wrappers/include/event_wrapper.h" 19 #include "system_wrappers/include/event_wrapper.h"
20 #include "system_wrappers/include/trace.h" 20 #include "system_wrappers/include/trace.h"
21 #include "voice_engine/channel.h" 21 #include "voice_engine/channel.h"
22 #include "voice_engine/channel_manager.h" 22 #include "voice_engine/channel_manager.h"
23 #include "voice_engine/statistics.h" 23 #include "voice_engine/statistics.h"
24 #include "voice_engine/utility.h" 24 #include "voice_engine/utility.h"
25 #include "voice_engine/voe_base_impl.h"
26 25
27 namespace webrtc { 26 namespace webrtc {
28 namespace voe { 27 namespace voe {
29 28
30 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION 29 // TODO(solenberg): The thread safety in this class is dubious.
31 // TODO(ajm): The thread safety of this is dubious...
32 void TransmitMixer::OnPeriodicProcess()
33 {
34 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1),
35 "TransmitMixer::OnPeriodicProcess()");
36
37 bool send_typing_noise_warning = false;
38 bool typing_noise_detected = false;
39 {
40 rtc::CritScope 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) {
48 rtc::CritScope cs(&_callbackCritSect);
49 if (_voiceEngineObserverPtr) {
50 if (typing_noise_detected) {
51 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1),
52 "TransmitMixer::OnPeriodicProcess() => "
53 "CallbackOnError(VE_TYPING_NOISE_WARNING)");
54 _voiceEngineObserverPtr->CallbackOnError(
55 -1,
56 VE_TYPING_NOISE_WARNING);
57 } else {
58 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1),
59 "TransmitMixer::OnPeriodicProcess() => "
60 "CallbackOnError(VE_TYPING_NOISE_OFF_WARNING)");
61 _voiceEngineObserverPtr->CallbackOnError(
62 -1,
63 VE_TYPING_NOISE_OFF_WARNING);
64 }
65 }
66 }
67 }
68 #endif // WEBRTC_VOICE_ENGINE_TYPING_DETECTION
69 30
70 int32_t 31 int32_t
71 TransmitMixer::Create(TransmitMixer*& mixer, uint32_t instanceId) 32 TransmitMixer::Create(TransmitMixer*& mixer, uint32_t instanceId)
72 { 33 {
73 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, -1), 34 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, -1),
74 "TransmitMixer::Create(instanceId=%d)", instanceId); 35 "TransmitMixer::Create(instanceId=%d)", instanceId);
75 mixer = new TransmitMixer(instanceId); 36 mixer = new TransmitMixer(instanceId);
76 if (mixer == NULL) 37 if (mixer == NULL)
77 { 38 {
78 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, -1), 39 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, -1),
79 "TransmitMixer::Create() unable to allocate memory" 40 "TransmitMixer::Create() unable to allocate memory"
80 "for mixer"); 41 "for mixer");
81 return -1; 42 return -1;
82 } 43 }
83 return 0; 44 return 0;
84 } 45 }
85 46
86 void 47 void
87 TransmitMixer::Destroy(TransmitMixer*& mixer) 48 TransmitMixer::Destroy(TransmitMixer*& mixer)
88 { 49 {
89 if (mixer) 50 if (mixer)
90 { 51 {
91 delete mixer; 52 delete mixer;
92 mixer = NULL; 53 mixer = NULL;
93 } 54 }
94 } 55 }
95 56
96 TransmitMixer::TransmitMixer(uint32_t instanceId) : 57 TransmitMixer::TransmitMixer(uint32_t instanceId) :
97 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
98 _monitorModule(this),
99 #endif
100 _instanceId(instanceId) 58 _instanceId(instanceId)
101 { 59 {
102 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), 60 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1),
103 "TransmitMixer::TransmitMixer() - ctor"); 61 "TransmitMixer::TransmitMixer() - ctor");
104 } 62 }
105 63
106 TransmitMixer::~TransmitMixer() 64 TransmitMixer::~TransmitMixer() = default;
107 { 65
108 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), 66 void TransmitMixer::SetEngineInformation(ChannelManager* channelManager) {
109 "TransmitMixer::~TransmitMixer() - dtor"); 67 _channelManagerPtr = channelManager;
110 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
111 if (_processThreadPtr)
112 _processThreadPtr->DeRegisterModule(&_monitorModule);
113 #endif
114 } 68 }
115 69
116 int32_t 70 int32_t
117 TransmitMixer::SetEngineInformation(ProcessThread& processThread,
118 Statistics& engineStatistics,
119 ChannelManager& channelManager)
120 {
121 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1),
122 "TransmitMixer::SetEngineInformation()");
123
124 _processThreadPtr = &processThread;
125 _engineStatisticsPtr = &engineStatistics;
126 _channelManagerPtr = &channelManager;
127
128 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
129 _processThreadPtr->RegisterModule(&_monitorModule, RTC_FROM_HERE);
130 #endif
131 return 0;
132 }
133
134 int32_t
135 TransmitMixer::RegisterVoiceEngineObserver(VoiceEngineObserver& observer)
136 {
137 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1),
138 "TransmitMixer::RegisterVoiceEngineObserver()");
139 rtc::CritScope cs(&_callbackCritSect);
140
141 if (_voiceEngineObserverPtr)
142 {
143 _engineStatisticsPtr->SetLastError(
144 VE_INVALID_OPERATION, kTraceError,
145 "RegisterVoiceEngineObserver() observer already enabled");
146 return -1;
147 }
148 _voiceEngineObserverPtr = &observer;
149 return 0;
150 }
151
152 int32_t
153 TransmitMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule) 71 TransmitMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule)
154 { 72 {
155 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), 73 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1),
156 "TransmitMixer::SetAudioProcessingModule(" 74 "TransmitMixer::SetAudioProcessingModule("
157 "audioProcessingModule=0x%x)", 75 "audioProcessingModule=0x%x)",
158 audioProcessingModule); 76 audioProcessingModule);
159 audioproc_ = audioProcessingModule; 77 audioproc_ = audioProcessingModule;
160 return 0; 78 return 0;
161 } 79 }
162 80
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 if (err != 0) { 234 if (err != 0) {
317 LOG(LS_ERROR) << "ProcessStream() error: " << err; 235 LOG(LS_ERROR) << "ProcessStream() error: " << err;
318 assert(false); 236 assert(false);
319 } 237 }
320 238
321 // Store new capture level. Only updated when analog AGC is enabled. 239 // Store new capture level. Only updated when analog AGC is enabled.
322 _captureLevel = agc->stream_analog_level(); 240 _captureLevel = agc->stream_analog_level();
323 } 241 }
324 242
325 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION 243 #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
326 void TransmitMixer::TypingDetection(bool keyPressed) 244 void TransmitMixer::TypingDetection(bool key_pressed)
327 { 245 {
328 // We let the VAD determine if we're using this feature or not. 246 // We let the VAD determine if we're using this feature or not.
329 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) { 247 if (_audioFrame.vad_activity_ == AudioFrame::kVadUnknown) {
330 return; 248 return;
331 } 249 }
332 250
333 bool vadActive = _audioFrame.vad_activity_ == AudioFrame::kVadActive; 251 bool vad_active = _audioFrame.vad_activity_ == AudioFrame::kVadActive;
334 if (_typingDetection.Process(keyPressed, vadActive)) { 252 bool typing_detected = typing_detection_.Process(key_pressed, vad_active);
335 rtc::CritScope cs(&_critSect); 253
336 _typingNoiseWarningPending = true; 254 rtc::CritScope cs(&lock_);
337 _typingNoiseDetected = true; 255 typing_noise_detected_ = typing_detected;
338 } else {
339 rtc::CritScope cs(&_critSect);
340 // If there is already a warning pending, do not change the state.
341 // Otherwise set a warning pending if last callback was for noise detected.
342 if (!_typingNoiseWarningPending && _typingNoiseDetected) {
343 _typingNoiseWarningPending = true;
344 _typingNoiseDetected = false;
345 }
346 }
347 } 256 }
348 #endif 257 #endif
349 258
350 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { 259 void TransmitMixer::EnableStereoChannelSwapping(bool enable) {
351 swap_stereo_channels_ = enable; 260 swap_stereo_channels_ = enable;
352 } 261 }
353 262
354 bool TransmitMixer::IsStereoChannelSwappingEnabled() { 263 bool TransmitMixer::IsStereoChannelSwappingEnabled() {
355 return swap_stereo_channels_; 264 return swap_stereo_channels_;
356 } 265 }
357 266
267 bool TransmitMixer::typing_noise_detected() const {
268 rtc::CritScope cs(&lock_);
269 return typing_noise_detected_;
270 }
271
358 } // namespace voe 272 } // namespace voe
359 } // namespace webrtc 273 } // namespace webrtc
OLDNEW
« no previous file with comments | « voice_engine/transmit_mixer.h ('k') | voice_engine/voe_base_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698