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