1717#ifndef SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_AUDIOENGINE_H_
1818#define SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_AUDIOENGINE_H_
1919
20+ #import < AVFAudio/AVFAudio.h>
21+
2022#include < atomic>
2123#include < memory>
2224
3133#include " sdk/objc/native/src/audio/audio_session_observer.h"
3234
3335RTC_FWD_DECL_OBJC_CLASS (RTC_OBJC_TYPE(RTCNativeAudioSessionDelegateAdapter));
34- RTC_FWD_DECL_OBJC_CLASS (AVAudioEngine);
35- RTC_FWD_DECL_OBJC_CLASS (AVAudioSourceNode);
36- RTC_FWD_DECL_OBJC_CLASS (AVAudioSinkNode);
37- RTC_FWD_DECL_OBJC_CLASS (AVAudioFormat);
38- RTC_FWD_DECL_OBJC_CLASS (AVAudioMixerNode);
39- RTC_FWD_DECL_OBJC_CLASS (AVAudioUnitEQ);
4036
4137namespace webrtc {
4238
4339class FineAudioBuffer;
4440
45- class AudioEngineDevice : public AudioDeviceGeneric ,
41+ class AudioEngineDevice : public AudioDeviceModule ,
4642 public AudioSessionObserver {
4743 public:
4844 explicit AudioEngineDevice (bool bypass_voice_processing);
4945 ~AudioEngineDevice () override;
5046
51- void AttachAudioBuffer (AudioDeviceBuffer* audioBuffer) override ;
52-
53- InitStatus Init () override ;
47+ int32_t Init () override;
5448 int32_t Terminate () override;
5549 bool Initialized () const override;
5650
@@ -68,16 +62,18 @@ class AudioEngineDevice : public AudioDeviceGeneric,
6862 int32_t StopRecording () override;
6963 bool Recording () const override;
7064
71- int32_t PlayoutDelay (uint16_t & delayMS) const override ;
65+ int32_t PlayoutDelay (uint16_t * delayMS) const override;
7266 int32_t GetPlayoutUnderrunCount () const override { return -1 ; }
7367
74- // int GetPlayoutAudioParameters(AudioParameters* params) const override;
75- // int GetRecordAudioParameters(AudioParameters* params) const override;
68+ #if defined(WEBRTC_IOS)
69+ int GetPlayoutAudioParameters (AudioParameters* params) const override;
70+ int GetRecordAudioParameters (AudioParameters* params) const override;
71+ #endif
7672
7773 int32_t ActiveAudioLayer (
78- AudioDeviceModule::AudioLayer& audioLayer) const override ;
79- int32_t PlayoutIsAvailable (bool & available) override ;
80- int32_t RecordingIsAvailable (bool & available) override ;
74+ AudioDeviceModule::AudioLayer* audioLayer) const override;
75+ int32_t PlayoutIsAvailable (bool * available) override;
76+ int32_t RecordingIsAvailable (bool * available) override;
8177 int16_t PlayoutDevices () override;
8278 int16_t RecordingDevices () override;
8379 int32_t PlayoutDeviceName (uint16_t index, char name[kAdmMaxDeviceNameSize ],
@@ -94,28 +90,40 @@ class AudioEngineDevice : public AudioDeviceGeneric,
9490 bool SpeakerIsInitialized () const override;
9591 int32_t InitMicrophone () override;
9692 bool MicrophoneIsInitialized () const override;
97- int32_t SpeakerVolumeIsAvailable (bool & available) override ;
93+ int32_t SpeakerVolumeIsAvailable (bool * available) override;
9894 int32_t SetSpeakerVolume (uint32_t volume) override;
99- int32_t SpeakerVolume (uint32_t & volume) const override ;
100- int32_t MaxSpeakerVolume (uint32_t & maxVolume) const override ;
101- int32_t MinSpeakerVolume (uint32_t & minVolume) const override ;
102- int32_t MicrophoneVolumeIsAvailable (bool & available) override ;
95+ int32_t SpeakerVolume (uint32_t * volume) const override;
96+ int32_t MaxSpeakerVolume (uint32_t * maxVolume) const override;
97+ int32_t MinSpeakerVolume (uint32_t * minVolume) const override;
98+ int32_t MicrophoneVolumeIsAvailable (bool * available) override;
10399 int32_t SetMicrophoneVolume (uint32_t volume) override;
104- int32_t MicrophoneVolume (uint32_t & volume) const override ;
105- int32_t MaxMicrophoneVolume (uint32_t & maxVolume) const override ;
106- int32_t MinMicrophoneVolume (uint32_t & minVolume) const override ;
107- int32_t MicrophoneMuteIsAvailable (bool & available) override ;
100+ int32_t MicrophoneVolume (uint32_t * volume) const override;
101+ int32_t MaxMicrophoneVolume (uint32_t * maxVolume) const override;
102+ int32_t MinMicrophoneVolume (uint32_t * minVolume) const override;
103+ int32_t MicrophoneMuteIsAvailable (bool * available) override;
108104 int32_t SetMicrophoneMute (bool enable) override;
109- int32_t MicrophoneMute (bool & enabled) const override ;
110- int32_t SpeakerMuteIsAvailable (bool & available) override ;
105+ int32_t MicrophoneMute (bool * enabled) const override;
106+ int32_t SpeakerMuteIsAvailable (bool * available) override;
111107 int32_t SetSpeakerMute (bool enable) override;
112- int32_t SpeakerMute (bool & enabled) const override ;
113- int32_t StereoPlayoutIsAvailable (bool & available) override ;
108+ int32_t SpeakerMute (bool * enabled) const override;
109+ int32_t StereoPlayoutIsAvailable (bool * available) const override;
114110 int32_t SetStereoPlayout (bool enable) override;
115- int32_t StereoPlayout (bool & enabled) const override ;
116- int32_t StereoRecordingIsAvailable (bool & available) override ;
111+ int32_t StereoPlayout (bool * enabled) const override;
112+ int32_t StereoRecordingIsAvailable (bool * available) const override;
117113 int32_t SetStereoRecording (bool enable) override;
118- int32_t StereoRecording (bool & enabled) const override ;
114+ int32_t StereoRecording (bool * enabled) const override;
115+
116+ int32_t RegisterAudioCallback (AudioTransport* audioCallback) override;
117+
118+ // Only supported on Android.
119+ bool BuiltInAECIsAvailable () const override;
120+ bool BuiltInAGCIsAvailable () const override;
121+ bool BuiltInNSIsAvailable () const override;
122+
123+ // Enables the built-in audio effects. Only supported on Android.
124+ int32_t EnableBuiltInAEC (bool enable) override;
125+ int32_t EnableBuiltInAGC (bool enable) override;
126+ int32_t EnableBuiltInNS (bool enable) override;
119127
120128 // AudioSessionObserver methods. May be called from any thread.
121129 void OnInterruptionBegin () override;
@@ -128,6 +136,17 @@ class AudioEngineDevice : public AudioDeviceGeneric,
128136
129137 int32_t SetObserver (AudioDeviceObserver* observer) override;
130138
139+ int32_t SetManualRenderingMode (bool enable);
140+ int32_t ManualRenderingMode (bool * enabled);
141+
142+ int32_t SetAdvancedDucking (bool enable);
143+ int32_t AdvancedDucking (bool * enabled);
144+
145+ int32_t SetDuckingLevel (long level);
146+ int32_t DuckingLevel (long * level);
147+
148+ int32_t InitAndStartRecording ();
149+
131150 private:
132151 struct EngineState {
133152 bool input_enabled = false ;
@@ -138,6 +157,11 @@ class AudioEngineDevice : public AudioDeviceGeneric,
138157 bool input_muted = false ;
139158 bool is_interrupted = false ;
140159
160+ bool is_manual_mode = false ;
161+ bool voice_processing = true ;
162+ bool advanced_ducking = true ;
163+ long ducking_level = 0 ; // 0 = Default
164+
141165 bool operator==(const EngineState& rhs) const ;
142166 bool operator!=(const EngineState& rhs) const ;
143167
@@ -150,40 +174,36 @@ class AudioEngineDevice : public AudioDeviceGeneric,
150174
151175 EngineState engine_state_ RTC_GUARDED_BY (thread_);
152176
177+ AVAudioInputNode* InputNode ();
178+ AVAudioOutputNode* OutputNode ();
179+
153180 bool IsMicrophonePermissionGranted ();
154181 void SetEngineState (std::function<EngineState (EngineState)> state_transform);
155182 void UpdateEngineState (EngineState old_state, EngineState new_state);
156183
157- // Configures the audio session for WebRTC.
158- bool ConfigureAudioSession ();
159-
160- // Like above, but requires caller to already hold session lock.
161- bool ConfigureAudioSessionLocked ();
162-
163- // Unconfigures the audio session.
164- void UnconfigureAudioSession ();
165-
166184 // AudioEngine observer methods. May be called from any thread.
167185 void OnEngineConfigurationChange ();
168186
169187 void DebugAudioEngine ();
170188
189+ void StartRenderLoop ();
190+ AVAudioEngineManualRenderingBlock render_block_;
191+
171192 // Determines whether voice processing should be enabled or disabled.
172193 const bool bypass_voice_processing_;
173194
174- // Native I/O audio thread checker.
175- SequenceChecker io_thread_checker_;
176-
177195 // Thread that this object is created on.
178196 rtc::Thread* thread_;
197+ std::unique_ptr<rtc::Thread> render_thread_;
198+ AVAudioPCMBuffer* render_buffer_;
179199
180- AudioDeviceBuffer* audio_device_buffer_;
200+ const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
201+ std::unique_ptr<AudioDeviceBuffer> audio_device_buffer_;
202+ std::unique_ptr<FineAudioBuffer> fine_audio_buffer_;
181203
182204 AudioParameters playout_parameters_;
183205 AudioParameters record_parameters_;
184206
185- std::unique_ptr<FineAudioBuffer> fine_audio_buffer_;
186-
187207 // Set to true after successful call to Init(), false otherwise.
188208 bool initialized_ RTC_GUARDED_BY (thread_);
189209
@@ -193,9 +213,6 @@ class AudioEngineDevice : public AudioDeviceGeneric,
193213 RTC_OBJC_TYPE (RTCNativeAudioSessionDelegateAdapter) * audio_session_observer_
194214 RTC_GUARDED_BY (thread_);
195215
196- // Set to true if we've activated the audio session.
197- bool has_configured_session_ RTC_GUARDED_BY (thread_);
198-
199216 // Avoids running pending task after `this` is Terminated.
200217 rtc::scoped_refptr<PendingTaskSafetyFlag> safety_ =
201218 PendingTaskSafetyFlag::Create ();
@@ -206,8 +223,7 @@ class AudioEngineDevice : public AudioDeviceGeneric,
206223
207224 // AVAudioEngine objects
208225 AVAudioEngine* audio_engine_;
209- AVAudioFormat* rtc_internal_format_; // Int16
210- AVAudioFormat* engine_internal_format_; // Float32
226+ AVAudioFormat* manual_render_rtc_format_; // Int16
211227
212228 // Output related
213229 AVAudioSourceNode* source_node_;
0 commit comments