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" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "rtc_base/constructor_magic.h" |
| 22 | #include "rtc_base/critical_section.h" |
| 23 | #include "rtc_base/ref_count.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 | |
Niels Möller | ac63ac7 | 2019-01-08 13:47:12 +0100 | [diff] [blame] | 33 | class AudioState : 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 | |
Mirko Bonadei | 8fdcac3 | 2018-08-28 16:30:18 +0200 | [diff] [blame] | 38 | AudioProcessing* audio_processing() override; |
| 39 | AudioTransport* audio_transport() override; |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 40 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 41 | void SetPlayout(bool enabled) override; |
| 42 | void SetRecording(bool enabled) override; |
| 43 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 44 | void SetStereoChannelSwapping(bool enable) override; |
| 45 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 46 | AudioDeviceModule* audio_device_module() { |
| 47 | RTC_DCHECK(config_.audio_device_module); |
| 48 | return config_.audio_device_module.get(); |
| 49 | } |
| 50 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 51 | bool typing_noise_detected() const; |
| 52 | |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 53 | void AddReceivingStream(webrtc::AudioReceiveStream* stream); |
| 54 | void RemoveReceivingStream(webrtc::AudioReceiveStream* stream); |
| 55 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 56 | void AddSendingStream(webrtc::AudioSendStream* stream, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 57 | int sample_rate_hz, |
| 58 | size_t num_channels); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 59 | void RemoveSendingStream(webrtc::AudioSendStream* stream); |
| 60 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 61 | private: |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 62 | void UpdateAudioTransportWithSendingStreams(); |
| 63 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 64 | rtc::ThreadChecker thread_checker_; |
| 65 | rtc::ThreadChecker process_thread_checker_; |
| 66 | const webrtc::AudioState::Config config_; |
Fredrik Solenberg | aaedf75 | 2017-12-18 13:09:12 +0100 | [diff] [blame] | 67 | bool recording_enabled_ = true; |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 68 | bool playout_enabled_ = true; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 69 | |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 70 | // Transports mixed audio from the mixer to the audio device and |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 71 | // recorded audio to the sending streams. |
| 72 | AudioTransportImpl audio_transport_; |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 73 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 74 | // Null audio poller is used to continue polling the audio streams if audio |
| 75 | // playout is disabled so that audio processing still happens and the audio |
| 76 | // stats are still updated. |
| 77 | std::unique_ptr<NullAudioPoller> null_audio_poller_; |
| 78 | |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 79 | std::unordered_set<webrtc::AudioReceiveStream*> receiving_streams_; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 80 | struct StreamProperties { |
| 81 | int sample_rate_hz = 0; |
| 82 | size_t num_channels = 0; |
| 83 | }; |
| 84 | std::map<webrtc::AudioSendStream*, StreamProperties> sending_streams_; |
| 85 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 86 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState); |
| 87 | }; |
| 88 | } // namespace internal |
| 89 | } // namespace webrtc |
| 90 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 91 | #endif // AUDIO_AUDIO_STATE_H_ |