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