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 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 14 | #include <map> |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 15 | #include <memory> |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 16 | #include <unordered_set> |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 17 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 18 | #include "audio/audio_transport_impl.h" |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 19 | #include "audio/null_audio_poller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "call/audio_state.h" |
| 21 | #include "rtc_base/constructormagic.h" |
| 22 | #include "rtc_base/criticalsection.h" |
Niels Möller | 6f72f56 | 2017-10-19 13:15:17 +0200 | [diff] [blame] | 23 | #include "rtc_base/refcount.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "rtc_base/thread_checker.h" |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 27 | |
| 28 | class AudioSendStream; |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 29 | class AudioReceiveStream; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 30 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 31 | namespace internal { |
| 32 | |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 33 | class AudioState final : public webrtc::AudioState { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 34 | public: |
| 35 | explicit AudioState(const AudioState::Config& config); |
| 36 | ~AudioState() override; |
| 37 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 38 | AudioProcessing* audio_processing() override { |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 39 | RTC_DCHECK(config_.audio_processing); |
| 40 | return config_.audio_processing.get(); |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 41 | } |
Fredrik Solenberg | 63e6072 | 2017-11-20 22:12:21 +0100 | [diff] [blame] | 42 | AudioTransport* audio_transport() override { |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 43 | return &audio_transport_; |
Fredrik Solenberg | 63e6072 | 2017-11-20 22:12:21 +0100 | [diff] [blame] | 44 | } |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 45 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 46 | void SetPlayout(bool enabled) override; |
| 47 | void SetRecording(bool enabled) override; |
| 48 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 49 | Stats GetAudioInputStats() const override; |
| 50 | void SetStereoChannelSwapping(bool enable) override; |
| 51 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 52 | AudioDeviceModule* audio_device_module() { |
| 53 | RTC_DCHECK(config_.audio_device_module); |
| 54 | return config_.audio_device_module.get(); |
| 55 | } |
| 56 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 57 | bool typing_noise_detected() const; |
| 58 | |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 59 | void AddReceivingStream(webrtc::AudioReceiveStream* stream); |
| 60 | void RemoveReceivingStream(webrtc::AudioReceiveStream* stream); |
| 61 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 62 | void AddSendingStream(webrtc::AudioSendStream* stream, |
| 63 | int sample_rate_hz, size_t num_channels); |
| 64 | void RemoveSendingStream(webrtc::AudioSendStream* stream); |
| 65 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 66 | private: |
| 67 | // rtc::RefCountInterface implementation. |
Niels Möller | 6f72f56 | 2017-10-19 13:15:17 +0200 | [diff] [blame] | 68 | void AddRef() const override; |
| 69 | rtc::RefCountReleaseStatus Release() const override; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 70 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 71 | void UpdateAudioTransportWithSendingStreams(); |
| 72 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 73 | rtc::ThreadChecker thread_checker_; |
| 74 | rtc::ThreadChecker process_thread_checker_; |
| 75 | const webrtc::AudioState::Config config_; |
Fredrik Solenberg | aaedf75 | 2017-12-18 13:09:12 +0100 | [diff] [blame] | 76 | bool recording_enabled_ = true; |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 77 | bool playout_enabled_ = true; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 78 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 79 | // Reference count; implementation copied from rtc::RefCountedObject. |
Niels Möller | 9155e49 | 2017-10-23 11:22:30 +0200 | [diff] [blame] | 80 | // TODO(nisse): Use RefCountedObject or RefCountedBase instead. |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 81 | mutable volatile int ref_count_ = 0; |
| 82 | |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 83 | // Transports mixed audio from the mixer to the audio device and |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 84 | // recorded audio to the sending streams. |
| 85 | AudioTransportImpl audio_transport_; |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 86 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 87 | // Null audio poller is used to continue polling the audio streams if audio |
| 88 | // playout is disabled so that audio processing still happens and the audio |
| 89 | // stats are still updated. |
| 90 | std::unique_ptr<NullAudioPoller> null_audio_poller_; |
| 91 | |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 92 | std::unordered_set<webrtc::AudioReceiveStream*> receiving_streams_; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 93 | struct StreamProperties { |
| 94 | int sample_rate_hz = 0; |
| 95 | size_t num_channels = 0; |
| 96 | }; |
| 97 | std::map<webrtc::AudioSendStream*, StreamProperties> sending_streams_; |
| 98 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 99 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState); |
| 100 | }; |
| 101 | } // namespace internal |
| 102 | } // namespace webrtc |
| 103 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 104 | #endif // AUDIO_AUDIO_STATE_H_ |