blob: 307f5cec4bc458d570d266f497d4efed271b1c6d [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
11#ifndef WEBRTC_AUDIO_AUDIO_STATE_H_
12#define WEBRTC_AUDIO_AUDIO_STATE_H_
13
kjellandera69d9732016-08-31 07:33:05 -070014#include "webrtc/api/call/audio_state.h"
aleloidd310712016-11-17 06:28:59 -080015#include "webrtc/audio/audio_transport_proxy.h"
solenberg566ef242015-11-06 15:34:49 -080016#include "webrtc/audio/scoped_voe_interface.h"
17#include "webrtc/base/constructormagic.h"
18#include "webrtc/base/criticalsection.h"
19#include "webrtc/base/thread_checker.h"
20#include "webrtc/voice_engine/include/voe_base.h"
21
22namespace webrtc {
23namespace internal {
24
25class AudioState final : public webrtc::AudioState,
26 public webrtc::VoiceEngineObserver {
27 public:
28 explicit AudioState(const AudioState::Config& config);
29 ~AudioState() override;
30
31 VoiceEngine* voice_engine();
aleloidd310712016-11-17 06:28:59 -080032
33 rtc::scoped_refptr<AudioMixer> mixer();
solenberg566ef242015-11-06 15:34:49 -080034 bool typing_noise_detected() const;
35
36 private:
37 // rtc::RefCountInterface implementation.
38 int AddRef() const override;
39 int Release() const override;
40
41 // webrtc::VoiceEngineObserver implementation.
42 void CallbackOnError(int channel_id, int err_code) override;
43
44 rtc::ThreadChecker thread_checker_;
45 rtc::ThreadChecker process_thread_checker_;
46 const webrtc::AudioState::Config config_;
47
48 // We hold one interface pointer to the VoE to make sure it is kept alive.
49 ScopedVoEInterface<VoEBase> voe_base_;
50
51 // The critical section isn't strictly needed in this case, but xSAN bots may
52 // trigger on unprotected cross-thread access.
pbos5ad935c2016-01-25 03:52:44 -080053 rtc::CriticalSection crit_sect_;
solenberg566ef242015-11-06 15:34:49 -080054 bool typing_noise_detected_ GUARDED_BY(crit_sect_) = false;
55
56 // Reference count; implementation copied from rtc::RefCountedObject.
57 mutable volatile int ref_count_ = 0;
58
aleloidd310712016-11-17 06:28:59 -080059 // Transports mixed audio from the mixer to the audio device and
60 // recorded audio to the VoE AudioTransport.
61 AudioTransportProxy audio_transport_proxy_;
62
solenberg566ef242015-11-06 15:34:49 -080063 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioState);
64};
65} // namespace internal
66} // namespace webrtc
67
68#endif // WEBRTC_AUDIO_AUDIO_STATE_H_