1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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 
11 #ifndef SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_MODULE_IOS_H_
12 #define SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_MODULE_IOS_H_
13 
14 #include <memory>
15 
16 #include "audio_device_ios.h"
17 
18 #include "api/task_queue/task_queue_factory.h"
19 #include "modules/audio_device/audio_device_buffer.h"
20 #include "modules/audio_device/include/audio_device.h"
21 #include "rtc_base/checks.h"
22 
23 namespace webrtc {
24 
25 class AudioDeviceGeneric;
26 
27 namespace ios_adm {
28 
29 class AudioDeviceModuleIOS : public AudioDeviceModule {
30  public:
31   int32_t AttachAudioBuffer();
32 
33   AudioDeviceModuleIOS();
34   ~AudioDeviceModuleIOS() override;
35 
36   // Retrieve the currently utilized audio layer
37   int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override;
38 
39   // Full-duplex transportation of PCM audio
40   int32_t RegisterAudioCallback(AudioTransport* audioCallback) override;
41 
42   // Main initializaton and termination
43   int32_t Init() override;
44   int32_t Terminate() override;
45   bool Initialized() const override;
46 
47   // Device enumeration
48   int16_t PlayoutDevices() override;
49   int16_t RecordingDevices() override;
50   int32_t PlayoutDeviceName(uint16_t index,
51                             char name[kAdmMaxDeviceNameSize],
52                             char guid[kAdmMaxGuidSize]) override;
53   int32_t RecordingDeviceName(uint16_t index,
54                               char name[kAdmMaxDeviceNameSize],
55                               char guid[kAdmMaxGuidSize]) override;
56 
57   // Device selection
58   int32_t SetPlayoutDevice(uint16_t index) override;
59   int32_t SetPlayoutDevice(WindowsDeviceType device) override;
60   int32_t SetRecordingDevice(uint16_t index) override;
61   int32_t SetRecordingDevice(WindowsDeviceType device) override;
62 
63   // Audio transport initialization
64   int32_t PlayoutIsAvailable(bool* available) override;
65   int32_t InitPlayout() override;
66   bool PlayoutIsInitialized() const override;
67   int32_t RecordingIsAvailable(bool* available) override;
68   int32_t InitRecording() override;
69   bool RecordingIsInitialized() const override;
70 
71   // Audio transport control
72   int32_t StartPlayout() override;
73   int32_t StopPlayout() override;
74   bool Playing() const override;
75   int32_t StartRecording() override;
76   int32_t StopRecording() override;
77   bool Recording() const override;
78 
79   // Audio mixer initialization
80   int32_t InitSpeaker() override;
81   bool SpeakerIsInitialized() const override;
82   int32_t InitMicrophone() override;
83   bool MicrophoneIsInitialized() const override;
84 
85   // Speaker volume controls
86   int32_t SpeakerVolumeIsAvailable(bool* available) override;
87   int32_t SetSpeakerVolume(uint32_t volume) override;
88   int32_t SpeakerVolume(uint32_t* volume) const override;
89   int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override;
90   int32_t MinSpeakerVolume(uint32_t* minVolume) const override;
91 
92   // Microphone volume controls
93   int32_t MicrophoneVolumeIsAvailable(bool* available) override;
94   int32_t SetMicrophoneVolume(uint32_t volume) override;
95   int32_t MicrophoneVolume(uint32_t* volume) const override;
96   int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override;
97   int32_t MinMicrophoneVolume(uint32_t* minVolume) const override;
98 
99   // Speaker mute control
100   int32_t SpeakerMuteIsAvailable(bool* available) override;
101   int32_t SetSpeakerMute(bool enable) override;
102   int32_t SpeakerMute(bool* enabled) const override;
103 
104   // Microphone mute control
105   int32_t MicrophoneMuteIsAvailable(bool* available) override;
106   int32_t SetMicrophoneMute(bool enable) override;
107   int32_t MicrophoneMute(bool* enabled) const override;
108 
109   // Stereo support
110   int32_t StereoPlayoutIsAvailable(bool* available) const override;
111   int32_t SetStereoPlayout(bool enable) override;
112   int32_t StereoPlayout(bool* enabled) const override;
113   int32_t StereoRecordingIsAvailable(bool* available) const override;
114   int32_t SetStereoRecording(bool enable) override;
115   int32_t StereoRecording(bool* enabled) const override;
116 
117   // Delay information and control
118   int32_t PlayoutDelay(uint16_t* delayMS) const override;
119 
120   bool BuiltInAECIsAvailable() const override;
121   int32_t EnableBuiltInAEC(bool enable) override;
122   bool BuiltInAGCIsAvailable() const override;
123   int32_t EnableBuiltInAGC(bool enable) override;
124   bool BuiltInNSIsAvailable() const override;
125   int32_t EnableBuiltInNS(bool enable) override;
126 
127   int32_t GetPlayoutUnderrunCount() const override;
128 
129 #if defined(WEBRTC_IOS)
130   int GetPlayoutAudioParameters(AudioParameters* params) const override;
131   int GetRecordAudioParameters(AudioParameters* params) const override;
132 #endif  // WEBRTC_IOS
133  private:
134   bool initialized_ = false;
135   const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
136   std::unique_ptr<AudioDeviceIOS> audio_device_;
137   std::unique_ptr<AudioDeviceBuffer> audio_device_buffer_;
138 };
139 }  // namespace ios_adm
140 }  // namespace webrtc
141 
142 #endif  // SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_MODULE_IOS_H_
143