| 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 "audio/audio_state.h" | 11 #include "audio/audio_state.h" |
| 12 | 12 |
| 13 #include "modules/audio_device/include/audio_device.h" | 13 #include "modules/audio_device/include/audio_device.h" |
| 14 #include "rtc_base/atomicops.h" | 14 #include "rtc_base/atomicops.h" |
| 15 #include "rtc_base/checks.h" | 15 #include "rtc_base/checks.h" |
| 16 #include "rtc_base/logging.h" | 16 #include "rtc_base/logging.h" |
| 17 #include "voice_engine/include/voe_errors.h" | 17 #include "voice_engine/transmit_mixer.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 namespace internal { | 20 namespace internal { |
| 21 | 21 |
| 22 AudioState::AudioState(const AudioState::Config& config) | 22 AudioState::AudioState(const AudioState::Config& config) |
| 23 : config_(config), | 23 : config_(config), |
| 24 voe_base_(config.voice_engine), | 24 voe_base_(config.voice_engine), |
| 25 audio_transport_proxy_(voe_base_->audio_transport(), | 25 audio_transport_proxy_(voe_base_->audio_transport(), |
| 26 config_.audio_processing.get(), | 26 config_.audio_processing.get(), |
| 27 config_.audio_mixer) { | 27 config_.audio_mixer) { |
| 28 process_thread_checker_.DetachFromThread(); | 28 process_thread_checker_.DetachFromThread(); |
| 29 RTC_DCHECK(config_.audio_mixer); | 29 RTC_DCHECK(config_.audio_mixer); |
| 30 | 30 |
| 31 // Only one AudioState should be created per VoiceEngine. | |
| 32 RTC_CHECK(voe_base_->RegisterVoiceEngineObserver(*this) != -1); | |
| 33 | |
| 34 auto* const device = voe_base_->audio_device_module(); | 31 auto* const device = voe_base_->audio_device_module(); |
| 35 RTC_DCHECK(device); | 32 RTC_DCHECK(device); |
| 36 | 33 |
| 37 // This is needed for the Chrome implementation of RegisterAudioCallback. | 34 // This is needed for the Chrome implementation of RegisterAudioCallback. |
| 38 device->RegisterAudioCallback(nullptr); | 35 device->RegisterAudioCallback(nullptr); |
| 39 device->RegisterAudioCallback(&audio_transport_proxy_); | 36 device->RegisterAudioCallback(&audio_transport_proxy_); |
| 40 } | 37 } |
| 41 | 38 |
| 42 AudioState::~AudioState() { | 39 AudioState::~AudioState() { |
| 43 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 40 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 44 voe_base_->DeRegisterVoiceEngineObserver(); | |
| 45 } | 41 } |
| 46 | 42 |
| 47 VoiceEngine* AudioState::voice_engine() { | 43 VoiceEngine* AudioState::voice_engine() { |
| 48 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 44 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 return config_.voice_engine; | 45 return config_.voice_engine; |
| 50 } | 46 } |
| 51 | 47 |
| 52 rtc::scoped_refptr<AudioMixer> AudioState::mixer() { | 48 rtc::scoped_refptr<AudioMixer> AudioState::mixer() { |
| 53 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 49 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 return config_.audio_mixer; | 50 return config_.audio_mixer; |
| 55 } | 51 } |
| 56 | 52 |
| 57 bool AudioState::typing_noise_detected() const { | 53 bool AudioState::typing_noise_detected() const { |
| 58 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 54 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 59 rtc::CritScope lock(&crit_sect_); | 55 // TODO(solenberg): Remove const_cast once AudioState owns transmit mixer |
| 60 return typing_noise_detected_; | 56 // functionality. |
| 57 voe::TransmitMixer* transmit_mixer = |
| 58 const_cast<AudioState*>(this)->voe_base_->transmit_mixer(); |
| 59 return transmit_mixer->typing_noise_detected(); |
| 61 } | 60 } |
| 62 | 61 |
| 63 // Reference count; implementation copied from rtc::RefCountedObject. | 62 // Reference count; implementation copied from rtc::RefCountedObject. |
| 64 int AudioState::AddRef() const { | 63 int AudioState::AddRef() const { |
| 65 return rtc::AtomicOps::Increment(&ref_count_); | 64 return rtc::AtomicOps::Increment(&ref_count_); |
| 66 } | 65 } |
| 67 | 66 |
| 68 // Reference count; implementation copied from rtc::RefCountedObject. | 67 // Reference count; implementation copied from rtc::RefCountedObject. |
| 69 int AudioState::Release() const { | 68 int AudioState::Release() const { |
| 70 int count = rtc::AtomicOps::Decrement(&ref_count_); | 69 int count = rtc::AtomicOps::Decrement(&ref_count_); |
| 71 if (!count) { | 70 if (!count) { |
| 72 delete this; | 71 delete this; |
| 73 } | 72 } |
| 74 return count; | 73 return count; |
| 75 } | 74 } |
| 76 | |
| 77 void AudioState::CallbackOnError(int channel_id, int err_code) { | |
| 78 RTC_DCHECK(process_thread_checker_.CalledOnValidThread()); | |
| 79 | |
| 80 // All call sites in VoE, as of this writing, specify -1 as channel_id. | |
| 81 RTC_DCHECK(channel_id == -1); | |
| 82 LOG(LS_INFO) << "VoiceEngine error " << err_code << " reported on channel " | |
| 83 << channel_id << "."; | |
| 84 if (err_code == VE_TYPING_NOISE_WARNING) { | |
| 85 rtc::CritScope lock(&crit_sect_); | |
| 86 typing_noise_detected_ = true; | |
| 87 } else if (err_code == VE_TYPING_NOISE_OFF_WARNING) { | |
| 88 rtc::CritScope lock(&crit_sect_); | |
| 89 typing_noise_detected_ = false; | |
| 90 } | |
| 91 } | |
| 92 } // namespace internal | 75 } // namespace internal |
| 93 | 76 |
| 94 rtc::scoped_refptr<AudioState> AudioState::Create( | 77 rtc::scoped_refptr<AudioState> AudioState::Create( |
| 95 const AudioState::Config& config) { | 78 const AudioState::Config& config) { |
| 96 return rtc::scoped_refptr<AudioState>(new internal::AudioState(config)); | 79 return rtc::scoped_refptr<AudioState>(new internal::AudioState(config)); |
| 97 } | 80 } |
| 98 } // namespace webrtc | 81 } // namespace webrtc |
| OLD | NEW |