audio_state.h 2.8 KB

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