audio_state.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef AUDIO_AUDIO_STATE_H_
  11. #define AUDIO_AUDIO_STATE_H_
  12. #include <map>
  13. #include <memory>
  14. #include <unordered_set>
  15. #include "audio/audio_transport_impl.h"
  16. #include "audio/null_audio_poller.h"
  17. #include "call/audio_state.h"
  18. #include "rtc_base/constructor_magic.h"
  19. #include "rtc_base/critical_section.h"
  20. #include "rtc_base/ref_count.h"
  21. #include "rtc_base/thread_checker.h"
  22. namespace webrtc {
  23. class AudioSendStream;
  24. class AudioReceiveStream;
  25. namespace internal {
  26. class AudioState : public webrtc::AudioState {
  27. public:
  28. explicit AudioState(const AudioState::Config& config);
  29. ~AudioState() override;
  30. AudioProcessing* audio_processing() override;
  31. AudioTransport* audio_transport() override;
  32. void SetPlayout(bool enabled) override;
  33. void SetRecording(bool enabled) override;
  34. void SetStereoChannelSwapping(bool enable) override;
  35. AudioDeviceModule* audio_device_module() {
  36. RTC_DCHECK(config_.audio_device_module);
  37. return config_.audio_device_module.get();
  38. }
  39. bool typing_noise_detected() const;
  40. void AddReceivingStream(webrtc::AudioReceiveStream* stream);
  41. void RemoveReceivingStream(webrtc::AudioReceiveStream* stream);
  42. void AddSendingStream(webrtc::AudioSendStream* stream,
  43. int sample_rate_hz,
  44. size_t num_channels);
  45. void RemoveSendingStream(webrtc::AudioSendStream* stream);
  46. private:
  47. void UpdateAudioTransportWithSendingStreams();
  48. void UpdateNullAudioPollerState();
  49. rtc::ThreadChecker thread_checker_;
  50. rtc::ThreadChecker process_thread_checker_;
  51. const webrtc::AudioState::Config config_;
  52. bool recording_enabled_ = true;
  53. bool playout_enabled_ = true;
  54. // Transports mixed audio from the mixer to the audio device and
  55. // recorded audio to the sending streams.
  56. AudioTransportImpl audio_transport_;
  57. // Null audio poller is used to continue polling the audio streams if audio
  58. // playout is disabled so that audio processing still happens and the audio
  59. // stats are still updated.
  60. std::unique_ptr<NullAudioPoller> null_audio_poller_;
  61. std::unordered_set<webrtc::AudioReceiveStream*> receiving_streams_;
  62. struct StreamProperties {
  63. int sample_rate_hz = 0;
  64. size_t num_channels = 0;
  65. };
  66. std::map<webrtc::AudioSendStream*, StreamProperties> sending_streams_;
  67. RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState);
  68. };
  69. } // namespace internal
  70. } // namespace webrtc
  71. #endif // AUDIO_AUDIO_STATE_H_