| 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
|
|
|