blob: b378f9ffce17bf7f9cb5df1f00ef59980d52e5f7 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
henrike@webrtc.org70efc322012-02-23 17:45:33 +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
xians@webrtc.org597b4472012-10-11 15:41:55 +000011#ifndef MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_
12#define MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/audio_device/include/audio_device_defines.h"
15#include "modules/include/module.h"
16#include "rtc_base/scoped_ref_ptr.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
19
henrika@google.com73d65512011-09-07 15:11:18 +000020class AudioDeviceModule : public RefCountedModule {
21 public:
22 enum ErrorCode {
23 kAdmErrNone = 0,
24 kAdmErrArgument = 1
25 };
niklase@google.com470e71d2011-07-07 08:21:25 +000026
henrika@google.com73d65512011-09-07 15:11:18 +000027 enum AudioLayer {
28 kPlatformDefaultAudio = 0,
henrika@google.com73d65512011-09-07 15:11:18 +000029 kWindowsCoreAudio = 2,
30 kLinuxAlsaAudio = 3,
31 kLinuxPulseAudio = 4,
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +000032 kAndroidJavaAudio = 5,
henrika521f7a82016-05-31 07:03:17 -070033 kAndroidOpenSLESAudio = 6,
34 kAndroidJavaInputAndOpenSLESOutputAudio = 7,
henrikab2619892015-05-18 16:49:16 +020035 kDummyAudio = 8
henrika@google.com73d65512011-09-07 15:11:18 +000036 };
niklase@google.com470e71d2011-07-07 08:21:25 +000037
henrika@google.com73d65512011-09-07 15:11:18 +000038 enum WindowsDeviceType {
39 kDefaultCommunicationDevice = -1,
40 kDefaultDevice = -2
41 };
niklase@google.com470e71d2011-07-07 08:21:25 +000042
henrika@google.com73d65512011-09-07 15:11:18 +000043 enum ChannelType {
44 kChannelLeft = 0,
45 kChannelRight = 1,
46 kChannelBoth = 2
47 };
niklase@google.com470e71d2011-07-07 08:21:25 +000048
henrika@google.com73d65512011-09-07 15:11:18 +000049 public:
Peter Boström4adbbcf2016-05-03 15:51:26 -040050 // Create an ADM.
51 static rtc::scoped_refptr<AudioDeviceModule> Create(
52 const int32_t id,
53 const AudioLayer audio_layer);
54
solenbergdf5bb652017-09-27 10:58:59 -070055 // TODO(solenberg): Remove temporary implementation of Module interface.
56 int64_t TimeUntilNextProcess() override {
57 // Make sure Process() isn't called very often.
58 return 1000000;
59 }
60 void Process() override {}
61
henrika@google.com73d65512011-09-07 15:11:18 +000062 // Retrieve the currently utilized audio layer
63 virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
henrika@google.com73d65512011-09-07 15:11:18 +000065 // Error handling
66 virtual ErrorCode LastError() const = 0;
solenbergdf5bb652017-09-27 10:58:59 -070067 virtual int32_t RegisterEventObserver(AudioDeviceObserver* eventCallback) {
68 return 0;
69 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070
henrika@google.com73d65512011-09-07 15:11:18 +000071 // Full-duplex transportation of PCM audio
72 virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000073
henrika@google.com73d65512011-09-07 15:11:18 +000074 // Main initialization and termination
75 virtual int32_t Init() = 0;
76 virtual int32_t Terminate() = 0;
77 virtual bool Initialized() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
henrika@google.com73d65512011-09-07 15:11:18 +000079 // Device enumeration
80 virtual int16_t PlayoutDevices() = 0;
81 virtual int16_t RecordingDevices() = 0;
82 virtual int32_t PlayoutDeviceName(uint16_t index,
83 char name[kAdmMaxDeviceNameSize],
84 char guid[kAdmMaxGuidSize]) = 0;
85 virtual int32_t RecordingDeviceName(uint16_t index,
niklase@google.com470e71d2011-07-07 08:21:25 +000086 char name[kAdmMaxDeviceNameSize],
87 char guid[kAdmMaxGuidSize]) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
henrika@google.com73d65512011-09-07 15:11:18 +000089 // Device selection
90 virtual int32_t SetPlayoutDevice(uint16_t index) = 0;
91 virtual int32_t SetPlayoutDevice(WindowsDeviceType device) = 0;
92 virtual int32_t SetRecordingDevice(uint16_t index) = 0;
93 virtual int32_t SetRecordingDevice(WindowsDeviceType device) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
henrika@google.com73d65512011-09-07 15:11:18 +000095 // Audio transport initialization
96 virtual int32_t PlayoutIsAvailable(bool* available) = 0;
97 virtual int32_t InitPlayout() = 0;
98 virtual bool PlayoutIsInitialized() const = 0;
99 virtual int32_t RecordingIsAvailable(bool* available) = 0;
100 virtual int32_t InitRecording() = 0;
101 virtual bool RecordingIsInitialized() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
henrika@google.com73d65512011-09-07 15:11:18 +0000103 // Audio transport control
104 virtual int32_t StartPlayout() = 0;
105 virtual int32_t StopPlayout() = 0;
106 virtual bool Playing() const = 0;
107 virtual int32_t StartRecording() = 0;
108 virtual int32_t StopRecording() = 0;
109 virtual bool Recording() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
henrika@google.com73d65512011-09-07 15:11:18 +0000111 // Microphone Automatic Gain Control (AGC)
112 virtual int32_t SetAGC(bool enable) = 0;
113 virtual bool AGC() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
henrika@google.com73d65512011-09-07 15:11:18 +0000115 // Audio mixer initialization
henrika@google.com73d65512011-09-07 15:11:18 +0000116 virtual int32_t InitSpeaker() = 0;
117 virtual bool SpeakerIsInitialized() const = 0;
henrika@google.com73d65512011-09-07 15:11:18 +0000118 virtual int32_t InitMicrophone() = 0;
119 virtual bool MicrophoneIsInitialized() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
henrika@google.com73d65512011-09-07 15:11:18 +0000121 // Speaker volume controls
122 virtual int32_t SpeakerVolumeIsAvailable(bool* available) = 0;
123 virtual int32_t SetSpeakerVolume(uint32_t volume) = 0;
124 virtual int32_t SpeakerVolume(uint32_t* volume) const = 0;
125 virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const = 0;
126 virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
henrika@google.com73d65512011-09-07 15:11:18 +0000128 // Microphone volume controls
129 virtual int32_t MicrophoneVolumeIsAvailable(bool* available) = 0;
130 virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0;
131 virtual int32_t MicrophoneVolume(uint32_t* volume) const = 0;
132 virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const = 0;
133 virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
henrika@google.com73d65512011-09-07 15:11:18 +0000135 // Speaker mute control
136 virtual int32_t SpeakerMuteIsAvailable(bool* available) = 0;
137 virtual int32_t SetSpeakerMute(bool enable) = 0;
138 virtual int32_t SpeakerMute(bool* enabled) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
henrika@google.com73d65512011-09-07 15:11:18 +0000140 // Microphone mute control
141 virtual int32_t MicrophoneMuteIsAvailable(bool* available) = 0;
142 virtual int32_t SetMicrophoneMute(bool enable) = 0;
143 virtual int32_t MicrophoneMute(bool* enabled) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
henrika@google.com73d65512011-09-07 15:11:18 +0000145 // Stereo support
146 virtual int32_t StereoPlayoutIsAvailable(bool* available) const = 0;
147 virtual int32_t SetStereoPlayout(bool enable) = 0;
148 virtual int32_t StereoPlayout(bool* enabled) const = 0;
149 virtual int32_t StereoRecordingIsAvailable(bool* available) const = 0;
150 virtual int32_t SetStereoRecording(bool enable) = 0;
151 virtual int32_t StereoRecording(bool* enabled) const = 0;
152 virtual int32_t SetRecordingChannel(const ChannelType channel) = 0;
153 virtual int32_t RecordingChannel(ChannelType* channel) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
henrika98680422017-08-31 06:47:32 -0700155 // Delay information and control
henrika@google.com73d65512011-09-07 15:11:18 +0000156 virtual int32_t PlayoutDelay(uint16_t* delayMS) const = 0;
157 virtual int32_t RecordingDelay(uint16_t* delayMS) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
henrika@google.com73d65512011-09-07 15:11:18 +0000159 // Native sample rate controls (samples/sec)
160 virtual int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) = 0;
161 virtual int32_t RecordingSampleRate(uint32_t* samplesPerSec) const = 0;
162 virtual int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) = 0;
163 virtual int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000164
henrika@google.com73d65512011-09-07 15:11:18 +0000165 // Mobile device specific functions
henrika@google.com73d65512011-09-07 15:11:18 +0000166 virtual int32_t SetLoudspeakerStatus(bool enable) = 0;
167 virtual int32_t GetLoudspeakerStatus(bool* enabled) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000169 // Only supported on Android.
maxmorin88e31a32016-08-16 00:56:09 -0700170 virtual bool BuiltInAECIsAvailable() const = 0;
171 virtual bool BuiltInAGCIsAvailable() const = 0;
172 virtual bool BuiltInNSIsAvailable() const = 0;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000173
henrikac14f5ff2015-09-23 14:08:33 +0200174 // Enables the built-in audio effects. Only supported on Android.
maxmorin88e31a32016-08-16 00:56:09 -0700175 virtual int32_t EnableBuiltInAEC(bool enable) = 0;
176 virtual int32_t EnableBuiltInAGC(bool enable) = 0;
177 virtual int32_t EnableBuiltInNS(bool enable) = 0;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000178
maxmorin88e31a32016-08-16 00:56:09 -0700179// Only supported on iOS.
180#if defined(WEBRTC_IOS)
181 virtual int GetPlayoutAudioParameters(AudioParameters* params) const = 0;
182 virtual int GetRecordAudioParameters(AudioParameters* params) const = 0;
183#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200184
henrika@google.com73d65512011-09-07 15:11:18 +0000185 protected:
maxmorin88e31a32016-08-16 00:56:09 -0700186 ~AudioDeviceModule() override {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000187};
188
189} // namespace webrtc
190
xians@webrtc.org597b4472012-10-11 15:41:55 +0000191#endif // MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_