blob: efe9322576b4e619401c671d888bca5ec58ef2d5 [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
henrika4af73662017-10-11 13:16:17 +020011#ifndef MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_
12#define MODULES_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
Yves Gerey988cc082018-10-23 12:03:01 +020016#include <stdint.h>
kwibergf01633e2016-02-24 05:00:36 -080017#include <memory>
18
Danil Chapovalov1c41be62019-04-01 09:16:12 +020019#include "api/task_queue/task_queue_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_device/audio_device_buffer.h"
21#include "modules/audio_device/include/audio_device.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
henrika5b6afc02018-09-05 14:34:40 +020028class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
henrikaba35d052015-07-14 17:04:08 +020029 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
Danil Chapovalov1c41be62019-04-01 09:16:12 +020044 AudioDeviceModuleImpl(AudioLayer audio_layer,
45 TaskQueueFactory* task_queue_factory);
maxmorin88e31a32016-08-16 00:56:09 -070046 ~AudioDeviceModuleImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000047
henrikaba35d052015-07-14 17:04:08 +020048 // Retrieve the currently utilized audio layer
49 int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
henrikaba35d052015-07-14 17:04:08 +020051 // Full-duplex transportation of PCM audio
52 int32_t RegisterAudioCallback(AudioTransport* audioCallback) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
henrikaba35d052015-07-14 17:04:08 +020054 // Main initializaton and termination
55 int32_t Init() override;
56 int32_t Terminate() override;
57 bool Initialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
henrikaba35d052015-07-14 17:04:08 +020059 // Device enumeration
60 int16_t PlayoutDevices() override;
61 int16_t RecordingDevices() override;
62 int32_t PlayoutDeviceName(uint16_t index,
63 char name[kAdmMaxDeviceNameSize],
64 char guid[kAdmMaxGuidSize]) override;
65 int32_t RecordingDeviceName(uint16_t index,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000066 char name[kAdmMaxDeviceNameSize],
67 char guid[kAdmMaxGuidSize]) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
henrikaba35d052015-07-14 17:04:08 +020069 // Device selection
70 int32_t SetPlayoutDevice(uint16_t index) override;
71 int32_t SetPlayoutDevice(WindowsDeviceType device) override;
72 int32_t SetRecordingDevice(uint16_t index) override;
73 int32_t SetRecordingDevice(WindowsDeviceType device) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000074
henrikaba35d052015-07-14 17:04:08 +020075 // Audio transport initialization
76 int32_t PlayoutIsAvailable(bool* available) override;
77 int32_t InitPlayout() override;
78 bool PlayoutIsInitialized() const override;
79 int32_t RecordingIsAvailable(bool* available) override;
80 int32_t InitRecording() override;
81 bool RecordingIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000082
henrikaba35d052015-07-14 17:04:08 +020083 // Audio transport control
84 int32_t StartPlayout() override;
85 int32_t StopPlayout() override;
86 bool Playing() const override;
87 int32_t StartRecording() override;
88 int32_t StopRecording() override;
89 bool Recording() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000090
henrikaba35d052015-07-14 17:04:08 +020091 // Audio mixer initialization
92 int32_t InitSpeaker() override;
93 bool SpeakerIsInitialized() const override;
94 int32_t InitMicrophone() override;
95 bool MicrophoneIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000096
henrikaba35d052015-07-14 17:04:08 +020097 // Speaker volume controls
98 int32_t SpeakerVolumeIsAvailable(bool* available) override;
99 int32_t SetSpeakerVolume(uint32_t volume) override;
100 int32_t SpeakerVolume(uint32_t* volume) const override;
101 int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override;
102 int32_t MinSpeakerVolume(uint32_t* minVolume) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
henrikaba35d052015-07-14 17:04:08 +0200104 // Microphone volume controls
105 int32_t MicrophoneVolumeIsAvailable(bool* available) override;
106 int32_t SetMicrophoneVolume(uint32_t volume) override;
107 int32_t MicrophoneVolume(uint32_t* volume) const override;
108 int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override;
109 int32_t MinMicrophoneVolume(uint32_t* minVolume) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
henrikaba35d052015-07-14 17:04:08 +0200111 // Speaker mute control
112 int32_t SpeakerMuteIsAvailable(bool* available) override;
113 int32_t SetSpeakerMute(bool enable) override;
114 int32_t SpeakerMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
henrikaba35d052015-07-14 17:04:08 +0200116 // Microphone mute control
117 int32_t MicrophoneMuteIsAvailable(bool* available) override;
118 int32_t SetMicrophoneMute(bool enable) override;
119 int32_t MicrophoneMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
henrikaba35d052015-07-14 17:04:08 +0200121 // Stereo support
122 int32_t StereoPlayoutIsAvailable(bool* available) const override;
123 int32_t SetStereoPlayout(bool enable) override;
124 int32_t StereoPlayout(bool* enabled) const override;
125 int32_t StereoRecordingIsAvailable(bool* available) const override;
126 int32_t SetStereoRecording(bool enable) override;
127 int32_t StereoRecording(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
henrikaba35d052015-07-14 17:04:08 +0200129 // Delay information and control
henrikaba35d052015-07-14 17:04:08 +0200130 int32_t PlayoutDelay(uint16_t* delayMS) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
henrikac14f5ff2015-09-23 14:08:33 +0200132 bool BuiltInAECIsAvailable() const override;
133 int32_t EnableBuiltInAEC(bool enable) override;
134 bool BuiltInAGCIsAvailable() const override;
135 int32_t EnableBuiltInAGC(bool enable) override;
136 bool BuiltInNSIsAvailable() const override;
137 int32_t EnableBuiltInNS(bool enable) override;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000138
maxmorin88e31a32016-08-16 00:56:09 -0700139#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200140 int GetPlayoutAudioParameters(AudioParameters* params) const override;
141 int GetRecordAudioParameters(AudioParameters* params) const override;
maxmorin88e31a32016-08-16 00:56:09 -0700142#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200143
Tommi931e6582015-05-20 09:44:38 +0200144#if defined(WEBRTC_ANDROID)
henrikaba35d052015-07-14 17:04:08 +0200145 // Only use this acccessor for test purposes on Android.
146 AudioManager* GetAndroidAudioManagerForTest() {
henrika4af73662017-10-11 13:16:17 +0200147 return audio_manager_android_.get();
henrikaba35d052015-07-14 17:04:08 +0200148 }
henrika24e56e32015-05-19 11:48:51 +0200149#endif
henrika4af73662017-10-11 13:16:17 +0200150 AudioDeviceBuffer* GetAudioDeviceBuffer() { return &audio_device_buffer_; }
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000151
henrika5b6afc02018-09-05 14:34:40 +0200152 int RestartPlayoutInternally() override { return -1; }
153 int RestartRecordingInternally() override { return -1; }
154 int SetPlayoutSampleRate(uint32_t sample_rate) override { return -1; }
155 int SetRecordingSampleRate(uint32_t sample_rate) override { return -1; }
156
henrikaba35d052015-07-14 17:04:08 +0200157 private:
158 PlatformType Platform() const;
159 AudioLayer PlatformAudioLayer() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000160
henrika4af73662017-10-11 13:16:17 +0200161 AudioLayer audio_layer_;
162 PlatformType platform_type_ = kPlatformNotSupported;
163 bool initialized_ = false;
Tommi931e6582015-05-20 09:44:38 +0200164#if defined(WEBRTC_ANDROID)
henrika4af73662017-10-11 13:16:17 +0200165 // Should be declared first to ensure that it outlives other resources.
166 std::unique_ptr<AudioManager> audio_manager_android_;
henrikab2619892015-05-18 16:49:16 +0200167#endif
henrika4af73662017-10-11 13:16:17 +0200168 AudioDeviceBuffer audio_device_buffer_;
169 std::unique_ptr<AudioDeviceGeneric> audio_device_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000170};
171
172} // namespace webrtc
173
Tommi931e6582015-05-20 09:44:38 +0200174#endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
175
henrika4af73662017-10-11 13:16:17 +0200176#endif // MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_