niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ |
| 12 | #define MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 14 | #if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 15 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 17 | |
kwiberg | f01633e | 2016-02-24 05:00:36 -0800 | [diff] [blame] | 18 | #include <memory> |
| 19 | |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 20 | #include "api/task_queue/task_queue_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_device/audio_device_buffer.h" |
| 22 | #include "modules/audio_device/include/audio_device.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 24 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
| 26 | class AudioDeviceGeneric; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 27 | class AudioManager; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
henrika | 5b6afc0 | 2018-09-05 14:34:40 +0200 | [diff] [blame] | 29 | class AudioDeviceModuleImpl : public AudioDeviceModuleForTest { |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 30 | public: |
| 31 | enum PlatformType { |
| 32 | kPlatformNotSupported = 0, |
| 33 | kPlatformWin32 = 1, |
| 34 | kPlatformWinCe = 2, |
| 35 | kPlatformLinux = 3, |
| 36 | kPlatformMac = 4, |
| 37 | kPlatformAndroid = 5, |
| 38 | kPlatformIOS = 6 |
| 39 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 41 | int32_t CheckPlatform(); |
| 42 | int32_t CreatePlatformSpecificObjects(); |
| 43 | int32_t AttachAudioBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 45 | AudioDeviceModuleImpl(AudioLayer audio_layer, |
| 46 | TaskQueueFactory* task_queue_factory); |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 47 | ~AudioDeviceModuleImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 49 | // Retrieve the currently utilized audio layer |
| 50 | int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 52 | // Full-duplex transportation of PCM audio |
| 53 | int32_t RegisterAudioCallback(AudioTransport* audioCallback) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 55 | // Main initializaton and termination |
| 56 | int32_t Init() override; |
| 57 | int32_t Terminate() override; |
| 58 | bool Initialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 60 | // Device enumeration |
| 61 | int16_t PlayoutDevices() override; |
| 62 | int16_t RecordingDevices() override; |
| 63 | int32_t PlayoutDeviceName(uint16_t index, |
| 64 | char name[kAdmMaxDeviceNameSize], |
| 65 | char guid[kAdmMaxGuidSize]) override; |
| 66 | int32_t RecordingDeviceName(uint16_t index, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 67 | char name[kAdmMaxDeviceNameSize], |
| 68 | char guid[kAdmMaxGuidSize]) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 70 | // Device selection |
| 71 | int32_t SetPlayoutDevice(uint16_t index) override; |
| 72 | int32_t SetPlayoutDevice(WindowsDeviceType device) override; |
| 73 | int32_t SetRecordingDevice(uint16_t index) override; |
| 74 | int32_t SetRecordingDevice(WindowsDeviceType device) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 76 | // Audio transport initialization |
| 77 | int32_t PlayoutIsAvailable(bool* available) override; |
| 78 | int32_t InitPlayout() override; |
| 79 | bool PlayoutIsInitialized() const override; |
| 80 | int32_t RecordingIsAvailable(bool* available) override; |
| 81 | int32_t InitRecording() override; |
| 82 | bool RecordingIsInitialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 84 | // Audio transport control |
| 85 | int32_t StartPlayout() override; |
| 86 | int32_t StopPlayout() override; |
| 87 | bool Playing() const override; |
| 88 | int32_t StartRecording() override; |
| 89 | int32_t StopRecording() override; |
| 90 | bool Recording() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 92 | // Audio mixer initialization |
| 93 | int32_t InitSpeaker() override; |
| 94 | bool SpeakerIsInitialized() const override; |
| 95 | int32_t InitMicrophone() override; |
| 96 | bool MicrophoneIsInitialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 98 | // Speaker volume controls |
| 99 | int32_t SpeakerVolumeIsAvailable(bool* available) override; |
| 100 | int32_t SetSpeakerVolume(uint32_t volume) override; |
| 101 | int32_t SpeakerVolume(uint32_t* volume) const override; |
| 102 | int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override; |
| 103 | int32_t MinSpeakerVolume(uint32_t* minVolume) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 105 | // Microphone volume controls |
| 106 | int32_t MicrophoneVolumeIsAvailable(bool* available) override; |
| 107 | int32_t SetMicrophoneVolume(uint32_t volume) override; |
| 108 | int32_t MicrophoneVolume(uint32_t* volume) const override; |
| 109 | int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override; |
| 110 | int32_t MinMicrophoneVolume(uint32_t* minVolume) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 112 | // Speaker mute control |
| 113 | int32_t SpeakerMuteIsAvailable(bool* available) override; |
| 114 | int32_t SetSpeakerMute(bool enable) override; |
| 115 | int32_t SpeakerMute(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 117 | // Microphone mute control |
| 118 | int32_t MicrophoneMuteIsAvailable(bool* available) override; |
| 119 | int32_t SetMicrophoneMute(bool enable) override; |
| 120 | int32_t MicrophoneMute(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 122 | // Stereo support |
| 123 | int32_t StereoPlayoutIsAvailable(bool* available) const override; |
| 124 | int32_t SetStereoPlayout(bool enable) override; |
| 125 | int32_t StereoPlayout(bool* enabled) const override; |
| 126 | int32_t StereoRecordingIsAvailable(bool* available) const override; |
| 127 | int32_t SetStereoRecording(bool enable) override; |
| 128 | int32_t StereoRecording(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 130 | // Delay information and control |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 131 | int32_t PlayoutDelay(uint16_t* delayMS) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 133 | bool BuiltInAECIsAvailable() const override; |
| 134 | int32_t EnableBuiltInAEC(bool enable) override; |
| 135 | bool BuiltInAGCIsAvailable() const override; |
| 136 | int32_t EnableBuiltInAGC(bool enable) override; |
| 137 | bool BuiltInNSIsAvailable() const override; |
| 138 | int32_t EnableBuiltInNS(bool enable) override; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 139 | |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 140 | #if defined(WEBRTC_IOS) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 141 | int GetPlayoutAudioParameters(AudioParameters* params) const override; |
| 142 | int GetRecordAudioParameters(AudioParameters* params) const override; |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 143 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 144 | |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 145 | #if defined(WEBRTC_ANDROID) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 146 | // Only use this acccessor for test purposes on Android. |
| 147 | AudioManager* GetAndroidAudioManagerForTest() { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 148 | return audio_manager_android_.get(); |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 149 | } |
henrika | 24e56e3 | 2015-05-19 11:48:51 +0200 | [diff] [blame] | 150 | #endif |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 151 | AudioDeviceBuffer* GetAudioDeviceBuffer() { return &audio_device_buffer_; } |
henrika@webrtc.org | 474d1eb | 2015-03-09 12:39:53 +0000 | [diff] [blame] | 152 | |
henrika | 5b6afc0 | 2018-09-05 14:34:40 +0200 | [diff] [blame] | 153 | int RestartPlayoutInternally() override { return -1; } |
| 154 | int RestartRecordingInternally() override { return -1; } |
| 155 | int SetPlayoutSampleRate(uint32_t sample_rate) override { return -1; } |
| 156 | int SetRecordingSampleRate(uint32_t sample_rate) override { return -1; } |
| 157 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 158 | private: |
| 159 | PlatformType Platform() const; |
| 160 | AudioLayer PlatformAudioLayer() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 162 | AudioLayer audio_layer_; |
| 163 | PlatformType platform_type_ = kPlatformNotSupported; |
| 164 | bool initialized_ = false; |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 165 | #if defined(WEBRTC_ANDROID) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 166 | // Should be declared first to ensure that it outlives other resources. |
| 167 | std::unique_ptr<AudioManager> audio_manager_android_; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 168 | #endif |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 169 | AudioDeviceBuffer audio_device_buffer_; |
| 170 | std::unique_ptr<AudioDeviceGeneric> audio_device_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | } // namespace webrtc |
| 174 | |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 175 | #endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 176 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 177 | #endif // MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ |