OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/audio/audio_state.h" | 11 #include "webrtc/audio/audio_state.h" |
12 | 12 |
13 #include "webrtc/base/atomicops.h" | 13 #include "webrtc/base/atomicops.h" |
14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
16 #include "webrtc/voice_engine/include/voe_errors.h" | 16 #include "webrtc/voice_engine/include/voe_errors.h" |
| 17 #include "webrtc/modules/audio_device/include/audio_device.h" |
| 18 #include "webrtc/modules/audio_device/include/audio_device_defines.h" |
17 | 19 |
18 namespace webrtc { | 20 namespace webrtc { |
19 namespace internal { | 21 namespace internal { |
20 | 22 |
21 AudioState::AudioState(const AudioState::Config& config) | 23 AudioState::AudioState(const AudioState::Config& config, |
22 : config_(config), voe_base_(config.voice_engine) { | 24 webrtc::AudioDeviceModule* adm) |
| 25 : config_(config), voe_base_(config.voice_engine), adm_(adm) { |
23 process_thread_checker_.DetachFromThread(); | 26 process_thread_checker_.DetachFromThread(); |
| 27 |
24 // Only one AudioState should be created per VoiceEngine. | 28 // Only one AudioState should be created per VoiceEngine. |
25 RTC_CHECK(voe_base_->RegisterVoiceEngineObserver(*this) != -1); | 29 RTC_CHECK(voe_base_->RegisterVoiceEngineObserver(*this) != -1); |
| 30 if (!adm_) { |
| 31 adm_ = voe_base_->audio_device_module(); |
| 32 } |
26 } | 33 } |
27 | 34 |
28 AudioState::~AudioState() { | 35 AudioState::~AudioState() { |
29 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 36 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
30 voe_base_->DeRegisterVoiceEngineObserver(); | 37 voe_base_->DeRegisterVoiceEngineObserver(); |
31 } | 38 } |
32 | 39 |
33 VoiceEngine* AudioState::voice_engine() { | 40 VoiceEngine* AudioState::voice_engine() { |
34 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 41 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
35 return config_.voice_engine; | 42 return config_.voice_engine; |
36 } | 43 } |
37 | 44 |
| 45 AudioDeviceModule* AudioState::audio_device() { |
| 46 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 47 return adm_; |
| 48 } |
| 49 |
38 bool AudioState::typing_noise_detected() const { | 50 bool AudioState::typing_noise_detected() const { |
39 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 51 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
40 rtc::CritScope lock(&crit_sect_); | 52 rtc::CritScope lock(&crit_sect_); |
41 return typing_noise_detected_; | 53 return typing_noise_detected_; |
42 } | 54 } |
43 | 55 |
44 // Reference count; implementation copied from rtc::RefCountedObject. | 56 // Reference count; implementation copied from rtc::RefCountedObject. |
45 int AudioState::AddRef() const { | 57 int AudioState::AddRef() const { |
46 return rtc::AtomicOps::Increment(&ref_count_); | 58 return rtc::AtomicOps::Increment(&ref_count_); |
47 } | 59 } |
(...skipping 18 matching lines...) Expand all Loading... |
66 rtc::CritScope lock(&crit_sect_); | 78 rtc::CritScope lock(&crit_sect_); |
67 typing_noise_detected_ = true; | 79 typing_noise_detected_ = true; |
68 } else if (err_code == VE_TYPING_NOISE_OFF_WARNING) { | 80 } else if (err_code == VE_TYPING_NOISE_OFF_WARNING) { |
69 rtc::CritScope lock(&crit_sect_); | 81 rtc::CritScope lock(&crit_sect_); |
70 typing_noise_detected_ = false; | 82 typing_noise_detected_ = false; |
71 } | 83 } |
72 } | 84 } |
73 } // namespace internal | 85 } // namespace internal |
74 | 86 |
75 rtc::scoped_refptr<AudioState> AudioState::Create( | 87 rtc::scoped_refptr<AudioState> AudioState::Create( |
76 const AudioState::Config& config) { | 88 const AudioState::Config& config, |
77 return rtc::scoped_refptr<AudioState>(new internal::AudioState(config)); | 89 webrtc::AudioDeviceModule* adm) { |
| 90 return rtc::scoped_refptr<AudioState>(new internal::AudioState(config, adm)); |
78 } | 91 } |
79 } // namespace webrtc | 92 } // namespace webrtc |
OLD | NEW |