blob: 864ab48833f520f9d22088b7717aa4f515009832 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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_DEVICE_AUDIO_DEVICE_IMPL_H_
12#define AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Tommi931e6582015-05-20 09:44:38 +020014#if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
15
kwibergf01633e2016-02-24 05:00:36 -080016#include <memory>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_device/audio_device_buffer.h"
19#include "modules/audio_device/include/audio_device.h"
20#include "rtc_base/checks.h"
21#include "rtc_base/criticalsection.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
henrikaba35d052015-07-14 17:04:08 +020023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25class AudioDeviceGeneric;
henrikab2619892015-05-18 16:49:16 +020026class AudioManager;
niklase@google.com470e71d2011-07-07 08:21:25 +000027
henrikaba35d052015-07-14 17:04:08 +020028class AudioDeviceModuleImpl : public AudioDeviceModule {
29 public:
30 enum PlatformType {
31 kPlatformNotSupported = 0,
32 kPlatformWin32 = 1,
33 kPlatformWinCe = 2,
34 kPlatformLinux = 3,
35 kPlatformMac = 4,
36 kPlatformAndroid = 5,
37 kPlatformIOS = 6
38 };
niklase@google.com470e71d2011-07-07 08:21:25 +000039
henrikaba35d052015-07-14 17:04:08 +020040 int32_t CheckPlatform();
41 int32_t CreatePlatformSpecificObjects();
42 int32_t AttachAudioBuffer();
niklase@google.com470e71d2011-07-07 08:21:25 +000043
henrikaba35d052015-07-14 17:04:08 +020044 AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer);
maxmorin88e31a32016-08-16 00:56:09 -070045 ~AudioDeviceModuleImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
henrikaba35d052015-07-14 17:04:08 +020047 // Retrieve the currently utilized audio layer
48 int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000049
henrikaba35d052015-07-14 17:04:08 +020050 // Error handling
51 ErrorCode LastError() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
henrikaba35d052015-07-14 17:04:08 +020053 // Full-duplex transportation of PCM audio
54 int32_t RegisterAudioCallback(AudioTransport* audioCallback) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
henrikaba35d052015-07-14 17:04:08 +020056 // Main initializaton and termination
57 int32_t Init() override;
58 int32_t Terminate() override;
59 bool Initialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
henrikaba35d052015-07-14 17:04:08 +020061 // Device enumeration
62 int16_t PlayoutDevices() override;
63 int16_t RecordingDevices() override;
64 int32_t PlayoutDeviceName(uint16_t index,
65 char name[kAdmMaxDeviceNameSize],
66 char guid[kAdmMaxGuidSize]) override;
67 int32_t RecordingDeviceName(uint16_t index,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000068 char name[kAdmMaxDeviceNameSize],
69 char guid[kAdmMaxGuidSize]) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
henrikaba35d052015-07-14 17:04:08 +020071 // Device selection
72 int32_t SetPlayoutDevice(uint16_t index) override;
73 int32_t SetPlayoutDevice(WindowsDeviceType device) override;
74 int32_t SetRecordingDevice(uint16_t index) override;
75 int32_t SetRecordingDevice(WindowsDeviceType device) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000076
henrikaba35d052015-07-14 17:04:08 +020077 // Audio transport initialization
78 int32_t PlayoutIsAvailable(bool* available) override;
79 int32_t InitPlayout() override;
80 bool PlayoutIsInitialized() const override;
81 int32_t RecordingIsAvailable(bool* available) override;
82 int32_t InitRecording() override;
83 bool RecordingIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
henrikaba35d052015-07-14 17:04:08 +020085 // Audio transport control
86 int32_t StartPlayout() override;
87 int32_t StopPlayout() override;
88 bool Playing() const override;
89 int32_t StartRecording() override;
90 int32_t StopRecording() override;
91 bool Recording() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000092
henrikaba35d052015-07-14 17:04:08 +020093 // Microphone Automatic Gain Control (AGC)
94 int32_t SetAGC(bool enable) override;
95 bool AGC() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000096
henrikaba35d052015-07-14 17:04:08 +020097 // Audio mixer initialization
98 int32_t InitSpeaker() override;
99 bool SpeakerIsInitialized() const override;
100 int32_t InitMicrophone() override;
101 bool MicrophoneIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
henrikaba35d052015-07-14 17:04:08 +0200103 // Speaker volume controls
104 int32_t SpeakerVolumeIsAvailable(bool* available) override;
105 int32_t SetSpeakerVolume(uint32_t volume) override;
106 int32_t SpeakerVolume(uint32_t* volume) const override;
107 int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override;
108 int32_t MinSpeakerVolume(uint32_t* minVolume) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
henrikaba35d052015-07-14 17:04:08 +0200110 // Microphone volume controls
111 int32_t MicrophoneVolumeIsAvailable(bool* available) override;
112 int32_t SetMicrophoneVolume(uint32_t volume) override;
113 int32_t MicrophoneVolume(uint32_t* volume) const override;
114 int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override;
115 int32_t MinMicrophoneVolume(uint32_t* minVolume) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
henrikaba35d052015-07-14 17:04:08 +0200117 // Speaker mute control
118 int32_t SpeakerMuteIsAvailable(bool* available) override;
119 int32_t SetSpeakerMute(bool enable) override;
120 int32_t SpeakerMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
henrikaba35d052015-07-14 17:04:08 +0200122 // Microphone mute control
123 int32_t MicrophoneMuteIsAvailable(bool* available) override;
124 int32_t SetMicrophoneMute(bool enable) override;
125 int32_t MicrophoneMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
henrikaba35d052015-07-14 17:04:08 +0200127 // Stereo support
128 int32_t StereoPlayoutIsAvailable(bool* available) const override;
129 int32_t SetStereoPlayout(bool enable) override;
130 int32_t StereoPlayout(bool* enabled) const override;
131 int32_t StereoRecordingIsAvailable(bool* available) const override;
132 int32_t SetStereoRecording(bool enable) override;
133 int32_t StereoRecording(bool* enabled) const override;
134 int32_t SetRecordingChannel(const ChannelType channel) override;
135 int32_t RecordingChannel(ChannelType* channel) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
henrikaba35d052015-07-14 17:04:08 +0200137 // Delay information and control
henrikaba35d052015-07-14 17:04:08 +0200138 int32_t PlayoutDelay(uint16_t* delayMS) const override;
139 int32_t RecordingDelay(uint16_t* delayMS) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
henrikaba35d052015-07-14 17:04:08 +0200141 // Native sample rate controls (samples/sec)
142 int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) override;
143 int32_t RecordingSampleRate(uint32_t* samplesPerSec) const override;
144 int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) override;
145 int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
henrikaba35d052015-07-14 17:04:08 +0200147 // Mobile device specific functions
henrikaba35d052015-07-14 17:04:08 +0200148 int32_t SetLoudspeakerStatus(bool enable) override;
149 int32_t GetLoudspeakerStatus(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
henrikac14f5ff2015-09-23 14:08:33 +0200151 bool BuiltInAECIsAvailable() const override;
152 int32_t EnableBuiltInAEC(bool enable) override;
153 bool BuiltInAGCIsAvailable() const override;
154 int32_t EnableBuiltInAGC(bool enable) override;
155 bool BuiltInNSIsAvailable() const override;
156 int32_t EnableBuiltInNS(bool enable) override;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000157
maxmorin88e31a32016-08-16 00:56:09 -0700158#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200159 int GetPlayoutAudioParameters(AudioParameters* params) const override;
160 int GetRecordAudioParameters(AudioParameters* params) const override;
maxmorin88e31a32016-08-16 00:56:09 -0700161#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200162
163 int32_t Id() { return _id; }
Tommi931e6582015-05-20 09:44:38 +0200164#if defined(WEBRTC_ANDROID)
henrikaba35d052015-07-14 17:04:08 +0200165 // Only use this acccessor for test purposes on Android.
166 AudioManager* GetAndroidAudioManagerForTest() {
167 return _audioManagerAndroid.get();
168 }
henrika24e56e32015-05-19 11:48:51 +0200169#endif
henrikaba35d052015-07-14 17:04:08 +0200170 AudioDeviceBuffer* GetAudioDeviceBuffer() { return &_audioDeviceBuffer; }
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000171
henrikaba35d052015-07-14 17:04:08 +0200172 private:
173 PlatformType Platform() const;
174 AudioLayer PlatformAudioLayer() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
kthelgason6bfe49c2017-03-30 01:14:41 -0700176 rtc::CriticalSection _critSect;
kthelgason6bfe49c2017-03-30 01:14:41 -0700177 rtc::CriticalSection _critSectAudioCb;
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
henrikaba35d052015-07-14 17:04:08 +0200179 AudioDeviceGeneric* _ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000180
henrikaba35d052015-07-14 17:04:08 +0200181 AudioDeviceBuffer _audioDeviceBuffer;
Tommi931e6582015-05-20 09:44:38 +0200182#if defined(WEBRTC_ANDROID)
kwibergf01633e2016-02-24 05:00:36 -0800183 std::unique_ptr<AudioManager> _audioManagerAndroid;
henrikab2619892015-05-18 16:49:16 +0200184#endif
henrikaba35d052015-07-14 17:04:08 +0200185 int32_t _id;
186 AudioLayer _platformAudioLayer;
henrikaba35d052015-07-14 17:04:08 +0200187 PlatformType _platformType;
188 bool _initialized;
189 mutable ErrorCode _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000190};
191
192} // namespace webrtc
193
Tommi931e6582015-05-20 09:44:38 +0200194#endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
195
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200196#endif // MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_