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

Unified Diff: webrtc/audio/voice_engines.cc

Issue 1403363003: Move VoiceEngineObserver into AudioSendStream so that we detect typing noises and return properly i… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: more includes Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/audio/voice_engines.h ('k') | webrtc/audio/webrtc_audio.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/audio/voice_engines.cc
diff --git a/webrtc/audio/voice_engines.cc b/webrtc/audio/voice_engines.cc
new file mode 100644
index 0000000000000000000000000000000000000000..51895f0ea29ee3dbbdc284f67e04823cec74e49a
--- /dev/null
+++ b/webrtc/audio/voice_engines.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015 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
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/audio/voice_engines.h"
+
+#include "webrtc/audio/typing_noise_observer.h"
+#include "webrtc/base/checks.h"
+#include "webrtc/base/logging.h"
+#include "webrtc/voice_engine/include/voe_base.h"
+
+namespace webrtc {
+namespace internal {
+
+VoiceEngines::VoiceEngines() {
+ thread_checker_.DetachFromThread();
+}
+
+VoiceEngines::~VoiceEngines() {
+ RTC_DCHECK_EQ(voice_engines_.size(), 0u);
+}
+
+void VoiceEngines::RegisterVoiceEngine(VoiceEngine* voice_engine) {
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ RTC_DCHECK(voice_engine);
+ auto it = voice_engines_.find(voice_engine);
+ if (it == voice_engines_.end()) {
+ State state;
+ state.voe_base_ = VoEBase::GetInterface(voice_engine);
+ RTC_DCHECK(state.voe_base_);
+ state.observer_ = new TypingNoiseObserver();
+ if (state.voe_base_->RegisterVoiceEngineObserver(*state.observer_) == -1) {
+ LOG(LS_WARNING) << "VoEObserver already registered!";
+ delete state.observer_;
+ state.observer_ = nullptr;
+ }
+ it = voice_engines_.insert(voice_engines_.begin(),
+ std::make_pair(voice_engine, state));
+ }
+ it->second.ref_count_++;
+}
+
+void VoiceEngines::DeregisterVoiceEngine(VoiceEngine* voice_engine) {
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ auto it = voice_engines_.find(voice_engine);
+ RTC_DCHECK(it != voice_engines_.end());
+ State& state = it->second;
+ RTC_DCHECK(state.ref_count_ >= 1);
+ state.ref_count_--;
+ if (state.ref_count_ == 0) {
+ if (state.observer_) {
+ state.voe_base_->DeRegisterVoiceEngineObserver();
+ delete state.observer_;
+ state.observer_ = nullptr;
+ }
+ state.voe_base_->Release();
+ voice_engines_.erase(it);
+ }
+}
+
+bool VoiceEngines::GetTypingNoiseDetected(VoiceEngine* voice_engine) const {
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ auto it = voice_engines_.find(voice_engine);
+ RTC_DCHECK(it != voice_engines_.end());
+ if (it->second.observer_) {
+ return it->second.observer_->typing_noise_detected();
+ } else {
+ return false;
+ }
+}
+} // namespace internal
+} // namespace webrtc
« no previous file with comments | « webrtc/audio/voice_engines.h ('k') | webrtc/audio/webrtc_audio.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698