solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef AUDIO_AUDIO_STATE_H_ |
| 12 | #define AUDIO_AUDIO_STATE_H_ |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 14 | #include "audio/audio_transport_proxy.h" |
| 15 | #include "audio/scoped_voe_interface.h" |
| 16 | #include "call/audio_state.h" |
| 17 | #include "rtc_base/constructormagic.h" |
| 18 | #include "rtc_base/criticalsection.h" |
| 19 | #include "rtc_base/thread_checker.h" |
| 20 | #include "voice_engine/include/voe_base.h" |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace internal { |
| 24 | |
| 25 | class AudioState final : public webrtc::AudioState, |
| 26 | public webrtc::VoiceEngineObserver { |
| 27 | public: |
| 28 | explicit AudioState(const AudioState::Config& config); |
| 29 | ~AudioState() override; |
| 30 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 31 | AudioProcessing* audio_processing() override { |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 32 | RTC_DCHECK(config_.audio_processing); |
| 33 | return config_.audio_processing.get(); |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 34 | } |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 35 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 36 | VoiceEngine* voice_engine(); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 37 | rtc::scoped_refptr<AudioMixer> mixer(); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 38 | bool typing_noise_detected() const; |
| 39 | |
| 40 | private: |
| 41 | // rtc::RefCountInterface implementation. |
| 42 | int AddRef() const override; |
| 43 | int Release() const override; |
| 44 | |
| 45 | // webrtc::VoiceEngineObserver implementation. |
| 46 | void CallbackOnError(int channel_id, int err_code) override; |
| 47 | |
| 48 | rtc::ThreadChecker thread_checker_; |
| 49 | rtc::ThreadChecker process_thread_checker_; |
| 50 | const webrtc::AudioState::Config config_; |
| 51 | |
| 52 | // We hold one interface pointer to the VoE to make sure it is kept alive. |
| 53 | ScopedVoEInterface<VoEBase> voe_base_; |
| 54 | |
| 55 | // The critical section isn't strictly needed in this case, but xSAN bots may |
| 56 | // trigger on unprotected cross-thread access. |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 57 | rtc::CriticalSection crit_sect_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 58 | bool typing_noise_detected_ RTC_GUARDED_BY(crit_sect_) = false; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 59 | |
| 60 | // Reference count; implementation copied from rtc::RefCountedObject. |
| 61 | mutable volatile int ref_count_ = 0; |
| 62 | |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 63 | // Transports mixed audio from the mixer to the audio device and |
| 64 | // recorded audio to the VoE AudioTransport. |
| 65 | AudioTransportProxy audio_transport_proxy_; |
| 66 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 67 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState); |
| 68 | }; |
| 69 | } // namespace internal |
| 70 | } // namespace webrtc |
| 71 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 72 | #endif // AUDIO_AUDIO_STATE_H_ |