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

Side by Side 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, 1 month 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 | « webrtc/audio/voice_engines.h ('k') | webrtc/audio/webrtc_audio.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/audio/voice_engines.h"
12
13 #include "webrtc/audio/typing_noise_observer.h"
14 #include "webrtc/base/checks.h"
15 #include "webrtc/base/logging.h"
16 #include "webrtc/voice_engine/include/voe_base.h"
17
18 namespace webrtc {
19 namespace internal {
20
21 VoiceEngines::VoiceEngines() {
22 thread_checker_.DetachFromThread();
23 }
24
25 VoiceEngines::~VoiceEngines() {
26 RTC_DCHECK_EQ(voice_engines_.size(), 0u);
27 }
28
29 void VoiceEngines::RegisterVoiceEngine(VoiceEngine* voice_engine) {
30 RTC_DCHECK(thread_checker_.CalledOnValidThread());
31 RTC_DCHECK(voice_engine);
32 auto it = voice_engines_.find(voice_engine);
33 if (it == voice_engines_.end()) {
34 State state;
35 state.voe_base_ = VoEBase::GetInterface(voice_engine);
36 RTC_DCHECK(state.voe_base_);
37 state.observer_ = new TypingNoiseObserver();
38 if (state.voe_base_->RegisterVoiceEngineObserver(*state.observer_) == -1) {
39 LOG(LS_WARNING) << "VoEObserver already registered!";
40 delete state.observer_;
41 state.observer_ = nullptr;
42 }
43 it = voice_engines_.insert(voice_engines_.begin(),
44 std::make_pair(voice_engine, state));
45 }
46 it->second.ref_count_++;
47 }
48
49 void VoiceEngines::DeregisterVoiceEngine(VoiceEngine* voice_engine) {
50 RTC_DCHECK(thread_checker_.CalledOnValidThread());
51 auto it = voice_engines_.find(voice_engine);
52 RTC_DCHECK(it != voice_engines_.end());
53 State& state = it->second;
54 RTC_DCHECK(state.ref_count_ >= 1);
55 state.ref_count_--;
56 if (state.ref_count_ == 0) {
57 if (state.observer_) {
58 state.voe_base_->DeRegisterVoiceEngineObserver();
59 delete state.observer_;
60 state.observer_ = nullptr;
61 }
62 state.voe_base_->Release();
63 voice_engines_.erase(it);
64 }
65 }
66
67 bool VoiceEngines::GetTypingNoiseDetected(VoiceEngine* voice_engine) const {
68 RTC_DCHECK(thread_checker_.CalledOnValidThread());
69 auto it = voice_engines_.find(voice_engine);
70 RTC_DCHECK(it != voice_engines_.end());
71 if (it->second.observer_) {
72 return it->second.observer_->typing_noise_detected();
73 } else {
74 return false;
75 }
76 }
77 } // namespace internal
78 } // namespace webrtc
OLDNEW
« 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