• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <unordered_set>
17 
18 #include "audio/audio_transport_impl.h"
19 #include "audio/null_audio_poller.h"
20 #include "call/audio_state.h"
21 #include "rtc_base/constructor_magic.h"
22 #include "rtc_base/ref_count.h"
23 #include "rtc_base/thread_checker.h"
24 
25 namespace webrtc {
26 
27 class AudioSendStream;
28 class AudioReceiveStream;
29 
30 namespace internal {
31 
32 class AudioState : public webrtc::AudioState {
33  public:
34   explicit AudioState(const AudioState::Config& config);
35   ~AudioState() override;
36 
37   AudioProcessing* audio_processing() override;
38   AudioTransport* audio_transport() override;
39 
40   void SetPlayout(bool enabled) override;
41   void SetRecording(bool enabled) override;
42 
43   void SetStereoChannelSwapping(bool enable) override;
44 
audio_device_module()45   AudioDeviceModule* audio_device_module() {
46     RTC_DCHECK(config_.audio_device_module);
47     return config_.audio_device_module.get();
48   }
49 
50   bool typing_noise_detected() const;
51 
52   void AddReceivingStream(webrtc::AudioReceiveStream* stream);
53   void RemoveReceivingStream(webrtc::AudioReceiveStream* stream);
54 
55   void AddSendingStream(webrtc::AudioSendStream* stream,
56                         int sample_rate_hz,
57                         size_t num_channels);
58   void RemoveSendingStream(webrtc::AudioSendStream* stream);
59 
60  private:
61   void UpdateAudioTransportWithSendingStreams();
62   void UpdateNullAudioPollerState();
63 
64   rtc::ThreadChecker thread_checker_;
65   rtc::ThreadChecker process_thread_checker_;
66   const webrtc::AudioState::Config config_;
67   bool recording_enabled_ = true;
68   bool playout_enabled_ = true;
69 
70   // Transports mixed audio from the mixer to the audio device and
71   // recorded audio to the sending streams.
72   AudioTransportImpl audio_transport_;
73 
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 
79   std::unordered_set<webrtc::AudioReceiveStream*> receiving_streams_;
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 
86   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState);
87 };
88 }  // namespace internal
89 }  // namespace webrtc
90 
91 #endif  // AUDIO_AUDIO_STATE_H_
92