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 AUDIO_AUDIO_STATE_H_ 12 #define AUDIO_AUDIO_STATE_H_ 13 14 #include <map> 15 #include <memory> 16 17 #include "api/sequence_checker.h" 18 #include "audio/audio_transport_impl.h" 19 #include "call/audio_state.h" 20 #include "rtc_base/containers/flat_set.h" 21 #include "rtc_base/ref_count.h" 22 #include "rtc_base/task_utils/repeating_task.h" 23 #include "rtc_base/thread_annotations.h" 24 25 namespace webrtc { 26 27 class AudioSendStream; 28 class AudioReceiveStreamInterface; 29 30 namespace internal { 31 32 class AudioState : public webrtc::AudioState { 33 public: 34 explicit AudioState(const AudioState::Config& config); 35 36 AudioState() = delete; 37 AudioState(const AudioState&) = delete; 38 AudioState& operator=(const AudioState&) = delete; 39 40 ~AudioState() override; 41 42 AudioProcessing* audio_processing() override; 43 AudioTransport* audio_transport() override; 44 45 void SetPlayout(bool enabled) override; 46 void SetRecording(bool enabled) override; 47 48 void SetStereoChannelSwapping(bool enable) override; 49 audio_device_module()50 AudioDeviceModule* audio_device_module() { 51 RTC_DCHECK(config_.audio_device_module); 52 return config_.audio_device_module.get(); 53 } 54 55 void AddReceivingStream(webrtc::AudioReceiveStreamInterface* stream); 56 void RemoveReceivingStream(webrtc::AudioReceiveStreamInterface* stream); 57 58 void AddSendingStream(webrtc::AudioSendStream* stream, 59 int sample_rate_hz, 60 size_t num_channels); 61 void RemoveSendingStream(webrtc::AudioSendStream* stream); 62 63 private: 64 void UpdateAudioTransportWithSendingStreams(); 65 void UpdateNullAudioPollerState() RTC_RUN_ON(&thread_checker_); 66 67 SequenceChecker thread_checker_; 68 SequenceChecker process_thread_checker_; 69 const webrtc::AudioState::Config config_; 70 bool recording_enabled_ = true; 71 bool playout_enabled_ = true; 72 73 // Transports mixed audio from the mixer to the audio device and 74 // recorded audio to the sending streams. 75 AudioTransportImpl audio_transport_; 76 77 // Null audio poller is used to continue polling the audio streams if audio 78 // playout is disabled so that audio processing still happens and the audio 79 // stats are still updated. 80 RepeatingTaskHandle null_audio_poller_ RTC_GUARDED_BY(&thread_checker_); 81 82 webrtc::flat_set<webrtc::AudioReceiveStreamInterface*> receiving_streams_; 83 struct StreamProperties { 84 int sample_rate_hz = 0; 85 size_t num_channels = 0; 86 }; 87 std::map<webrtc::AudioSendStream*, StreamProperties> sending_streams_; 88 }; 89 } // namespace internal 90 } // namespace webrtc 91 92 #endif // AUDIO_AUDIO_STATE_H_ 93