blob: afe53b3240328d941769858e345898cd7c123819 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_device/audio_device_buffer.h"
20#include "modules/audio_device/include/audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
henrikaba35d052015-07-14 17:04:08 +020022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24class AudioDeviceGeneric;
henrikab2619892015-05-18 16:49:16 +020025class AudioManager;
niklase@google.com470e71d2011-07-07 08:21:25 +000026
henrika5b6afc02018-09-05 14:34:40 +020027class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
henrikaba35d052015-07-14 17:04:08 +020028 public:
29 enum PlatformType {
30 kPlatformNotSupported = 0,
31 kPlatformWin32 = 1,
32 kPlatformWinCe = 2,
33 kPlatformLinux = 3,
34 kPlatformMac = 4,
35 kPlatformAndroid = 5,
36 kPlatformIOS = 6
37 };
niklase@google.com470e71d2011-07-07 08:21:25 +000038
henrikaba35d052015-07-14 17:04:08 +020039 int32_t CheckPlatform();
40 int32_t CreatePlatformSpecificObjects();
41 int32_t AttachAudioBuffer();
niklase@google.com470e71d2011-07-07 08:21:25 +000042
henrika5ff64832017-10-11 15:14:51 +020043 AudioDeviceModuleImpl(const AudioLayer audioLayer);
maxmorin88e31a32016-08-16 00:56:09 -070044 ~AudioDeviceModuleImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
henrikaba35d052015-07-14 17:04:08 +020046 // Retrieve the currently utilized audio layer
47 int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
henrikaba35d052015-07-14 17:04:08 +020049 // Full-duplex transportation of PCM audio
50 int32_t RegisterAudioCallback(AudioTransport* audioCallback) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
henrikaba35d052015-07-14 17:04:08 +020052 // Main initializaton and termination
53 int32_t Init() override;
54 int32_t Terminate() override;
55 bool Initialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
henrikaba35d052015-07-14 17:04:08 +020057 // Device enumeration
58 int16_t PlayoutDevices() override;
59 int16_t RecordingDevices() override;
60 int32_t PlayoutDeviceName(uint16_t index,
61 char name[kAdmMaxDeviceNameSize],
62 char guid[kAdmMaxGuidSize]) override;
63 int32_t RecordingDeviceName(uint16_t index,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000064 char name[kAdmMaxDeviceNameSize],
65 char guid[kAdmMaxGuidSize]) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000066
henrikaba35d052015-07-14 17:04:08 +020067 // Device selection
68 int32_t SetPlayoutDevice(uint16_t index) override;
69 int32_t SetPlayoutDevice(WindowsDeviceType device) override;
70 int32_t SetRecordingDevice(uint16_t index) override;
71 int32_t SetRecordingDevice(WindowsDeviceType device) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
henrikaba35d052015-07-14 17:04:08 +020073 // Audio transport initialization
74 int32_t PlayoutIsAvailable(bool* available) override;
75 int32_t InitPlayout() override;
76 bool PlayoutIsInitialized() const override;
77 int32_t RecordingIsAvailable(bool* available) override;
78 int32_t InitRecording() override;
79 bool RecordingIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
henrikaba35d052015-07-14 17:04:08 +020081 // Audio transport control
82 int32_t StartPlayout() override;
83 int32_t StopPlayout() override;
84 bool Playing() const override;
85 int32_t StartRecording() override;
86 int32_t StopRecording() override;
87 bool Recording() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
henrikaba35d052015-07-14 17:04:08 +020089 // Audio mixer initialization
90 int32_t InitSpeaker() override;
91 bool SpeakerIsInitialized() const override;
92 int32_t InitMicrophone() override;
93 bool MicrophoneIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
henrikaba35d052015-07-14 17:04:08 +020095 // Speaker volume controls
96 int32_t SpeakerVolumeIsAvailable(bool* available) override;
97 int32_t SetSpeakerVolume(uint32_t volume) override;
98 int32_t SpeakerVolume(uint32_t* volume) const override;
99 int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override;
100 int32_t MinSpeakerVolume(uint32_t* minVolume) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
henrikaba35d052015-07-14 17:04:08 +0200102 // Microphone volume controls
103 int32_t MicrophoneVolumeIsAvailable(bool* available) override;
104 int32_t SetMicrophoneVolume(uint32_t volume) override;
105 int32_t MicrophoneVolume(uint32_t* volume) const override;
106 int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override;
107 int32_t MinMicrophoneVolume(uint32_t* minVolume) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
henrikaba35d052015-07-14 17:04:08 +0200109 // Speaker mute control
110 int32_t SpeakerMuteIsAvailable(bool* available) override;
111 int32_t SetSpeakerMute(bool enable) override;
112 int32_t SpeakerMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
henrikaba35d052015-07-14 17:04:08 +0200114 // Microphone mute control
115 int32_t MicrophoneMuteIsAvailable(bool* available) override;
116 int32_t SetMicrophoneMute(bool enable) override;
117 int32_t MicrophoneMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
henrikaba35d052015-07-14 17:04:08 +0200119 // Stereo support
120 int32_t StereoPlayoutIsAvailable(bool* available) const override;
121 int32_t SetStereoPlayout(bool enable) override;
122 int32_t StereoPlayout(bool* enabled) const override;
123 int32_t StereoRecordingIsAvailable(bool* available) const override;
124 int32_t SetStereoRecording(bool enable) override;
125 int32_t StereoRecording(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
henrikaba35d052015-07-14 17:04:08 +0200127 // Delay information and control
henrikaba35d052015-07-14 17:04:08 +0200128 int32_t PlayoutDelay(uint16_t* delayMS) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
henrikac14f5ff2015-09-23 14:08:33 +0200130 bool BuiltInAECIsAvailable() const override;
131 int32_t EnableBuiltInAEC(bool enable) override;
132 bool BuiltInAGCIsAvailable() const override;
133 int32_t EnableBuiltInAGC(bool enable) override;
134 bool BuiltInNSIsAvailable() const override;
135 int32_t EnableBuiltInNS(bool enable) override;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000136
maxmorin88e31a32016-08-16 00:56:09 -0700137#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200138 int GetPlayoutAudioParameters(AudioParameters* params) const override;
139 int GetRecordAudioParameters(AudioParameters* params) const override;
maxmorin88e31a32016-08-16 00:56:09 -0700140#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200141
Tommi931e6582015-05-20 09:44:38 +0200142#if defined(WEBRTC_ANDROID)
henrikaba35d052015-07-14 17:04:08 +0200143 // Only use this acccessor for test purposes on Android.
144 AudioManager* GetAndroidAudioManagerForTest() {
henrika4af73662017-10-11 13:16:17 +0200145 return audio_manager_android_.get();
henrikaba35d052015-07-14 17:04:08 +0200146 }
henrika24e56e32015-05-19 11:48:51 +0200147#endif
henrika4af73662017-10-11 13:16:17 +0200148 AudioDeviceBuffer* GetAudioDeviceBuffer() { return &audio_device_buffer_; }
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000149
henrika5b6afc02018-09-05 14:34:40 +0200150 int RestartPlayoutInternally() override { return -1; }
151 int RestartRecordingInternally() override { return -1; }
152 int SetPlayoutSampleRate(uint32_t sample_rate) override { return -1; }
153 int SetRecordingSampleRate(uint32_t sample_rate) override { return -1; }
154
henrikaba35d052015-07-14 17:04:08 +0200155 private:
156 PlatformType Platform() const;
157 AudioLayer PlatformAudioLayer() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
henrika4af73662017-10-11 13:16:17 +0200159 AudioLayer audio_layer_;
160 PlatformType platform_type_ = kPlatformNotSupported;
161 bool initialized_ = false;
Tommi931e6582015-05-20 09:44:38 +0200162#if defined(WEBRTC_ANDROID)
henrika4af73662017-10-11 13:16:17 +0200163 // Should be declared first to ensure that it outlives other resources.
164 std::unique_ptr<AudioManager> audio_manager_android_;
henrikab2619892015-05-18 16:49:16 +0200165#endif
henrika4af73662017-10-11 13:16:17 +0200166 AudioDeviceBuffer audio_device_buffer_;
167 std::unique_ptr<AudioDeviceGeneric> audio_device_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168};
169
170} // namespace webrtc
171
Tommi931e6582015-05-20 09:44:38 +0200172#endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
173
henrika4af73662017-10-11 13:16:17 +0200174#endif // MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_