blob: 14dc78891b1ef7382aedccc791a0c97599543b77 [file] [log] [blame]
solenberg566ef242015-11-06 15:34:49 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef AUDIO_AUDIO_STATE_H_
12#define AUDIO_AUDIO_STATE_H_
solenberg566ef242015-11-06 15:34:49 -080013
Fredrik Solenberg2a877972017-12-15 16:42:15 +010014#include <map>
henrika5f6bf242017-11-01 11:06:56 +010015#include <memory>
16
Fredrik Solenberg2a877972017-12-15 16:42:15 +010017#include "audio/audio_transport_impl.h"
henrika5f6bf242017-11-01 11:06:56 +010018#include "audio/null_audio_poller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "audio/scoped_voe_interface.h"
20#include "call/audio_state.h"
21#include "rtc_base/constructormagic.h"
22#include "rtc_base/criticalsection.h"
Niels Möller6f72f562017-10-19 13:15:17 +020023#include "rtc_base/refcount.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/thread_checker.h"
25#include "voice_engine/include/voe_base.h"
solenberg566ef242015-11-06 15:34:49 -080026
27namespace webrtc {
Fredrik Solenberg2a877972017-12-15 16:42:15 +010028
29class AudioSendStream;
30
solenberg566ef242015-11-06 15:34:49 -080031namespace internal {
32
solenbergfc3a2e32017-09-26 09:35:01 -070033class AudioState final : public webrtc::AudioState {
solenberg566ef242015-11-06 15:34:49 -080034 public:
35 explicit AudioState(const AudioState::Config& config);
36 ~AudioState() override;
37
peaha9cc40b2017-06-29 08:32:09 -070038 AudioProcessing* audio_processing() override {
peahe67bedb2017-07-07 04:25:11 -070039 RTC_DCHECK(config_.audio_processing);
40 return config_.audio_processing.get();
peaha9cc40b2017-06-29 08:32:09 -070041 }
Fredrik Solenberg63e60722017-11-20 22:12:21 +010042 AudioTransport* audio_transport() override {
Fredrik Solenberg2a877972017-12-15 16:42:15 +010043 return &audio_transport_;
Fredrik Solenberg63e60722017-11-20 22:12:21 +010044 }
aleloidd310712016-11-17 06:28:59 -080045
henrika5f6bf242017-11-01 11:06:56 +010046 void SetPlayout(bool enabled) override;
47 void SetRecording(bool enabled) override;
48
Fredrik Solenberg2a877972017-12-15 16:42:15 +010049 Stats GetAudioInputStats() const override;
50 void SetStereoChannelSwapping(bool enable) override;
51
peaha9cc40b2017-06-29 08:32:09 -070052 VoiceEngine* voice_engine();
aleloidd310712016-11-17 06:28:59 -080053 rtc::scoped_refptr<AudioMixer> mixer();
solenberg566ef242015-11-06 15:34:49 -080054 bool typing_noise_detected() const;
55
Fredrik Solenberg2a877972017-12-15 16:42:15 +010056 void AddSendingStream(webrtc::AudioSendStream* stream,
57 int sample_rate_hz, size_t num_channels);
58 void RemoveSendingStream(webrtc::AudioSendStream* stream);
59
solenberg566ef242015-11-06 15:34:49 -080060 private:
61 // rtc::RefCountInterface implementation.
Niels Möller6f72f562017-10-19 13:15:17 +020062 void AddRef() const override;
63 rtc::RefCountReleaseStatus Release() const override;
solenberg566ef242015-11-06 15:34:49 -080064
Fredrik Solenberg2a877972017-12-15 16:42:15 +010065 void UpdateAudioTransportWithSendingStreams();
66
solenberg566ef242015-11-06 15:34:49 -080067 rtc::ThreadChecker thread_checker_;
68 rtc::ThreadChecker process_thread_checker_;
69 const webrtc::AudioState::Config config_;
70
71 // We hold one interface pointer to the VoE to make sure it is kept alive.
72 ScopedVoEInterface<VoEBase> voe_base_;
73
solenberg566ef242015-11-06 15:34:49 -080074 // Reference count; implementation copied from rtc::RefCountedObject.
Niels Möller9155e492017-10-23 11:22:30 +020075 // TODO(nisse): Use RefCountedObject or RefCountedBase instead.
solenberg566ef242015-11-06 15:34:49 -080076 mutable volatile int ref_count_ = 0;
77
aleloidd310712016-11-17 06:28:59 -080078 // Transports mixed audio from the mixer to the audio device and
Fredrik Solenberg2a877972017-12-15 16:42:15 +010079 // recorded audio to the sending streams.
80 AudioTransportImpl audio_transport_;
aleloidd310712016-11-17 06:28:59 -080081
henrika5f6bf242017-11-01 11:06:56 +010082 // 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 std::unique_ptr<NullAudioPoller> null_audio_poller_;
86
Fredrik Solenberg2a877972017-12-15 16:42:15 +010087 struct StreamProperties {
88 int sample_rate_hz = 0;
89 size_t num_channels = 0;
90 };
91 std::map<webrtc::AudioSendStream*, StreamProperties> sending_streams_;
92
solenberg566ef242015-11-06 15:34:49 -080093 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState);
94};
95} // namespace internal
96} // namespace webrtc
97
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020098#endif // AUDIO_AUDIO_STATE_H_