blob: f4bddbfa855cf656aaffe6e65a34c558d9936a6d [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
henrika5f6bf242017-11-01 11:06:56 +010014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "audio/audio_transport_proxy.h"
henrika5f6bf242017-11-01 11:06:56 +010017#include "audio/null_audio_poller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "audio/scoped_voe_interface.h"
19#include "call/audio_state.h"
20#include "rtc_base/constructormagic.h"
21#include "rtc_base/criticalsection.h"
Niels Möller6f72f562017-10-19 13:15:17 +020022#include "rtc_base/refcount.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/thread_checker.h"
24#include "voice_engine/include/voe_base.h"
solenberg566ef242015-11-06 15:34:49 -080025
26namespace webrtc {
27namespace internal {
28
solenbergfc3a2e32017-09-26 09:35:01 -070029class AudioState final : public webrtc::AudioState {
solenberg566ef242015-11-06 15:34:49 -080030 public:
31 explicit AudioState(const AudioState::Config& config);
32 ~AudioState() override;
33
peaha9cc40b2017-06-29 08:32:09 -070034 AudioProcessing* audio_processing() override {
peahe67bedb2017-07-07 04:25:11 -070035 RTC_DCHECK(config_.audio_processing);
36 return config_.audio_processing.get();
peaha9cc40b2017-06-29 08:32:09 -070037 }
Fredrik Solenberg63e60722017-11-20 22:12:21 +010038 AudioTransport* audio_transport() override {
39 return &audio_transport_proxy_;
40 }
aleloidd310712016-11-17 06:28:59 -080041
henrika5f6bf242017-11-01 11:06:56 +010042 void SetPlayout(bool enabled) override;
43 void SetRecording(bool enabled) override;
44
peaha9cc40b2017-06-29 08:32:09 -070045 VoiceEngine* voice_engine();
aleloidd310712016-11-17 06:28:59 -080046 rtc::scoped_refptr<AudioMixer> mixer();
solenberg566ef242015-11-06 15:34:49 -080047 bool typing_noise_detected() const;
48
49 private:
50 // rtc::RefCountInterface implementation.
Niels Möller6f72f562017-10-19 13:15:17 +020051 void AddRef() const override;
52 rtc::RefCountReleaseStatus Release() const override;
solenberg566ef242015-11-06 15:34:49 -080053
solenberg566ef242015-11-06 15:34:49 -080054 rtc::ThreadChecker thread_checker_;
55 rtc::ThreadChecker process_thread_checker_;
56 const webrtc::AudioState::Config config_;
57
58 // We hold one interface pointer to the VoE to make sure it is kept alive.
59 ScopedVoEInterface<VoEBase> voe_base_;
60
solenberg566ef242015-11-06 15:34:49 -080061 // Reference count; implementation copied from rtc::RefCountedObject.
Niels Möller9155e492017-10-23 11:22:30 +020062 // TODO(nisse): Use RefCountedObject or RefCountedBase instead.
solenberg566ef242015-11-06 15:34:49 -080063 mutable volatile int ref_count_ = 0;
64
aleloidd310712016-11-17 06:28:59 -080065 // Transports mixed audio from the mixer to the audio device and
66 // recorded audio to the VoE AudioTransport.
67 AudioTransportProxy audio_transport_proxy_;
68
henrika5f6bf242017-11-01 11:06:56 +010069 // Null audio poller is used to continue polling the audio streams if audio
70 // playout is disabled so that audio processing still happens and the audio
71 // stats are still updated.
72 std::unique_ptr<NullAudioPoller> null_audio_poller_;
73
solenberg566ef242015-11-06 15:34:49 -080074 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState);
75};
76} // namespace internal
77} // namespace webrtc
78
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#endif // AUDIO_AUDIO_STATE_H_