blob: 936ee6cb0473ddce3199b3b33c277f1eb73ce879 [file] [log] [blame]
Yves Gerey665174f2018-06-19 13:03:051/*
henrike@webrtc.org70efc322012-02-23 17:45:332 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:253 *
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:5511#ifndef MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_
12#define MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_
niklase@google.com470e71d2011-07-07 08:21:2513
Fredrik Hernqvistefbe7532023-01-13 15:42:3614#include "absl/types/optional.h"
Mirko Bonadeid9708072019-01-25 19:26:4815#include "api/scoped_refptr.h"
Danil Chapovalov1c41be62019-04-01 07:16:1216#include "api/task_queue/task_queue_factory.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "modules/audio_device/include/audio_device_defines.h"
Steve Anton10542f22019-01-11 17:11:0018#include "rtc_base/ref_count.h"
niklase@google.com470e71d2011-07-07 08:21:2519
20namespace webrtc {
21
henrika5b6afc02018-09-05 12:34:4022class AudioDeviceModuleForTest;
23
Fredrik Solenberga32dd012017-10-04 11:27:2124class AudioDeviceModule : public rtc::RefCountInterface {
henrika@google.com73d65512011-09-07 15:11:1825 public:
henrika@google.com73d65512011-09-07 15:11:1826 enum AudioLayer {
27 kPlatformDefaultAudio = 0,
henrikaec9c7452018-06-08 14:10:0328 kWindowsCoreAudio,
Anders Klemetseb8c4ca2019-12-06 02:41:3929 kWindowsCoreAudio2,
henrikaec9c7452018-06-08 14:10:0330 kLinuxAlsaAudio,
31 kLinuxPulseAudio,
32 kAndroidJavaAudio,
33 kAndroidOpenSLESAudio,
34 kAndroidJavaInputAndOpenSLESOutputAudio,
35 kAndroidAAudioAudio,
36 kAndroidJavaInputAndAAudioOutputAudio,
37 kDummyAudio,
henrika@google.com73d65512011-09-07 15:11:1838 };
niklase@google.com470e71d2011-07-07 08:21:2539
henrika@google.com73d65512011-09-07 15:11:1840 enum WindowsDeviceType {
41 kDefaultCommunicationDevice = -1,
42 kDefaultDevice = -2
43 };
niklase@google.com470e71d2011-07-07 08:21:2544
Fredrik Hernqvistefbe7532023-01-13 15:42:3645 struct Stats {
46 // The fields below correspond to similarly-named fields in the WebRTC stats
47 // spec. https://w3c.github.io/webrtc-stats/#playoutstats-dict*
48 double synthesized_samples_duration_s = 0;
49 uint64_t synthesized_samples_events = 0;
50 double total_samples_duration_s = 0;
51 double total_playout_delay_s = 0;
52 uint64_t total_samples_count = 0;
53 };
54
henrika@google.com73d65512011-09-07 15:11:1855 public:
henrika5b6afc02018-09-05 12:34:4056 // Creates a default ADM for usage in production code.
henrika616e3132017-11-13 11:47:5957 static rtc::scoped_refptr<AudioDeviceModule> Create(
Danil Chapovalov1c41be62019-04-01 07:16:1258 AudioLayer audio_layer,
59 TaskQueueFactory* task_queue_factory);
henrika5b6afc02018-09-05 12:34:4060 // Creates an ADM with support for extra test methods. Don't use this factory
61 // in production code.
62 static rtc::scoped_refptr<AudioDeviceModuleForTest> CreateForTest(
Danil Chapovalov1c41be62019-04-01 07:16:1263 AudioLayer audio_layer,
64 TaskQueueFactory* task_queue_factory);
Peter Boström4adbbcf2016-05-03 19:51:2665
henrika@google.com73d65512011-09-07 15:11:1866 // Retrieve the currently utilized audio layer
67 virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0;
niklase@google.com470e71d2011-07-07 08:21:2568
henrika@google.com73d65512011-09-07 15:11:1869 // Full-duplex transportation of PCM audio
70 virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) = 0;
niklase@google.com470e71d2011-07-07 08:21:2571
henrika@google.com73d65512011-09-07 15:11:1872 // Main initialization and termination
73 virtual int32_t Init() = 0;
74 virtual int32_t Terminate() = 0;
75 virtual bool Initialized() const = 0;
niklase@google.com470e71d2011-07-07 08:21:2576
henrika@google.com73d65512011-09-07 15:11:1877 // Device enumeration
78 virtual int16_t PlayoutDevices() = 0;
79 virtual int16_t RecordingDevices() = 0;
80 virtual int32_t PlayoutDeviceName(uint16_t index,
81 char name[kAdmMaxDeviceNameSize],
82 char guid[kAdmMaxGuidSize]) = 0;
83 virtual int32_t RecordingDeviceName(uint16_t index,
niklase@google.com470e71d2011-07-07 08:21:2584 char name[kAdmMaxDeviceNameSize],
85 char guid[kAdmMaxGuidSize]) = 0;
niklase@google.com470e71d2011-07-07 08:21:2586
henrika@google.com73d65512011-09-07 15:11:1887 // Device selection
88 virtual int32_t SetPlayoutDevice(uint16_t index) = 0;
89 virtual int32_t SetPlayoutDevice(WindowsDeviceType device) = 0;
90 virtual int32_t SetRecordingDevice(uint16_t index) = 0;
91 virtual int32_t SetRecordingDevice(WindowsDeviceType device) = 0;
niklase@google.com470e71d2011-07-07 08:21:2592
henrika@google.com73d65512011-09-07 15:11:1893 // Audio transport initialization
94 virtual int32_t PlayoutIsAvailable(bool* available) = 0;
95 virtual int32_t InitPlayout() = 0;
96 virtual bool PlayoutIsInitialized() const = 0;
97 virtual int32_t RecordingIsAvailable(bool* available) = 0;
98 virtual int32_t InitRecording() = 0;
99 virtual bool RecordingIsInitialized() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25100
henrika@google.com73d65512011-09-07 15:11:18101 // Audio transport control
102 virtual int32_t StartPlayout() = 0;
103 virtual int32_t StopPlayout() = 0;
104 virtual bool Playing() const = 0;
105 virtual int32_t StartRecording() = 0;
106 virtual int32_t StopRecording() = 0;
107 virtual bool Recording() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25108
henrika@google.com73d65512011-09-07 15:11:18109 // Audio mixer initialization
henrika@google.com73d65512011-09-07 15:11:18110 virtual int32_t InitSpeaker() = 0;
111 virtual bool SpeakerIsInitialized() const = 0;
henrika@google.com73d65512011-09-07 15:11:18112 virtual int32_t InitMicrophone() = 0;
113 virtual bool MicrophoneIsInitialized() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25114
henrika@google.com73d65512011-09-07 15:11:18115 // Speaker volume controls
116 virtual int32_t SpeakerVolumeIsAvailable(bool* available) = 0;
117 virtual int32_t SetSpeakerVolume(uint32_t volume) = 0;
118 virtual int32_t SpeakerVolume(uint32_t* volume) const = 0;
119 virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const = 0;
120 virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25121
henrika@google.com73d65512011-09-07 15:11:18122 // Microphone volume controls
123 virtual int32_t MicrophoneVolumeIsAvailable(bool* available) = 0;
124 virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0;
125 virtual int32_t MicrophoneVolume(uint32_t* volume) const = 0;
126 virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const = 0;
127 virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25128
henrika@google.com73d65512011-09-07 15:11:18129 // Speaker mute control
130 virtual int32_t SpeakerMuteIsAvailable(bool* available) = 0;
131 virtual int32_t SetSpeakerMute(bool enable) = 0;
132 virtual int32_t SpeakerMute(bool* enabled) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25133
henrika@google.com73d65512011-09-07 15:11:18134 // Microphone mute control
135 virtual int32_t MicrophoneMuteIsAvailable(bool* available) = 0;
136 virtual int32_t SetMicrophoneMute(bool enable) = 0;
137 virtual int32_t MicrophoneMute(bool* enabled) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25138
henrika@google.com73d65512011-09-07 15:11:18139 // Stereo support
140 virtual int32_t StereoPlayoutIsAvailable(bool* available) const = 0;
141 virtual int32_t SetStereoPlayout(bool enable) = 0;
142 virtual int32_t StereoPlayout(bool* enabled) const = 0;
143 virtual int32_t StereoRecordingIsAvailable(bool* available) const = 0;
144 virtual int32_t SetStereoRecording(bool enable) = 0;
145 virtual int32_t StereoRecording(bool* enabled) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25146
henrika6592f2c2017-10-17 12:47:44147 // Playout delay
henrika@google.com73d65512011-09-07 15:11:18148 virtual int32_t PlayoutDelay(uint16_t* delayMS) const = 0;
henrika6592f2c2017-10-17 12:47:44149
henrika@webrtc.orga954c072014-12-09 16:22:09150 // Only supported on Android.
maxmorin88e31a32016-08-16 07:56:09151 virtual bool BuiltInAECIsAvailable() const = 0;
152 virtual bool BuiltInAGCIsAvailable() const = 0;
153 virtual bool BuiltInNSIsAvailable() const = 0;
henrika@webrtc.orga954c072014-12-09 16:22:09154
henrikac14f5ff2015-09-23 12:08:33155 // Enables the built-in audio effects. Only supported on Android.
maxmorin88e31a32016-08-16 07:56:09156 virtual int32_t EnableBuiltInAEC(bool enable) = 0;
157 virtual int32_t EnableBuiltInAGC(bool enable) = 0;
158 virtual int32_t EnableBuiltInNS(bool enable) = 0;
andrew@webrtc.orga3c6d612011-09-13 17:17:49159
Alex Narestbbeb1092019-08-16 09:49:04160 // Play underrun count. Only supported on Android.
161 // TODO(alexnarest): Make it abstract after upstream projects support it.
162 virtual int32_t GetPlayoutUnderrunCount() const { return -1; }
163
Fredrik Hernqvistefbe7532023-01-13 15:42:36164 // Used to generate RTC stats. If not implemented, RTCAudioPlayoutStats will
165 // not be present in the stats.
166 virtual absl::optional<Stats> GetStats() const { return absl::nullopt; }
167
maxmorin88e31a32016-08-16 07:56:09168// Only supported on iOS.
169#if defined(WEBRTC_IOS)
170 virtual int GetPlayoutAudioParameters(AudioParameters* params) const = 0;
171 virtual int GetRecordAudioParameters(AudioParameters* params) const = 0;
172#endif // WEBRTC_IOS
henrikaba35d052015-07-14 15:04:08173
henrika@google.com73d65512011-09-07 15:11:18174 protected:
maxmorin88e31a32016-08-16 07:56:09175 ~AudioDeviceModule() override {}
niklase@google.com470e71d2011-07-07 08:21:25176};
177
henrika5b6afc02018-09-05 12:34:40178// Extends the default ADM interface with some extra test methods.
179// Intended for usage in tests only and requires a unique factory method.
180class AudioDeviceModuleForTest : public AudioDeviceModule {
181 public:
182 // Triggers internal restart sequences of audio streaming. Can be used by
183 // tests to emulate events corresponding to e.g. removal of an active audio
184 // device or other actions which causes the stream to be disconnected.
185 virtual int RestartPlayoutInternally() = 0;
186 virtual int RestartRecordingInternally() = 0;
187
188 virtual int SetPlayoutSampleRate(uint32_t sample_rate) = 0;
189 virtual int SetRecordingSampleRate(uint32_t sample_rate) = 0;
190};
191
niklase@google.com470e71d2011-07-07 08:21:25192} // namespace webrtc
193
xians@webrtc.org597b4472012-10-11 15:41:55194#endif // MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_